Created
November 19, 2025 08:27
-
-
Save ernado/b8d576d3b20b73b452483e09297b9997 to your computer and use it in GitHub Desktop.
sonic decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package bench | |
| import ( | |
| "encoding/hex" | |
| "encoding/json" | |
| ) | |
| type SpanID [8]byte | |
| func (s *SpanID) UnmarshalJSON(data []byte) error { | |
| hex.Decode((*s)[:], data[1:len(data)-1]) | |
| return nil | |
| } | |
| func (s SpanID) String() string { | |
| return hex.EncodeToString(s[:]) | |
| } | |
| type TraceID [16]byte | |
| func (t *TraceID) UnmarshalJSON(data []byte) error { | |
| hex.Decode((*t)[:], data[1:len(data)-1]) | |
| return nil | |
| } | |
| func (t TraceID) String() string { | |
| return hex.EncodeToString(t[:]) | |
| } | |
| type OTEL struct { | |
| Timestamp int64 `json:"Timestamp,string"` | |
| Attributes map[string]json.RawMessage | |
| Resource map[string]json.RawMessage | |
| TraceID TraceID | |
| SpanID SpanID | |
| SeverityNumber byte | |
| Body json.RawMessage | |
| } | |
| func (o *OTEL) Reset() { | |
| o.Body = o.Body[:0] | |
| o.SeverityNumber = 0 | |
| o.TraceID = TraceID{} | |
| o.SpanID = SpanID{} | |
| o.Timestamp = 0 | |
| clear(o.Attributes) | |
| clear(o.Resource) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment