mirror of https://github.com/goccy/go-json.git
Add test cases of omitempty/string tag for int type
This commit is contained in:
parent
135a3c0cfb
commit
8ab0aa7168
223
coverage_test.go
223
coverage_test.go
|
@ -34,6 +34,7 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
indentExpected string
|
||||
data interface{}
|
||||
}{
|
||||
// HeadIntZero
|
||||
{
|
||||
name: "HeadIntZero",
|
||||
expected: `{"a":0}`,
|
||||
|
@ -46,6 +47,30 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A int `json:"a"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "HeadIntZeroOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "HeadIntZeroString",
|
||||
expected: `{"a":"0"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "0"
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,string"`
|
||||
}{},
|
||||
},
|
||||
|
||||
// HeadInt
|
||||
{
|
||||
name: "HeadInt",
|
||||
expected: `{"a":1}`,
|
||||
|
@ -58,6 +83,32 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A int `json:"a"`
|
||||
}{A: 1},
|
||||
},
|
||||
{
|
||||
name: "HeadIntOmitEmpty",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}{A: 1},
|
||||
},
|
||||
{
|
||||
name: "HeadIntString",
|
||||
expected: `{"a":"1"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1"
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,string"`
|
||||
}{A: 1},
|
||||
},
|
||||
|
||||
// HeadIntPtr
|
||||
{
|
||||
name: "HeadIntPtr",
|
||||
expected: `{"a":1}`,
|
||||
|
@ -70,6 +121,32 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A *int `json:"a"`
|
||||
}{A: intptr(1)},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrOmitEmpty",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
}{A: intptr(1)},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrString",
|
||||
expected: `{"a":"1"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1"
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,string"`
|
||||
}{A: intptr(1)},
|
||||
},
|
||||
|
||||
// HeadIntPtrNil
|
||||
{
|
||||
name: "HeadIntPtrNil",
|
||||
expected: `{"a":null}`,
|
||||
|
@ -82,6 +159,30 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A *int `json:"a"`
|
||||
}{A: nil},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrNilOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
}{A: nil},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrNilString",
|
||||
expected: `{"a":""}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": ""
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,string"`
|
||||
}{A: nil},
|
||||
},
|
||||
|
||||
// PtrHeadIntZero
|
||||
{
|
||||
name: "PtrHeadIntZero",
|
||||
expected: `{"a":0}`,
|
||||
|
@ -94,6 +195,30 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A int `json:"a"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntZeroOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntZeroString",
|
||||
expected: `{"a":"0"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "0"
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,string"`
|
||||
}{},
|
||||
},
|
||||
|
||||
// PtrHeadInt
|
||||
{
|
||||
name: "PtrHeadInt",
|
||||
expected: `{"a":1}`,
|
||||
|
@ -106,6 +231,32 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A int `json:"a"`
|
||||
}{A: 1},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntOmitEmpty",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}{A: 1},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntString",
|
||||
expected: `{"a":"1"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1"
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,string"`
|
||||
}{A: 1},
|
||||
},
|
||||
|
||||
// PtrHeadIntPtr
|
||||
{
|
||||
name: "PtrHeadIntPtr",
|
||||
expected: `{"a":1}`,
|
||||
|
@ -118,6 +269,32 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A *int `json:"a"`
|
||||
}{A: intptr(1)},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrOmitEmpty",
|
||||
expected: `{"a":1}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
}{A: intptr(1)},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrString",
|
||||
expected: `{"a":"1"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1"
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,string"`
|
||||
}{A: intptr(1)},
|
||||
},
|
||||
|
||||
// PtrHeadIntPtrNil
|
||||
{
|
||||
name: "PtrHeadIntPtrNil",
|
||||
expected: `{"a":null}`,
|
||||
|
@ -130,6 +307,30 @@ func TestCoverStructHeadInt(t *testing.T) {
|
|||
A *int `json:"a"`
|
||||
}{A: nil},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrNilOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
}{A: nil},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrNilString",
|
||||
expected: `{"a":""}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": ""
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,string"`
|
||||
}{A: nil},
|
||||
},
|
||||
|
||||
// PtrHeadIntNil
|
||||
{
|
||||
name: "PtrHeadIntNil",
|
||||
expected: `null`,
|
||||
|
@ -140,6 +341,28 @@ null
|
|||
A *int `json:"a"`
|
||||
})(nil),
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntNilOmitEmpty",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
})(nil),
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntNilString",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *int `json:"a,string"`
|
||||
})(nil),
|
||||
},
|
||||
|
||||
// HeadIntZeroMultiFields
|
||||
{
|
||||
name: "HeadIntZeroMultiFields",
|
||||
expected: `{"a":0,"b":0}`,
|
||||
|
|
272
encode_vm.go
272
encode_vm.go
|
@ -648,6 +648,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadIntOnly, opStructFieldHeadIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
|
@ -655,6 +700,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntOnly, opStructFieldHeadOmitEmptyIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
v := int64(e.ptrToInt(p))
|
||||
if v != 0 {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, v)
|
||||
b = encodeComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntOnly, opStructFieldHeadStringTagIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
|
@ -677,6 +741,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
p = e.ptrToPtr(p)
|
||||
if p != 0 {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeComma(b)
|
||||
}
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
b = append(b, code.key...)
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -698,6 +805,48 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtrOnly:
|
||||
b = append(b, '{')
|
||||
p := load(ctxptr, code.idx)
|
||||
if p != 0 {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = encodeComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
b = append(b, code.key...)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldHeadIntNPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -732,6 +881,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadIntOnly, opStructFieldAnonymousHeadIntOnly:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
|
@ -2694,51 +2882,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
store(ctxptr, code.idx, p)
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
@ -3567,45 +3710,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
code = code.next
|
||||
store(ctxptr, code.idx, ptr+code.offset)
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
|
|
@ -610,6 +610,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadIntOnly, opStructFieldHeadIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
|
@ -617,6 +662,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntOnly, opStructFieldHeadOmitEmptyIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
v := int64(e.ptrToInt(p))
|
||||
if v != 0 {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, v)
|
||||
b = encodeComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntOnly, opStructFieldHeadStringTagIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
|
@ -639,6 +703,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
p = e.ptrToPtr(p)
|
||||
if p != 0 {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeComma(b)
|
||||
}
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
b = append(b, code.escapedKey...)
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -660,6 +767,48 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtrOnly:
|
||||
b = append(b, '{')
|
||||
p := load(ctxptr, code.idx)
|
||||
if p != 0 {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = encodeComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
b = append(b, code.escapedKey...)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
case opStructFieldHeadIntNPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -694,6 +843,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadIntOnly, opStructFieldAnonymousHeadIntOnly:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
|
@ -2663,72 +2851,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
store(ctxptr, code.idx, p)
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntOnly:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
b = append(b, '{')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
@ -3557,45 +3679,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
code = code.next
|
||||
store(ctxptr, code.idx, ptr+code.offset)
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{')
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldAnonymousHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
|
|
@ -646,6 +646,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadIntOnly, opStructFieldHeadIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
|
@ -655,6 +703,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntOnly, opStructFieldHeadOmitEmptyIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
v := int64(e.ptrToInt(p))
|
||||
if v != 0 {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, v)
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntOnly, opStructFieldHeadStringTagIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
|
@ -679,6 +749,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
p = e.ptrToPtr(p)
|
||||
if p != 0 {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -702,6 +819,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
if p != 0 {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldHeadIntNPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -2719,34 +2882,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
store(ctxptr, code.idx, p)
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, '{', '\n')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
@ -3164,29 +3299,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
code = code.next
|
||||
store(ctxptr, code.idx, p)
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
|
|
@ -646,6 +646,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadIntOnly, opStructFieldHeadIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
|
@ -655,6 +703,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntOnly, opStructFieldHeadOmitEmptyIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
v := int64(e.ptrToInt(p))
|
||||
if v != 0 {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, v)
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntOnly, opStructFieldHeadStringTagIntOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
|
@ -679,6 +749,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
p = e.ptrToPtr(p)
|
||||
if p != 0 {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagIntPtr:
|
||||
store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx)))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
p = e.ptrToPtr(p)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -702,6 +819,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadOmitEmptyIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
if p != 0 {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructFieldPtrHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
break
|
||||
}
|
||||
store(ctxptr, code.idx, e.ptrToPtr(p))
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagIntPtrOnly:
|
||||
p := load(ctxptr, code.idx)
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p+code.offset)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
case opStructFieldHeadIntNPtr:
|
||||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
|
@ -2719,34 +2882,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
store(ctxptr, code.idx, p)
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, '{', '\n')
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v == 0 {
|
||||
code = code.nextField
|
||||
} else {
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
}
|
||||
case opStructFieldPtrHeadOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
@ -3164,29 +3299,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
code = code.next
|
||||
store(ctxptr, code.idx, p)
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
store(ctxptr, code.idx, e.ptrToPtr(ptr))
|
||||
}
|
||||
fallthrough
|
||||
case opStructFieldHeadStringTagInt:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr == 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = encodeNull(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
b = e.encodeIndent(b, code.indent+1)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = encodeIndentComma(b)
|
||||
code = code.next
|
||||
}
|
||||
case opStructFieldPtrHeadStringTagInt8:
|
||||
ptr := load(ctxptr, code.idx)
|
||||
if ptr != 0 {
|
||||
|
|
Loading…
Reference in New Issue