MCPcopy Create free account
hub / github.com/cortexproject/cortex / MarshalJSON

Method MarshalJSON

pkg/cortexpb/compat.go:203–217  ·  view source on GitHub ↗

MarshalJSON implements json.Marshaler.

()

Source from the content-addressed store, hash-verified

201
202// MarshalJSON implements json.Marshaler.
203func (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.
220func (s *Sample) UnmarshalJSON(b []byte) error {

Callers 1

getOTLPHttpRequestFunction · 0.45

Calls 1

MarshalMethod · 0.45

Tested by 1

getOTLPHttpRequestFunction · 0.36