forked from OpenBazaar/openbazaar-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
38 lines (29 loc) · 857 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package repo
import (
"encoding/json"
"errors"
"github.com/golang/protobuf/ptypes/any"
"github.com/OpenBazaar/openbazaar-go/pb"
)
// ErrUnknownMessage - notify an invalid message
var ErrUnknownMessage = errors.New("unknown or invalid message")
// Message - wrapper for pb.Message
type Message struct {
Msg pb.Message
}
// MarshalJSON - invoke the pb.Message marshaller
func (m *Message) MarshalJSON() ([]byte, error) {
return json.Marshal(m.Msg)
}
// UnmarshalJSON - invoke the pb.Message unmarshaller
func (m *Message) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &m.Msg)
}
// GetMessageType - return the pb.Message messageType
func (m *Message) GetMessageType() pb.Message_MessageType {
return m.Msg.MessageType
}
// GetPayload - return the pb.Message payload
func (m *Message) GetPayload() *any.Any {
return m.Msg.Payload
}