forked from tormoder/fit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.go
53 lines (43 loc) · 840 Bytes
/
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 fit
import (
"bytes"
"strconv"
"sync"
)
type jsonEncodeState struct {
bytes.Buffer
scratch [64]byte
}
var jsonEncodeStatePool sync.Pool
func newJSONEncodeState() *jsonEncodeState {
if v := jsonEncodeStatePool.Get(); v != nil {
e := v.(*jsonEncodeState)
e.Reset()
return e
}
return new(jsonEncodeState)
}
func (j *jsonEncodeState) writeFieldName(s string) {
j.WriteByte('"')
j.WriteString(s)
j.WriteByte('"')
j.WriteByte(':')
}
func (j *jsonEncodeState) writeStringBytes(b []byte) {
j.WriteByte('"')
j.Write(b)
j.WriteByte('"')
}
func (j *jsonEncodeState) writeUint(u uint64) {
b := strconv.AppendUint(j.scratch[:0], u, 10)
j.Write(b)
}
func (j *jsonEncodeState) open() {
j.WriteByte('{')
}
func (j *jsonEncodeState) close() {
j.WriteByte('}')
}
func (j *jsonEncodeState) c() {
j.WriteByte(',')
}