MarshalJSON implements json.Marshaler.
()
| 201 | |
| 202 | // MarshalJSON implements json.Marshaler. |
| 203 | func (s Sample) MarshalJSON() ([]byte, error) { |
| 204 | if isTesting && math.IsNaN(s.Value) { |
| 205 | return nil, fmt.Errorf("test sample") |
| 206 | } |
| 207 | |
| 208 | t, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(model.Time(s.TimestampMs)) |
| 209 | if err != nil { |
| 210 | return nil, err |
| 211 | } |
| 212 | v, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(model.SampleValue(s.Value)) |
| 213 | if err != nil { |
| 214 | return nil, err |
| 215 | } |
| 216 | return fmt.Appendf(nil, "[%s,%s]", t, v), nil |
| 217 | } |
| 218 | |
| 219 | // UnmarshalJSON implements json.Unmarshaler. |
| 220 | func (s *Sample) UnmarshalJSON(b []byte) error { |