diff --git a/broker/broker.go b/broker/broker.go index 5fa134e8..f95de4b4 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -5,6 +5,7 @@ import ( "context" "errors" + "go.unistack.org/micro/v3/codec" "go.unistack.org/micro/v3/metadata" ) @@ -85,33 +86,12 @@ type Event interface { SetError(err error) } -// RawMessage is a raw encoded JSON value. -// It implements Marshaler and Unmarshaler and can be used to delay decoding or precompute a encoding. -type RawMessage []byte - -// MarshalJSON returns m as the JSON encoding of m. -func (m *RawMessage) MarshalJSON() ([]byte, error) { - if m == nil { - return []byte("null"), nil - } - return *m, nil -} - -// UnmarshalJSON sets *m to a copy of data. -func (m *RawMessage) UnmarshalJSON(data []byte) error { - if m == nil { - return errors.New("RawMessage UnmarshalJSON on nil pointer") - } - *m = append((*m)[0:0], data...) - return nil -} - // Message is used to transfer data type Message struct { // Header contains message metadata Header metadata.Metadata // Body contains message body - Body RawMessage + Body codec.RawMessage } // NewMessage create broker message with topic filled diff --git a/codec/codec.go b/codec/codec.go index 89a0bdec..20231315 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -84,3 +84,24 @@ func MarshalAppend(buf []byte, c Codec, v interface{}, opts ...Option) ([]byte, return append(buf, mbuf...), nil } + +// RawMessage is a raw encoded JSON value. +// It implements Marshaler and Unmarshaler and can be used to delay decoding or precompute a encoding. +type RawMessage []byte + +// MarshalJSON returns m as the JSON encoding of m. +func (m *RawMessage) MarshalJSON() ([]byte, error) { + if m == nil { + return []byte("null"), nil + } + return *m, nil +} + +// UnmarshalJSON sets *m to a copy of data. +func (m *RawMessage) UnmarshalJSON(data []byte) error { + if m == nil { + return errors.New("RawMessage UnmarshalJSON on nil pointer") + } + *m = append((*m)[0:0], data...) + return nil +}