msgpack.go 979 B

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