@@ -25,6 +25,7 @@ import (
25
25
26
26
func init () {
27
27
jsoniter .RegisterTypeEncoderFunc ("model.HistogramBucket" , marshalHistogramBucketJSON , marshalHistogramBucketJSONIsEmpty )
28
+ jsoniter .RegisterTypeEncoderFunc ("model.SampleHistogramPair" , marshalSampleHistogramPairJSON , marshalSampleHistogramPairJSONIsEmpty )
28
29
}
29
30
30
31
type FloatString float64
@@ -136,20 +137,25 @@ type SampleHistogramPair struct {
136
137
Histogram * SampleHistogram
137
138
}
138
139
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
+
139
154
func (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
- }
145
155
if s .Histogram == nil {
146
156
return nil , fmt .Errorf ("histogram is nil" )
147
157
}
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 )
153
159
}
154
160
155
161
func (s * SampleHistogramPair ) UnmarshalJSON (buf []byte ) error {
0 commit comments