@@ -25,6 +25,7 @@ import (
2525
2626func init () {
2727 jsoniter .RegisterTypeEncoderFunc ("model.HistogramBucket" , marshalHistogramBucketJSON , marshalHistogramBucketJSONIsEmpty )
28+ jsoniter .RegisterTypeEncoderFunc ("model.SampleHistogramPair" , marshalSampleHistogramPairJSON , marshalSampleHistogramPairJSONIsEmpty )
2829}
2930
3031type FloatString float64
@@ -136,20 +137,25 @@ type SampleHistogramPair struct {
136137 Histogram * SampleHistogram
137138}
138139
140+ // marshalSampleHistogramPairJSON writes `[ts, "val"]`.
141+ func marshalSampleHistogramPairJSON (ptr unsafe.Pointer , stream * jsoniter.Stream ) {
142+ p := * ((* SampleHistogramPair )(ptr ))
143+ stream .WriteArrayStart ()
144+ MarshalTimestamp (int64 (p .Timestamp ), stream )
145+ stream .WriteMore ()
146+ MarshalHistogram (* p .Histogram , stream )
147+ stream .WriteArrayEnd ()
148+ }
149+
150+ func marshalSampleHistogramPairJSONIsEmpty (ptr unsafe.Pointer ) bool {
151+ return false
152+ }
153+
139154func (s SampleHistogramPair ) MarshalJSON () ([]byte , error ) {
140- jsoni := jsoniter .ConfigCompatibleWithStandardLibrary
141- t , err := jsoni .Marshal (s .Timestamp )
142- if err != nil {
143- return nil , err
144- }
145155 if s .Histogram == nil {
146156 return nil , fmt .Errorf ("histogram is nil" )
147157 }
148- v , err := jsoni .Marshal (s .Histogram )
149- if err != nil {
150- return nil , err
151- }
152- return []byte (fmt .Sprintf ("[%s,%s]" , t , v )), nil
158+ return jsoniter .ConfigCompatibleWithStandardLibrary .Marshal (s )
153159}
154160
155161func (s * SampleHistogramPair ) UnmarshalJSON (buf []byte ) error {
0 commit comments