forked from flachnetz/dd-zipkin-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.go
53 lines (44 loc) · 1.1 KB
/
json.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package codec
import (
"github.com/flachnetz/dd-zipkin-proxy/cache"
"github.com/flachnetz/dd-zipkin-proxy/codec/hyperjson"
"github.com/pkg/errors"
"sync"
"unsafe"
)
const pooledBufferSliceLength = 8 * 1024
var bufferPool = sync.Pool{
New: func() interface{} {
return make([]byte, pooledBufferSliceLength)
},
}
func endpointValueDecoder(target unsafe.Pointer, p *hyperjson.Parser) error {
next, err := p.NextType()
if err != nil {
return err
}
if next == hyperjson.TypeNull {
*(*endpoint)(target) = endpoint{
ServiceName: "",
}
return p.Skip()
}
var decoder = hyperjson.MakeStructDecoder([]hyperjson.Field{
{
JsonName: "serviceName",
Decoder: hyperjson.StringValueDecoder,
Offset: hyperjson.OffsetOf(endpoint{}, "ServiceName"),
},
})
return decoder(target, p)
}
// Decodes any type of literal to a string
func anyValueDecoder(target unsafe.Pointer, p *hyperjson.Parser) error {
tok, err := p.ReadLiteral()
if err != nil {
return errors.WithMessage(err, "decode value")
}
// assign to target
*(*string)(target) = cache.StringForByteSliceCopy(tok.Value)
return nil
}