From 861236119af04c4ec41bf7309e3394aacecf91ad Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 18 Jan 2021 21:50:52 +0900 Subject: [PATCH 1/2] 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...) From 5eaa3c023c5bb52a52b4ca703a2cc915b4bdc006 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 18 Jan 2021 22:35:10 +0900 Subject: [PATCH 2/2] Add test cases for int64 type --- cover_int64_test.go | 1948 +++++++++++++++++++++++++++++++++++ encode_vm.go | 437 ++++++-- encode_vm_escaped.go | 476 ++++++--- encode_vm_escaped_indent.go | 412 +++++++- encode_vm_indent.go | 428 ++++++-- 5 files changed, 3379 insertions(+), 322 deletions(-) diff --git a/cover_int64_test.go b/cover_int64_test.go index 4d371c6..990cc0c 100644 --- a/cover_int64_test.go +++ b/cover_int64_test.go @@ -12,9 +12,22 @@ func TestCoverInt64(t *testing.T) { type structInt64 struct { A int64 `json:"a"` } + type structInt64OmitEmpty struct { + A int64 `json:"a,omitempty"` + } + type structInt64String struct { + A int64 `json:"a,string"` + } + type structInt64Ptr struct { A *int64 `json:"a"` } + type structInt64PtrOmitEmpty struct { + A *int64 `json:"a,omitempty"` + } + type structInt64PtrString struct { + A *int64 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverInt64(t *testing.T) { indentExpected string data interface{} }{ + // HeadInt64Zero { name: "HeadInt64Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverInt64(t *testing.T) { A int64 `json:"a"` }{}, }, + { + name: "HeadInt64ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int64 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadInt64ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A int64 `json:"a,string"` + }{}, + }, + + // HeadInt64 { name: "HeadInt64", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverInt64(t *testing.T) { A int64 `json:"a"` }{A: 1}, }, + { + name: "HeadInt64OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A int64 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadInt64String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A int64 `json:"a,string"` + }{A: 1}, + }, + + // HeadInt64Ptr { name: "HeadInt64Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverInt64(t *testing.T) { A *int64 `json:"a"` }{A: int64ptr(1)}, }, + { + name: "HeadInt64PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *int64 `json:"a,omitempty"` + }{A: int64ptr(1)}, + }, + { + name: "HeadInt64PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *int64 `json:"a,string"` + }{A: int64ptr(1)}, + }, + + // HeadInt64PtrNil { name: "HeadInt64PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverInt64(t *testing.T) { A *int64 `json:"a"` }{A: nil}, }, + { + name: "HeadInt64PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int64 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadInt64PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *int64 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt64Zero { name: "PtrHeadInt64Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverInt64(t *testing.T) { A int64 `json:"a"` }{}, }, + { + name: "PtrHeadInt64ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int64 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadInt64ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A int64 `json:"a,string"` + }{}, + }, + + // PtrHeadInt64 { name: "PtrHeadInt64", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverInt64(t *testing.T) { A int64 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadInt64OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A int64 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadInt64String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A int64 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadInt64Ptr { name: "PtrHeadInt64Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverInt64(t *testing.T) { A *int64 `json:"a"` }{A: int64ptr(1)}, }, + { + name: "PtrHeadInt64PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *int64 `json:"a,omitempty"` + }{A: int64ptr(1)}, + }, + { + name: "PtrHeadInt64PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *int64 `json:"a,string"` + }{A: int64ptr(1)}, + }, + + // PtrHeadInt64PtrNil { name: "PtrHeadInt64PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverInt64(t *testing.T) { A *int64 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadInt64PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int64 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt64PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *int64 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadInt64Nil { name: "PtrHeadInt64Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *int64 `json:"a"` })(nil), }, + { + name: "PtrHeadInt64NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int64 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt64NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int64 `json:"a,string"` + })(nil), + }, + + // HeadInt64ZeroMultiFields { name: "HeadInt64ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B int64 `json:"b"` }{}, }, + { + name: "HeadInt64ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadInt64ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + }{}, + }, + + // HeadInt64MultiFields { name: "HeadInt64MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B int64 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadInt64MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadInt64MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadInt64PtrMultiFields { name: "HeadInt64PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *int64 `json:"b"` }{A: int64ptr(1), B: int64ptr(2)}, }, + { + name: "HeadInt64PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + }{A: int64ptr(1), B: int64ptr(2)}, + }, + { + name: "HeadInt64PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + }{A: int64ptr(1), B: int64ptr(2)}, + }, + + // HeadInt64PtrNilMultiFields { name: "HeadInt64PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *int64 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadInt64PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadInt64PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt64ZeroMultiFields { name: "PtrHeadInt64ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B int64 `json:"b"` }{}, }, + { + name: "PtrHeadInt64ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadInt64ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + }{}, + }, + + // PtrHeadInt64MultiFields { name: "PtrHeadInt64MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B int64 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadInt64MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadInt64MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadInt64PtrMultiFields { name: "PtrHeadInt64PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *int64 `json:"b"` }{A: int64ptr(1), B: int64ptr(2)}, }, + { + name: "PtrHeadInt64PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + }{A: int64ptr(1), B: int64ptr(2)}, + }, + { + name: "PtrHeadInt64PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + }{A: int64ptr(1), B: int64ptr(2)}, + }, + + // PtrHeadInt64PtrNilMultiFields { name: "PtrHeadInt64PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *int64 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadInt64PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt64PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt64NilMultiFields { name: "PtrHeadInt64NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *int64 `json:"b"` })(nil), }, + { + name: "PtrHeadInt64NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadInt64NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + })(nil), + }, + + // HeadInt64ZeroNotRoot { name: "HeadInt64ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadInt64ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A int64 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt64ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A int64 `json:"a,string"` + } + }{}, + }, + + // HeadInt64NotRoot { name: "HeadInt64NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A int64 `json:"a"` }{A: 1}}, }, + { + name: "HeadInt64NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A int64 `json:"a,omitempty"` + } + }{A: struct { + A int64 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadInt64NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A int64 `json:"a,string"` + } + }{A: struct { + A int64 `json:"a,string"` + }{A: 1}}, + }, + + // HeadInt64PtrNotRoot { name: "HeadInt64PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *int64 `json:"a"` }{int64ptr(1)}}, }, + { + name: "HeadInt64PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *int64 `json:"a,omitempty"` + } + }{A: struct { + A *int64 `json:"a,omitempty"` + }{int64ptr(1)}}, + }, + { + name: "HeadInt64PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *int64 `json:"a,string"` + } + }{A: struct { + A *int64 `json:"a,string"` + }{int64ptr(1)}}, + }, + + // HeadInt64PtrNilNotRoot { name: "HeadInt64PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadInt64PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *int64 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadInt64PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *int64 `json:"a,string"` + } + }{}, + }, + + // PtrHeadInt64ZeroNotRoot { name: "PtrHeadInt64ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A int64 `json:"a"` })}, }, + { + name: "PtrHeadInt64ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A int64 `json:"a,omitempty"` + } + }{A: new(struct { + A int64 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadInt64ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A int64 `json:"a,string"` + } + }{A: new(struct { + A int64 `json:"a,string"` + })}, + }, + + // PtrHeadInt64NotRoot { name: "PtrHeadInt64NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A int64 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadInt64NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A int64 `json:"a,omitempty"` + } + }{A: &(struct { + A int64 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadInt64NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A int64 `json:"a,string"` + } + }{A: &(struct { + A int64 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadInt64PtrNotRoot { name: "PtrHeadInt64PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *int64 `json:"a"` }{A: int64ptr(1)})}, }, + { + name: "PtrHeadInt64PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *int64 `json:"a,omitempty"` + } + }{A: &(struct { + A *int64 `json:"a,omitempty"` + }{A: int64ptr(1)})}, + }, + { + name: "PtrHeadInt64PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *int64 `json:"a,string"` + } + }{A: &(struct { + A *int64 `json:"a,string"` + }{A: int64ptr(1)})}, + }, + + // PtrHeadInt64PtrNilNotRoot { name: "PtrHeadInt64PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *int64 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadInt64PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *int64 `json:"a,omitempty"` + } + }{A: &(struct { + A *int64 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadInt64PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *int64 `json:"a,string"` + } + }{A: &(struct { + A *int64 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadInt64NilNotRoot { name: "PtrHeadInt64NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadInt64NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *int64 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadInt64NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *int64 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadInt64ZeroMultiFieldsNotRoot { name: "HeadInt64ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadInt64ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A int64 `json:"a,omitempty"` + } + B struct { + B int64 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadInt64ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A int64 `json:"a,string"` + } + B struct { + B int64 `json:"b,string"` + } + }{}, + }, + + // HeadInt64MultiFieldsNotRoot { name: "HeadInt64MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B int64 `json:"b"` }{B: 2}}, }, + { + name: "HeadInt64MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A int64 `json:"a,omitempty"` + } + B struct { + B int64 `json:"b,omitempty"` + } + }{A: struct { + A int64 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int64 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadInt64MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A int64 `json:"a,string"` + } + B struct { + B int64 `json:"b,string"` + } + }{A: struct { + A int64 `json:"a,string"` + }{A: 1}, B: struct { + B int64 `json:"b,string"` + }{B: 2}}, + }, + + // HeadInt64PtrMultiFieldsNotRoot { name: "HeadInt64PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *int64 `json:"b"` }{B: int64ptr(2)}}, }, + { + name: "HeadInt64PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *int64 `json:"a,omitempty"` + } + B struct { + B *int64 `json:"b,omitempty"` + } + }{A: struct { + A *int64 `json:"a,omitempty"` + }{A: int64ptr(1)}, B: struct { + B *int64 `json:"b,omitempty"` + }{B: int64ptr(2)}}, + }, + { + name: "HeadInt64PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *int64 `json:"a,string"` + } + B struct { + B *int64 `json:"b,string"` + } + }{A: struct { + A *int64 `json:"a,string"` + }{A: int64ptr(1)}, B: struct { + B *int64 `json:"b,string"` + }{B: int64ptr(2)}}, + }, + + // HeadInt64PtrNilMultiFieldsNotRoot { name: "HeadInt64PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *int64 `json:"b"` }{B: nil}}, }, + { + name: "HeadInt64PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *int64 `json:"a,omitempty"` + } + B struct { + B *int64 `json:"b,omitempty"` + } + }{A: struct { + A *int64 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *int64 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadInt64PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *int64 `json:"a,string"` + } + B struct { + B *int64 `json:"b,string"` + } + }{A: struct { + A *int64 `json:"a,string"` + }{A: nil}, B: struct { + B *int64 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadInt64ZeroMultiFieldsNotRoot { name: "PtrHeadInt64ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadInt64ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A int64 `json:"a,omitempty"` + } + B struct { + B int64 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadInt64ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A int64 `json:"a,string"` + } + B struct { + B int64 `json:"b,string"` + } + }{}, + }, + + // PtrHeadInt64MultiFieldsNotRoot { name: "PtrHeadInt64MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B int64 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadInt64MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A int64 `json:"a,omitempty"` + } + B struct { + B int64 `json:"b,omitempty"` + } + }{A: struct { + A int64 `json:"a,omitempty"` + }{A: 1}, B: struct { + B int64 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadInt64MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A int64 `json:"a,string"` + } + B struct { + B int64 `json:"b,string"` + } + }{A: struct { + A int64 `json:"a,string"` + }{A: 1}, B: struct { + B int64 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadInt64PtrMultiFieldsNotRoot { name: "PtrHeadInt64PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *int64 `json:"b"` }{B: int64ptr(2)})}, }, + { + name: "PtrHeadInt64PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *int64 `json:"a,omitempty"` + } + B *struct { + B *int64 `json:"b,omitempty"` + } + }{A: &(struct { + A *int64 `json:"a,omitempty"` + }{A: int64ptr(1)}), B: &(struct { + B *int64 `json:"b,omitempty"` + }{B: int64ptr(2)})}, + }, + { + name: "PtrHeadInt64PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *int64 `json:"a,string"` + } + B *struct { + B *int64 `json:"b,string"` + } + }{A: &(struct { + A *int64 `json:"a,string"` + }{A: int64ptr(1)}), B: &(struct { + B *int64 `json:"b,string"` + }{B: int64ptr(2)})}, + }, + + // PtrHeadInt64PtrNilMultiFieldsNotRoot { name: "PtrHeadInt64PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt64PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int64 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *int64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt64PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int64 `json:"a,string"` + } `json:",string"` + B *struct { + B *int64 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadInt64NilMultiFieldsNotRoot { name: "PtrHeadInt64NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadInt64NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int64 `json:"a,omitempty"` + } + B *struct { + B *int64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt64NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int64 `json:"a,string"` + } + B *struct { + B *int64 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt64DoubleMultiFieldsNotRoot { name: "PtrHeadInt64DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B int64 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadInt64DoubleMultiFieldsNotRootOmitEmpty", + 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 int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + } + B *struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + } + }{A: &(struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadInt64DoubleMultiFieldsNotRootString", + 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 int64 `json:"a,string"` + B int64 `json:"b,string"` + } + B *struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + } + }{A: &(struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadInt64NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt64NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt64NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt64NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + } + B *struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt64NilDoubleMultiFieldsNotRoot { name: "PtrHeadInt64NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadInt64NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + } + B *struct { + A int64 `json:"a,omitempty"` + B int64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt64NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + } + B *struct { + A int64 `json:"a,string"` + B int64 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadInt64PtrDoubleMultiFieldsNotRoot { name: "PtrHeadInt64PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *int64 `json:"b"` }{A: int64ptr(3), B: int64ptr(4)})}, }, + { + name: "PtrHeadInt64PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + } + B *struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + } + }{A: &(struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + }{A: int64ptr(1), B: int64ptr(2)}), B: &(struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + }{A: int64ptr(3), B: int64ptr(4)})}, + }, + { + name: "PtrHeadInt64PtrDoubleMultiFieldsNotRootString", + 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 *int64 `json:"a,string"` + B *int64 `json:"b,string"` + } + B *struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + } + }{A: &(struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + }{A: int64ptr(1), B: int64ptr(2)}), B: &(struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + }{A: int64ptr(3), B: int64ptr(4)})}, + }, + + // PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + } + B *struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + } + B *struct { + A *int64 `json:"a,omitempty"` + B *int64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadInt64PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + } + B *struct { + A *int64 `json:"a,string"` + B *int64 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadInt64 { name: "AnonymousHeadInt64", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadInt64OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt64OmitEmpty + B int64 `json:"b,omitempty"` + }{ + structInt64OmitEmpty: structInt64OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadInt64String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt64String + B int64 `json:"b,string"` + }{ + structInt64String: structInt64String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadInt64 { name: "PtrAnonymousHeadInt64", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadInt64OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt64OmitEmpty + B int64 `json:"b,omitempty"` + }{ + structInt64OmitEmpty: &structInt64OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadInt64String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt64String + B int64 `json:"b,string"` + }{ + structInt64String: &structInt64String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadInt64 { name: "NilPtrAnonymousHeadInt64", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadInt64OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt64OmitEmpty + B int64 `json:"b,omitempty"` + }{ + structInt64OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadInt64String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt64String + B int64 `json:"b,string"` + }{ + structInt64String: nil, + B: 2, + }, + }, + + // AnonymousHeadInt64Ptr { name: "AnonymousHeadInt64Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: int64ptr(2), }, }, + { + name: "AnonymousHeadInt64PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structInt64PtrOmitEmpty + B *int64 `json:"b,omitempty"` + }{ + structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: int64ptr(1)}, + B: int64ptr(2), + }, + }, + { + name: "AnonymousHeadInt64PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structInt64PtrString + B *int64 `json:"b,string"` + }{ + structInt64PtrString: structInt64PtrString{A: int64ptr(1)}, + B: int64ptr(2), + }, + }, + + // AnonymousHeadInt64PtrNil { name: "AnonymousHeadInt64PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: int64ptr(2), }, }, + { + name: "AnonymousHeadInt64PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structInt64PtrOmitEmpty + B *int64 `json:"b,omitempty"` + }{ + structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: nil}, + B: int64ptr(2), + }, + }, + { + name: "AnonymousHeadInt64PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structInt64PtrString + B *int64 `json:"b,string"` + }{ + structInt64PtrString: structInt64PtrString{A: nil}, + B: int64ptr(2), + }, + }, + + // PtrAnonymousHeadInt64Ptr { name: "PtrAnonymousHeadInt64Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: int64ptr(2), }, }, + { + name: "PtrAnonymousHeadInt64PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structInt64PtrOmitEmpty + B *int64 `json:"b,omitempty"` + }{ + structInt64PtrOmitEmpty: &structInt64PtrOmitEmpty{A: int64ptr(1)}, + B: int64ptr(2), + }, + }, + { + name: "PtrAnonymousHeadInt64PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structInt64PtrString + B *int64 `json:"b,string"` + }{ + structInt64PtrString: &structInt64PtrString{A: int64ptr(1)}, + B: int64ptr(2), + }, + }, + + // NilPtrAnonymousHeadInt64Ptr { name: "NilPtrAnonymousHeadInt64Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: int64ptr(2), }, }, + { + name: "NilPtrAnonymousHeadInt64PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structInt64PtrOmitEmpty + B *int64 `json:"b,omitempty"` + }{ + structInt64PtrOmitEmpty: nil, + B: int64ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadInt64PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structInt64PtrString + B *int64 `json:"b,string"` + }{ + structInt64PtrString: nil, + B: int64ptr(2), + }, + }, + + // AnonymousHeadInt64Only { name: "AnonymousHeadInt64Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structInt64: structInt64{A: 1}, }, }, + { + name: "AnonymousHeadInt64OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt64OmitEmpty + }{ + structInt64OmitEmpty: structInt64OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadInt64OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt64String + }{ + structInt64String: structInt64String{A: 1}, + }, + }, + + // PtrAnonymousHeadInt64Only { name: "PtrAnonymousHeadInt64Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structInt64: &structInt64{A: 1}, }, }, + { + name: "PtrAnonymousHeadInt64OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt64OmitEmpty + }{ + structInt64OmitEmpty: &structInt64OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadInt64OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt64String + }{ + structInt64String: &structInt64String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadInt64Only { name: "NilPtrAnonymousHeadInt64Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structInt64: nil, }, }, + { + name: "NilPtrAnonymousHeadInt64OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt64OmitEmpty + }{ + structInt64OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt64OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt64String + }{ + structInt64String: nil, + }, + }, + + // AnonymousHeadInt64PtrOnly { name: "AnonymousHeadInt64PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structInt64Ptr: structInt64Ptr{A: int64ptr(1)}, }, }, + { + name: "AnonymousHeadInt64PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structInt64PtrOmitEmpty + }{ + structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: int64ptr(1)}, + }, + }, + { + name: "AnonymousHeadInt64PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structInt64PtrString + }{ + structInt64PtrString: structInt64PtrString{A: int64ptr(1)}, + }, + }, + + // AnonymousHeadInt64PtrNilOnly { name: "AnonymousHeadInt64PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structInt64Ptr: structInt64Ptr{A: nil}, }, }, + { + name: "AnonymousHeadInt64PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structInt64PtrOmitEmpty + }{ + structInt64PtrOmitEmpty: structInt64PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadInt64PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structInt64PtrString + }{ + structInt64PtrString: structInt64PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadInt64PtrOnly { name: "PtrAnonymousHeadInt64PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structInt64Ptr: &structInt64Ptr{A: int64ptr(1)}, }, }, + { + name: "PtrAnonymousHeadInt64PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structInt64PtrOmitEmpty + }{ + structInt64PtrOmitEmpty: &structInt64PtrOmitEmpty{A: int64ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadInt64PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structInt64PtrString + }{ + structInt64PtrString: &structInt64PtrString{A: int64ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadInt64PtrOnly { name: "NilPtrAnonymousHeadInt64PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structInt64Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadInt64PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt64PtrOmitEmpty + }{ + structInt64PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadInt64PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structInt64PtrString + }{ + structInt64PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { diff --git a/encode_vm.go b/encode_vm.go index 5ca7430..01761cc 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -2419,7 +2419,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldPtrHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2436,6 +2435,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt64: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt64Only, opStructFieldHeadInt64Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -2443,6 +2487,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendInt(b, e.ptrToInt64(p)) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Only, opStructFieldHeadOmitEmptyInt64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToInt64(p) + if v != 0 { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt64Only, opStructFieldHeadStringTagInt64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2465,6 +2528,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2486,6 +2592,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64PtrOnly: + 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 opStructFieldHeadOmitEmptyInt64PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, e.ptrToInt64(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt64PtrOnly: + 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 opStructFieldHeadStringTagInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt64NPtr: + 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, e.ptrToInt64(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2499,6 +2668,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Only, opStructFieldAnonymousHeadInt64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2509,6 +2717,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Only, opStructFieldAnonymousHeadOmitEmptyInt64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64Only, opStructFieldAnonymousHeadStringTagInt64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2527,6 +2762,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2545,6 +2818,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendInt(b, e.ptrToInt64(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldPtrHeadUint: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3918,51 +4230,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendInt(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendInt(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4611,45 +4878,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt64: - 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, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6237,6 +6465,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyInt64Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendInt(b, e.ptrToInt64(p)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt64Ptr: + 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, e.ptrToInt64(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt64NPtr: + 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, e.ptrToInt64(p)) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 3cfb7ca..2bdb2e6 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -2379,7 +2379,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next - case opStructFieldPtrHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2396,6 +2395,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToInt64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt64: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadInt64Only, opStructFieldHeadInt64Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -2403,6 +2447,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendInt(b, e.ptrToInt64(p)) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Only, opStructFieldHeadOmitEmptyInt64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToInt64(p) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt64Only, opStructFieldHeadStringTagInt64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2425,6 +2488,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2446,6 +2552,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64PtrOnly: + 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 opStructFieldHeadOmitEmptyInt64PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, e.ptrToInt64(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt64PtrOnly: + 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 opStructFieldHeadStringTagInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadInt64NPtr: + 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, e.ptrToInt64(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2459,6 +2628,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Only, opStructFieldAnonymousHeadInt64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2469,6 +2677,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Only, opStructFieldAnonymousHeadOmitEmptyInt64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64Only, opStructFieldAnonymousHeadStringTagInt64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2487,6 +2722,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2505,6 +2778,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendInt(b, e.ptrToInt64(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendInt(b, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3885,51 +4196,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToInt64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendInt(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToInt64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendInt(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4578,85 +4844,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt64: - 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, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagInt64Only: - p := load(ctxptr, code.idx) - if p == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - break - } - fallthrough - case opStructFieldHeadStringTagInt64Only: - p := load(ctxptr, code.idx) - b = append(b, '{') - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(p+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - case opStructFieldPtrHeadStringTagInt64PtrOnly: - p := load(ctxptr, code.idx) - if p == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - break - } - fallthrough - case opStructFieldHeadStringTagInt64PtrOnly: - 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, e.ptrToInt64(p+code.offset)) - b = append(b, '"') - } - b = encodeComma(b) - code = code.next - case opStructFieldPtrAnonymousHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6263,6 +6450,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyInt64Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendInt(b, e.ptrToInt64(p)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagInt64Ptr: + 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, e.ptrToInt64(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndInt64NPtr: + 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, e.ptrToInt64(p)) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint: 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 353b0dc..a004754 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -2602,6 +2602,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt64: + 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.ptrToInt64(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, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt64: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt64Only, opStructFieldHeadInt64Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -2611,6 +2659,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendInt(b, e.ptrToInt64(p)) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Only, opStructFieldHeadOmitEmptyInt64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToInt64(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 opStructFieldPtrHeadStringTagInt64Only, opStructFieldHeadStringTagInt64Only: + 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, e.ptrToInt64(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2635,6 +2705,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2658,6 +2775,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64PtrOnly: + 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 opStructFieldHeadOmitEmptyInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt64PtrOnly: + 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 opStructFieldHeadStringTagInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt64NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -2696,6 +2859,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(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, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Only, opStructFieldAnonymousHeadInt64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2708,6 +2908,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Only, opStructFieldAnonymousHeadOmitEmptyInt64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(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, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64Only, opStructFieldAnonymousHeadStringTagInt64Only: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2728,6 +2959,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2748,6 +3021,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3992,34 +4307,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt64: - 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.ptrToInt64(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, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4324,29 +4611,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt64: - 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, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5625,8 +5889,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = appendInt(b, 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 opStructEndStringTagInt64: ptr := load(ctxptr, code.headIdx) @@ -5650,6 +5923,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt64Ptr: + 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, e.ptrToInt64(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 opStructEndStringTagInt64Ptr: + 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, e.ptrToInt64(p)) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 4ccdce6..325275c 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -2602,6 +2602,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyInt64: + 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.ptrToInt64(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, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagInt64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagInt64: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadInt64Only, opStructFieldHeadInt64Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -2611,6 +2659,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, e.ptrToInt64(p)) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Only, opStructFieldHeadOmitEmptyInt64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToInt64(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 opStructFieldPtrHeadStringTagInt64Only, opStructFieldHeadStringTagInt64Only: + 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, e.ptrToInt64(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2635,6 +2705,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2658,6 +2775,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyInt64PtrOnly: + 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 opStructFieldHeadOmitEmptyInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagInt64PtrOnly: + 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 opStructFieldHeadStringTagInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadInt64NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -2696,6 +2859,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(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, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Only, opStructFieldAnonymousHeadInt64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2708,6 +2908,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Only, opStructFieldAnonymousHeadOmitEmptyInt64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToInt64(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, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagInt64Only, opStructFieldAnonymousHeadStringTagInt64Only: + 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, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadInt64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2728,6 +2959,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64Ptr: + 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, e.ptrToInt64(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64Ptr: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadInt64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2748,6 +3021,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagInt64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagInt64PtrOnly: + 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, e.ptrToInt64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3992,34 +4307,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyInt64: - 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.ptrToInt64(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, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4324,29 +4611,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagInt64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagInt64: - 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, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagUint: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5617,15 +5881,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendInt(b, e.ptrToInt64(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next - case opStructEndStringTagInt64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendInt(b, e.ptrToInt64(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next case opStructEndOmitEmptyInt64: ptr := load(ctxptr, code.headIdx) v := e.ptrToInt64(ptr + code.offset) @@ -5634,7 +5889,25 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = appendInt(b, v) + b = e.appendStructEndIndent(b, code.indent-1) + } else { + last := len(b) - 1 + if b[last-1] == '{' { + // doesn't exist any fields + b[last] = '}' + } else { + b = append(b, '}') + } + b = encodeIndentComma(b) } + code = code.next + case opStructEndStringTagInt64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendInt(b, e.ptrToInt64(ptr+code.offset)) + b = append(b, '"') b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndInt64Ptr: @@ -5650,6 +5923,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyInt64Ptr: + 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, e.ptrToInt64(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 opStructEndStringTagInt64Ptr: + 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, e.ptrToInt64(p)) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint: b = e.encodeIndent(b, code.indent) b = append(b, code.key...)