This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Unable to marshal / unmarshal AddrInfo within my struct #176
Comments
This seems to be a problem with // Message stores a type of message and a body.
// The message is the data that gets passed between nodes when they communicate.
type Message struct {
ID string `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.
func NewMessage(b []byte, o peer.AddrInfo) Message {
return Message{
ID: "identifier",
Body: b,
OriginNode: o,
}
}
// Marshal takes a node message and marshals it into an array of bytes.
func (m Message) Marshal() ([]byte, error) {
return json.Marshal(m)
}
// UnmarshalMessage takes a slice of bytes and a returns a message struct.
func UnmarshalMessage(input []byte) (Message, error) {
msg := Message{}
return msg, json.Unmarshal(input, &msg)
} I'm not really familiar with
|
It looks like we need to implement BinaryUnmarshal. |
But I'm not sure how to actually do this unless we want to define a custom "binary" format for address info objects. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
?The text was updated successfully, but these errors were encountered: