You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 6, 2022. It is now read-only.
I need to unicast messages to other peers on my network. I want to store the AddrInfo struct on my message so I have the nodes addr who unicast me so I can send a response back.
funcinit() {
gob.Register(&Message{})
}
// Message stores a type of message and a body.// The message is the data that gets passed between nodes when they communicate.typeMessagestruct {
IDstring`json:"id"`Body []byte`json:"body"`// the actual payload.OriginNode peer.AddrInfo`json:"origin_node"`// the node that sent the message
}
// NewMessage builds up a new message.funcNewMessage(b []byte, o peer.AddrInfo) Message {
returnMessage{
ID: uuid.New().String(),
Body: b,
OriginNode: o,
}
}
// Marshal takes a node message and marshals it into an array of bytes.func (mMessage) Marshal() []byte {
varbuf bytes.Bufferenc:=gob.NewEncoder(&buf)
iferr:=enc.Encode(m); err!=nil {
zap.S().Fatal(err)
}
returnbuf.Bytes()
}
// UnmarshalMessage takes a slice of bytes and a returns a message struct.funcUnmarshalMessage(input []byte) (Message, error) {
msg:=Message{}
buf:=bytes.NewBuffer(input)
dec:=gob.NewDecoder(buf)
iferr:=dec.Decode(&msg); err!=nil {
returnMessage{}, err
}
returnmsg, nil
}
When I marshal my message struct and then attempt to unmarshal I receive the following error:
panic: interface conversion: interface is nil, not encoding.BinaryUnmarshaler [recovered]
panic: interface conversion: interface is nil, not encoding.BinaryUnmarshaler
UnmarshalMessage(0xc0001c7200, 0x454, 0x480, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, .
Is there something I need to do to be able to marshal and unmarshal my struct that contains the peer.AddrInfo ?
I need to unicast messages to other peers on my network. I want to store the AddrInfo struct on my message so I have the nodes addr who unicast me so I can send a response back.
When I marshal my message struct and then attempt to unmarshal I receive the following error:
Is there something I need to do to be able to marshal and unmarshal my struct that contains the
peer.AddrInfo?