From a5c43958f940ffdc350cf4703b6e616f68e134ec Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 17 Jan 2021 22:06:16 +0900 Subject: [PATCH] Add test cases for int16 type --- cover_int16_test.go | 1948 +++++++++++++++++++++++++++++++++++ encode_vm_escaped.go | 435 ++++++-- encode_vm_escaped_indent.go | 412 +++++++- encode_vm_indent.go | 412 +++++++- 4 files changed, 3019 insertions(+), 188 deletions(-) diff --git a/cover_int16_test.go b/cover_int16_test.go index ce3f100..20b1fdf 100644 --- a/cover_int16_test.go +++ b/cover_int16_test.go @@ -12,9 +12,22 @@ func TestCoverInt16(t *testing.T) { type structInt16 struct { A int16 `json:"a"` } + type structInt16OmitEmpty struct { + A int16 `json:"a,omitempty"` + } + type structInt16String struct { + A int16 `json:"a,string"` + } + type structInt16Ptr struct { A *int16 `json:"a"` } + type structInt16PtrOmitEmpty struct { + A *int16 `json:"a,omitempty"` + } + type structInt16PtrString struct { + A *int16 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverInt16(t *testing.T) { indentExpected string data interface{} }{ + // HeadInt16Zero { name: "HeadInt16Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverInt16(t *testing.T) { A int16 `json:"a"` }{}, }, + { + name: "HeadInt16ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int16 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadInt16ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A int16 `json:"a,string"` + }{}, + }, + + // HeadInt16 { name: "HeadInt16", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverInt16(t *testing.T) { A int16 `json:"a"` }{A: 1}, }, + { + name: "HeadInt16OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A int16 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadInt16String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A int16 `json:"a,string"` + }{A: 1}, + }, + + // HeadInt16Ptr { name: "HeadInt16Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverInt16(t *testing.T) { A *int16 `json:"a"` }{A: int16ptr(1)}, }, + { + name: "HeadInt16PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *int16 `json:"a,omitempty"` + }{A: int16ptr(1)}, + }, + { + name: "HeadInt16PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *int16 `json:"a,string"` + }{A: int16ptr(1)}, + }, + + // HeadInt16PtrNil { name: "HeadInt16PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverInt16(t *testing.T) { A *int16 `json:"a"` }{A: nil}, }, + { + name: "HeadInt16PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int16 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadInt16PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *int16 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt16Zero { name: "PtrHeadInt16Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverInt16(t *testing.T) { A int16 `json:"a"` }{}, }, + { + name: "PtrHeadInt16ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int16 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadInt16ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A int16 `json:"a,string"` + }{}, + }, + + // PtrHeadInt16 { name: "PtrHeadInt16", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverInt16(t *testing.T) { A int16 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadInt16OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A int16 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadInt16String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A int16 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadInt16Ptr { name: "PtrHeadInt16Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverInt16(t *testing.T) { A *int16 `json:"a"` }{A: int16ptr(1)}, }, + { + name: "PtrHeadInt16PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *int16 `json:"a,omitempty"` + }{A: int16ptr(1)}, + }, + { + name: "PtrHeadInt16PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *int16 `json:"a,string"` + }{A: int16ptr(1)}, + }, + + // PtrHeadInt16PtrNil { name: "PtrHeadInt16PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverInt16(t *testing.T) { A *int16 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadInt16PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int16 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt16PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *int16 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt16Nil { name: "PtrHeadInt16Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *int16 `json:"a"` })(nil), }, + { + name: "PtrHeadInt16NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int16 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt16NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int16 `json:"a,string"` + })(nil), + }, + + // HeadInt16ZeroMultiFields { name: "HeadInt16ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B int16 `json:"b"` }{}, }, + { + name: "HeadInt16ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadInt16ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + }{}, + }, + + // HeadInt16MultiFields { name: "HeadInt16MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B int16 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadInt16MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadInt16MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadInt16PtrMultiFields { name: "HeadInt16PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *int16 `json:"b"` }{A: int16ptr(1), B: int16ptr(2)}, }, + { + name: "HeadInt16PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + }{A: int16ptr(1), B: int16ptr(2)}, + }, + { + name: "HeadInt16PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + }{A: int16ptr(1), B: int16ptr(2)}, + }, + + // HeadInt16PtrNilMultiFields { name: "HeadInt16PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *int16 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadInt16PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadInt16PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt16ZeroMultiFields { name: "PtrHeadInt16ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B int16 `json:"b"` }{}, }, + { + name: "PtrHeadInt16ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadInt16ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + }{}, + }, + + // PtrHeadInt16MultiFields { name: "PtrHeadInt16MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B int16 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadInt16MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadInt16MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadInt16PtrMultiFields { name: "PtrHeadInt16PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *int16 `json:"b"` }{A: int16ptr(1), B: int16ptr(2)}, }, + { + name: "PtrHeadInt16PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + }{A: int16ptr(1), B: int16ptr(2)}, + }, + { + name: "PtrHeadInt16PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + }{A: int16ptr(1), B: int16ptr(2)}, + }, + + // PtrHeadInt16PtrNilMultiFields { name: "PtrHeadInt16PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *int16 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadInt16PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt16PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt16NilMultiFields { name: "PtrHeadInt16NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *int16 `json:"b"` })(nil), }, + { + name: "PtrHeadInt16NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt16NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + })(nil), + }, + + // HeadInt16ZeroNotRoot { name: "HeadInt16ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadInt16ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A int16 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt16ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A int16 `json:"a,string"` + } + }{}, + }, + + // HeadInt16NotRoot { name: "HeadInt16NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A int16 `json:"a"` }{A: 1}}, }, + { + name: "HeadInt16NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A int16 `json:"a,omitempty"` + } + }{A: struct { + A int16 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadInt16NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A int16 `json:"a,string"` + } + }{A: struct { + A int16 `json:"a,string"` + }{A: 1}}, + }, + + // HeadInt16PtrNotRoot { name: "HeadInt16PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *int16 `json:"a"` }{int16ptr(1)}}, }, + { + name: "HeadInt16PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *int16 `json:"a,omitempty"` + } + }{A: struct { + A *int16 `json:"a,omitempty"` + }{int16ptr(1)}}, + }, + { + name: "HeadInt16PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *int16 `json:"a,string"` + } + }{A: struct { + A *int16 `json:"a,string"` + }{int16ptr(1)}}, + }, + + // HeadInt16PtrNilNotRoot { name: "HeadInt16PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadInt16PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *int16 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt16PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *int16 `json:"a,string"` + } + }{}, + }, + + // PtrHeadInt16ZeroNotRoot { name: "PtrHeadInt16ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A int16 `json:"a"` })}, }, + { + name: "PtrHeadInt16ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A int16 `json:"a,omitempty"` + } + }{A: new(struct { + A int16 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadInt16ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A int16 `json:"a,string"` + } + }{A: new(struct { + A int16 `json:"a,string"` + })}, + }, + + // PtrHeadInt16NotRoot { name: "PtrHeadInt16NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A int16 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadInt16NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A int16 `json:"a,omitempty"` + } + }{A: &(struct { + A int16 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadInt16NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A int16 `json:"a,string"` + } + }{A: &(struct { + A int16 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadInt16PtrNotRoot { name: "PtrHeadInt16PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *int16 `json:"a"` }{A: int16ptr(1)})}, }, + { + name: "PtrHeadInt16PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *int16 `json:"a,omitempty"` + } + }{A: &(struct { + A *int16 `json:"a,omitempty"` + }{A: int16ptr(1)})}, + }, + { + name: "PtrHeadInt16PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *int16 `json:"a,string"` + } + }{A: &(struct { + A *int16 `json:"a,string"` + }{A: int16ptr(1)})}, + }, + + // PtrHeadInt16PtrNilNotRoot { name: "PtrHeadInt16PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *int16 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadInt16PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *int16 `json:"a,omitempty"` + } + }{A: &(struct { + A *int16 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadInt16PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *int16 `json:"a,string"` + } + }{A: &(struct { + A *int16 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadInt16NilNotRoot { name: "PtrHeadInt16NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadInt16NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *int16 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt16NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *int16 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadInt16ZeroMultiFieldsNotRoot { name: "HeadInt16ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadInt16ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A int16 `json:"a,omitempty"` + } + B struct { + B int16 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadInt16ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A int16 `json:"a,string"` + } + B struct { + B int16 `json:"b,string"` + } + }{}, + }, + + // HeadInt16MultiFieldsNotRoot { name: "HeadInt16MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B int16 `json:"b"` }{B: 2}}, }, + { + name: "HeadInt16MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A int16 `json:"a,omitempty"` + } + B struct { + B int16 `json:"b,omitempty"` + } + }{A: struct { + A int16 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int16 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadInt16MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A int16 `json:"a,string"` + } + B struct { + B int16 `json:"b,string"` + } + }{A: struct { + A int16 `json:"a,string"` + }{A: 1}, B: struct { + B int16 `json:"b,string"` + }{B: 2}}, + }, + + // HeadInt16PtrMultiFieldsNotRoot { name: "HeadInt16PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *int16 `json:"b"` }{B: int16ptr(2)}}, }, + { + name: "HeadInt16PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *int16 `json:"a,omitempty"` + } + B struct { + B *int16 `json:"b,omitempty"` + } + }{A: struct { + A *int16 `json:"a,omitempty"` + }{A: int16ptr(1)}, B: struct { + B *int16 `json:"b,omitempty"` + }{B: int16ptr(2)}}, + }, + { + name: "HeadInt16PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *int16 `json:"a,string"` + } + B struct { + B *int16 `json:"b,string"` + } + }{A: struct { + A *int16 `json:"a,string"` + }{A: int16ptr(1)}, B: struct { + B *int16 `json:"b,string"` + }{B: int16ptr(2)}}, + }, + + // HeadInt16PtrNilMultiFieldsNotRoot { name: "HeadInt16PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *int16 `json:"b"` }{B: nil}}, }, + { + name: "HeadInt16PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *int16 `json:"a,omitempty"` + } + B struct { + B *int16 `json:"b,omitempty"` + } + }{A: struct { + A *int16 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *int16 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadInt16PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *int16 `json:"a,string"` + } + B struct { + B *int16 `json:"b,string"` + } + }{A: struct { + A *int16 `json:"a,string"` + }{A: nil}, B: struct { + B *int16 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadInt16ZeroMultiFieldsNotRoot { name: "PtrHeadInt16ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadInt16ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A int16 `json:"a,omitempty"` + } + B struct { + B int16 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadInt16ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A int16 `json:"a,string"` + } + B struct { + B int16 `json:"b,string"` + } + }{}, + }, + + // PtrHeadInt16MultiFieldsNotRoot { name: "PtrHeadInt16MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B int16 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadInt16MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A int16 `json:"a,omitempty"` + } + B struct { + B int16 `json:"b,omitempty"` + } + }{A: struct { + A int16 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int16 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadInt16MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A int16 `json:"a,string"` + } + B struct { + B int16 `json:"b,string"` + } + }{A: struct { + A int16 `json:"a,string"` + }{A: 1}, B: struct { + B int16 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadInt16PtrMultiFieldsNotRoot { name: "PtrHeadInt16PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *int16 `json:"b"` }{B: int16ptr(2)})}, }, + { + name: "PtrHeadInt16PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *int16 `json:"a,omitempty"` + } + B *struct { + B *int16 `json:"b,omitempty"` + } + }{A: &(struct { + A *int16 `json:"a,omitempty"` + }{A: int16ptr(1)}), B: &(struct { + B *int16 `json:"b,omitempty"` + }{B: int16ptr(2)})}, + }, + { + name: "PtrHeadInt16PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *int16 `json:"a,string"` + } + B *struct { + B *int16 `json:"b,string"` + } + }{A: &(struct { + A *int16 `json:"a,string"` + }{A: int16ptr(1)}), B: &(struct { + B *int16 `json:"b,string"` + }{B: int16ptr(2)})}, + }, + + // PtrHeadInt16PtrNilMultiFieldsNotRoot { name: "PtrHeadInt16PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt16PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int16 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *int16 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt16PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int16 `json:"a,string"` + } `json:",string"` + B *struct { + B *int16 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt16NilMultiFieldsNotRoot { name: "PtrHeadInt16NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadInt16NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int16 `json:"a,omitempty"` + } + B *struct { + B *int16 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt16NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int16 `json:"a,string"` + } + B *struct { + B *int16 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt16DoubleMultiFieldsNotRoot { name: "PtrHeadInt16DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B int16 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadInt16DoubleMultiFieldsNotRootOmitEmpty", + 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 int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + } + B *struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + } + }{A: &(struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadInt16DoubleMultiFieldsNotRootString", + 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 int16 `json:"a,string"` + B int16 `json:"b,string"` + } + B *struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + } + }{A: &(struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadInt16NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt16NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt16NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt16NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + } + B *struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt16NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt16NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadInt16NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + } + B *struct { + A int16 `json:"a,omitempty"` + B int16 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt16NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + } + B *struct { + A int16 `json:"a,string"` + B int16 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt16PtrDoubleMultiFieldsNotRoot { name: "PtrHeadInt16PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *int16 `json:"b"` }{A: int16ptr(3), B: int16ptr(4)})}, }, + { + name: "PtrHeadInt16PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + } + B *struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + } + }{A: &(struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + }{A: int16ptr(1), B: int16ptr(2)}), B: &(struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + }{A: int16ptr(3), B: int16ptr(4)})}, + }, + { + name: "PtrHeadInt16PtrDoubleMultiFieldsNotRootString", + 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 *int16 `json:"a,string"` + B *int16 `json:"b,string"` + } + B *struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + } + }{A: &(struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + }{A: int16ptr(1), B: int16ptr(2)}), B: &(struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + }{A: int16ptr(3), B: int16ptr(4)})}, + }, + + // PtrHeadInt16PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt16PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt16PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt16PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + } + B *struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt16PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt16PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadInt16PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + } + B *struct { + A *int16 `json:"a,omitempty"` + B *int16 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt16PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + } + B *struct { + A *int16 `json:"a,string"` + B *int16 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadInt16 { name: "AnonymousHeadInt16", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadInt16OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt16OmitEmpty + B int16 `json:"b,omitempty"` + }{ + structInt16OmitEmpty: structInt16OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadInt16String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt16String + B int16 `json:"b,string"` + }{ + structInt16String: structInt16String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadInt16 { name: "PtrAnonymousHeadInt16", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadInt16OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt16OmitEmpty + B int16 `json:"b,omitempty"` + }{ + structInt16OmitEmpty: &structInt16OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadInt16String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt16String + B int16 `json:"b,string"` + }{ + structInt16String: &structInt16String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadInt16 { name: "NilPtrAnonymousHeadInt16", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadInt16OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt16OmitEmpty + B int16 `json:"b,omitempty"` + }{ + structInt16OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadInt16String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt16String + B int16 `json:"b,string"` + }{ + structInt16String: nil, + B: 2, + }, + }, + + // AnonymousHeadInt16Ptr { name: "AnonymousHeadInt16Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: int16ptr(2), }, }, + { + name: "AnonymousHeadInt16PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt16PtrOmitEmpty + B *int16 `json:"b,omitempty"` + }{ + structInt16PtrOmitEmpty: structInt16PtrOmitEmpty{A: int16ptr(1)}, + B: int16ptr(2), + }, + }, + { + name: "AnonymousHeadInt16PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt16PtrString + B *int16 `json:"b,string"` + }{ + structInt16PtrString: structInt16PtrString{A: int16ptr(1)}, + B: int16ptr(2), + }, + }, + + // AnonymousHeadInt16PtrNil { name: "AnonymousHeadInt16PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: int16ptr(2), }, }, + { + name: "AnonymousHeadInt16PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structInt16PtrOmitEmpty + B *int16 `json:"b,omitempty"` + }{ + structInt16PtrOmitEmpty: structInt16PtrOmitEmpty{A: nil}, + B: int16ptr(2), + }, + }, + { + name: "AnonymousHeadInt16PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structInt16PtrString + B *int16 `json:"b,string"` + }{ + structInt16PtrString: structInt16PtrString{A: nil}, + B: int16ptr(2), + }, + }, + + // PtrAnonymousHeadInt16Ptr { name: "PtrAnonymousHeadInt16Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: int16ptr(2), }, }, + { + name: "PtrAnonymousHeadInt16PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt16PtrOmitEmpty + B *int16 `json:"b,omitempty"` + }{ + structInt16PtrOmitEmpty: &structInt16PtrOmitEmpty{A: int16ptr(1)}, + B: int16ptr(2), + }, + }, + { + name: "PtrAnonymousHeadInt16PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt16PtrString + B *int16 `json:"b,string"` + }{ + structInt16PtrString: &structInt16PtrString{A: int16ptr(1)}, + B: int16ptr(2), + }, + }, + + // NilPtrAnonymousHeadInt16Ptr { name: "NilPtrAnonymousHeadInt16Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: int16ptr(2), }, }, + { + name: "NilPtrAnonymousHeadInt16PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt16PtrOmitEmpty + B *int16 `json:"b,omitempty"` + }{ + structInt16PtrOmitEmpty: nil, + B: int16ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadInt16PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt16PtrString + B *int16 `json:"b,string"` + }{ + structInt16PtrString: nil, + B: int16ptr(2), + }, + }, + + // AnonymousHeadInt16Only { name: "AnonymousHeadInt16Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structInt16: structInt16{A: 1}, }, }, + { + name: "AnonymousHeadInt16OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt16OmitEmpty + }{ + structInt16OmitEmpty: structInt16OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadInt16OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt16String + }{ + structInt16String: structInt16String{A: 1}, + }, + }, + + // PtrAnonymousHeadInt16Only { name: "PtrAnonymousHeadInt16Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structInt16: &structInt16{A: 1}, }, }, + { + name: "PtrAnonymousHeadInt16OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt16OmitEmpty + }{ + structInt16OmitEmpty: &structInt16OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadInt16OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt16String + }{ + structInt16String: &structInt16String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadInt16Only { name: "NilPtrAnonymousHeadInt16Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structInt16: nil, }, }, + { + name: "NilPtrAnonymousHeadInt16OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt16OmitEmpty + }{ + structInt16OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt16OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt16String + }{ + structInt16String: nil, + }, + }, + + // AnonymousHeadInt16PtrOnly { name: "AnonymousHeadInt16PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structInt16Ptr: structInt16Ptr{A: int16ptr(1)}, }, }, + { + name: "AnonymousHeadInt16PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt16PtrOmitEmpty + }{ + structInt16PtrOmitEmpty: structInt16PtrOmitEmpty{A: int16ptr(1)}, + }, + }, + { + name: "AnonymousHeadInt16PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt16PtrString + }{ + structInt16PtrString: structInt16PtrString{A: int16ptr(1)}, + }, + }, + + // AnonymousHeadInt16PtrNilOnly { name: "AnonymousHeadInt16PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structInt16Ptr: structInt16Ptr{A: nil}, }, }, + { + name: "AnonymousHeadInt16PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structInt16PtrOmitEmpty + }{ + structInt16PtrOmitEmpty: structInt16PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadInt16PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structInt16PtrString + }{ + structInt16PtrString: structInt16PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadInt16PtrOnly { name: "PtrAnonymousHeadInt16PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structInt16Ptr: &structInt16Ptr{A: int16ptr(1)}, }, }, + { + name: "PtrAnonymousHeadInt16PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt16PtrOmitEmpty + }{ + structInt16PtrOmitEmpty: &structInt16PtrOmitEmpty{A: int16ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadInt16PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt16PtrString + }{ + structInt16PtrString: &structInt16PtrString{A: int16ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadInt16PtrOnly { name: "NilPtrAnonymousHeadInt16PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structInt16Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadInt16PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt16PtrOmitEmpty + }{ + structInt16PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt16PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt16PtrString + }{ + structInt16PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 98e5978..d368f64 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -1521,6 +1521,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt16(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 opStructFieldPtrHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt16: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt16Only, opStructFieldHeadInt16Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -1528,6 +1573,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendInt(b, int64(e.ptrToInt16(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Only, opStructFieldHeadOmitEmptyInt16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := int64(e.ptrToInt16(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt16Only, opStructFieldHeadStringTagInt16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt16(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1550,6 +1614,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt16Ptr: + 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.ptrToInt16(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt16Ptr: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1571,6 +1678,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16PtrOnly: + 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 opStructFieldHeadOmitEmptyInt16PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt16PtrOnly: + 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 opStructFieldHeadStringTagInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt16NPtr: + 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.ptrToInt16(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1584,6 +1754,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt16: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Only, opStructFieldAnonymousHeadInt16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1594,6 +1803,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Only, opStructFieldAnonymousHeadOmitEmptyInt16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadStringTagInt16Only, opStructFieldAnonymousHeadStringTagInt16Only: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1612,6 +1848,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16Ptr: + 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.ptrToInt16(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16Ptr: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1630,6 +1904,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt16(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3260,51 +3572,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt16(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 opStructFieldPtrHeadOmitEmptyInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4043,45 +4310,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt16: - 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.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt16: - 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.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5660,6 +5888,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyInt16Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt16(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt16Ptr: + b = append(b, code.escapedKey...) + 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.ptrToInt16(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt16NPtr: + 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.ptrToInt16(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndInt32: 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 39ed3cb..dc352cc 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -1644,6 +1644,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt16: + 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.ptrToInt16(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 opStructFieldPtrHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt16: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt16Only, opStructFieldHeadInt16Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -1653,6 +1701,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt16(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Only, opStructFieldHeadOmitEmptyInt16Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := int64(e.ptrToInt16(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 opStructFieldPtrHeadStringTagInt16Only, opStructFieldHeadStringTagInt16Only: + 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.ptrToInt16(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1677,6 +1747,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt16Ptr: + 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.ptrToInt16(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt16Ptr: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1700,6 +1817,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16PtrOnly: + 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 opStructFieldHeadOmitEmptyInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt16PtrOnly: + 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 opStructFieldHeadStringTagInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt16NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -1738,6 +1901,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadStringTagInt16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Only, opStructFieldAnonymousHeadInt16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1750,6 +1950,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Only, opStructFieldAnonymousHeadOmitEmptyInt16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadStringTagInt16Only, opStructFieldAnonymousHeadStringTagInt16Only: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1770,6 +2001,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16Ptr: + 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.ptrToInt16(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16Ptr: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1790,6 +2063,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3362,34 +3677,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt16: - 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.ptrToInt16(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 opStructFieldPtrHeadOmitEmptyInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3750,29 +4037,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt16: - 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.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4927,8 +5191,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op 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) } - b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) @@ -4952,6 +5225,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt16Ptr: + 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.ptrToInt16(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 opStructEndStringTagInt16Ptr: + 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.ptrToInt16(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt32: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 416b186..236cd7c 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -1644,6 +1644,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt16: + 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.ptrToInt16(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 opStructFieldPtrHeadStringTagInt16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt16: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt16Only, opStructFieldHeadInt16Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -1653,6 +1701,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt16(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Only, opStructFieldHeadOmitEmptyInt16Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := int64(e.ptrToInt16(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 opStructFieldPtrHeadStringTagInt16Only, opStructFieldHeadStringTagInt16Only: + 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.ptrToInt16(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1677,6 +1747,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt16Ptr: + 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.ptrToInt16(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt16Ptr: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1700,6 +1817,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt16PtrOnly: + 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 opStructFieldHeadOmitEmptyInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt16PtrOnly: + 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 opStructFieldHeadStringTagInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt16NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -1738,6 +1901,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadStringTagInt16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Only, opStructFieldAnonymousHeadInt16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -1750,6 +1950,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Only, opStructFieldAnonymousHeadOmitEmptyInt16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt16(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 opStructFieldPtrAnonymousHeadStringTagInt16Only, opStructFieldAnonymousHeadStringTagInt16Only: + 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.ptrToInt16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1770,6 +2001,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16Ptr: + 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.ptrToInt16(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16Ptr: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -1790,6 +2063,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt16PtrOnly: + 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.ptrToInt16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3362,34 +3677,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt16: - 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.ptrToInt16(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 opStructFieldPtrHeadOmitEmptyInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -3750,29 +4037,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt16: - 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.ptrToInt16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4927,8 +5191,17 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( 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) } - b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndStringTagInt16: ptr := load(ctxptr, code.headIdx) @@ -4952,6 +5225,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt16Ptr: + 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.ptrToInt16(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 opStructEndStringTagInt16Ptr: + 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.ptrToInt16(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt32: b = e.encodeIndent(b, code.indent) b = append(b, code.key...)