From 861236119af04c4ec41bf7309e3394aacecf91ad Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 18 Jan 2021 21:50:52 +0900 Subject: [PATCH] Add test cases for int32 type --- cover_int32_test.go | 1948 +++++++++++++++++++++++++++++++++++ encode_vm.go | 436 ++++++-- encode_vm_escaped.go | 436 ++++++-- encode_vm_escaped_indent.go | 412 +++++++- encode_vm_indent.go | 412 +++++++- 5 files changed, 3372 insertions(+), 272 deletions(-) diff --git a/cover_int32_test.go b/cover_int32_test.go index c1e558e..f4f87db 100644 --- a/cover_int32_test.go +++ b/cover_int32_test.go @@ -12,9 +12,22 @@ func TestCoverInt32(t *testing.T) { type structInt32 struct { A int32 `json:"a"` } + type structInt32OmitEmpty struct { + A int32 `json:"a,omitempty"` + } + type structInt32String struct { + A int32 `json:"a,string"` + } + type structInt32Ptr struct { A *int32 `json:"a"` } + type structInt32PtrOmitEmpty struct { + A *int32 `json:"a,omitempty"` + } + type structInt32PtrString struct { + A *int32 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverInt32(t *testing.T) { indentExpected string data interface{} }{ + // HeadInt32Zero { name: "HeadInt32Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverInt32(t *testing.T) { A int32 `json:"a"` }{}, }, + { + name: "HeadInt32ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int32 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadInt32ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A int32 `json:"a,string"` + }{}, + }, + + // HeadInt32 { name: "HeadInt32", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverInt32(t *testing.T) { A int32 `json:"a"` }{A: 1}, }, + { + name: "HeadInt32OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A int32 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadInt32String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A int32 `json:"a,string"` + }{A: 1}, + }, + + // HeadInt32Ptr { name: "HeadInt32Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverInt32(t *testing.T) { A *int32 `json:"a"` }{A: int32ptr(1)}, }, + { + name: "HeadInt32PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *int32 `json:"a,omitempty"` + }{A: int32ptr(1)}, + }, + { + name: "HeadInt32PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *int32 `json:"a,string"` + }{A: int32ptr(1)}, + }, + + // HeadInt32PtrNil { name: "HeadInt32PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverInt32(t *testing.T) { A *int32 `json:"a"` }{A: nil}, }, + { + name: "HeadInt32PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int32 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadInt32PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *int32 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt32Zero { name: "PtrHeadInt32Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverInt32(t *testing.T) { A int32 `json:"a"` }{}, }, + { + name: "PtrHeadInt32ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int32 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadInt32ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A int32 `json:"a,string"` + }{}, + }, + + // PtrHeadInt32 { name: "PtrHeadInt32", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverInt32(t *testing.T) { A int32 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadInt32OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A int32 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadInt32String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A int32 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadInt32Ptr { name: "PtrHeadInt32Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverInt32(t *testing.T) { A *int32 `json:"a"` }{A: int32ptr(1)}, }, + { + name: "PtrHeadInt32PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *int32 `json:"a,omitempty"` + }{A: int32ptr(1)}, + }, + { + name: "PtrHeadInt32PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *int32 `json:"a,string"` + }{A: int32ptr(1)}, + }, + + // PtrHeadInt32PtrNil { name: "PtrHeadInt32PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverInt32(t *testing.T) { A *int32 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadInt32PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int32 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt32PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *int32 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt32Nil { name: "PtrHeadInt32Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *int32 `json:"a"` })(nil), }, + { + name: "PtrHeadInt32NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int32 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt32NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int32 `json:"a,string"` + })(nil), + }, + + // HeadInt32ZeroMultiFields { name: "HeadInt32ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B int32 `json:"b"` }{}, }, + { + name: "HeadInt32ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadInt32ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + }{}, + }, + + // HeadInt32MultiFields { name: "HeadInt32MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B int32 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadInt32MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadInt32MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadInt32PtrMultiFields { name: "HeadInt32PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *int32 `json:"b"` }{A: int32ptr(1), B: int32ptr(2)}, }, + { + name: "HeadInt32PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + }{A: int32ptr(1), B: int32ptr(2)}, + }, + { + name: "HeadInt32PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + }{A: int32ptr(1), B: int32ptr(2)}, + }, + + // HeadInt32PtrNilMultiFields { name: "HeadInt32PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *int32 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadInt32PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadInt32PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt32ZeroMultiFields { name: "PtrHeadInt32ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B int32 `json:"b"` }{}, }, + { + name: "PtrHeadInt32ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadInt32ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + }{}, + }, + + // PtrHeadInt32MultiFields { name: "PtrHeadInt32MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B int32 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadInt32MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadInt32MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadInt32PtrMultiFields { name: "PtrHeadInt32PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *int32 `json:"b"` }{A: int32ptr(1), B: int32ptr(2)}, }, + { + name: "PtrHeadInt32PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + }{A: int32ptr(1), B: int32ptr(2)}, + }, + { + name: "PtrHeadInt32PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + }{A: int32ptr(1), B: int32ptr(2)}, + }, + + // PtrHeadInt32PtrNilMultiFields { name: "PtrHeadInt32PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *int32 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadInt32PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt32PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt32NilMultiFields { name: "PtrHeadInt32NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *int32 `json:"b"` })(nil), }, + { + name: "PtrHeadInt32NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt32NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + })(nil), + }, + + // HeadInt32ZeroNotRoot { name: "HeadInt32ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadInt32ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A int32 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt32ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A int32 `json:"a,string"` + } + }{}, + }, + + // HeadInt32NotRoot { name: "HeadInt32NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A int32 `json:"a"` }{A: 1}}, }, + { + name: "HeadInt32NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A int32 `json:"a,omitempty"` + } + }{A: struct { + A int32 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadInt32NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A int32 `json:"a,string"` + } + }{A: struct { + A int32 `json:"a,string"` + }{A: 1}}, + }, + + // HeadInt32PtrNotRoot { name: "HeadInt32PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *int32 `json:"a"` }{int32ptr(1)}}, }, + { + name: "HeadInt32PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *int32 `json:"a,omitempty"` + } + }{A: struct { + A *int32 `json:"a,omitempty"` + }{int32ptr(1)}}, + }, + { + name: "HeadInt32PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *int32 `json:"a,string"` + } + }{A: struct { + A *int32 `json:"a,string"` + }{int32ptr(1)}}, + }, + + // HeadInt32PtrNilNotRoot { name: "HeadInt32PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadInt32PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *int32 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt32PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *int32 `json:"a,string"` + } + }{}, + }, + + // PtrHeadInt32ZeroNotRoot { name: "PtrHeadInt32ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A int32 `json:"a"` })}, }, + { + name: "PtrHeadInt32ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A int32 `json:"a,omitempty"` + } + }{A: new(struct { + A int32 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadInt32ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A int32 `json:"a,string"` + } + }{A: new(struct { + A int32 `json:"a,string"` + })}, + }, + + // PtrHeadInt32NotRoot { name: "PtrHeadInt32NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A int32 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadInt32NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A int32 `json:"a,omitempty"` + } + }{A: &(struct { + A int32 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadInt32NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A int32 `json:"a,string"` + } + }{A: &(struct { + A int32 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadInt32PtrNotRoot { name: "PtrHeadInt32PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *int32 `json:"a"` }{A: int32ptr(1)})}, }, + { + name: "PtrHeadInt32PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *int32 `json:"a,omitempty"` + } + }{A: &(struct { + A *int32 `json:"a,omitempty"` + }{A: int32ptr(1)})}, + }, + { + name: "PtrHeadInt32PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *int32 `json:"a,string"` + } + }{A: &(struct { + A *int32 `json:"a,string"` + }{A: int32ptr(1)})}, + }, + + // PtrHeadInt32PtrNilNotRoot { name: "PtrHeadInt32PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *int32 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadInt32PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *int32 `json:"a,omitempty"` + } + }{A: &(struct { + A *int32 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadInt32PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *int32 `json:"a,string"` + } + }{A: &(struct { + A *int32 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadInt32NilNotRoot { name: "PtrHeadInt32NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadInt32NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *int32 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt32NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *int32 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadInt32ZeroMultiFieldsNotRoot { name: "HeadInt32ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadInt32ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A int32 `json:"a,omitempty"` + } + B struct { + B int32 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadInt32ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A int32 `json:"a,string"` + } + B struct { + B int32 `json:"b,string"` + } + }{}, + }, + + // HeadInt32MultiFieldsNotRoot { name: "HeadInt32MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B int32 `json:"b"` }{B: 2}}, }, + { + name: "HeadInt32MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A int32 `json:"a,omitempty"` + } + B struct { + B int32 `json:"b,omitempty"` + } + }{A: struct { + A int32 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int32 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadInt32MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A int32 `json:"a,string"` + } + B struct { + B int32 `json:"b,string"` + } + }{A: struct { + A int32 `json:"a,string"` + }{A: 1}, B: struct { + B int32 `json:"b,string"` + }{B: 2}}, + }, + + // HeadInt32PtrMultiFieldsNotRoot { name: "HeadInt32PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *int32 `json:"b"` }{B: int32ptr(2)}}, }, + { + name: "HeadInt32PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *int32 `json:"a,omitempty"` + } + B struct { + B *int32 `json:"b,omitempty"` + } + }{A: struct { + A *int32 `json:"a,omitempty"` + }{A: int32ptr(1)}, B: struct { + B *int32 `json:"b,omitempty"` + }{B: int32ptr(2)}}, + }, + { + name: "HeadInt32PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *int32 `json:"a,string"` + } + B struct { + B *int32 `json:"b,string"` + } + }{A: struct { + A *int32 `json:"a,string"` + }{A: int32ptr(1)}, B: struct { + B *int32 `json:"b,string"` + }{B: int32ptr(2)}}, + }, + + // HeadInt32PtrNilMultiFieldsNotRoot { name: "HeadInt32PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *int32 `json:"b"` }{B: nil}}, }, + { + name: "HeadInt32PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *int32 `json:"a,omitempty"` + } + B struct { + B *int32 `json:"b,omitempty"` + } + }{A: struct { + A *int32 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *int32 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadInt32PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *int32 `json:"a,string"` + } + B struct { + B *int32 `json:"b,string"` + } + }{A: struct { + A *int32 `json:"a,string"` + }{A: nil}, B: struct { + B *int32 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadInt32ZeroMultiFieldsNotRoot { name: "PtrHeadInt32ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadInt32ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A int32 `json:"a,omitempty"` + } + B struct { + B int32 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadInt32ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A int32 `json:"a,string"` + } + B struct { + B int32 `json:"b,string"` + } + }{}, + }, + + // PtrHeadInt32MultiFieldsNotRoot { name: "PtrHeadInt32MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B int32 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadInt32MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A int32 `json:"a,omitempty"` + } + B struct { + B int32 `json:"b,omitempty"` + } + }{A: struct { + A int32 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int32 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadInt32MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A int32 `json:"a,string"` + } + B struct { + B int32 `json:"b,string"` + } + }{A: struct { + A int32 `json:"a,string"` + }{A: 1}, B: struct { + B int32 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadInt32PtrMultiFieldsNotRoot { name: "PtrHeadInt32PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *int32 `json:"b"` }{B: int32ptr(2)})}, }, + { + name: "PtrHeadInt32PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *int32 `json:"a,omitempty"` + } + B *struct { + B *int32 `json:"b,omitempty"` + } + }{A: &(struct { + A *int32 `json:"a,omitempty"` + }{A: int32ptr(1)}), B: &(struct { + B *int32 `json:"b,omitempty"` + }{B: int32ptr(2)})}, + }, + { + name: "PtrHeadInt32PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *int32 `json:"a,string"` + } + B *struct { + B *int32 `json:"b,string"` + } + }{A: &(struct { + A *int32 `json:"a,string"` + }{A: int32ptr(1)}), B: &(struct { + B *int32 `json:"b,string"` + }{B: int32ptr(2)})}, + }, + + // PtrHeadInt32PtrNilMultiFieldsNotRoot { name: "PtrHeadInt32PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt32PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int32 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *int32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt32PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int32 `json:"a,string"` + } `json:",string"` + B *struct { + B *int32 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt32NilMultiFieldsNotRoot { name: "PtrHeadInt32NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadInt32NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int32 `json:"a,omitempty"` + } + B *struct { + B *int32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt32NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int32 `json:"a,string"` + } + B *struct { + B *int32 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt32DoubleMultiFieldsNotRoot { name: "PtrHeadInt32DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B int32 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadInt32DoubleMultiFieldsNotRootOmitEmpty", + 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 int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + } + B *struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + } + }{A: &(struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadInt32DoubleMultiFieldsNotRootString", + 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 int32 `json:"a,string"` + B int32 `json:"b,string"` + } + B *struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + } + }{A: &(struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadInt32NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt32NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt32NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt32NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + } + B *struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt32NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt32NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadInt32NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + } + B *struct { + A int32 `json:"a,omitempty"` + B int32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt32NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + } + B *struct { + A int32 `json:"a,string"` + B int32 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt32PtrDoubleMultiFieldsNotRoot { name: "PtrHeadInt32PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *int32 `json:"b"` }{A: int32ptr(3), B: int32ptr(4)})}, }, + { + name: "PtrHeadInt32PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + } + B *struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + } + }{A: &(struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + }{A: int32ptr(1), B: int32ptr(2)}), B: &(struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + }{A: int32ptr(3), B: int32ptr(4)})}, + }, + { + name: "PtrHeadInt32PtrDoubleMultiFieldsNotRootString", + 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 *int32 `json:"a,string"` + B *int32 `json:"b,string"` + } + B *struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + } + }{A: &(struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + }{A: int32ptr(1), B: int32ptr(2)}), B: &(struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + }{A: int32ptr(3), B: int32ptr(4)})}, + }, + + // PtrHeadInt32PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt32PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt32PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt32PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + } + B *struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt32PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt32PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadInt32PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + } + B *struct { + A *int32 `json:"a,omitempty"` + B *int32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt32PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + } + B *struct { + A *int32 `json:"a,string"` + B *int32 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadInt32 { name: "AnonymousHeadInt32", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadInt32OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt32OmitEmpty + B int32 `json:"b,omitempty"` + }{ + structInt32OmitEmpty: structInt32OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadInt32String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt32String + B int32 `json:"b,string"` + }{ + structInt32String: structInt32String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadInt32 { name: "PtrAnonymousHeadInt32", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadInt32OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt32OmitEmpty + B int32 `json:"b,omitempty"` + }{ + structInt32OmitEmpty: &structInt32OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadInt32String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt32String + B int32 `json:"b,string"` + }{ + structInt32String: &structInt32String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadInt32 { name: "NilPtrAnonymousHeadInt32", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadInt32OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt32OmitEmpty + B int32 `json:"b,omitempty"` + }{ + structInt32OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadInt32String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt32String + B int32 `json:"b,string"` + }{ + structInt32String: nil, + B: 2, + }, + }, + + // AnonymousHeadInt32Ptr { name: "AnonymousHeadInt32Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: int32ptr(2), }, }, + { + name: "AnonymousHeadInt32PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt32PtrOmitEmpty + B *int32 `json:"b,omitempty"` + }{ + structInt32PtrOmitEmpty: structInt32PtrOmitEmpty{A: int32ptr(1)}, + B: int32ptr(2), + }, + }, + { + name: "AnonymousHeadInt32PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt32PtrString + B *int32 `json:"b,string"` + }{ + structInt32PtrString: structInt32PtrString{A: int32ptr(1)}, + B: int32ptr(2), + }, + }, + + // AnonymousHeadInt32PtrNil { name: "AnonymousHeadInt32PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: int32ptr(2), }, }, + { + name: "AnonymousHeadInt32PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structInt32PtrOmitEmpty + B *int32 `json:"b,omitempty"` + }{ + structInt32PtrOmitEmpty: structInt32PtrOmitEmpty{A: nil}, + B: int32ptr(2), + }, + }, + { + name: "AnonymousHeadInt32PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structInt32PtrString + B *int32 `json:"b,string"` + }{ + structInt32PtrString: structInt32PtrString{A: nil}, + B: int32ptr(2), + }, + }, + + // PtrAnonymousHeadInt32Ptr { name: "PtrAnonymousHeadInt32Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: int32ptr(2), }, }, + { + name: "PtrAnonymousHeadInt32PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt32PtrOmitEmpty + B *int32 `json:"b,omitempty"` + }{ + structInt32PtrOmitEmpty: &structInt32PtrOmitEmpty{A: int32ptr(1)}, + B: int32ptr(2), + }, + }, + { + name: "PtrAnonymousHeadInt32PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt32PtrString + B *int32 `json:"b,string"` + }{ + structInt32PtrString: &structInt32PtrString{A: int32ptr(1)}, + B: int32ptr(2), + }, + }, + + // NilPtrAnonymousHeadInt32Ptr { name: "NilPtrAnonymousHeadInt32Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: int32ptr(2), }, }, + { + name: "NilPtrAnonymousHeadInt32PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt32PtrOmitEmpty + B *int32 `json:"b,omitempty"` + }{ + structInt32PtrOmitEmpty: nil, + B: int32ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadInt32PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt32PtrString + B *int32 `json:"b,string"` + }{ + structInt32PtrString: nil, + B: int32ptr(2), + }, + }, + + // AnonymousHeadInt32Only { name: "AnonymousHeadInt32Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structInt32: structInt32{A: 1}, }, }, + { + name: "AnonymousHeadInt32OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt32OmitEmpty + }{ + structInt32OmitEmpty: structInt32OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadInt32OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt32String + }{ + structInt32String: structInt32String{A: 1}, + }, + }, + + // PtrAnonymousHeadInt32Only { name: "PtrAnonymousHeadInt32Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structInt32: &structInt32{A: 1}, }, }, + { + name: "PtrAnonymousHeadInt32OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt32OmitEmpty + }{ + structInt32OmitEmpty: &structInt32OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadInt32OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt32String + }{ + structInt32String: &structInt32String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadInt32Only { name: "NilPtrAnonymousHeadInt32Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structInt32: nil, }, }, + { + name: "NilPtrAnonymousHeadInt32OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt32OmitEmpty + }{ + structInt32OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt32OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt32String + }{ + structInt32String: nil, + }, + }, + + // AnonymousHeadInt32PtrOnly { name: "AnonymousHeadInt32PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structInt32Ptr: structInt32Ptr{A: int32ptr(1)}, }, }, + { + name: "AnonymousHeadInt32PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt32PtrOmitEmpty + }{ + structInt32PtrOmitEmpty: structInt32PtrOmitEmpty{A: int32ptr(1)}, + }, + }, + { + name: "AnonymousHeadInt32PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt32PtrString + }{ + structInt32PtrString: structInt32PtrString{A: int32ptr(1)}, + }, + }, + + // AnonymousHeadInt32PtrNilOnly { name: "AnonymousHeadInt32PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structInt32Ptr: structInt32Ptr{A: nil}, }, }, + { + name: "AnonymousHeadInt32PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structInt32PtrOmitEmpty + }{ + structInt32PtrOmitEmpty: structInt32PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadInt32PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structInt32PtrString + }{ + structInt32PtrString: structInt32PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadInt32PtrOnly { name: "PtrAnonymousHeadInt32PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structInt32Ptr: &structInt32Ptr{A: int32ptr(1)}, }, }, + { + name: "PtrAnonymousHeadInt32PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt32PtrOmitEmpty + }{ + structInt32PtrOmitEmpty: &structInt32PtrOmitEmpty{A: int32ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadInt32PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt32PtrString + }{ + structInt32PtrString: &structInt32PtrString{A: int32ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadInt32PtrOnly { name: "NilPtrAnonymousHeadInt32PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structInt32Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadInt32PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt32PtrOmitEmpty + }{ + structInt32PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt32PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt32PtrString + }{ + structInt32PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { diff --git a/encode_vm.go b/encode_vm.go index f709239..5ca7430 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -1998,6 +1998,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt32(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 opStructFieldPtrHeadStringTagInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt32Only, opStructFieldHeadInt32Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -2005,6 +2050,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendInt(b, int64(e.ptrToInt32(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Only, opStructFieldHeadOmitEmptyInt32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := int64(e.ptrToInt32(p)) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt32Only, opStructFieldHeadStringTagInt32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt32(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2027,6 +2091,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2048,6 +2155,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32PtrOnly: + 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 opStructFieldHeadOmitEmptyInt32PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt32(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt32PtrOnly: + 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 opStructFieldHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt32NPtr: + 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.ptrToInt32(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2061,6 +2231,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Only, opStructFieldAnonymousHeadInt32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2071,6 +2280,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Only, opStructFieldAnonymousHeadOmitEmptyInt32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32Only, opStructFieldAnonymousHeadStringTagInt32Only: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2089,6 +2325,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2107,6 +2381,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt32(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3605,51 +3918,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt32(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 opStructFieldPtrHeadOmitEmptyInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4343,45 +4611,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt32: - 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.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt32: - 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.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5935,6 +6164,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyInt32Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, int64(e.ptrToInt32(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt32Ptr: + b = append(b, code.key...) + 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.ptrToInt32(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt32NPtr: + 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.ptrToInt32(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndInt64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index d368f64..3cfb7ca 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -1958,6 +1958,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt32(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 opStructFieldPtrHeadStringTagInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt32Only, opStructFieldHeadInt32Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -1965,6 +2010,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendInt(b, int64(e.ptrToInt32(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Only, opStructFieldHeadOmitEmptyInt32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := int64(e.ptrToInt32(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt32Only, opStructFieldHeadStringTagInt32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, int64(e.ptrToInt32(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -1987,6 +2051,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2008,6 +2115,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32PtrOnly: + 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 opStructFieldHeadOmitEmptyInt32PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt32(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt32PtrOnly: + 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 opStructFieldHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt32NPtr: + 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.ptrToInt32(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2021,6 +2191,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Only, opStructFieldAnonymousHeadInt32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2031,6 +2240,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Only, opStructFieldAnonymousHeadOmitEmptyInt32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32Only, opStructFieldAnonymousHeadStringTagInt32Only: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2049,6 +2285,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2067,6 +2341,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt32(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3572,51 +3885,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt32(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 opStructFieldPtrHeadOmitEmptyInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4310,45 +4578,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt32: - 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.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt32: - 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.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5961,6 +6190,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyInt32Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, int64(e.ptrToInt32(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt32Ptr: + 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.ptrToInt32(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt32NPtr: + 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.ptrToInt32(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndInt64: 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 dc352cc..353b0dc 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -2123,6 +2123,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt32: + 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.ptrToInt32(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 opStructFieldPtrHeadStringTagInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt32Only, opStructFieldHeadInt32Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -2132,6 +2180,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, int64(e.ptrToInt32(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Only, opStructFieldHeadOmitEmptyInt32Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := int64(e.ptrToInt32(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 opStructFieldPtrHeadStringTagInt32Only, opStructFieldHeadStringTagInt32Only: + 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.ptrToInt32(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2156,6 +2226,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2179,6 +2296,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32PtrOnly: + 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 opStructFieldHeadOmitEmptyInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt32PtrOnly: + 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 opStructFieldHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt32NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -2217,6 +2380,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Only, opStructFieldAnonymousHeadInt32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2229,6 +2429,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Only, opStructFieldAnonymousHeadOmitEmptyInt32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32Only, opStructFieldAnonymousHeadStringTagInt32Only: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2249,6 +2480,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2269,6 +2542,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3677,34 +3992,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt32: - 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.ptrToInt32(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 opStructFieldPtrHeadOmitEmptyInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4037,29 +4324,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt32: - 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.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5276,8 +5540,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 opStructEndStringTagInt32: ptr := load(ctxptr, code.headIdx) @@ -5301,6 +5574,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt32Ptr: + 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.ptrToInt32(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 opStructEndStringTagInt32Ptr: + 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.ptrToInt32(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt64: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 236cd7c..4ccdce6 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -2123,6 +2123,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt32: + 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.ptrToInt32(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 opStructFieldPtrHeadStringTagInt32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt32Only, opStructFieldHeadInt32Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -2132,6 +2180,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, int64(e.ptrToInt32(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Only, opStructFieldHeadOmitEmptyInt32Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := int64(e.ptrToInt32(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 opStructFieldPtrHeadStringTagInt32Only, opStructFieldHeadStringTagInt32Only: + 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.ptrToInt32(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2156,6 +2226,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2179,6 +2296,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt32PtrOnly: + 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 opStructFieldHeadOmitEmptyInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt32PtrOnly: + 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 opStructFieldHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt32NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -2217,6 +2380,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Only, opStructFieldAnonymousHeadInt32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2229,6 +2429,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Only, opStructFieldAnonymousHeadOmitEmptyInt32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt32(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 opStructFieldPtrAnonymousHeadStringTagInt32Only, opStructFieldAnonymousHeadStringTagInt32Only: + 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.ptrToInt32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2249,6 +2480,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32Ptr: + 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.ptrToInt32(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32Ptr: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2269,6 +2542,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt32PtrOnly: + 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.ptrToInt32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3677,34 +3992,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt32: - 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.ptrToInt32(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 opStructFieldPtrHeadOmitEmptyInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4037,29 +4324,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt32: - 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.ptrToInt32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagInt64: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5276,8 +5540,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 opStructEndStringTagInt32: ptr := load(ctxptr, code.headIdx) @@ -5301,6 +5574,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt32Ptr: + 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.ptrToInt32(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 opStructEndStringTagInt32Ptr: + 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.ptrToInt32(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndInt64: b = e.encodeIndent(b, code.indent) b = append(b, code.key...)