Debian Codegraph @

pdata/internal/bytesid.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package internal // import "go.opentelemetry.io/collector/pdata/internal"
5
6 import (
7 "encoding/hex"
8
9 "go.opentelemetry.io/collector/pdata/internal/json"
10 )
11
12 // unmarshalJSON inflates trace id from hex string, possibly enclosed in quotes.
13 // Called by Protobuf JSON deserialization.
14 func unmarshalJSON(dst []byte, iter *json.Iterator) {
15 src := iter.ReadStringAsSlice()
16 if len(src) == 0 {
17 return
18 }
19
20 if len(dst) != hex.DecodedLen(len(src)) {
21 iter.ReportError("ID.UnmarshalJSONIter", "length mismatch")
22 return
23 }
24
25 _, err := hex.Decode(dst, src)
26 if err != nil {
27 iter.ReportError("ID.UnmarshalJSONIter", err.Error())
28 return
29 }
30 }