diff --git a/message_and_subject.go b/message_and_subject.go index 58a5a2c..c9ed378 100644 --- a/message_and_subject.go +++ b/message_and_subject.go @@ -9,6 +9,7 @@ import ( // --- Message type Message struct { + _ struct{} `cbor:",toarray"` // The node to send the message to. ToNode Node `json:"toNode" yaml:"toNode"` // ToNodes to specify several hosts to send message to in the diff --git a/process.go b/process.go index 2f60557..407c8c2 100644 --- a/process.go +++ b/process.go @@ -338,7 +338,8 @@ func (p process) messageSubscriberHandler(natsConn *nats.Conn, thisNode string, message := Message{} - // Is serializatio + // Check if serialization is specified. + // Will default to gob serialization if nothing is specified. if val, ok := msg.Header["serial"]; ok { // fmt.Printf(" * DEBUG: ok = %v, map = %v, len of val = %v\n", ok, msg.Header, len(val)) switch val[0] { @@ -351,8 +352,9 @@ func (p process) messageSubscriberHandler(natsConn *nats.Conn, thisNode string, return } default: // Deaults to gob if no match was found. - buf := bytes.NewBuffer(msgData) - gobDec := gob.NewDecoder(buf) + r := bytes.NewReader(msgData) + gobDec := gob.NewDecoder(r) + err := gobDec.Decode(&message) if err != nil { er := fmt.Errorf("error: gob decoding failed: %v", err) @@ -364,8 +366,9 @@ func (p process) messageSubscriberHandler(natsConn *nats.Conn, thisNode string, } else { // Default to gob if serialization flag was not specified. - buf := bytes.NewBuffer(msgData) - gobDec := gob.NewDecoder(buf) + r := bytes.NewReader(msgData) + gobDec := gob.NewDecoder(r) + err := gobDec.Decode(&message) if err != nil { er := fmt.Errorf("error: gob decoding failed: %v", err)