message.go 458 B

12345678910111213141516171819
  1. package borealis
  2. import "github.com/fxamacker/cbor/v2"
  3. type MessageEncoderV1 struct{}
  4. func (encoder *MessageEncoderV1) Encode(stream string, message interface{}) ([]byte, error) {
  5. return cbor.Marshal(message)
  6. }
  7. func (encoder *MessageEncoderV1) Decode(stream string, input []byte, messagePtr interface{}) error {
  8. switch message := messagePtr.(type) {
  9. case *[]byte:
  10. *message = input
  11. return nil
  12. default:
  13. return cbor.Unmarshal(input, message)
  14. }
  15. }