(ptr unsafe.Pointer, iter *jsoniter.Iterator)
| 249 | } |
| 250 | |
| 251 | func SampleJsoniterDecode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { |
| 252 | if !iter.ReadArray() { |
| 253 | iter.ReportError("cortexpb.Sample", "expected [") |
| 254 | return |
| 255 | } |
| 256 | |
| 257 | t := model.Time(iter.ReadFloat64() * float64(time.Second/time.Millisecond)) |
| 258 | |
| 259 | if !iter.ReadArray() { |
| 260 | iter.ReportError("cortexpb.Sample", "expected ,") |
| 261 | return |
| 262 | } |
| 263 | |
| 264 | bs := iter.ReadStringAsSlice() |
| 265 | ss := *(*string)(unsafe.Pointer(&bs)) |
| 266 | v, err := strconv.ParseFloat(ss, 64) |
| 267 | if err != nil { |
| 268 | iter.ReportError("cortexpb.Sample", err.Error()) |
| 269 | return |
| 270 | } |
| 271 | |
| 272 | if isTesting && math.IsNaN(v) { |
| 273 | iter.Error = fmt.Errorf("test sample") |
| 274 | return |
| 275 | } |
| 276 | |
| 277 | if iter.ReadArray() { |
| 278 | iter.ReportError("cortexpb.Sample", "expected ]") |
| 279 | } |
| 280 | |
| 281 | *(*Sample)(ptr) = Sample{ |
| 282 | TimestampMs: int64(t), |
| 283 | Value: v, |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | func init() { |
| 288 | jsoniter.RegisterTypeEncoderFunc("cortexpb.Sample", SampleJsoniterEncode, func(unsafe.Pointer) bool { return false }) |
no test coverage detected