event.go 837 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package borealis
  2. import (
  3. "encoding/json"
  4. )
  5. type Event struct {
  6. Type uint16
  7. TimestampS uint32
  8. TimestampMS uint16
  9. SequentialID uint64
  10. UniqueID []byte
  11. Payload interface{}
  12. }
  13. func (event Event) MarshalJSON() ([]byte, error) {
  14. array := []interface{}{
  15. event.Type,
  16. event.TimestampS,
  17. event.TimestampMS,
  18. event.SequentialID,
  19. event.UniqueID,
  20. event.Payload,
  21. }
  22. return json.Marshal(array)
  23. }
  24. func (event *Event) UnmarshalJSON(input []byte) error {
  25. array := []interface{}{}
  26. if err := json.Unmarshal(input, &array); err != nil {
  27. return err
  28. }
  29. event.Type = uint16(array[0].(float64))
  30. event.TimestampS = uint32(array[1].(float64))
  31. event.TimestampMS = uint16(array[2].(float64))
  32. event.SequentialID = uint64(array[3].(float64))
  33. event.UniqueID = array[4].([]byte)
  34. event.Payload = array[5]
  35. return nil
  36. }