mirror of https://github.com/goccy/go-json.git
Fix opcode for end of omitempty int type
This commit is contained in:
parent
8ab0aa7168
commit
fd1085102c
322
coverage_test.go
322
coverage_test.go
|
@ -377,6 +377,33 @@ null
|
|||
B int `json:"b"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "HeadIntZeroMultiFieldsOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,omitempty"`
|
||||
B int `json:"b,omitempty"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "HeadIntZeroMultiFields",
|
||||
expected: `{"a":"0","b":"0"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "0",
|
||||
"b": "0"
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,string"`
|
||||
B int `json:"b,string"`
|
||||
}{},
|
||||
},
|
||||
|
||||
// HeadIntMultiFields
|
||||
{
|
||||
name: "HeadIntMultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
|
@ -391,6 +418,36 @@ null
|
|||
B int `json:"b"`
|
||||
}{A: 1, B: 2},
|
||||
},
|
||||
{
|
||||
name: "HeadIntMultiFieldsOmitEmpty",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,omitempty"`
|
||||
B int `json:"b,omitempty"`
|
||||
}{A: 1, B: 2},
|
||||
},
|
||||
{
|
||||
name: "HeadIntMultiFieldsString",
|
||||
expected: `{"a":"1","b":"2"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1",
|
||||
"b": "2"
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A int `json:"a,string"`
|
||||
B int `json:"b,string"`
|
||||
}{A: 1, B: 2},
|
||||
},
|
||||
|
||||
// HeadIntPtrMultiFields
|
||||
{
|
||||
name: "HeadIntPtrMultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
|
@ -405,6 +462,36 @@ null
|
|||
B *int `json:"b"`
|
||||
}{A: intptr(1), B: intptr(2)},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrMultiFieldsOmitEmpty",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
B *int `json:"b,omitempty"`
|
||||
}{A: intptr(1), B: intptr(2)},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrMultiFieldsString",
|
||||
expected: `{"a":"1","b":"2"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1",
|
||||
"b": "2"
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,string"`
|
||||
B *int `json:"b,string"`
|
||||
}{A: intptr(1), B: intptr(2)},
|
||||
},
|
||||
|
||||
// HeadIntPtrNilMultiFields
|
||||
{
|
||||
name: "HeadIntPtrNilMultiFields",
|
||||
expected: `{"a":null,"b":null}`,
|
||||
|
@ -419,6 +506,33 @@ null
|
|||
B *int `json:"b"`
|
||||
}{A: nil, B: nil},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrNilMultiFieldsOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
B *int `json:"b,omitempty"`
|
||||
}{A: nil, B: nil},
|
||||
},
|
||||
{
|
||||
name: "HeadIntPtrNilMultiFieldsString",
|
||||
expected: `{"a":"","b":""}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "",
|
||||
"b": ""
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A *int `json:"a,string"`
|
||||
B *int `json:"b,string"`
|
||||
}{A: nil, B: nil},
|
||||
},
|
||||
|
||||
// PtrHeadIntZeroMultiFields
|
||||
{
|
||||
name: "PtrHeadIntZeroMultiFields",
|
||||
expected: `{"a":0,"b":0}`,
|
||||
|
@ -433,6 +547,33 @@ null
|
|||
B int `json:"b"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntZeroMultiFieldsOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,omitempty"`
|
||||
B int `json:"b,omitempty"`
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntZeroMultiFieldsString",
|
||||
expected: `{"a":"0","b":"0"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "0",
|
||||
"b": "0"
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,string"`
|
||||
B int `json:"b,string"`
|
||||
}{},
|
||||
},
|
||||
|
||||
// PtrHeadIntMultiFields
|
||||
{
|
||||
name: "PtrHeadIntMultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
|
@ -447,6 +588,36 @@ null
|
|||
B int `json:"b"`
|
||||
}{A: 1, B: 2},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntMultiFieldsOmitEmpty",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,omitempty"`
|
||||
B int `json:"b,omitempty"`
|
||||
}{A: 1, B: 2},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntMultiFieldsString",
|
||||
expected: `{"a":"1","b":"2"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1",
|
||||
"b": "2"
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A int `json:"a,string"`
|
||||
B int `json:"b,string"`
|
||||
}{A: 1, B: 2},
|
||||
},
|
||||
|
||||
// PtrHeadIntPtrMultiFields
|
||||
{
|
||||
name: "PtrHeadIntPtrMultiFields",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
|
@ -461,6 +632,36 @@ null
|
|||
B *int `json:"b"`
|
||||
}{A: intptr(1), B: intptr(2)},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrMultiFieldsOmitEmpty",
|
||||
expected: `{"a":1,"b":2}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
B *int `json:"b,omitempty"`
|
||||
}{A: intptr(1), B: intptr(2)},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrMultiFieldsString",
|
||||
expected: `{"a":"1","b":"2"}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "1",
|
||||
"b": "2"
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,string"`
|
||||
B *int `json:"b,string"`
|
||||
}{A: intptr(1), B: intptr(2)},
|
||||
},
|
||||
|
||||
// PtrHeadIntPtrNilMultiFields
|
||||
{
|
||||
name: "PtrHeadIntPtrNilMultiFields",
|
||||
expected: `{"a":null,"b":null}`,
|
||||
|
@ -475,6 +676,33 @@ null
|
|||
B *int `json:"b"`
|
||||
}{A: nil, B: nil},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrNilMultiFieldsOmitEmpty",
|
||||
expected: `{}`,
|
||||
indentExpected: `
|
||||
{}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
B *int `json:"b,omitempty"`
|
||||
}{A: nil, B: nil},
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntPtrNilMultiFieldsString",
|
||||
expected: `{"a":"","b":""}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"a": "",
|
||||
"b": ""
|
||||
}
|
||||
`,
|
||||
data: &struct {
|
||||
A *int `json:"a,string"`
|
||||
B *int `json:"b,string"`
|
||||
}{A: nil, B: nil},
|
||||
},
|
||||
|
||||
// PtrHeadIntNilMultiFields
|
||||
{
|
||||
name: "PtrHeadIntNilMultiFields",
|
||||
expected: `null`,
|
||||
|
@ -486,6 +714,30 @@ null
|
|||
B *int `json:"b"`
|
||||
})(nil),
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntNilMultiFieldsOmitEmpty",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *int `json:"a,omitempty"`
|
||||
B *int `json:"b,omitempty"`
|
||||
})(nil),
|
||||
},
|
||||
{
|
||||
name: "PtrHeadIntNilMultiFieldsString",
|
||||
expected: `null`,
|
||||
indentExpected: `
|
||||
null
|
||||
`,
|
||||
data: (*struct {
|
||||
A *int `json:"a,string"`
|
||||
B *int `json:"b,string"`
|
||||
})(nil),
|
||||
},
|
||||
|
||||
// HeadIntZeroNotRoot
|
||||
{
|
||||
name: "HeadIntZeroNotRoot",
|
||||
expected: `{"A":{"a":0}}`,
|
||||
|
@ -502,6 +754,38 @@ null
|
|||
}
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "HeadIntZeroNotRootOmitEmpty",
|
||||
expected: `{"A":{}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}
|
||||
}{},
|
||||
},
|
||||
{
|
||||
name: "HeadIntZeroNotRootString",
|
||||
expected: `{"A":{"a":"0"}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": "0"
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int `json:"a,string"`
|
||||
}
|
||||
}{},
|
||||
},
|
||||
|
||||
// HeadIntNotRoot
|
||||
{
|
||||
name: "HeadIntNotRoot",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
|
@ -520,6 +804,44 @@ null
|
|||
A int `json:"a"`
|
||||
}{A: 1}},
|
||||
},
|
||||
{
|
||||
name: "HeadIntNotRootOmitEmpty",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": 1
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}
|
||||
}{A: struct {
|
||||
A int `json:"a,omitempty"`
|
||||
}{A: 1}},
|
||||
},
|
||||
{
|
||||
name: "HeadIntNotRootString",
|
||||
expected: `{"A":{"a":"1"}}`,
|
||||
indentExpected: `
|
||||
{
|
||||
"A": {
|
||||
"a": "1"
|
||||
}
|
||||
}
|
||||
`,
|
||||
data: struct {
|
||||
A struct {
|
||||
A int `json:"a,string"`
|
||||
}
|
||||
}{A: struct {
|
||||
A int `json:"a,string"`
|
||||
}{A: 1}},
|
||||
},
|
||||
|
||||
// HeadIntPtrNotRoot
|
||||
{
|
||||
name: "HeadIntPtrNotRoot",
|
||||
expected: `{"A":{"a":1}}`,
|
||||
|
|
68
encode_vm.go
68
encode_vm.go
|
@ -5127,6 +5127,29 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
code = code.next
|
||||
case opStructAnonymousEnd:
|
||||
code = code.next
|
||||
case opStructEndInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(v))
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndIntPtr:
|
||||
b = append(b, code.key...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
|
@ -5138,6 +5161,28 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyIntPtr:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p != 0 {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagIntPtr:
|
||||
b = append(b, code.key...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndIntNPtr:
|
||||
b = append(b, code.key...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
|
@ -5155,12 +5200,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndInt8Ptr:
|
||||
b = append(b, code.key...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
|
@ -5426,15 +5465,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
b = encodeNoEscapedString(b, *(*string)(unsafe.Pointer(&bytes)))
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = append(b, code.key...)
|
||||
b = appendInt(b, int64(v))
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt8(ptr + code.offset)
|
||||
|
@ -5596,14 +5626,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte
|
|||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.key...)
|
||||
|
|
|
@ -5155,6 +5155,29 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
code = code.next
|
||||
case opStructAnonymousEnd:
|
||||
code = code.next
|
||||
case opStructEndInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndIntPtr:
|
||||
b = append(b, code.escapedKey...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
|
@ -5166,6 +5189,28 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyIntPtr:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p != 0 {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagIntPtr:
|
||||
b = append(b, code.escapedKey...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndIntNPtr:
|
||||
b = append(b, code.escapedKey...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
|
@ -5183,12 +5228,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndInt8Ptr:
|
||||
b = append(b, code.escapedKey...)
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
|
@ -5454,15 +5493,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
b = encodeEscapedString(b, *(*string)(unsafe.Pointer(&bytes)))
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = append(b, code.escapedKey...)
|
||||
b = appendInt(b, int64(v))
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt8(ptr + code.offset)
|
||||
|
@ -5624,14 +5654,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode)
|
|||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = appendStructEnd(b)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = append(b, code.escapedKey...)
|
||||
|
|
|
@ -4321,6 +4321,35 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
} else {
|
||||
last := len(b) - 1
|
||||
if b[last-1] == '{' {
|
||||
// doesn't exist any fields
|
||||
b[last] = '}'
|
||||
} else {
|
||||
b = append(b, '}')
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndIntPtr:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
|
@ -4334,6 +4363,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyIntPtr:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p != 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
} else {
|
||||
last := len(b) - 1
|
||||
if b[last-1] == '{' {
|
||||
// doesn't exist any fields
|
||||
b[last] = '}'
|
||||
} else {
|
||||
b = append(b, '}')
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructEndStringTagIntPtr:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndInt8:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
|
@ -4615,17 +4679,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
b = append(b, buf.Bytes()...)
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt8(ptr + code.offset)
|
||||
|
@ -4783,15 +4836,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op
|
|||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.escapedKey...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
|
|
|
@ -756,7 +756,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
p := load(ctxptr, code.idx)
|
||||
if p == 0 {
|
||||
b = encodeNull(b)
|
||||
b = encodeComma(b)
|
||||
b = encodeIndentComma(b)
|
||||
code = code.end.next
|
||||
} else {
|
||||
b = append(b, '{', '\n')
|
||||
|
@ -4321,6 +4321,35 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
} else {
|
||||
last := len(b) - 1
|
||||
if b[last-1] == '{' {
|
||||
// doesn't exist any fields
|
||||
b[last] = '}'
|
||||
} else {
|
||||
b = append(b, '}')
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndIntPtr:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
|
@ -4334,6 +4363,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyIntPtr:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p != 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
} else {
|
||||
last := len(b) - 1
|
||||
if b[last-1] == '{' {
|
||||
// doesn't exist any fields
|
||||
b[last] = '}'
|
||||
} else {
|
||||
b = append(b, '}')
|
||||
}
|
||||
b = encodeIndentComma(b)
|
||||
}
|
||||
code = code.next
|
||||
case opStructEndStringTagIntPtr:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
p := e.ptrToPtr(ptr + code.offset)
|
||||
if p == 0 {
|
||||
b = append(b, `""`...)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(p)))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndInt8:
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
|
@ -4615,17 +4679,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
b = append(b, buf.Bytes()...)
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt(ptr + code.offset)
|
||||
if v != 0 {
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ')
|
||||
b = appendInt(b, int64(v))
|
||||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndOmitEmptyInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
v := e.ptrToInt8(ptr + code.offset)
|
||||
|
@ -4783,15 +4836,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) (
|
|||
}
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
b = append(b, code.key...)
|
||||
b = append(b, ' ', '"')
|
||||
b = appendInt(b, int64(e.ptrToInt(ptr+code.offset)))
|
||||
b = append(b, '"')
|
||||
b = e.appendStructEndIndent(b, code.indent-1)
|
||||
code = code.next
|
||||
case opStructEndStringTagInt8:
|
||||
ptr := load(ctxptr, code.headIdx)
|
||||
b = e.encodeIndent(b, code.indent)
|
||||
|
|
Loading…
Reference in New Issue