msgpack.go (979B)
1 package msgpack 2 3 import "fmt" 4 5 type Marshaler interface { 6 MarshalMsgpack() ([]byte, error) 7 } 8 9 type Unmarshaler interface { 10 UnmarshalMsgpack([]byte) error 11 } 12 13 type CustomEncoder interface { 14 EncodeMsgpack(*Encoder) error 15 } 16 17 type CustomDecoder interface { 18 DecodeMsgpack(*Decoder) error 19 } 20 21 //------------------------------------------------------------------------------ 22 23 type RawMessage []byte 24 25 var ( 26 _ CustomEncoder = (RawMessage)(nil) 27 _ CustomDecoder = (*RawMessage)(nil) 28 ) 29 30 func (m RawMessage) EncodeMsgpack(enc *Encoder) error { 31 return enc.write(m) 32 } 33 34 func (m *RawMessage) DecodeMsgpack(dec *Decoder) error { 35 msg, err := dec.DecodeRaw() 36 if err != nil { 37 return err 38 } 39 *m = msg 40 return nil 41 } 42 43 //------------------------------------------------------------------------------ 44 45 type unexpectedCodeError struct { 46 code byte 47 hint string 48 } 49 50 func (err unexpectedCodeError) Error() string { 51 return fmt.Sprintf("msgpack: unexpected code=%x decoding %s", err.code, err.hint) 52 }