event.go 409 B

1234567891011121314151617181920212223
  1. package borealis
  2. import (
  3. "encoding/json"
  4. )
  5. type Event struct {
  6. Type uint16
  7. }
  8. func (event Event) MarshalJSON() ([]byte, error) {
  9. array := []interface{}{event.Type}
  10. return json.Marshal(array)
  11. }
  12. func (event *Event) UnmarshalJSON(input []byte) error {
  13. array := []interface{}{}
  14. if err := json.Unmarshal(input, &array); err != nil {
  15. return err
  16. }
  17. event.Type = uint16(array[0].(float64))
  18. return nil
  19. }