(dec *jsontext.Decoder)
| 24 | var nullBytes = []byte("null") |
| 25 | |
| 26 | func (s *SamplePair) UnmarshalJSONFrom(dec *jsontext.Decoder) error { |
| 27 | if t, err := dec.ReadToken(); err != nil { |
| 28 | return err |
| 29 | } else if t.Kind() == jsontext.KindNull { |
| 30 | return nil |
| 31 | } else if t.Kind() != jsontext.KindBeginArray { |
| 32 | return errors.New("expected [") |
| 33 | } |
| 34 | |
| 35 | // Loop until we see the end of the array (tolerate arrays of any length). |
| 36 | for i := 0; dec.PeekKind() != jsontext.KindEndArray; i++ { |
| 37 | switch i { |
| 38 | case 0: |
| 39 | if v, err := dec.ReadValue(); err != nil { |
| 40 | return err |
| 41 | } else if bytes.Equal(v, nullBytes) { |
| 42 | // Skip null values to match SamplePair#UnmarshalJSON behavior. |
| 43 | } else if err := s.Timestamp.UnmarshalJSON(v); err != nil { |
| 44 | return err |
| 45 | } |
| 46 | case 1: |
| 47 | if v, err := dec.ReadValue(); err != nil { |
| 48 | return err |
| 49 | } else if bytes.Equal(v, nullBytes) { |
| 50 | // Skip null values to match SamplePair#UnmarshalJSON behavior. |
| 51 | } else if err := s.Value.UnmarshalJSON(v); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | default: |
| 55 | // Skip any remaining array items to match UnmarshalJSON behavior. |
| 56 | if err := dec.SkipValue(); err != nil { |
| 57 | return err |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Read the final end array token. |
| 63 | if t, err := dec.ReadToken(); err != nil { |
| 64 | return err |
| 65 | } else if t.Kind() != jsontext.KindEndArray { |
| 66 | return errors.New("expected ]") |
| 67 | } |
| 68 | |
| 69 | return nil |
| 70 | } |
nothing calls this directly
no test coverage detected