From e9efe2fcedfdc5225bf9cfef7d2f4562a1873cda Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 17 Jan 2021 02:53:54 +0900 Subject: [PATCH] Add test cases for int8 type --- cover_int8_test.go | 1948 +++++++++++++++++++++++++++++++++++ encode_vm.go | 557 +++++++--- encode_vm_escaped.go | 557 +++++++--- encode_vm_escaped_indent.go | 530 ++++++++-- encode_vm_indent.go | 531 ++++++++-- 5 files changed, 3611 insertions(+), 512 deletions(-) diff --git a/cover_int8_test.go b/cover_int8_test.go index 24ddd7e..3dd8d0a 100644 --- a/cover_int8_test.go +++ b/cover_int8_test.go @@ -12,9 +12,22 @@ func TestCoverInt8(t *testing.T) { type structInt8 struct { A int8 `json:"a"` } + type structInt8OmitEmpty struct { + A int8 `json:"a,omitempty"` + } + type structInt8String struct { + A int8 `json:"a,string"` + } + type structInt8Ptr struct { A *int8 `json:"a"` } + type structInt8PtrOmitEmpty struct { + A *int8 `json:"a,omitempty"` + } + type structInt8PtrString struct { + A *int8 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverInt8(t *testing.T) { indentExpected string data interface{} }{ + // HeadInt8Zero { name: "HeadInt8Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverInt8(t *testing.T) { A int8 `json:"a"` }{}, }, + { + name: "HeadInt8ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int8 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadInt8ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A int8 `json:"a,string"` + }{}, + }, + + // HeadInt8 { name: "HeadInt8", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverInt8(t *testing.T) { A int8 `json:"a"` }{A: 1}, }, + { + name: "HeadInt8OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A int8 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadInt8String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A int8 `json:"a,string"` + }{A: 1}, + }, + + // HeadInt8Ptr { name: "HeadInt8Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverInt8(t *testing.T) { A *int8 `json:"a"` }{A: int8ptr(1)}, }, + { + name: "HeadInt8PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *int8 `json:"a,omitempty"` + }{A: int8ptr(1)}, + }, + { + name: "HeadInt8PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *int8 `json:"a,string"` + }{A: int8ptr(1)}, + }, + + // HeadInt8PtrNil { name: "HeadInt8PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverInt8(t *testing.T) { A *int8 `json:"a"` }{A: nil}, }, + { + name: "HeadInt8PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int8 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadInt8PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *int8 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt8Zero { name: "PtrHeadInt8Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverInt8(t *testing.T) { A int8 `json:"a"` }{}, }, + { + name: "PtrHeadInt8ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int8 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadInt8ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A int8 `json:"a,string"` + }{}, + }, + + // PtrHeadInt8 { name: "PtrHeadInt8", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverInt8(t *testing.T) { A int8 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadInt8OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A int8 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadInt8String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A int8 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadInt8Ptr { name: "PtrHeadInt8Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverInt8(t *testing.T) { A *int8 `json:"a"` }{A: int8ptr(1)}, }, + { + name: "PtrHeadInt8PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *int8 `json:"a,omitempty"` + }{A: int8ptr(1)}, + }, + { + name: "PtrHeadInt8PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *int8 `json:"a,string"` + }{A: int8ptr(1)}, + }, + + // PtrHeadInt8PtrNil { name: "PtrHeadInt8PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverInt8(t *testing.T) { A *int8 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadInt8PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int8 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt8PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *int8 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt8Nil { name: "PtrHeadInt8Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *int8 `json:"a"` })(nil), }, + { + name: "PtrHeadInt8NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int8 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt8NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int8 `json:"a,string"` + })(nil), + }, + + // HeadInt8ZeroMultiFields { name: "HeadInt8ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B int8 `json:"b"` }{}, }, + { + name: "HeadInt8ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadInt8ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + }{}, + }, + + // HeadInt8MultiFields { name: "HeadInt8MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B int8 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadInt8MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadInt8MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadInt8PtrMultiFields { name: "HeadInt8PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *int8 `json:"b"` }{A: int8ptr(1), B: int8ptr(2)}, }, + { + name: "HeadInt8PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + }{A: int8ptr(1), B: int8ptr(2)}, + }, + { + name: "HeadInt8PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + }{A: int8ptr(1), B: int8ptr(2)}, + }, + + // HeadInt8PtrNilMultiFields { name: "HeadInt8PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *int8 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadInt8PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadInt8PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt8ZeroMultiFields { name: "PtrHeadInt8ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B int8 `json:"b"` }{}, }, + { + name: "PtrHeadInt8ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadInt8ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + }{}, + }, + + // PtrHeadInt8MultiFields { name: "PtrHeadInt8MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B int8 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadInt8MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadInt8MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadInt8PtrMultiFields { name: "PtrHeadInt8PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *int8 `json:"b"` }{A: int8ptr(1), B: int8ptr(2)}, }, + { + name: "PtrHeadInt8PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + }{A: int8ptr(1), B: int8ptr(2)}, + }, + { + name: "PtrHeadInt8PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + }{A: int8ptr(1), B: int8ptr(2)}, + }, + + // PtrHeadInt8PtrNilMultiFields { name: "PtrHeadInt8PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *int8 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadInt8PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt8PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt8NilMultiFields { name: "PtrHeadInt8NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *int8 `json:"b"` })(nil), }, + { + name: "PtrHeadInt8NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt8NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + })(nil), + }, + + // HeadInt8ZeroNotRoot { name: "HeadInt8ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadInt8ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A int8 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt8ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A int8 `json:"a,string"` + } + }{}, + }, + + // HeadInt8NotRoot { name: "HeadInt8NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A int8 `json:"a"` }{A: 1}}, }, + { + name: "HeadInt8NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A int8 `json:"a,omitempty"` + } + }{A: struct { + A int8 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadInt8NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A int8 `json:"a,string"` + } + }{A: struct { + A int8 `json:"a,string"` + }{A: 1}}, + }, + + // HeadInt8PtrNotRoot { name: "HeadInt8PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *int8 `json:"a"` }{int8ptr(1)}}, }, + { + name: "HeadInt8PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *int8 `json:"a,omitempty"` + } + }{A: struct { + A *int8 `json:"a,omitempty"` + }{int8ptr(1)}}, + }, + { + name: "HeadInt8PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *int8 `json:"a,string"` + } + }{A: struct { + A *int8 `json:"a,string"` + }{int8ptr(1)}}, + }, + + // HeadInt8PtrNilNotRoot { name: "HeadInt8PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadInt8PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *int8 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt8PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *int8 `json:"a,string"` + } + }{}, + }, + + // PtrHeadInt8ZeroNotRoot { name: "PtrHeadInt8ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A int8 `json:"a"` })}, }, + { + name: "PtrHeadInt8ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A int8 `json:"a,omitempty"` + } + }{A: new(struct { + A int8 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadInt8ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A int8 `json:"a,string"` + } + }{A: new(struct { + A int8 `json:"a,string"` + })}, + }, + + // PtrHeadInt8NotRoot { name: "PtrHeadInt8NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A int8 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadInt8NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A int8 `json:"a,omitempty"` + } + }{A: &(struct { + A int8 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadInt8NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A int8 `json:"a,string"` + } + }{A: &(struct { + A int8 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadInt8PtrNotRoot { name: "PtrHeadInt8PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *int8 `json:"a"` }{A: int8ptr(1)})}, }, + { + name: "PtrHeadInt8PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *int8 `json:"a,omitempty"` + } + }{A: &(struct { + A *int8 `json:"a,omitempty"` + }{A: int8ptr(1)})}, + }, + { + name: "PtrHeadInt8PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *int8 `json:"a,string"` + } + }{A: &(struct { + A *int8 `json:"a,string"` + }{A: int8ptr(1)})}, + }, + + // PtrHeadInt8PtrNilNotRoot { name: "PtrHeadInt8PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *int8 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadInt8PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *int8 `json:"a,omitempty"` + } + }{A: &(struct { + A *int8 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadInt8PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *int8 `json:"a,string"` + } + }{A: &(struct { + A *int8 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadInt8NilNotRoot { name: "PtrHeadInt8NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadInt8NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *int8 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt8NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *int8 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadInt8ZeroMultiFieldsNotRoot { name: "HeadInt8ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadInt8ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A int8 `json:"a,omitempty"` + } + B struct { + B int8 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadInt8ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A int8 `json:"a,string"` + } + B struct { + B int8 `json:"b,string"` + } + }{}, + }, + + // HeadInt8MultiFieldsNotRoot { name: "HeadInt8MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B int8 `json:"b"` }{B: 2}}, }, + { + name: "HeadInt8MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A int8 `json:"a,omitempty"` + } + B struct { + B int8 `json:"b,omitempty"` + } + }{A: struct { + A int8 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int8 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadInt8MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A int8 `json:"a,string"` + } + B struct { + B int8 `json:"b,string"` + } + }{A: struct { + A int8 `json:"a,string"` + }{A: 1}, B: struct { + B int8 `json:"b,string"` + }{B: 2}}, + }, + + // HeadInt8PtrMultiFieldsNotRoot { name: "HeadInt8PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *int8 `json:"b"` }{B: int8ptr(2)}}, }, + { + name: "HeadInt8PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *int8 `json:"a,omitempty"` + } + B struct { + B *int8 `json:"b,omitempty"` + } + }{A: struct { + A *int8 `json:"a,omitempty"` + }{A: int8ptr(1)}, B: struct { + B *int8 `json:"b,omitempty"` + }{B: int8ptr(2)}}, + }, + { + name: "HeadInt8PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *int8 `json:"a,string"` + } + B struct { + B *int8 `json:"b,string"` + } + }{A: struct { + A *int8 `json:"a,string"` + }{A: int8ptr(1)}, B: struct { + B *int8 `json:"b,string"` + }{B: int8ptr(2)}}, + }, + + // HeadInt8PtrNilMultiFieldsNotRoot { name: "HeadInt8PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *int8 `json:"b"` }{B: nil}}, }, + { + name: "HeadInt8PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *int8 `json:"a,omitempty"` + } + B struct { + B *int8 `json:"b,omitempty"` + } + }{A: struct { + A *int8 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *int8 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadInt8PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *int8 `json:"a,string"` + } + B struct { + B *int8 `json:"b,string"` + } + }{A: struct { + A *int8 `json:"a,string"` + }{A: nil}, B: struct { + B *int8 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadInt8ZeroMultiFieldsNotRoot { name: "PtrHeadInt8ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadInt8ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A int8 `json:"a,omitempty"` + } + B struct { + B int8 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadInt8ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A int8 `json:"a,string"` + } + B struct { + B int8 `json:"b,string"` + } + }{}, + }, + + // PtrHeadInt8MultiFieldsNotRoot { name: "PtrHeadInt8MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B int8 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadInt8MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A int8 `json:"a,omitempty"` + } + B struct { + B int8 `json:"b,omitempty"` + } + }{A: struct { + A int8 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int8 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadInt8MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A int8 `json:"a,string"` + } + B struct { + B int8 `json:"b,string"` + } + }{A: struct { + A int8 `json:"a,string"` + }{A: 1}, B: struct { + B int8 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadInt8PtrMultiFieldsNotRoot { name: "PtrHeadInt8PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *int8 `json:"b"` }{B: int8ptr(2)})}, }, + { + name: "PtrHeadInt8PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *int8 `json:"a,omitempty"` + } + B *struct { + B *int8 `json:"b,omitempty"` + } + }{A: &(struct { + A *int8 `json:"a,omitempty"` + }{A: int8ptr(1)}), B: &(struct { + B *int8 `json:"b,omitempty"` + }{B: int8ptr(2)})}, + }, + { + name: "PtrHeadInt8PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *int8 `json:"a,string"` + } + B *struct { + B *int8 `json:"b,string"` + } + }{A: &(struct { + A *int8 `json:"a,string"` + }{A: int8ptr(1)}), B: &(struct { + B *int8 `json:"b,string"` + }{B: int8ptr(2)})}, + }, + + // PtrHeadInt8PtrNilMultiFieldsNotRoot { name: "PtrHeadInt8PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt8PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int8 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *int8 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt8PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int8 `json:"a,string"` + } `json:",string"` + B *struct { + B *int8 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt8NilMultiFieldsNotRoot { name: "PtrHeadInt8NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadInt8NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int8 `json:"a,omitempty"` + } + B *struct { + B *int8 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt8NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int8 `json:"a,string"` + } + B *struct { + B *int8 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt8DoubleMultiFieldsNotRoot { name: "PtrHeadInt8DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B int8 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadInt8DoubleMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, + indentExpected: ` +{ + "A": { + "a": 1, + "b": 2 + }, + "B": { + "a": 3, + "b": 4 + } +} +`, + data: &struct { + A *struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + } + B *struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + } + }{A: &(struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadInt8DoubleMultiFieldsNotRootString", + expected: `{"A":{"a":"1","b":"2"},"B":{"a":"3","b":"4"}}`, + indentExpected: ` +{ + "A": { + "a": "1", + "b": "2" + }, + "B": { + "a": "3", + "b": "4" + } +} +`, + data: &struct { + A *struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + } + B *struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + } + }{A: &(struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadInt8NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt8NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt8NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt8NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + } + B *struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt8NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt8NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadInt8NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + } + B *struct { + A int8 `json:"a,omitempty"` + B int8 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt8NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + } + B *struct { + A int8 `json:"a,string"` + B int8 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt8PtrDoubleMultiFieldsNotRoot { name: "PtrHeadInt8PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *int8 `json:"b"` }{A: int8ptr(3), B: int8ptr(4)})}, }, + { + name: "PtrHeadInt8PtrDoubleMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, + indentExpected: ` +{ + "A": { + "a": 1, + "b": 2 + }, + "B": { + "a": 3, + "b": 4 + } +} +`, + data: &struct { + A *struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + } + B *struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + } + }{A: &(struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + }{A: int8ptr(1), B: int8ptr(2)}), B: &(struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + }{A: int8ptr(3), B: int8ptr(4)})}, + }, + { + name: "PtrHeadInt8PtrDoubleMultiFieldsNotRootString", + expected: `{"A":{"a":"1","b":"2"},"B":{"a":"3","b":"4"}}`, + indentExpected: ` +{ + "A": { + "a": "1", + "b": "2" + }, + "B": { + "a": "3", + "b": "4" + } +} +`, + data: &struct { + A *struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + } + B *struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + } + }{A: &(struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + }{A: int8ptr(1), B: int8ptr(2)}), B: &(struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + }{A: int8ptr(3), B: int8ptr(4)})}, + }, + + // PtrHeadInt8PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + } + B *struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt8PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + } + B *struct { + A *int8 `json:"a,omitempty"` + B *int8 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt8PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + } + B *struct { + A *int8 `json:"a,string"` + B *int8 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadInt8 { name: "AnonymousHeadInt8", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadInt8OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt8OmitEmpty + B int8 `json:"b,omitempty"` + }{ + structInt8OmitEmpty: structInt8OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadInt8String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt8String + B int8 `json:"b,string"` + }{ + structInt8String: structInt8String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadInt8 { name: "PtrAnonymousHeadInt8", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadInt8OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt8OmitEmpty + B int8 `json:"b,omitempty"` + }{ + structInt8OmitEmpty: &structInt8OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadInt8String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt8String + B int8 `json:"b,string"` + }{ + structInt8String: &structInt8String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadInt8 { name: "NilPtrAnonymousHeadInt8", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadInt8OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt8OmitEmpty + B int8 `json:"b,omitempty"` + }{ + structInt8OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadInt8String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt8String + B int8 `json:"b,string"` + }{ + structInt8String: nil, + B: 2, + }, + }, + + // AnonymousHeadInt8Ptr { name: "AnonymousHeadInt8Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: int8ptr(2), }, }, + { + name: "AnonymousHeadInt8PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt8PtrOmitEmpty + B *int8 `json:"b,omitempty"` + }{ + structInt8PtrOmitEmpty: structInt8PtrOmitEmpty{A: int8ptr(1)}, + B: int8ptr(2), + }, + }, + { + name: "AnonymousHeadInt8PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt8PtrString + B *int8 `json:"b,string"` + }{ + structInt8PtrString: structInt8PtrString{A: int8ptr(1)}, + B: int8ptr(2), + }, + }, + + // AnonymousHeadInt8PtrNil { name: "AnonymousHeadInt8PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: int8ptr(2), }, }, + { + name: "AnonymousHeadInt8PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structInt8PtrOmitEmpty + B *int8 `json:"b,omitempty"` + }{ + structInt8PtrOmitEmpty: structInt8PtrOmitEmpty{A: nil}, + B: int8ptr(2), + }, + }, + { + name: "AnonymousHeadInt8PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structInt8PtrString + B *int8 `json:"b,string"` + }{ + structInt8PtrString: structInt8PtrString{A: nil}, + B: int8ptr(2), + }, + }, + + // PtrAnonymousHeadInt8Ptr { name: "PtrAnonymousHeadInt8Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: int8ptr(2), }, }, + { + name: "PtrAnonymousHeadInt8PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt8PtrOmitEmpty + B *int8 `json:"b,omitempty"` + }{ + structInt8PtrOmitEmpty: &structInt8PtrOmitEmpty{A: int8ptr(1)}, + B: int8ptr(2), + }, + }, + { + name: "PtrAnonymousHeadInt8PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt8PtrString + B *int8 `json:"b,string"` + }{ + structInt8PtrString: &structInt8PtrString{A: int8ptr(1)}, + B: int8ptr(2), + }, + }, + + // NilPtrAnonymousHeadInt8Ptr { name: "NilPtrAnonymousHeadInt8Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: int8ptr(2), }, }, + { + name: "NilPtrAnonymousHeadInt8PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt8PtrOmitEmpty + B *int8 `json:"b,omitempty"` + }{ + structInt8PtrOmitEmpty: nil, + B: int8ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadInt8PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt8PtrString + B *int8 `json:"b,string"` + }{ + structInt8PtrString: nil, + B: int8ptr(2), + }, + }, + + // AnonymousHeadInt8Only { name: "AnonymousHeadInt8Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structInt8: structInt8{A: 1}, }, }, + { + name: "AnonymousHeadInt8OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt8OmitEmpty + }{ + structInt8OmitEmpty: structInt8OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadInt8OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt8String + }{ + structInt8String: structInt8String{A: 1}, + }, + }, + + // PtrAnonymousHeadInt8Only { name: "PtrAnonymousHeadInt8Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structInt8: &structInt8{A: 1}, }, }, + { + name: "PtrAnonymousHeadInt8OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt8OmitEmpty + }{ + structInt8OmitEmpty: &structInt8OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadInt8OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt8String + }{ + structInt8String: &structInt8String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadInt8Only { name: "NilPtrAnonymousHeadInt8Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structInt8: nil, }, }, + { + name: "NilPtrAnonymousHeadInt8OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt8OmitEmpty + }{ + structInt8OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt8OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt8String + }{ + structInt8String: nil, + }, + }, + + // AnonymousHeadInt8PtrOnly { name: "AnonymousHeadInt8PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structInt8Ptr: structInt8Ptr{A: int8ptr(1)}, }, }, + { + name: "AnonymousHeadInt8PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt8PtrOmitEmpty + }{ + structInt8PtrOmitEmpty: structInt8PtrOmitEmpty{A: int8ptr(1)}, + }, + }, + { + name: "AnonymousHeadInt8PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt8PtrString + }{ + structInt8PtrString: structInt8PtrString{A: int8ptr(1)}, + }, + }, + + // AnonymousHeadInt8PtrNilOnly { name: "AnonymousHeadInt8PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structInt8Ptr: structInt8Ptr{A: nil}, }, }, + { + name: "AnonymousHeadInt8PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structInt8PtrOmitEmpty + }{ + structInt8PtrOmitEmpty: structInt8PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadInt8PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structInt8PtrString + }{ + structInt8PtrString: structInt8PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadInt8PtrOnly { name: "PtrAnonymousHeadInt8PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structInt8Ptr: &structInt8Ptr{A: int8ptr(1)}, }, }, + { + name: "PtrAnonymousHeadInt8PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt8PtrOmitEmpty + }{ + structInt8PtrOmitEmpty: &structInt8PtrOmitEmpty{A: int8ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadInt8PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt8PtrString + }{ + structInt8PtrString: &structInt8PtrString{A: int8ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadInt8PtrOnly { name: "NilPtrAnonymousHeadInt8PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structInt8Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadInt8PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt8PtrOmitEmpty + }{ + structInt8PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt8PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt8PtrString + }{ + structInt8PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { diff --git a/encode_vm.go b/encode_vm.go index c68caf6..e5b7deb 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -1124,6 +1124,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt8(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 opStructFieldPtrHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt8: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt8Only, opStructFieldHeadInt8Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -1131,6 +1176,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendInt(b, int64(e.ptrToInt8(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Only, opStructFieldHeadOmitEmptyInt8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := int64(e.ptrToInt8(p)) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt8Only, opStructFieldHeadStringTagInt8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1153,6 +1217,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt8Ptr: + 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.ptrToInt8(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt8Ptr: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1174,6 +1281,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8PtrOnly: + 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 opStructFieldHeadOmitEmptyInt8PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt8PtrOnly: + 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 opStructFieldHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt8NPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{') + b = append(b, code.key...) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = e.ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1187,6 +1357,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(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 opStructFieldPtrAnonymousHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt8: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Only, opStructFieldAnonymousHeadInt8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1197,6 +1406,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Only, opStructFieldAnonymousHeadOmitEmptyInt8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(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 opStructFieldPtrAnonymousHeadStringTagInt8Only, opStructFieldAnonymousHeadStringTagInt8Only: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1215,6 +1451,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = e.ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt8(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.key...) + p = e.ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1233,6 +1507,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2981,51 +3293,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt8(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 opStructFieldPtrAnonymousHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt8(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 opStructFieldPtrHeadOmitEmptyInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3809,45 +4076,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt8: - 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.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt8: - 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.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4506,6 +4734,29 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte ptr := load(ctxptr, code.headIdx) + code.offset code = code.next store(ctxptr, code.idx, ptr) + case opStructFieldInt: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt: + 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 = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt: + 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 = encodeComma(b) + code = code.next case opStructFieldIntPtr: b = append(b, code.key...) ptr := load(ctxptr, code.headIdx) @@ -4534,10 +4785,27 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldInt: + case opStructFieldInt8: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldInt8Ptr: @@ -4551,12 +4819,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldInt8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = encodeComma(b) - code = code.next case opStructFieldInt16Ptr: b = append(b, code.key...) ptr := load(ctxptr, code.headIdx) @@ -4845,24 +5107,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, p) } - case opStructFieldOmitEmptyInt: - 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 = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - } - code = code.next case opStructFieldOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -5065,22 +5309,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = append(b, code.key...) code = code.next store(ctxptr, code.idx, p) - case opStructFieldStringTagInt: - 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 = encodeComma(b) - code = code.next - case opStructFieldStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next case opStructFieldStringTagInt16: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -5299,6 +5527,29 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndInt8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(ptr + code.offset) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = appendStructEnd(b) + code = code.next case opStructEndInt8Ptr: b = append(b, code.key...) ptr := load(ctxptr, code.headIdx) @@ -5310,10 +5561,43 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndInt8: + case opStructEndOmitEmptyInt8Ptr: ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt8(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt8Ptr: b = append(b, code.key...) - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt8NPtr: + b = append(b, code.key...) + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + for i := 0; i < code.ptrNum-1; i++ { + if p == 0 { + break + } + p = e.ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, int64(e.ptrToInt8(p))) + } b = appendStructEnd(b) code = code.next case opStructEndInt16Ptr: @@ -5564,15 +5848,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 opStructEndOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(ptr + code.offset) - if v != 0 { - b = append(b, code.key...) - b = appendInt(b, int64(v)) - } - b = appendStructEnd(b) - code = code.next case opStructEndOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -5725,14 +6000,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next - case opStructEndStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 862b923..97d43b6 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -1084,6 +1084,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt8(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 opStructFieldPtrHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt8: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt8Only, opStructFieldHeadInt8Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -1091,6 +1136,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendInt(b, int64(e.ptrToInt8(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Only, opStructFieldHeadOmitEmptyInt8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := int64(e.ptrToInt8(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt8Only, opStructFieldHeadStringTagInt8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1113,6 +1177,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt8Ptr: + 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.ptrToInt8(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt8Ptr: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1134,6 +1241,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8PtrOnly: + 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 opStructFieldHeadOmitEmptyInt8PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt8PtrOnly: + 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 opStructFieldHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt8NPtr: + p := load(ctxptr, code.idx) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '{') + b = append(b, code.escapedKey...) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = e.ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1147,6 +1317,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(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 opStructFieldPtrAnonymousHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt8: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Only, opStructFieldAnonymousHeadInt8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1157,6 +1366,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Only, opStructFieldAnonymousHeadOmitEmptyInt8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(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 opStructFieldPtrAnonymousHeadStringTagInt8Only, opStructFieldAnonymousHeadStringTagInt8Only: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1175,6 +1411,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = e.ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt8(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = append(b, code.escapedKey...) + p = e.ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1193,6 +1467,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2948,51 +3260,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt8(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 opStructFieldPtrAnonymousHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt8(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 opStructFieldPtrHeadOmitEmptyInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3776,45 +4043,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt8: - 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.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt8: - 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.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4532,6 +4760,29 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) ptr := load(ctxptr, code.headIdx) + code.offset code = code.next store(ctxptr, code.idx, ptr) + case opStructFieldInt: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt: + 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 = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt: + 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 = encodeComma(b) + code = code.next case opStructFieldIntPtr: b = append(b, code.escapedKey...) ptr := load(ctxptr, code.headIdx) @@ -4560,10 +4811,27 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldInt: + case opStructFieldInt8: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = encodeComma(b) + code = code.next + case opStructFieldOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(v)) + b = encodeComma(b) + } + code = code.next + case opStructFieldStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') b = encodeComma(b) code = code.next case opStructFieldInt8Ptr: @@ -4577,12 +4845,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldInt8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = encodeComma(b) - code = code.next case opStructFieldInt16Ptr: b = append(b, code.escapedKey...) ptr := load(ctxptr, code.headIdx) @@ -4871,24 +5133,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, p) } - case opStructFieldOmitEmptyInt: - 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 = encodeComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, int64(v)) - b = encodeComma(b) - } - code = code.next case opStructFieldOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -5091,22 +5335,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = append(b, code.escapedKey...) code = code.next store(ctxptr, code.idx, p) - case opStructFieldStringTagInt: - 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 = encodeComma(b) - code = code.next - case opStructFieldStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next case opStructFieldStringTagInt16: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -5325,6 +5553,29 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndInt8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = appendStructEnd(b) + code = code.next + case opStructEndOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(ptr + code.offset) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(v)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = appendStructEnd(b) + code = code.next case opStructEndInt8Ptr: b = append(b, code.escapedKey...) ptr := load(ctxptr, code.headIdx) @@ -5336,10 +5587,43 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndInt8: + case opStructEndOmitEmptyInt8Ptr: ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt8(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt8Ptr: b = append(b, code.escapedKey...) - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt8NPtr: + b = append(b, code.escapedKey...) + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + for i := 0; i < code.ptrNum-1; i++ { + if p == 0 { + break + } + p = e.ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, int64(e.ptrToInt8(p))) + } b = appendStructEnd(b) code = code.next case opStructEndInt16Ptr: @@ -5590,15 +5874,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 opStructEndOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(ptr + code.offset) - if v != 0 { - b = append(b, code.escapedKey...) - b = appendInt(b, int64(v)) - } - b = appendStructEnd(b) - code = code.next case opStructEndOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -5751,14 +6026,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next - case opStructEndStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = appendStructEnd(b) - code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) diff --git a/encode_vm_escaped_indent.go b/encode_vm_escaped_indent.go index 1194054..89f3e40 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -1165,6 +1165,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt8: + 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.ptrToInt8(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 opStructFieldPtrHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt8: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt8Only, opStructFieldHeadInt8Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -1174,6 +1222,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt8(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Only, opStructFieldHeadOmitEmptyInt8Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := int64(e.ptrToInt8(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 opStructFieldPtrHeadStringTagInt8Only, opStructFieldHeadStringTagInt8Only: + 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.ptrToInt8(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1198,6 +1268,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt8Ptr: + 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.ptrToInt8(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt8Ptr: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1221,6 +1338,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8PtrOnly: + 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 opStructFieldHeadOmitEmptyInt8PtrOnly: + 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.ptrToInt8(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt8PtrOnly: + 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 opStructFieldHeadStringTagInt8PtrOnly: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt8NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -1259,6 +1422,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Only, opStructFieldAnonymousHeadInt8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1271,6 +1471,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Only, opStructFieldAnonymousHeadOmitEmptyInt8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt8Only, opStructFieldAnonymousHeadStringTagInt8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1291,6 +1522,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = e.ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + p = e.ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1311,6 +1584,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3047,34 +3362,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt8: - 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.ptrToInt8(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 opStructFieldPtrHeadOmitEmptyInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3463,29 +3750,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt8: - 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.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3804,6 +4068,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt: + 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 = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt: + 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 = encodeIndentComma(b) + code = code.next case opStructFieldInt8: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -3812,6 +4096,26 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(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 = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldInt16: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4037,28 +4341,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldOmitEmptyInt: - 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 = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(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 = encodeIndentComma(b) - } - code = code.next case opStructFieldOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -4288,24 +4570,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, ' ') code = code.next store(ctxptr, code.idx, p) - case opStructFieldStringTagInt: - 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 = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next case opStructFieldStringTagInt16: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent) @@ -4570,6 +4834,35 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(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 opStructEndStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt8Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4583,6 +4876,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt8Ptr: + 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.ptrToInt8(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 opStructEndStringTagInt8Ptr: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt16: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -4843,17 +5171,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 opStructEndOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(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 opStructEndOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -5000,15 +5317,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next - case opStructEndStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 5e2976d..eee093c 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -1165,6 +1165,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt8: + 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.ptrToInt8(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 opStructFieldPtrHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt8: + 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.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt8Only, opStructFieldHeadInt8Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -1174,6 +1222,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt8(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Only, opStructFieldHeadOmitEmptyInt8Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := int64(e.ptrToInt8(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 opStructFieldPtrHeadStringTagInt8Only, opStructFieldHeadStringTagInt8Only: + 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.ptrToInt8(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1198,6 +1268,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt8Ptr: + 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.key...) + b = append(b, ' ') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt8Ptr: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1221,6 +1338,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt8PtrOnly: + 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 opStructFieldHeadOmitEmptyInt8PtrOnly: + 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.ptrToInt8(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt8PtrOnly: + 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 opStructFieldHeadStringTagInt8PtrOnly: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt8NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -1259,6 +1422,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Only, opStructFieldAnonymousHeadInt8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1271,6 +1471,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Only, opStructFieldAnonymousHeadOmitEmptyInt8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt8Only, opStructFieldAnonymousHeadStringTagInt8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1291,6 +1522,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + p = e.ptrToPtr(p) + if p == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8Ptr: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + p = e.ptrToPtr(p) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1311,6 +1584,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt8PtrOnly: + p := load(ctxptr, code.idx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3047,34 +3362,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt8: - 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.ptrToInt8(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 opStructFieldPtrHeadOmitEmptyInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3463,29 +3750,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt8: - 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.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt16: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3804,6 +4068,26 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt: + 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 = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt: + 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 = encodeIndentComma(b) + code = code.next case opStructFieldInt8: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -3812,6 +4096,27 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) b = encodeIndentComma(b) code = code.next + case opStructFieldOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(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 = encodeIndentComma(b) + } + code = code.next + case opStructFieldStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + case opStructFieldInt16: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4037,28 +4342,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldOmitEmptyInt: - 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 = encodeIndentComma(b) - } - code = code.next - case opStructFieldOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(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 = encodeIndentComma(b) - } - code = code.next case opStructFieldOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -4288,24 +4571,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, ' ') code = code.next store(ctxptr, code.idx, p) - case opStructFieldStringTagInt: - 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 = encodeIndentComma(b) - code = code.next - case opStructFieldStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next case opStructFieldStringTagInt16: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent) @@ -4570,6 +4835,35 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt8: + ptr := load(ctxptr, code.headIdx) + v := e.ptrToInt8(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 opStructEndStringTagInt8: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) + b = append(b, '"') + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt8Ptr: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4583,6 +4877,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt8Ptr: + 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.ptrToInt8(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 opStructEndStringTagInt8Ptr: + 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 = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt8(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt16: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -4843,17 +5172,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 opStructEndOmitEmptyInt8: - ptr := load(ctxptr, code.headIdx) - v := e.ptrToInt8(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 opStructEndOmitEmptyInt16: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt16(ptr + code.offset) @@ -5000,15 +5318,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next - case opStructEndStringTagInt8: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) b = e.encodeIndent(b, code.indent)