message.go 433 B

1234567891011121314151617
  1. package borealis
  2. type V1MessageCodec[T any] struct{}
  3. func (encoder *V1MessageCodec[T]) Encode(stream string, message any) ([]byte, error) {
  4. event := message.(RawEvent[T])
  5. output, err := event.EncodeCBOR()
  6. if err != nil {
  7. return nil, err
  8. }
  9. return output, nil
  10. }
  11. func (encoder *V1MessageCodec[T]) Decode(stream string, input []byte, messagePtr any) error {
  12. event := messagePtr.(RawEvent[T])
  13. return event.DecodeCBOR(input)
  14. }