diff --git a/cover_helper_test.go b/cover_helper_test.go index 0ff4300..766a2b1 100644 --- a/cover_helper_test.go +++ b/cover_helper_test.go @@ -1,5 +1,10 @@ package json_test +import ( + "bytes" + stdjson "encoding/json" +) + func intptr(v int) *int { return &v } func int8ptr(v int8) *int8 { return &v } func int16ptr(v int16) *int16 { return &v } @@ -13,3 +18,14 @@ func uint64ptr(v uint64) *uint64 { return &v } func float32ptr(v float32) *float32 { return &v } func float64ptr(v float64) *float64 { return &v } func stringptr(v string) *string { return &v } + +func encodeByEncodingJSON(data interface{}, indent, escape bool) string { + var buf bytes.Buffer + enc := stdjson.NewEncoder(&buf) + enc.SetEscapeHTML(escape) + if indent { + enc.SetIndent("", " ") + } + enc.Encode(data) + return buf.String() +} diff --git a/cover_int16_test.go b/cover_int16_test.go index 20b1fdf..933bdc5 100644 --- a/cover_int16_test.go +++ b/cover_int16_test.go @@ -2922,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_int32_test.go b/cover_int32_test.go index f4f87db..80110ae 100644 --- a/cover_int32_test.go +++ b/cover_int32_test.go @@ -2922,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_int64_test.go b/cover_int64_test.go index 990cc0c..18cf876 100644 --- a/cover_int64_test.go +++ b/cover_int64_test.go @@ -2922,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_int8_test.go b/cover_int8_test.go index 3dd8d0a..617efa3 100644 --- a/cover_int8_test.go +++ b/cover_int8_test.go @@ -2922,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_int_test.go b/cover_int_test.go index d50b9ce..1456271 100644 --- a/cover_int_test.go +++ b/cover_int_test.go @@ -2922,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_uint16_test.go b/cover_uint16_test.go index f6fa937..c9834ba 100644 --- a/cover_uint16_test.go +++ b/cover_uint16_test.go @@ -12,9 +12,22 @@ func TestCoverUint16(t *testing.T) { type structUint16 struct { A uint16 `json:"a"` } + type structUint16OmitEmpty struct { + A uint16 `json:"a,omitempty"` + } + type structUint16String struct { + A uint16 `json:"a,string"` + } + type structUint16Ptr struct { A *uint16 `json:"a"` } + type structUint16PtrOmitEmpty struct { + A *uint16 `json:"a,omitempty"` + } + type structUint16PtrString struct { + A *uint16 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverUint16(t *testing.T) { indentExpected string data interface{} }{ + // HeadUint16Zero { name: "HeadUint16Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverUint16(t *testing.T) { A uint16 `json:"a"` }{}, }, + { + name: "HeadUint16ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint16 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadUint16ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A uint16 `json:"a,string"` + }{}, + }, + + // HeadUint16 { name: "HeadUint16", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverUint16(t *testing.T) { A uint16 `json:"a"` }{A: 1}, }, + { + name: "HeadUint16OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A uint16 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadUint16String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A uint16 `json:"a,string"` + }{A: 1}, + }, + + // HeadUint16Ptr { name: "HeadUint16Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverUint16(t *testing.T) { A *uint16 `json:"a"` }{A: uint16ptr(1)}, }, + { + name: "HeadUint16PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *uint16 `json:"a,omitempty"` + }{A: uint16ptr(1)}, + }, + { + name: "HeadUint16PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *uint16 `json:"a,string"` + }{A: uint16ptr(1)}, + }, + + // HeadUint16PtrNil { name: "HeadUint16PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverUint16(t *testing.T) { A *uint16 `json:"a"` }{A: nil}, }, + { + name: "HeadUint16PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint16 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadUint16PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *uint16 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint16Zero { name: "PtrHeadUint16Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverUint16(t *testing.T) { A uint16 `json:"a"` }{}, }, + { + name: "PtrHeadUint16ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint16 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadUint16ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A uint16 `json:"a,string"` + }{}, + }, + + // PtrHeadUint16 { name: "PtrHeadUint16", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverUint16(t *testing.T) { A uint16 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadUint16OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A uint16 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadUint16String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A uint16 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadUint16Ptr { name: "PtrHeadUint16Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverUint16(t *testing.T) { A *uint16 `json:"a"` }{A: uint16ptr(1)}, }, + { + name: "PtrHeadUint16PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *uint16 `json:"a,omitempty"` + }{A: uint16ptr(1)}, + }, + { + name: "PtrHeadUint16PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *uint16 `json:"a,string"` + }{A: uint16ptr(1)}, + }, + + // PtrHeadUint16PtrNil { name: "PtrHeadUint16PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverUint16(t *testing.T) { A *uint16 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadUint16PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint16 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint16PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *uint16 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint16Nil { name: "PtrHeadUint16Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *uint16 `json:"a"` })(nil), }, + { + name: "PtrHeadUint16NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint16 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint16NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint16 `json:"a,string"` + })(nil), + }, + + // HeadUint16ZeroMultiFields { name: "HeadUint16ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B uint16 `json:"b"` }{}, }, + { + name: "HeadUint16ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadUint16ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + }{}, + }, + + // HeadUint16MultiFields { name: "HeadUint16MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B uint16 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadUint16MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadUint16MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadUint16PtrMultiFields { name: "HeadUint16PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *uint16 `json:"b"` }{A: uint16ptr(1), B: uint16ptr(2)}, }, + { + name: "HeadUint16PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + }{A: uint16ptr(1), B: uint16ptr(2)}, + }, + { + name: "HeadUint16PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + }{A: uint16ptr(1), B: uint16ptr(2)}, + }, + + // HeadUint16PtrNilMultiFields { name: "HeadUint16PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *uint16 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadUint16PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadUint16PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint16ZeroMultiFields { name: "PtrHeadUint16ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B uint16 `json:"b"` }{}, }, + { + name: "PtrHeadUint16ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadUint16ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + }{}, + }, + + // PtrHeadUint16MultiFields { name: "PtrHeadUint16MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B uint16 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadUint16MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadUint16MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadUint16PtrMultiFields { name: "PtrHeadUint16PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *uint16 `json:"b"` }{A: uint16ptr(1), B: uint16ptr(2)}, }, + { + name: "PtrHeadUint16PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + }{A: uint16ptr(1), B: uint16ptr(2)}, + }, + { + name: "PtrHeadUint16PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + }{A: uint16ptr(1), B: uint16ptr(2)}, + }, + + // PtrHeadUint16PtrNilMultiFields { name: "PtrHeadUint16PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *uint16 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadUint16PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint16PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint16NilMultiFields { name: "PtrHeadUint16NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *uint16 `json:"b"` })(nil), }, + { + name: "PtrHeadUint16NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint16NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + })(nil), + }, + + // HeadUint16ZeroNotRoot { name: "HeadUint16ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadUint16ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A uint16 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint16ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A uint16 `json:"a,string"` + } + }{}, + }, + + // HeadUint16NotRoot { name: "HeadUint16NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A uint16 `json:"a"` }{A: 1}}, }, + { + name: "HeadUint16NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A uint16 `json:"a,omitempty"` + } + }{A: struct { + A uint16 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadUint16NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A uint16 `json:"a,string"` + } + }{A: struct { + A uint16 `json:"a,string"` + }{A: 1}}, + }, + + // HeadUint16PtrNotRoot { name: "HeadUint16PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *uint16 `json:"a"` }{uint16ptr(1)}}, }, + { + name: "HeadUint16PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *uint16 `json:"a,omitempty"` + } + }{A: struct { + A *uint16 `json:"a,omitempty"` + }{uint16ptr(1)}}, + }, + { + name: "HeadUint16PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *uint16 `json:"a,string"` + } + }{A: struct { + A *uint16 `json:"a,string"` + }{uint16ptr(1)}}, + }, + + // HeadUint16PtrNilNotRoot { name: "HeadUint16PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadUint16PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *uint16 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint16PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *uint16 `json:"a,string"` + } + }{}, + }, + + // PtrHeadUint16ZeroNotRoot { name: "PtrHeadUint16ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A uint16 `json:"a"` })}, }, + { + name: "PtrHeadUint16ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A uint16 `json:"a,omitempty"` + } + }{A: new(struct { + A uint16 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadUint16ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A uint16 `json:"a,string"` + } + }{A: new(struct { + A uint16 `json:"a,string"` + })}, + }, + + // PtrHeadUint16NotRoot { name: "PtrHeadUint16NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A uint16 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadUint16NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A uint16 `json:"a,omitempty"` + } + }{A: &(struct { + A uint16 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadUint16NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A uint16 `json:"a,string"` + } + }{A: &(struct { + A uint16 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadUint16PtrNotRoot { name: "PtrHeadUint16PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *uint16 `json:"a"` }{A: uint16ptr(1)})}, }, + { + name: "PtrHeadUint16PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *uint16 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint16 `json:"a,omitempty"` + }{A: uint16ptr(1)})}, + }, + { + name: "PtrHeadUint16PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *uint16 `json:"a,string"` + } + }{A: &(struct { + A *uint16 `json:"a,string"` + }{A: uint16ptr(1)})}, + }, + + // PtrHeadUint16PtrNilNotRoot { name: "PtrHeadUint16PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *uint16 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadUint16PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *uint16 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint16 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadUint16PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *uint16 `json:"a,string"` + } + }{A: &(struct { + A *uint16 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadUint16NilNotRoot { name: "PtrHeadUint16NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadUint16NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *uint16 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint16NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *uint16 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadUint16ZeroMultiFieldsNotRoot { name: "HeadUint16ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadUint16ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A uint16 `json:"a,omitempty"` + } + B struct { + B uint16 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadUint16ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A uint16 `json:"a,string"` + } + B struct { + B uint16 `json:"b,string"` + } + }{}, + }, + + // HeadUint16MultiFieldsNotRoot { name: "HeadUint16MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B uint16 `json:"b"` }{B: 2}}, }, + { + name: "HeadUint16MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A uint16 `json:"a,omitempty"` + } + B struct { + B uint16 `json:"b,omitempty"` + } + }{A: struct { + A uint16 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint16 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadUint16MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A uint16 `json:"a,string"` + } + B struct { + B uint16 `json:"b,string"` + } + }{A: struct { + A uint16 `json:"a,string"` + }{A: 1}, B: struct { + B uint16 `json:"b,string"` + }{B: 2}}, + }, + + // HeadUint16PtrMultiFieldsNotRoot { name: "HeadUint16PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *uint16 `json:"b"` }{B: uint16ptr(2)}}, }, + { + name: "HeadUint16PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *uint16 `json:"a,omitempty"` + } + B struct { + B *uint16 `json:"b,omitempty"` + } + }{A: struct { + A *uint16 `json:"a,omitempty"` + }{A: uint16ptr(1)}, B: struct { + B *uint16 `json:"b,omitempty"` + }{B: uint16ptr(2)}}, + }, + { + name: "HeadUint16PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *uint16 `json:"a,string"` + } + B struct { + B *uint16 `json:"b,string"` + } + }{A: struct { + A *uint16 `json:"a,string"` + }{A: uint16ptr(1)}, B: struct { + B *uint16 `json:"b,string"` + }{B: uint16ptr(2)}}, + }, + + // HeadUint16PtrNilMultiFieldsNotRoot { name: "HeadUint16PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *uint16 `json:"b"` }{B: nil}}, }, + { + name: "HeadUint16PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *uint16 `json:"a,omitempty"` + } + B struct { + B *uint16 `json:"b,omitempty"` + } + }{A: struct { + A *uint16 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *uint16 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadUint16PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *uint16 `json:"a,string"` + } + B struct { + B *uint16 `json:"b,string"` + } + }{A: struct { + A *uint16 `json:"a,string"` + }{A: nil}, B: struct { + B *uint16 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadUint16ZeroMultiFieldsNotRoot { name: "PtrHeadUint16ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadUint16ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A uint16 `json:"a,omitempty"` + } + B struct { + B uint16 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadUint16ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A uint16 `json:"a,string"` + } + B struct { + B uint16 `json:"b,string"` + } + }{}, + }, + + // PtrHeadUint16MultiFieldsNotRoot { name: "PtrHeadUint16MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B uint16 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadUint16MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A uint16 `json:"a,omitempty"` + } + B struct { + B uint16 `json:"b,omitempty"` + } + }{A: struct { + A uint16 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint16 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadUint16MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A uint16 `json:"a,string"` + } + B struct { + B uint16 `json:"b,string"` + } + }{A: struct { + A uint16 `json:"a,string"` + }{A: 1}, B: struct { + B uint16 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadUint16PtrMultiFieldsNotRoot { name: "PtrHeadUint16PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *uint16 `json:"b"` }{B: uint16ptr(2)})}, }, + { + name: "PtrHeadUint16PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *uint16 `json:"a,omitempty"` + } + B *struct { + B *uint16 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint16 `json:"a,omitempty"` + }{A: uint16ptr(1)}), B: &(struct { + B *uint16 `json:"b,omitempty"` + }{B: uint16ptr(2)})}, + }, + { + name: "PtrHeadUint16PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *uint16 `json:"a,string"` + } + B *struct { + B *uint16 `json:"b,string"` + } + }{A: &(struct { + A *uint16 `json:"a,string"` + }{A: uint16ptr(1)}), B: &(struct { + B *uint16 `json:"b,string"` + }{B: uint16ptr(2)})}, + }, + + // PtrHeadUint16PtrNilMultiFieldsNotRoot { name: "PtrHeadUint16PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint16PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint16 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *uint16 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint16PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint16 `json:"a,string"` + } `json:",string"` + B *struct { + B *uint16 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint16NilMultiFieldsNotRoot { name: "PtrHeadUint16NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadUint16NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint16 `json:"a,omitempty"` + } + B *struct { + B *uint16 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint16NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint16 `json:"a,string"` + } + B *struct { + B *uint16 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint16DoubleMultiFieldsNotRoot { name: "PtrHeadUint16DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B uint16 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadUint16DoubleMultiFieldsNotRootOmitEmpty", + 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 uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + } + B *struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + } + }{A: &(struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadUint16DoubleMultiFieldsNotRootString", + 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 uint16 `json:"a,string"` + B uint16 `json:"b,string"` + } + B *struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + } + }{A: &(struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadUint16NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint16NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint16NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint16NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + } + B *struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint16NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint16NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadUint16NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + } + B *struct { + A uint16 `json:"a,omitempty"` + B uint16 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint16NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + } + B *struct { + A uint16 `json:"a,string"` + B uint16 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint16PtrDoubleMultiFieldsNotRoot { name: "PtrHeadUint16PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *uint16 `json:"b"` }{A: uint16ptr(3), B: uint16ptr(4)})}, }, + { + name: "PtrHeadUint16PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + } + B *struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + }{A: uint16ptr(1), B: uint16ptr(2)}), B: &(struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + }{A: uint16ptr(3), B: uint16ptr(4)})}, + }, + { + name: "PtrHeadUint16PtrDoubleMultiFieldsNotRootString", + 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 *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + } + B *struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + } + }{A: &(struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + }{A: uint16ptr(1), B: uint16ptr(2)}), B: &(struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + }{A: uint16ptr(3), B: uint16ptr(4)})}, + }, + + // PtrHeadUint16PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint16PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint16PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint16PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + } + B *struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint16PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint16PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadUint16PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + } + B *struct { + A *uint16 `json:"a,omitempty"` + B *uint16 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint16PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + } + B *struct { + A *uint16 `json:"a,string"` + B *uint16 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadUint16 { name: "AnonymousHeadUint16", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadUint16OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint16OmitEmpty + B uint16 `json:"b,omitempty"` + }{ + structUint16OmitEmpty: structUint16OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadUint16String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint16String + B uint16 `json:"b,string"` + }{ + structUint16String: structUint16String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadUint16 { name: "PtrAnonymousHeadUint16", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadUint16OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint16OmitEmpty + B uint16 `json:"b,omitempty"` + }{ + structUint16OmitEmpty: &structUint16OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadUint16String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint16String + B uint16 `json:"b,string"` + }{ + structUint16String: &structUint16String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadUint16 { name: "NilPtrAnonymousHeadUint16", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadUint16OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint16OmitEmpty + B uint16 `json:"b,omitempty"` + }{ + structUint16OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadUint16String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint16String + B uint16 `json:"b,string"` + }{ + structUint16String: nil, + B: 2, + }, + }, + + // AnonymousHeadUint16Ptr { name: "AnonymousHeadUint16Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: uint16ptr(2), }, }, + { + name: "AnonymousHeadUint16PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint16PtrOmitEmpty + B *uint16 `json:"b,omitempty"` + }{ + structUint16PtrOmitEmpty: structUint16PtrOmitEmpty{A: uint16ptr(1)}, + B: uint16ptr(2), + }, + }, + { + name: "AnonymousHeadUint16PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint16PtrString + B *uint16 `json:"b,string"` + }{ + structUint16PtrString: structUint16PtrString{A: uint16ptr(1)}, + B: uint16ptr(2), + }, + }, + + // AnonymousHeadUint16PtrNil { name: "AnonymousHeadUint16PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: uint16ptr(2), }, }, + { + name: "AnonymousHeadUint16PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structUint16PtrOmitEmpty + B *uint16 `json:"b,omitempty"` + }{ + structUint16PtrOmitEmpty: structUint16PtrOmitEmpty{A: nil}, + B: uint16ptr(2), + }, + }, + { + name: "AnonymousHeadUint16PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structUint16PtrString + B *uint16 `json:"b,string"` + }{ + structUint16PtrString: structUint16PtrString{A: nil}, + B: uint16ptr(2), + }, + }, + + // PtrAnonymousHeadUint16Ptr { name: "PtrAnonymousHeadUint16Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: uint16ptr(2), }, }, + { + name: "PtrAnonymousHeadUint16PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint16PtrOmitEmpty + B *uint16 `json:"b,omitempty"` + }{ + structUint16PtrOmitEmpty: &structUint16PtrOmitEmpty{A: uint16ptr(1)}, + B: uint16ptr(2), + }, + }, + { + name: "PtrAnonymousHeadUint16PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint16PtrString + B *uint16 `json:"b,string"` + }{ + structUint16PtrString: &structUint16PtrString{A: uint16ptr(1)}, + B: uint16ptr(2), + }, + }, + + // NilPtrAnonymousHeadUint16Ptr { name: "NilPtrAnonymousHeadUint16Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: uint16ptr(2), }, }, + { + name: "NilPtrAnonymousHeadUint16PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint16PtrOmitEmpty + B *uint16 `json:"b,omitempty"` + }{ + structUint16PtrOmitEmpty: nil, + B: uint16ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadUint16PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint16PtrString + B *uint16 `json:"b,string"` + }{ + structUint16PtrString: nil, + B: uint16ptr(2), + }, + }, + + // AnonymousHeadUint16Only { name: "AnonymousHeadUint16Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structUint16: structUint16{A: 1}, }, }, + { + name: "AnonymousHeadUint16OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint16OmitEmpty + }{ + structUint16OmitEmpty: structUint16OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadUint16OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint16String + }{ + structUint16String: structUint16String{A: 1}, + }, + }, + + // PtrAnonymousHeadUint16Only { name: "PtrAnonymousHeadUint16Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structUint16: &structUint16{A: 1}, }, }, + { + name: "PtrAnonymousHeadUint16OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint16OmitEmpty + }{ + structUint16OmitEmpty: &structUint16OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadUint16OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint16String + }{ + structUint16String: &structUint16String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadUint16Only { name: "NilPtrAnonymousHeadUint16Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structUint16: nil, }, }, + { + name: "NilPtrAnonymousHeadUint16OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint16OmitEmpty + }{ + structUint16OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint16OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint16String + }{ + structUint16String: nil, + }, + }, + + // AnonymousHeadUint16PtrOnly { name: "AnonymousHeadUint16PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structUint16Ptr: structUint16Ptr{A: uint16ptr(1)}, }, }, + { + name: "AnonymousHeadUint16PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint16PtrOmitEmpty + }{ + structUint16PtrOmitEmpty: structUint16PtrOmitEmpty{A: uint16ptr(1)}, + }, + }, + { + name: "AnonymousHeadUint16PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint16PtrString + }{ + structUint16PtrString: structUint16PtrString{A: uint16ptr(1)}, + }, + }, + + // AnonymousHeadUint16PtrNilOnly { name: "AnonymousHeadUint16PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structUint16Ptr: structUint16Ptr{A: nil}, }, }, + { + name: "AnonymousHeadUint16PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structUint16PtrOmitEmpty + }{ + structUint16PtrOmitEmpty: structUint16PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadUint16PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structUint16PtrString + }{ + structUint16PtrString: structUint16PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadUint16PtrOnly { name: "PtrAnonymousHeadUint16PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structUint16Ptr: &structUint16Ptr{A: uint16ptr(1)}, }, }, + { + name: "PtrAnonymousHeadUint16PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint16PtrOmitEmpty + }{ + structUint16PtrOmitEmpty: &structUint16PtrOmitEmpty{A: uint16ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadUint16PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint16PtrString + }{ + structUint16PtrString: &structUint16PtrString{A: uint16ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadUint16PtrOnly { name: "NilPtrAnonymousHeadUint16PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structUint16Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadUint16PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint16PtrOmitEmpty + }{ + structUint16PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint16PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint16PtrString + }{ + structUint16PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { @@ -974,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_uint32_test.go b/cover_uint32_test.go index 660cc26..811b1a0 100644 --- a/cover_uint32_test.go +++ b/cover_uint32_test.go @@ -12,9 +12,22 @@ func TestCoverUint32(t *testing.T) { type structUint32 struct { A uint32 `json:"a"` } + type structUint32OmitEmpty struct { + A uint32 `json:"a,omitempty"` + } + type structUint32String struct { + A uint32 `json:"a,string"` + } + type structUint32Ptr struct { A *uint32 `json:"a"` } + type structUint32PtrOmitEmpty struct { + A *uint32 `json:"a,omitempty"` + } + type structUint32PtrString struct { + A *uint32 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverUint32(t *testing.T) { indentExpected string data interface{} }{ + // HeadUint32Zero { name: "HeadUint32Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverUint32(t *testing.T) { A uint32 `json:"a"` }{}, }, + { + name: "HeadUint32ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint32 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadUint32ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A uint32 `json:"a,string"` + }{}, + }, + + // HeadUint32 { name: "HeadUint32", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverUint32(t *testing.T) { A uint32 `json:"a"` }{A: 1}, }, + { + name: "HeadUint32OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A uint32 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadUint32String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A uint32 `json:"a,string"` + }{A: 1}, + }, + + // HeadUint32Ptr { name: "HeadUint32Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverUint32(t *testing.T) { A *uint32 `json:"a"` }{A: uint32ptr(1)}, }, + { + name: "HeadUint32PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *uint32 `json:"a,omitempty"` + }{A: uint32ptr(1)}, + }, + { + name: "HeadUint32PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *uint32 `json:"a,string"` + }{A: uint32ptr(1)}, + }, + + // HeadUint32PtrNil { name: "HeadUint32PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverUint32(t *testing.T) { A *uint32 `json:"a"` }{A: nil}, }, + { + name: "HeadUint32PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint32 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadUint32PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *uint32 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint32Zero { name: "PtrHeadUint32Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverUint32(t *testing.T) { A uint32 `json:"a"` }{}, }, + { + name: "PtrHeadUint32ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint32 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadUint32ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A uint32 `json:"a,string"` + }{}, + }, + + // PtrHeadUint32 { name: "PtrHeadUint32", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverUint32(t *testing.T) { A uint32 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadUint32OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A uint32 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadUint32String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A uint32 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadUint32Ptr { name: "PtrHeadUint32Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverUint32(t *testing.T) { A *uint32 `json:"a"` }{A: uint32ptr(1)}, }, + { + name: "PtrHeadUint32PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *uint32 `json:"a,omitempty"` + }{A: uint32ptr(1)}, + }, + { + name: "PtrHeadUint32PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *uint32 `json:"a,string"` + }{A: uint32ptr(1)}, + }, + + // PtrHeadUint32PtrNil { name: "PtrHeadUint32PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverUint32(t *testing.T) { A *uint32 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadUint32PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint32 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint32PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *uint32 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint32Nil { name: "PtrHeadUint32Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *uint32 `json:"a"` })(nil), }, + { + name: "PtrHeadUint32NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint32 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint32NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint32 `json:"a,string"` + })(nil), + }, + + // HeadUint32ZeroMultiFields { name: "HeadUint32ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B uint32 `json:"b"` }{}, }, + { + name: "HeadUint32ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadUint32ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + }{}, + }, + + // HeadUint32MultiFields { name: "HeadUint32MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B uint32 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadUint32MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadUint32MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadUint32PtrMultiFields { name: "HeadUint32PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *uint32 `json:"b"` }{A: uint32ptr(1), B: uint32ptr(2)}, }, + { + name: "HeadUint32PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + }{A: uint32ptr(1), B: uint32ptr(2)}, + }, + { + name: "HeadUint32PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + }{A: uint32ptr(1), B: uint32ptr(2)}, + }, + + // HeadUint32PtrNilMultiFields { name: "HeadUint32PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *uint32 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadUint32PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadUint32PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint32ZeroMultiFields { name: "PtrHeadUint32ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B uint32 `json:"b"` }{}, }, + { + name: "PtrHeadUint32ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadUint32ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + }{}, + }, + + // PtrHeadUint32MultiFields { name: "PtrHeadUint32MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B uint32 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadUint32MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadUint32MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadUint32PtrMultiFields { name: "PtrHeadUint32PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *uint32 `json:"b"` }{A: uint32ptr(1), B: uint32ptr(2)}, }, + { + name: "PtrHeadUint32PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + }{A: uint32ptr(1), B: uint32ptr(2)}, + }, + { + name: "PtrHeadUint32PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + }{A: uint32ptr(1), B: uint32ptr(2)}, + }, + + // PtrHeadUint32PtrNilMultiFields { name: "PtrHeadUint32PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *uint32 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadUint32PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint32PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint32NilMultiFields { name: "PtrHeadUint32NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *uint32 `json:"b"` })(nil), }, + { + name: "PtrHeadUint32NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint32NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + })(nil), + }, + + // HeadUint32ZeroNotRoot { name: "HeadUint32ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadUint32ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A uint32 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint32ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A uint32 `json:"a,string"` + } + }{}, + }, + + // HeadUint32NotRoot { name: "HeadUint32NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A uint32 `json:"a"` }{A: 1}}, }, + { + name: "HeadUint32NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A uint32 `json:"a,omitempty"` + } + }{A: struct { + A uint32 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadUint32NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A uint32 `json:"a,string"` + } + }{A: struct { + A uint32 `json:"a,string"` + }{A: 1}}, + }, + + // HeadUint32PtrNotRoot { name: "HeadUint32PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *uint32 `json:"a"` }{uint32ptr(1)}}, }, + { + name: "HeadUint32PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *uint32 `json:"a,omitempty"` + } + }{A: struct { + A *uint32 `json:"a,omitempty"` + }{uint32ptr(1)}}, + }, + { + name: "HeadUint32PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *uint32 `json:"a,string"` + } + }{A: struct { + A *uint32 `json:"a,string"` + }{uint32ptr(1)}}, + }, + + // HeadUint32PtrNilNotRoot { name: "HeadUint32PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadUint32PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *uint32 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint32PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *uint32 `json:"a,string"` + } + }{}, + }, + + // PtrHeadUint32ZeroNotRoot { name: "PtrHeadUint32ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A uint32 `json:"a"` })}, }, + { + name: "PtrHeadUint32ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A uint32 `json:"a,omitempty"` + } + }{A: new(struct { + A uint32 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadUint32ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A uint32 `json:"a,string"` + } + }{A: new(struct { + A uint32 `json:"a,string"` + })}, + }, + + // PtrHeadUint32NotRoot { name: "PtrHeadUint32NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A uint32 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadUint32NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A uint32 `json:"a,omitempty"` + } + }{A: &(struct { + A uint32 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadUint32NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A uint32 `json:"a,string"` + } + }{A: &(struct { + A uint32 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadUint32PtrNotRoot { name: "PtrHeadUint32PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *uint32 `json:"a"` }{A: uint32ptr(1)})}, }, + { + name: "PtrHeadUint32PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *uint32 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint32 `json:"a,omitempty"` + }{A: uint32ptr(1)})}, + }, + { + name: "PtrHeadUint32PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *uint32 `json:"a,string"` + } + }{A: &(struct { + A *uint32 `json:"a,string"` + }{A: uint32ptr(1)})}, + }, + + // PtrHeadUint32PtrNilNotRoot { name: "PtrHeadUint32PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *uint32 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadUint32PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *uint32 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint32 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadUint32PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *uint32 `json:"a,string"` + } + }{A: &(struct { + A *uint32 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadUint32NilNotRoot { name: "PtrHeadUint32NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadUint32NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *uint32 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint32NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *uint32 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadUint32ZeroMultiFieldsNotRoot { name: "HeadUint32ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadUint32ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A uint32 `json:"a,omitempty"` + } + B struct { + B uint32 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadUint32ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A uint32 `json:"a,string"` + } + B struct { + B uint32 `json:"b,string"` + } + }{}, + }, + + // HeadUint32MultiFieldsNotRoot { name: "HeadUint32MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B uint32 `json:"b"` }{B: 2}}, }, + { + name: "HeadUint32MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A uint32 `json:"a,omitempty"` + } + B struct { + B uint32 `json:"b,omitempty"` + } + }{A: struct { + A uint32 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint32 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadUint32MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A uint32 `json:"a,string"` + } + B struct { + B uint32 `json:"b,string"` + } + }{A: struct { + A uint32 `json:"a,string"` + }{A: 1}, B: struct { + B uint32 `json:"b,string"` + }{B: 2}}, + }, + + // HeadUint32PtrMultiFieldsNotRoot { name: "HeadUint32PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *uint32 `json:"b"` }{B: uint32ptr(2)}}, }, + { + name: "HeadUint32PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *uint32 `json:"a,omitempty"` + } + B struct { + B *uint32 `json:"b,omitempty"` + } + }{A: struct { + A *uint32 `json:"a,omitempty"` + }{A: uint32ptr(1)}, B: struct { + B *uint32 `json:"b,omitempty"` + }{B: uint32ptr(2)}}, + }, + { + name: "HeadUint32PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *uint32 `json:"a,string"` + } + B struct { + B *uint32 `json:"b,string"` + } + }{A: struct { + A *uint32 `json:"a,string"` + }{A: uint32ptr(1)}, B: struct { + B *uint32 `json:"b,string"` + }{B: uint32ptr(2)}}, + }, + + // HeadUint32PtrNilMultiFieldsNotRoot { name: "HeadUint32PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *uint32 `json:"b"` }{B: nil}}, }, + { + name: "HeadUint32PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *uint32 `json:"a,omitempty"` + } + B struct { + B *uint32 `json:"b,omitempty"` + } + }{A: struct { + A *uint32 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *uint32 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadUint32PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *uint32 `json:"a,string"` + } + B struct { + B *uint32 `json:"b,string"` + } + }{A: struct { + A *uint32 `json:"a,string"` + }{A: nil}, B: struct { + B *uint32 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadUint32ZeroMultiFieldsNotRoot { name: "PtrHeadUint32ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadUint32ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A uint32 `json:"a,omitempty"` + } + B struct { + B uint32 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadUint32ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A uint32 `json:"a,string"` + } + B struct { + B uint32 `json:"b,string"` + } + }{}, + }, + + // PtrHeadUint32MultiFieldsNotRoot { name: "PtrHeadUint32MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B uint32 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadUint32MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A uint32 `json:"a,omitempty"` + } + B struct { + B uint32 `json:"b,omitempty"` + } + }{A: struct { + A uint32 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint32 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadUint32MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A uint32 `json:"a,string"` + } + B struct { + B uint32 `json:"b,string"` + } + }{A: struct { + A uint32 `json:"a,string"` + }{A: 1}, B: struct { + B uint32 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadUint32PtrMultiFieldsNotRoot { name: "PtrHeadUint32PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *uint32 `json:"b"` }{B: uint32ptr(2)})}, }, + { + name: "PtrHeadUint32PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *uint32 `json:"a,omitempty"` + } + B *struct { + B *uint32 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint32 `json:"a,omitempty"` + }{A: uint32ptr(1)}), B: &(struct { + B *uint32 `json:"b,omitempty"` + }{B: uint32ptr(2)})}, + }, + { + name: "PtrHeadUint32PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *uint32 `json:"a,string"` + } + B *struct { + B *uint32 `json:"b,string"` + } + }{A: &(struct { + A *uint32 `json:"a,string"` + }{A: uint32ptr(1)}), B: &(struct { + B *uint32 `json:"b,string"` + }{B: uint32ptr(2)})}, + }, + + // PtrHeadUint32PtrNilMultiFieldsNotRoot { name: "PtrHeadUint32PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint32PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint32 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *uint32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint32PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint32 `json:"a,string"` + } `json:",string"` + B *struct { + B *uint32 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint32NilMultiFieldsNotRoot { name: "PtrHeadUint32NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadUint32NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint32 `json:"a,omitempty"` + } + B *struct { + B *uint32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint32NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint32 `json:"a,string"` + } + B *struct { + B *uint32 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint32DoubleMultiFieldsNotRoot { name: "PtrHeadUint32DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B uint32 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadUint32DoubleMultiFieldsNotRootOmitEmpty", + 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 uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + } + B *struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + } + }{A: &(struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadUint32DoubleMultiFieldsNotRootString", + 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 uint32 `json:"a,string"` + B uint32 `json:"b,string"` + } + B *struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + } + }{A: &(struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadUint32NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint32NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint32NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint32NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + } + B *struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint32NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint32NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadUint32NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + } + B *struct { + A uint32 `json:"a,omitempty"` + B uint32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint32NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + } + B *struct { + A uint32 `json:"a,string"` + B uint32 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint32PtrDoubleMultiFieldsNotRoot { name: "PtrHeadUint32PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *uint32 `json:"b"` }{A: uint32ptr(3), B: uint32ptr(4)})}, }, + { + name: "PtrHeadUint32PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + } + B *struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + }{A: uint32ptr(1), B: uint32ptr(2)}), B: &(struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + }{A: uint32ptr(3), B: uint32ptr(4)})}, + }, + { + name: "PtrHeadUint32PtrDoubleMultiFieldsNotRootString", + 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 *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + } + B *struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + } + }{A: &(struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + }{A: uint32ptr(1), B: uint32ptr(2)}), B: &(struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + }{A: uint32ptr(3), B: uint32ptr(4)})}, + }, + + // PtrHeadUint32PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint32PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint32PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint32PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + } + B *struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint32PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint32PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadUint32PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + } + B *struct { + A *uint32 `json:"a,omitempty"` + B *uint32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint32PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + } + B *struct { + A *uint32 `json:"a,string"` + B *uint32 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadUint32 { name: "AnonymousHeadUint32", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadUint32OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint32OmitEmpty + B uint32 `json:"b,omitempty"` + }{ + structUint32OmitEmpty: structUint32OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadUint32String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint32String + B uint32 `json:"b,string"` + }{ + structUint32String: structUint32String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadUint32 { name: "PtrAnonymousHeadUint32", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadUint32OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint32OmitEmpty + B uint32 `json:"b,omitempty"` + }{ + structUint32OmitEmpty: &structUint32OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadUint32String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint32String + B uint32 `json:"b,string"` + }{ + structUint32String: &structUint32String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadUint32 { name: "NilPtrAnonymousHeadUint32", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadUint32OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint32OmitEmpty + B uint32 `json:"b,omitempty"` + }{ + structUint32OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadUint32String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint32String + B uint32 `json:"b,string"` + }{ + structUint32String: nil, + B: 2, + }, + }, + + // AnonymousHeadUint32Ptr { name: "AnonymousHeadUint32Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: uint32ptr(2), }, }, + { + name: "AnonymousHeadUint32PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint32PtrOmitEmpty + B *uint32 `json:"b,omitempty"` + }{ + structUint32PtrOmitEmpty: structUint32PtrOmitEmpty{A: uint32ptr(1)}, + B: uint32ptr(2), + }, + }, + { + name: "AnonymousHeadUint32PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint32PtrString + B *uint32 `json:"b,string"` + }{ + structUint32PtrString: structUint32PtrString{A: uint32ptr(1)}, + B: uint32ptr(2), + }, + }, + + // AnonymousHeadUint32PtrNil { name: "AnonymousHeadUint32PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: uint32ptr(2), }, }, + { + name: "AnonymousHeadUint32PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structUint32PtrOmitEmpty + B *uint32 `json:"b,omitempty"` + }{ + structUint32PtrOmitEmpty: structUint32PtrOmitEmpty{A: nil}, + B: uint32ptr(2), + }, + }, + { + name: "AnonymousHeadUint32PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structUint32PtrString + B *uint32 `json:"b,string"` + }{ + structUint32PtrString: structUint32PtrString{A: nil}, + B: uint32ptr(2), + }, + }, + + // PtrAnonymousHeadUint32Ptr { name: "PtrAnonymousHeadUint32Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: uint32ptr(2), }, }, + { + name: "PtrAnonymousHeadUint32PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint32PtrOmitEmpty + B *uint32 `json:"b,omitempty"` + }{ + structUint32PtrOmitEmpty: &structUint32PtrOmitEmpty{A: uint32ptr(1)}, + B: uint32ptr(2), + }, + }, + { + name: "PtrAnonymousHeadUint32PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint32PtrString + B *uint32 `json:"b,string"` + }{ + structUint32PtrString: &structUint32PtrString{A: uint32ptr(1)}, + B: uint32ptr(2), + }, + }, + + // NilPtrAnonymousHeadUint32Ptr { name: "NilPtrAnonymousHeadUint32Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: uint32ptr(2), }, }, + { + name: "NilPtrAnonymousHeadUint32PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint32PtrOmitEmpty + B *uint32 `json:"b,omitempty"` + }{ + structUint32PtrOmitEmpty: nil, + B: uint32ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadUint32PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint32PtrString + B *uint32 `json:"b,string"` + }{ + structUint32PtrString: nil, + B: uint32ptr(2), + }, + }, + + // AnonymousHeadUint32Only { name: "AnonymousHeadUint32Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structUint32: structUint32{A: 1}, }, }, + { + name: "AnonymousHeadUint32OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint32OmitEmpty + }{ + structUint32OmitEmpty: structUint32OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadUint32OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint32String + }{ + structUint32String: structUint32String{A: 1}, + }, + }, + + // PtrAnonymousHeadUint32Only { name: "PtrAnonymousHeadUint32Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structUint32: &structUint32{A: 1}, }, }, + { + name: "PtrAnonymousHeadUint32OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint32OmitEmpty + }{ + structUint32OmitEmpty: &structUint32OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadUint32OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint32String + }{ + structUint32String: &structUint32String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadUint32Only { name: "NilPtrAnonymousHeadUint32Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structUint32: nil, }, }, + { + name: "NilPtrAnonymousHeadUint32OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint32OmitEmpty + }{ + structUint32OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint32OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint32String + }{ + structUint32String: nil, + }, + }, + + // AnonymousHeadUint32PtrOnly { name: "AnonymousHeadUint32PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structUint32Ptr: structUint32Ptr{A: uint32ptr(1)}, }, }, + { + name: "AnonymousHeadUint32PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint32PtrOmitEmpty + }{ + structUint32PtrOmitEmpty: structUint32PtrOmitEmpty{A: uint32ptr(1)}, + }, + }, + { + name: "AnonymousHeadUint32PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint32PtrString + }{ + structUint32PtrString: structUint32PtrString{A: uint32ptr(1)}, + }, + }, + + // AnonymousHeadUint32PtrNilOnly { name: "AnonymousHeadUint32PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structUint32Ptr: structUint32Ptr{A: nil}, }, }, + { + name: "AnonymousHeadUint32PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structUint32PtrOmitEmpty + }{ + structUint32PtrOmitEmpty: structUint32PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadUint32PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structUint32PtrString + }{ + structUint32PtrString: structUint32PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadUint32PtrOnly { name: "PtrAnonymousHeadUint32PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structUint32Ptr: &structUint32Ptr{A: uint32ptr(1)}, }, }, + { + name: "PtrAnonymousHeadUint32PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint32PtrOmitEmpty + }{ + structUint32PtrOmitEmpty: &structUint32PtrOmitEmpty{A: uint32ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadUint32PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint32PtrString + }{ + structUint32PtrString: &structUint32PtrString{A: uint32ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadUint32PtrOnly { name: "NilPtrAnonymousHeadUint32PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structUint32Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadUint32PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint32PtrOmitEmpty + }{ + structUint32PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint32PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint32PtrString + }{ + structUint32PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { @@ -974,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_uint64_test.go b/cover_uint64_test.go index c72911c..92f6c46 100644 --- a/cover_uint64_test.go +++ b/cover_uint64_test.go @@ -12,9 +12,22 @@ func TestCoverUint64(t *testing.T) { type structUint64 struct { A uint64 `json:"a"` } + type structUint64OmitEmpty struct { + A uint64 `json:"a,omitempty"` + } + type structUint64String struct { + A uint64 `json:"a,string"` + } + type structUint64Ptr struct { A *uint64 `json:"a"` } + type structUint64PtrOmitEmpty struct { + A *uint64 `json:"a,omitempty"` + } + type structUint64PtrString struct { + A *uint64 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverUint64(t *testing.T) { indentExpected string data interface{} }{ + // HeadUint64Zero { name: "HeadUint64Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverUint64(t *testing.T) { A uint64 `json:"a"` }{}, }, + { + name: "HeadUint64ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint64 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadUint64ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A uint64 `json:"a,string"` + }{}, + }, + + // HeadUint64 { name: "HeadUint64", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverUint64(t *testing.T) { A uint64 `json:"a"` }{A: 1}, }, + { + name: "HeadUint64OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A uint64 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadUint64String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A uint64 `json:"a,string"` + }{A: 1}, + }, + + // HeadUint64Ptr { name: "HeadUint64Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverUint64(t *testing.T) { A *uint64 `json:"a"` }{A: uint64ptr(1)}, }, + { + name: "HeadUint64PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *uint64 `json:"a,omitempty"` + }{A: uint64ptr(1)}, + }, + { + name: "HeadUint64PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *uint64 `json:"a,string"` + }{A: uint64ptr(1)}, + }, + + // HeadUint64PtrNil { name: "HeadUint64PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverUint64(t *testing.T) { A *uint64 `json:"a"` }{A: nil}, }, + { + name: "HeadUint64PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint64 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadUint64PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *uint64 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint64Zero { name: "PtrHeadUint64Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverUint64(t *testing.T) { A uint64 `json:"a"` }{}, }, + { + name: "PtrHeadUint64ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint64 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadUint64ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A uint64 `json:"a,string"` + }{}, + }, + + // PtrHeadUint64 { name: "PtrHeadUint64", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverUint64(t *testing.T) { A uint64 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadUint64OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A uint64 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadUint64String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A uint64 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadUint64Ptr { name: "PtrHeadUint64Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverUint64(t *testing.T) { A *uint64 `json:"a"` }{A: uint64ptr(1)}, }, + { + name: "PtrHeadUint64PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *uint64 `json:"a,omitempty"` + }{A: uint64ptr(1)}, + }, + { + name: "PtrHeadUint64PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *uint64 `json:"a,string"` + }{A: uint64ptr(1)}, + }, + + // PtrHeadUint64PtrNil { name: "PtrHeadUint64PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverUint64(t *testing.T) { A *uint64 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadUint64PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint64 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint64PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *uint64 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint64Nil { name: "PtrHeadUint64Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *uint64 `json:"a"` })(nil), }, + { + name: "PtrHeadUint64NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint64 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint64NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint64 `json:"a,string"` + })(nil), + }, + + // HeadUint64ZeroMultiFields { name: "HeadUint64ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B uint64 `json:"b"` }{}, }, + { + name: "HeadUint64ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadUint64ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + }{}, + }, + + // HeadUint64MultiFields { name: "HeadUint64MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B uint64 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadUint64MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadUint64MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadUint64PtrMultiFields { name: "HeadUint64PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *uint64 `json:"b"` }{A: uint64ptr(1), B: uint64ptr(2)}, }, + { + name: "HeadUint64PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + }{A: uint64ptr(1), B: uint64ptr(2)}, + }, + { + name: "HeadUint64PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + }{A: uint64ptr(1), B: uint64ptr(2)}, + }, + + // HeadUint64PtrNilMultiFields { name: "HeadUint64PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *uint64 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadUint64PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadUint64PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint64ZeroMultiFields { name: "PtrHeadUint64ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B uint64 `json:"b"` }{}, }, + { + name: "PtrHeadUint64ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadUint64ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + }{}, + }, + + // PtrHeadUint64MultiFields { name: "PtrHeadUint64MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B uint64 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadUint64MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadUint64MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadUint64PtrMultiFields { name: "PtrHeadUint64PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *uint64 `json:"b"` }{A: uint64ptr(1), B: uint64ptr(2)}, }, + { + name: "PtrHeadUint64PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + }{A: uint64ptr(1), B: uint64ptr(2)}, + }, + { + name: "PtrHeadUint64PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + }{A: uint64ptr(1), B: uint64ptr(2)}, + }, + + // PtrHeadUint64PtrNilMultiFields { name: "PtrHeadUint64PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *uint64 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadUint64PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint64PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint64NilMultiFields { name: "PtrHeadUint64NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *uint64 `json:"b"` })(nil), }, + { + name: "PtrHeadUint64NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint64NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + })(nil), + }, + + // HeadUint64ZeroNotRoot { name: "HeadUint64ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadUint64ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A uint64 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint64ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A uint64 `json:"a,string"` + } + }{}, + }, + + // HeadUint64NotRoot { name: "HeadUint64NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A uint64 `json:"a"` }{A: 1}}, }, + { + name: "HeadUint64NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A uint64 `json:"a,omitempty"` + } + }{A: struct { + A uint64 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadUint64NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A uint64 `json:"a,string"` + } + }{A: struct { + A uint64 `json:"a,string"` + }{A: 1}}, + }, + + // HeadUint64PtrNotRoot { name: "HeadUint64PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *uint64 `json:"a"` }{uint64ptr(1)}}, }, + { + name: "HeadUint64PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *uint64 `json:"a,omitempty"` + } + }{A: struct { + A *uint64 `json:"a,omitempty"` + }{uint64ptr(1)}}, + }, + { + name: "HeadUint64PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *uint64 `json:"a,string"` + } + }{A: struct { + A *uint64 `json:"a,string"` + }{uint64ptr(1)}}, + }, + + // HeadUint64PtrNilNotRoot { name: "HeadUint64PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadUint64PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *uint64 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint64PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *uint64 `json:"a,string"` + } + }{}, + }, + + // PtrHeadUint64ZeroNotRoot { name: "PtrHeadUint64ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A uint64 `json:"a"` })}, }, + { + name: "PtrHeadUint64ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A uint64 `json:"a,omitempty"` + } + }{A: new(struct { + A uint64 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadUint64ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A uint64 `json:"a,string"` + } + }{A: new(struct { + A uint64 `json:"a,string"` + })}, + }, + + // PtrHeadUint64NotRoot { name: "PtrHeadUint64NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A uint64 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadUint64NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A uint64 `json:"a,omitempty"` + } + }{A: &(struct { + A uint64 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadUint64NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A uint64 `json:"a,string"` + } + }{A: &(struct { + A uint64 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadUint64PtrNotRoot { name: "PtrHeadUint64PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *uint64 `json:"a"` }{A: uint64ptr(1)})}, }, + { + name: "PtrHeadUint64PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *uint64 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint64 `json:"a,omitempty"` + }{A: uint64ptr(1)})}, + }, + { + name: "PtrHeadUint64PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *uint64 `json:"a,string"` + } + }{A: &(struct { + A *uint64 `json:"a,string"` + }{A: uint64ptr(1)})}, + }, + + // PtrHeadUint64PtrNilNotRoot { name: "PtrHeadUint64PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *uint64 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadUint64PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *uint64 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint64 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadUint64PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *uint64 `json:"a,string"` + } + }{A: &(struct { + A *uint64 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadUint64NilNotRoot { name: "PtrHeadUint64NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadUint64NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *uint64 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint64NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *uint64 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadUint64ZeroMultiFieldsNotRoot { name: "HeadUint64ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadUint64ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A uint64 `json:"a,omitempty"` + } + B struct { + B uint64 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadUint64ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A uint64 `json:"a,string"` + } + B struct { + B uint64 `json:"b,string"` + } + }{}, + }, + + // HeadUint64MultiFieldsNotRoot { name: "HeadUint64MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B uint64 `json:"b"` }{B: 2}}, }, + { + name: "HeadUint64MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A uint64 `json:"a,omitempty"` + } + B struct { + B uint64 `json:"b,omitempty"` + } + }{A: struct { + A uint64 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint64 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadUint64MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A uint64 `json:"a,string"` + } + B struct { + B uint64 `json:"b,string"` + } + }{A: struct { + A uint64 `json:"a,string"` + }{A: 1}, B: struct { + B uint64 `json:"b,string"` + }{B: 2}}, + }, + + // HeadUint64PtrMultiFieldsNotRoot { name: "HeadUint64PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *uint64 `json:"b"` }{B: uint64ptr(2)}}, }, + { + name: "HeadUint64PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *uint64 `json:"a,omitempty"` + } + B struct { + B *uint64 `json:"b,omitempty"` + } + }{A: struct { + A *uint64 `json:"a,omitempty"` + }{A: uint64ptr(1)}, B: struct { + B *uint64 `json:"b,omitempty"` + }{B: uint64ptr(2)}}, + }, + { + name: "HeadUint64PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *uint64 `json:"a,string"` + } + B struct { + B *uint64 `json:"b,string"` + } + }{A: struct { + A *uint64 `json:"a,string"` + }{A: uint64ptr(1)}, B: struct { + B *uint64 `json:"b,string"` + }{B: uint64ptr(2)}}, + }, + + // HeadUint64PtrNilMultiFieldsNotRoot { name: "HeadUint64PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *uint64 `json:"b"` }{B: nil}}, }, + { + name: "HeadUint64PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *uint64 `json:"a,omitempty"` + } + B struct { + B *uint64 `json:"b,omitempty"` + } + }{A: struct { + A *uint64 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *uint64 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadUint64PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *uint64 `json:"a,string"` + } + B struct { + B *uint64 `json:"b,string"` + } + }{A: struct { + A *uint64 `json:"a,string"` + }{A: nil}, B: struct { + B *uint64 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadUint64ZeroMultiFieldsNotRoot { name: "PtrHeadUint64ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadUint64ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A uint64 `json:"a,omitempty"` + } + B struct { + B uint64 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadUint64ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A uint64 `json:"a,string"` + } + B struct { + B uint64 `json:"b,string"` + } + }{}, + }, + + // PtrHeadUint64MultiFieldsNotRoot { name: "PtrHeadUint64MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B uint64 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadUint64MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A uint64 `json:"a,omitempty"` + } + B struct { + B uint64 `json:"b,omitempty"` + } + }{A: struct { + A uint64 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint64 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadUint64MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A uint64 `json:"a,string"` + } + B struct { + B uint64 `json:"b,string"` + } + }{A: struct { + A uint64 `json:"a,string"` + }{A: 1}, B: struct { + B uint64 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadUint64PtrMultiFieldsNotRoot { name: "PtrHeadUint64PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *uint64 `json:"b"` }{B: uint64ptr(2)})}, }, + { + name: "PtrHeadUint64PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *uint64 `json:"a,omitempty"` + } + B *struct { + B *uint64 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint64 `json:"a,omitempty"` + }{A: uint64ptr(1)}), B: &(struct { + B *uint64 `json:"b,omitempty"` + }{B: uint64ptr(2)})}, + }, + { + name: "PtrHeadUint64PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *uint64 `json:"a,string"` + } + B *struct { + B *uint64 `json:"b,string"` + } + }{A: &(struct { + A *uint64 `json:"a,string"` + }{A: uint64ptr(1)}), B: &(struct { + B *uint64 `json:"b,string"` + }{B: uint64ptr(2)})}, + }, + + // PtrHeadUint64PtrNilMultiFieldsNotRoot { name: "PtrHeadUint64PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint64PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint64 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *uint64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint64PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint64 `json:"a,string"` + } `json:",string"` + B *struct { + B *uint64 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint64NilMultiFieldsNotRoot { name: "PtrHeadUint64NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadUint64NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint64 `json:"a,omitempty"` + } + B *struct { + B *uint64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint64NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint64 `json:"a,string"` + } + B *struct { + B *uint64 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint64DoubleMultiFieldsNotRoot { name: "PtrHeadUint64DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B uint64 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadUint64DoubleMultiFieldsNotRootOmitEmpty", + 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 uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + } + B *struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + } + }{A: &(struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadUint64DoubleMultiFieldsNotRootString", + 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 uint64 `json:"a,string"` + B uint64 `json:"b,string"` + } + B *struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + } + }{A: &(struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadUint64NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint64NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint64NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint64NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + } + B *struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint64NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint64NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadUint64NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + } + B *struct { + A uint64 `json:"a,omitempty"` + B uint64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint64NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + } + B *struct { + A uint64 `json:"a,string"` + B uint64 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint64PtrDoubleMultiFieldsNotRoot { name: "PtrHeadUint64PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *uint64 `json:"b"` }{A: uint64ptr(3), B: uint64ptr(4)})}, }, + { + name: "PtrHeadUint64PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + } + B *struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + }{A: uint64ptr(1), B: uint64ptr(2)}), B: &(struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + }{A: uint64ptr(3), B: uint64ptr(4)})}, + }, + { + name: "PtrHeadUint64PtrDoubleMultiFieldsNotRootString", + 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 *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + } + B *struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + } + }{A: &(struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + }{A: uint64ptr(1), B: uint64ptr(2)}), B: &(struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + }{A: uint64ptr(3), B: uint64ptr(4)})}, + }, + + // PtrHeadUint64PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint64PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint64PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint64PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + } + B *struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint64PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint64PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadUint64PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + } + B *struct { + A *uint64 `json:"a,omitempty"` + B *uint64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint64PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + } + B *struct { + A *uint64 `json:"a,string"` + B *uint64 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadUint64 { name: "AnonymousHeadUint64", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadUint64OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint64OmitEmpty + B uint64 `json:"b,omitempty"` + }{ + structUint64OmitEmpty: structUint64OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadUint64String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint64String + B uint64 `json:"b,string"` + }{ + structUint64String: structUint64String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadUint64 { name: "PtrAnonymousHeadUint64", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadUint64OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint64OmitEmpty + B uint64 `json:"b,omitempty"` + }{ + structUint64OmitEmpty: &structUint64OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadUint64String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint64String + B uint64 `json:"b,string"` + }{ + structUint64String: &structUint64String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadUint64 { name: "NilPtrAnonymousHeadUint64", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadUint64OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint64OmitEmpty + B uint64 `json:"b,omitempty"` + }{ + structUint64OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadUint64String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint64String + B uint64 `json:"b,string"` + }{ + structUint64String: nil, + B: 2, + }, + }, + + // AnonymousHeadUint64Ptr { name: "AnonymousHeadUint64Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: uint64ptr(2), }, }, + { + name: "AnonymousHeadUint64PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint64PtrOmitEmpty + B *uint64 `json:"b,omitempty"` + }{ + structUint64PtrOmitEmpty: structUint64PtrOmitEmpty{A: uint64ptr(1)}, + B: uint64ptr(2), + }, + }, + { + name: "AnonymousHeadUint64PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint64PtrString + B *uint64 `json:"b,string"` + }{ + structUint64PtrString: structUint64PtrString{A: uint64ptr(1)}, + B: uint64ptr(2), + }, + }, + + // AnonymousHeadUint64PtrNil { name: "AnonymousHeadUint64PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: uint64ptr(2), }, }, + { + name: "AnonymousHeadUint64PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structUint64PtrOmitEmpty + B *uint64 `json:"b,omitempty"` + }{ + structUint64PtrOmitEmpty: structUint64PtrOmitEmpty{A: nil}, + B: uint64ptr(2), + }, + }, + { + name: "AnonymousHeadUint64PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structUint64PtrString + B *uint64 `json:"b,string"` + }{ + structUint64PtrString: structUint64PtrString{A: nil}, + B: uint64ptr(2), + }, + }, + + // PtrAnonymousHeadUint64Ptr { name: "PtrAnonymousHeadUint64Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: uint64ptr(2), }, }, + { + name: "PtrAnonymousHeadUint64PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint64PtrOmitEmpty + B *uint64 `json:"b,omitempty"` + }{ + structUint64PtrOmitEmpty: &structUint64PtrOmitEmpty{A: uint64ptr(1)}, + B: uint64ptr(2), + }, + }, + { + name: "PtrAnonymousHeadUint64PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint64PtrString + B *uint64 `json:"b,string"` + }{ + structUint64PtrString: &structUint64PtrString{A: uint64ptr(1)}, + B: uint64ptr(2), + }, + }, + + // NilPtrAnonymousHeadUint64Ptr { name: "NilPtrAnonymousHeadUint64Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: uint64ptr(2), }, }, + { + name: "NilPtrAnonymousHeadUint64PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint64PtrOmitEmpty + B *uint64 `json:"b,omitempty"` + }{ + structUint64PtrOmitEmpty: nil, + B: uint64ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadUint64PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint64PtrString + B *uint64 `json:"b,string"` + }{ + structUint64PtrString: nil, + B: uint64ptr(2), + }, + }, + + // AnonymousHeadUint64Only { name: "AnonymousHeadUint64Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structUint64: structUint64{A: 1}, }, }, + { + name: "AnonymousHeadUint64OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint64OmitEmpty + }{ + structUint64OmitEmpty: structUint64OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadUint64OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint64String + }{ + structUint64String: structUint64String{A: 1}, + }, + }, + + // PtrAnonymousHeadUint64Only { name: "PtrAnonymousHeadUint64Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structUint64: &structUint64{A: 1}, }, }, + { + name: "PtrAnonymousHeadUint64OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint64OmitEmpty + }{ + structUint64OmitEmpty: &structUint64OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadUint64OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint64String + }{ + structUint64String: &structUint64String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadUint64Only { name: "NilPtrAnonymousHeadUint64Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structUint64: nil, }, }, + { + name: "NilPtrAnonymousHeadUint64OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint64OmitEmpty + }{ + structUint64OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint64OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint64String + }{ + structUint64String: nil, + }, + }, + + // AnonymousHeadUint64PtrOnly { name: "AnonymousHeadUint64PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structUint64Ptr: structUint64Ptr{A: uint64ptr(1)}, }, }, + { + name: "AnonymousHeadUint64PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint64PtrOmitEmpty + }{ + structUint64PtrOmitEmpty: structUint64PtrOmitEmpty{A: uint64ptr(1)}, + }, + }, + { + name: "AnonymousHeadUint64PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint64PtrString + }{ + structUint64PtrString: structUint64PtrString{A: uint64ptr(1)}, + }, + }, + + // AnonymousHeadUint64PtrNilOnly { name: "AnonymousHeadUint64PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structUint64Ptr: structUint64Ptr{A: nil}, }, }, + { + name: "AnonymousHeadUint64PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structUint64PtrOmitEmpty + }{ + structUint64PtrOmitEmpty: structUint64PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadUint64PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structUint64PtrString + }{ + structUint64PtrString: structUint64PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadUint64PtrOnly { name: "PtrAnonymousHeadUint64PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structUint64Ptr: &structUint64Ptr{A: uint64ptr(1)}, }, }, + { + name: "PtrAnonymousHeadUint64PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint64PtrOmitEmpty + }{ + structUint64PtrOmitEmpty: &structUint64PtrOmitEmpty{A: uint64ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadUint64PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint64PtrString + }{ + structUint64PtrString: &structUint64PtrString{A: uint64ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadUint64PtrOnly { name: "NilPtrAnonymousHeadUint64PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structUint64Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadUint64PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint64PtrOmitEmpty + }{ + structUint64PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint64PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint64PtrString + }{ + structUint64PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { @@ -974,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_uint8_test.go b/cover_uint8_test.go index 485b1e7..f463452 100644 --- a/cover_uint8_test.go +++ b/cover_uint8_test.go @@ -12,9 +12,22 @@ func TestCoverUint8(t *testing.T) { type structUint8 struct { A uint8 `json:"a"` } + type structUint8OmitEmpty struct { + A uint8 `json:"a,omitempty"` + } + type structUint8String struct { + A uint8 `json:"a,string"` + } + type structUint8Ptr struct { A *uint8 `json:"a"` } + type structUint8PtrOmitEmpty struct { + A *uint8 `json:"a,omitempty"` + } + type structUint8PtrString struct { + A *uint8 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverUint8(t *testing.T) { indentExpected string data interface{} }{ + // HeadUint8Zero { name: "HeadUint8Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverUint8(t *testing.T) { A uint8 `json:"a"` }{}, }, + { + name: "HeadUint8ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint8 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadUint8ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A uint8 `json:"a,string"` + }{}, + }, + + // HeadUint8 { name: "HeadUint8", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverUint8(t *testing.T) { A uint8 `json:"a"` }{A: 1}, }, + { + name: "HeadUint8OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A uint8 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadUint8String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A uint8 `json:"a,string"` + }{A: 1}, + }, + + // HeadUint8Ptr { name: "HeadUint8Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverUint8(t *testing.T) { A *uint8 `json:"a"` }{A: uint8ptr(1)}, }, + { + name: "HeadUint8PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *uint8 `json:"a,omitempty"` + }{A: uint8ptr(1)}, + }, + { + name: "HeadUint8PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *uint8 `json:"a,string"` + }{A: uint8ptr(1)}, + }, + + // HeadUint8PtrNil { name: "HeadUint8PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverUint8(t *testing.T) { A *uint8 `json:"a"` }{A: nil}, }, + { + name: "HeadUint8PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint8 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadUint8PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *uint8 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint8Zero { name: "PtrHeadUint8Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverUint8(t *testing.T) { A uint8 `json:"a"` }{}, }, + { + name: "PtrHeadUint8ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint8 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadUint8ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A uint8 `json:"a,string"` + }{}, + }, + + // PtrHeadUint8 { name: "PtrHeadUint8", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverUint8(t *testing.T) { A uint8 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadUint8OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A uint8 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadUint8String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A uint8 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadUint8Ptr { name: "PtrHeadUint8Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverUint8(t *testing.T) { A *uint8 `json:"a"` }{A: uint8ptr(1)}, }, + { + name: "PtrHeadUint8PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *uint8 `json:"a,omitempty"` + }{A: uint8ptr(1)}, + }, + { + name: "PtrHeadUint8PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *uint8 `json:"a,string"` + }{A: uint8ptr(1)}, + }, + + // PtrHeadUint8PtrNil { name: "PtrHeadUint8PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverUint8(t *testing.T) { A *uint8 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadUint8PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint8 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint8PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *uint8 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUint8Nil { name: "PtrHeadUint8Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *uint8 `json:"a"` })(nil), }, + { + name: "PtrHeadUint8NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint8 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint8NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint8 `json:"a,string"` + })(nil), + }, + + // HeadUint8ZeroMultiFields { name: "HeadUint8ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B uint8 `json:"b"` }{}, }, + { + name: "HeadUint8ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadUint8ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + }{}, + }, + + // HeadUint8MultiFields { name: "HeadUint8MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B uint8 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadUint8MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadUint8MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadUint8PtrMultiFields { name: "HeadUint8PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *uint8 `json:"b"` }{A: uint8ptr(1), B: uint8ptr(2)}, }, + { + name: "HeadUint8PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + }{A: uint8ptr(1), B: uint8ptr(2)}, + }, + { + name: "HeadUint8PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + }{A: uint8ptr(1), B: uint8ptr(2)}, + }, + + // HeadUint8PtrNilMultiFields { name: "HeadUint8PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *uint8 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadUint8PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadUint8PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint8ZeroMultiFields { name: "PtrHeadUint8ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B uint8 `json:"b"` }{}, }, + { + name: "PtrHeadUint8ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadUint8ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + }{}, + }, + + // PtrHeadUint8MultiFields { name: "PtrHeadUint8MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B uint8 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadUint8MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadUint8MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadUint8PtrMultiFields { name: "PtrHeadUint8PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *uint8 `json:"b"` }{A: uint8ptr(1), B: uint8ptr(2)}, }, + { + name: "PtrHeadUint8PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + }{A: uint8ptr(1), B: uint8ptr(2)}, + }, + { + name: "PtrHeadUint8PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + }{A: uint8ptr(1), B: uint8ptr(2)}, + }, + + // PtrHeadUint8PtrNilMultiFields { name: "PtrHeadUint8PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *uint8 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadUint8PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint8PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint8NilMultiFields { name: "PtrHeadUint8NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *uint8 `json:"b"` })(nil), }, + { + name: "PtrHeadUint8NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadUint8NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + })(nil), + }, + + // HeadUint8ZeroNotRoot { name: "HeadUint8ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadUint8ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A uint8 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint8ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A uint8 `json:"a,string"` + } + }{}, + }, + + // HeadUint8NotRoot { name: "HeadUint8NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A uint8 `json:"a"` }{A: 1}}, }, + { + name: "HeadUint8NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A uint8 `json:"a,omitempty"` + } + }{A: struct { + A uint8 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadUint8NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A uint8 `json:"a,string"` + } + }{A: struct { + A uint8 `json:"a,string"` + }{A: 1}}, + }, + + // HeadUint8PtrNotRoot { name: "HeadUint8PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *uint8 `json:"a"` }{uint8ptr(1)}}, }, + { + name: "HeadUint8PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *uint8 `json:"a,omitempty"` + } + }{A: struct { + A *uint8 `json:"a,omitempty"` + }{uint8ptr(1)}}, + }, + { + name: "HeadUint8PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *uint8 `json:"a,string"` + } + }{A: struct { + A *uint8 `json:"a,string"` + }{uint8ptr(1)}}, + }, + + // HeadUint8PtrNilNotRoot { name: "HeadUint8PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadUint8PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *uint8 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUint8PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *uint8 `json:"a,string"` + } + }{}, + }, + + // PtrHeadUint8ZeroNotRoot { name: "PtrHeadUint8ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A uint8 `json:"a"` })}, }, + { + name: "PtrHeadUint8ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A uint8 `json:"a,omitempty"` + } + }{A: new(struct { + A uint8 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadUint8ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A uint8 `json:"a,string"` + } + }{A: new(struct { + A uint8 `json:"a,string"` + })}, + }, + + // PtrHeadUint8NotRoot { name: "PtrHeadUint8NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A uint8 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadUint8NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A uint8 `json:"a,omitempty"` + } + }{A: &(struct { + A uint8 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadUint8NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A uint8 `json:"a,string"` + } + }{A: &(struct { + A uint8 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadUint8PtrNotRoot { name: "PtrHeadUint8PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *uint8 `json:"a"` }{A: uint8ptr(1)})}, }, + { + name: "PtrHeadUint8PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *uint8 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint8 `json:"a,omitempty"` + }{A: uint8ptr(1)})}, + }, + { + name: "PtrHeadUint8PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *uint8 `json:"a,string"` + } + }{A: &(struct { + A *uint8 `json:"a,string"` + }{A: uint8ptr(1)})}, + }, + + // PtrHeadUint8PtrNilNotRoot { name: "PtrHeadUint8PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *uint8 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadUint8PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *uint8 `json:"a,omitempty"` + } + }{A: &(struct { + A *uint8 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadUint8PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *uint8 `json:"a,string"` + } + }{A: &(struct { + A *uint8 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadUint8NilNotRoot { name: "PtrHeadUint8NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadUint8NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *uint8 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUint8NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *uint8 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadUint8ZeroMultiFieldsNotRoot { name: "HeadUint8ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadUint8ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A uint8 `json:"a,omitempty"` + } + B struct { + B uint8 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadUint8ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A uint8 `json:"a,string"` + } + B struct { + B uint8 `json:"b,string"` + } + }{}, + }, + + // HeadUint8MultiFieldsNotRoot { name: "HeadUint8MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B uint8 `json:"b"` }{B: 2}}, }, + { + name: "HeadUint8MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A uint8 `json:"a,omitempty"` + } + B struct { + B uint8 `json:"b,omitempty"` + } + }{A: struct { + A uint8 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint8 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadUint8MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A uint8 `json:"a,string"` + } + B struct { + B uint8 `json:"b,string"` + } + }{A: struct { + A uint8 `json:"a,string"` + }{A: 1}, B: struct { + B uint8 `json:"b,string"` + }{B: 2}}, + }, + + // HeadUint8PtrMultiFieldsNotRoot { name: "HeadUint8PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *uint8 `json:"b"` }{B: uint8ptr(2)}}, }, + { + name: "HeadUint8PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *uint8 `json:"a,omitempty"` + } + B struct { + B *uint8 `json:"b,omitempty"` + } + }{A: struct { + A *uint8 `json:"a,omitempty"` + }{A: uint8ptr(1)}, B: struct { + B *uint8 `json:"b,omitempty"` + }{B: uint8ptr(2)}}, + }, + { + name: "HeadUint8PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *uint8 `json:"a,string"` + } + B struct { + B *uint8 `json:"b,string"` + } + }{A: struct { + A *uint8 `json:"a,string"` + }{A: uint8ptr(1)}, B: struct { + B *uint8 `json:"b,string"` + }{B: uint8ptr(2)}}, + }, + + // HeadUint8PtrNilMultiFieldsNotRoot { name: "HeadUint8PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *uint8 `json:"b"` }{B: nil}}, }, + { + name: "HeadUint8PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *uint8 `json:"a,omitempty"` + } + B struct { + B *uint8 `json:"b,omitempty"` + } + }{A: struct { + A *uint8 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *uint8 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadUint8PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *uint8 `json:"a,string"` + } + B struct { + B *uint8 `json:"b,string"` + } + }{A: struct { + A *uint8 `json:"a,string"` + }{A: nil}, B: struct { + B *uint8 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadUint8ZeroMultiFieldsNotRoot { name: "PtrHeadUint8ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadUint8ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A uint8 `json:"a,omitempty"` + } + B struct { + B uint8 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadUint8ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A uint8 `json:"a,string"` + } + B struct { + B uint8 `json:"b,string"` + } + }{}, + }, + + // PtrHeadUint8MultiFieldsNotRoot { name: "PtrHeadUint8MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B uint8 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadUint8MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A uint8 `json:"a,omitempty"` + } + B struct { + B uint8 `json:"b,omitempty"` + } + }{A: struct { + A uint8 `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint8 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadUint8MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A uint8 `json:"a,string"` + } + B struct { + B uint8 `json:"b,string"` + } + }{A: struct { + A uint8 `json:"a,string"` + }{A: 1}, B: struct { + B uint8 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadUint8PtrMultiFieldsNotRoot { name: "PtrHeadUint8PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *uint8 `json:"b"` }{B: uint8ptr(2)})}, }, + { + name: "PtrHeadUint8PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *uint8 `json:"a,omitempty"` + } + B *struct { + B *uint8 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint8 `json:"a,omitempty"` + }{A: uint8ptr(1)}), B: &(struct { + B *uint8 `json:"b,omitempty"` + }{B: uint8ptr(2)})}, + }, + { + name: "PtrHeadUint8PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *uint8 `json:"a,string"` + } + B *struct { + B *uint8 `json:"b,string"` + } + }{A: &(struct { + A *uint8 `json:"a,string"` + }{A: uint8ptr(1)}), B: &(struct { + B *uint8 `json:"b,string"` + }{B: uint8ptr(2)})}, + }, + + // PtrHeadUint8PtrNilMultiFieldsNotRoot { name: "PtrHeadUint8PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint8PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint8 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *uint8 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint8PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint8 `json:"a,string"` + } `json:",string"` + B *struct { + B *uint8 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUint8NilMultiFieldsNotRoot { name: "PtrHeadUint8NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadUint8NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint8 `json:"a,omitempty"` + } + B *struct { + B *uint8 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint8NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint8 `json:"a,string"` + } + B *struct { + B *uint8 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint8DoubleMultiFieldsNotRoot { name: "PtrHeadUint8DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B uint8 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadUint8DoubleMultiFieldsNotRootOmitEmpty", + 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 uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + } + B *struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + } + }{A: &(struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadUint8DoubleMultiFieldsNotRootString", + 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 uint8 `json:"a,string"` + B uint8 `json:"b,string"` + } + B *struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + } + }{A: &(struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadUint8NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint8NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint8NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint8NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + } + B *struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint8NilDoubleMultiFieldsNotRoot { name: "PtrHeadUint8NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadUint8NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + } + B *struct { + A uint8 `json:"a,omitempty"` + B uint8 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint8NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + } + B *struct { + A uint8 `json:"a,string"` + B uint8 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUint8PtrDoubleMultiFieldsNotRoot { name: "PtrHeadUint8PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *uint8 `json:"b"` }{A: uint8ptr(3), B: uint8ptr(4)})}, }, + { + name: "PtrHeadUint8PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + } + B *struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + } + }{A: &(struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + }{A: uint8ptr(1), B: uint8ptr(2)}), B: &(struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + }{A: uint8ptr(3), B: uint8ptr(4)})}, + }, + { + name: "PtrHeadUint8PtrDoubleMultiFieldsNotRootString", + 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 *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + } + B *struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + } + }{A: &(struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + }{A: uint8ptr(1), B: uint8ptr(2)}), B: &(struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + }{A: uint8ptr(3), B: uint8ptr(4)})}, + }, + + // PtrHeadUint8PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint8PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUint8PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUint8PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + } + B *struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUint8PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUint8PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadUint8PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + } + B *struct { + A *uint8 `json:"a,omitempty"` + B *uint8 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUint8PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + } + B *struct { + A *uint8 `json:"a,string"` + B *uint8 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadUint8 { name: "AnonymousHeadUint8", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadUint8OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint8OmitEmpty + B uint8 `json:"b,omitempty"` + }{ + structUint8OmitEmpty: structUint8OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadUint8String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint8String + B uint8 `json:"b,string"` + }{ + structUint8String: structUint8String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadUint8 { name: "PtrAnonymousHeadUint8", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadUint8OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint8OmitEmpty + B uint8 `json:"b,omitempty"` + }{ + structUint8OmitEmpty: &structUint8OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadUint8String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint8String + B uint8 `json:"b,string"` + }{ + structUint8String: &structUint8String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadUint8 { name: "NilPtrAnonymousHeadUint8", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadUint8OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint8OmitEmpty + B uint8 `json:"b,omitempty"` + }{ + structUint8OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadUint8String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint8String + B uint8 `json:"b,string"` + }{ + structUint8String: nil, + B: 2, + }, + }, + + // AnonymousHeadUint8Ptr { name: "AnonymousHeadUint8Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: uint8ptr(2), }, }, + { + name: "AnonymousHeadUint8PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUint8PtrOmitEmpty + B *uint8 `json:"b,omitempty"` + }{ + structUint8PtrOmitEmpty: structUint8PtrOmitEmpty{A: uint8ptr(1)}, + B: uint8ptr(2), + }, + }, + { + name: "AnonymousHeadUint8PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUint8PtrString + B *uint8 `json:"b,string"` + }{ + structUint8PtrString: structUint8PtrString{A: uint8ptr(1)}, + B: uint8ptr(2), + }, + }, + + // AnonymousHeadUint8PtrNil { name: "AnonymousHeadUint8PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: uint8ptr(2), }, }, + { + name: "AnonymousHeadUint8PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structUint8PtrOmitEmpty + B *uint8 `json:"b,omitempty"` + }{ + structUint8PtrOmitEmpty: structUint8PtrOmitEmpty{A: nil}, + B: uint8ptr(2), + }, + }, + { + name: "AnonymousHeadUint8PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structUint8PtrString + B *uint8 `json:"b,string"` + }{ + structUint8PtrString: structUint8PtrString{A: nil}, + B: uint8ptr(2), + }, + }, + + // PtrAnonymousHeadUint8Ptr { name: "PtrAnonymousHeadUint8Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: uint8ptr(2), }, }, + { + name: "PtrAnonymousHeadUint8PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUint8PtrOmitEmpty + B *uint8 `json:"b,omitempty"` + }{ + structUint8PtrOmitEmpty: &structUint8PtrOmitEmpty{A: uint8ptr(1)}, + B: uint8ptr(2), + }, + }, + { + name: "PtrAnonymousHeadUint8PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUint8PtrString + B *uint8 `json:"b,string"` + }{ + structUint8PtrString: &structUint8PtrString{A: uint8ptr(1)}, + B: uint8ptr(2), + }, + }, + + // NilPtrAnonymousHeadUint8Ptr { name: "NilPtrAnonymousHeadUint8Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: uint8ptr(2), }, }, + { + name: "NilPtrAnonymousHeadUint8PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUint8PtrOmitEmpty + B *uint8 `json:"b,omitempty"` + }{ + structUint8PtrOmitEmpty: nil, + B: uint8ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadUint8PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUint8PtrString + B *uint8 `json:"b,string"` + }{ + structUint8PtrString: nil, + B: uint8ptr(2), + }, + }, + + // AnonymousHeadUint8Only { name: "AnonymousHeadUint8Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structUint8: structUint8{A: 1}, }, }, + { + name: "AnonymousHeadUint8OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint8OmitEmpty + }{ + structUint8OmitEmpty: structUint8OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadUint8OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint8String + }{ + structUint8String: structUint8String{A: 1}, + }, + }, + + // PtrAnonymousHeadUint8Only { name: "PtrAnonymousHeadUint8Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structUint8: &structUint8{A: 1}, }, }, + { + name: "PtrAnonymousHeadUint8OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint8OmitEmpty + }{ + structUint8OmitEmpty: &structUint8OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadUint8OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint8String + }{ + structUint8String: &structUint8String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadUint8Only { name: "NilPtrAnonymousHeadUint8Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structUint8: nil, }, }, + { + name: "NilPtrAnonymousHeadUint8OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint8OmitEmpty + }{ + structUint8OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint8OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint8String + }{ + structUint8String: nil, + }, + }, + + // AnonymousHeadUint8PtrOnly { name: "AnonymousHeadUint8PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structUint8Ptr: structUint8Ptr{A: uint8ptr(1)}, }, }, + { + name: "AnonymousHeadUint8PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUint8PtrOmitEmpty + }{ + structUint8PtrOmitEmpty: structUint8PtrOmitEmpty{A: uint8ptr(1)}, + }, + }, + { + name: "AnonymousHeadUint8PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUint8PtrString + }{ + structUint8PtrString: structUint8PtrString{A: uint8ptr(1)}, + }, + }, + + // AnonymousHeadUint8PtrNilOnly { name: "AnonymousHeadUint8PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structUint8Ptr: structUint8Ptr{A: nil}, }, }, + { + name: "AnonymousHeadUint8PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structUint8PtrOmitEmpty + }{ + structUint8PtrOmitEmpty: structUint8PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadUint8PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structUint8PtrString + }{ + structUint8PtrString: structUint8PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadUint8PtrOnly { name: "PtrAnonymousHeadUint8PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structUint8Ptr: &structUint8Ptr{A: uint8ptr(1)}, }, }, + { + name: "PtrAnonymousHeadUint8PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUint8PtrOmitEmpty + }{ + structUint8PtrOmitEmpty: &structUint8PtrOmitEmpty{A: uint8ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadUint8PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUint8PtrString + }{ + structUint8PtrString: &structUint8PtrString{A: uint8ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadUint8PtrOnly { name: "NilPtrAnonymousHeadUint8PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structUint8Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadUint8PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint8PtrOmitEmpty + }{ + structUint8PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUint8PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUint8PtrString + }{ + structUint8PtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { @@ -974,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/cover_uint_test.go b/cover_uint_test.go index b91128b..6abf39c 100644 --- a/cover_uint_test.go +++ b/cover_uint_test.go @@ -12,9 +12,22 @@ func TestCoverUint(t *testing.T) { type structUint struct { A uint `json:"a"` } + type structUintOmitEmpty struct { + A uint `json:"a,omitempty"` + } + type structUintString struct { + A uint `json:"a,string"` + } + type structUintPtr struct { A *uint `json:"a"` } + type structUintPtrOmitEmpty struct { + A *uint `json:"a,omitempty"` + } + type structUintPtrString struct { + A *uint `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverUint(t *testing.T) { indentExpected string data interface{} }{ + // HeadUintZero { name: "HeadUintZero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverUint(t *testing.T) { A uint `json:"a"` }{}, }, + { + name: "HeadUintZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint `json:"a,omitempty"` + }{}, + }, + { + name: "HeadUintZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A uint `json:"a,string"` + }{}, + }, + + // HeadUint { name: "HeadUint", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverUint(t *testing.T) { A uint `json:"a"` }{A: 1}, }, + { + name: "HeadUintOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A uint `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadUintString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A uint `json:"a,string"` + }{A: 1}, + }, + + // HeadUintPtr { name: "HeadUintPtr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverUint(t *testing.T) { A *uint `json:"a"` }{A: uptr(1)}, }, + { + name: "HeadUintPtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *uint `json:"a,omitempty"` + }{A: uptr(1)}, + }, + { + name: "HeadUintPtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *uint `json:"a,string"` + }{A: uptr(1)}, + }, + + // HeadUintPtrNil { name: "HeadUintPtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverUint(t *testing.T) { A *uint `json:"a"` }{A: nil}, }, + { + name: "HeadUintPtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadUintPtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *uint `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUintZero { name: "PtrHeadUintZero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverUint(t *testing.T) { A uint `json:"a"` }{}, }, + { + name: "PtrHeadUintZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadUintZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A uint `json:"a,string"` + }{}, + }, + + // PtrHeadUint { name: "PtrHeadUint", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverUint(t *testing.T) { A uint `json:"a"` }{A: 1}, }, + { + name: "PtrHeadUintOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A uint `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadUintString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A uint `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadUintPtr { name: "PtrHeadUintPtr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverUint(t *testing.T) { A *uint `json:"a"` }{A: uptr(1)}, }, + { + name: "PtrHeadUintPtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *uint `json:"a,omitempty"` + }{A: uptr(1)}, + }, + { + name: "PtrHeadUintPtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *uint `json:"a,string"` + }{A: uptr(1)}, + }, + + // PtrHeadUintPtrNil { name: "PtrHeadUintPtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverUint(t *testing.T) { A *uint `json:"a"` }{A: nil}, }, + { + name: "PtrHeadUintPtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUintPtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *uint `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadUintNil { name: "PtrHeadUintNil", expected: `null`, @@ -128,6 +342,28 @@ null A *uint `json:"a"` })(nil), }, + { + name: "PtrHeadUintNilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadUintNilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint `json:"a,string"` + })(nil), + }, + + // HeadUintZeroMultiFields { name: "HeadUintZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B uint `json:"b"` }{}, }, + { + name: "HeadUintZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + }{}, + }, + { + name: "HeadUintZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + }{}, + }, + + // HeadUintMultiFields { name: "HeadUintMultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B uint `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadUintMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadUintMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadUintPtrMultiFields { name: "HeadUintPtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *uint `json:"b"` }{A: uptr(1), B: uptr(2)}, }, + { + name: "HeadUintPtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + }{A: uptr(1), B: uptr(2)}, + }, + { + name: "HeadUintPtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + }{A: uptr(1), B: uptr(2)}, + }, + + // HeadUintPtrNilMultiFields { name: "HeadUintPtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *uint `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadUintPtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadUintPtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUintZeroMultiFields { name: "PtrHeadUintZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B uint `json:"b"` }{}, }, + { + name: "PtrHeadUintZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadUintZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + }{}, + }, + + // PtrHeadUintMultiFields { name: "PtrHeadUintMultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B uint `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadUintMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadUintMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadUintPtrMultiFields { name: "PtrHeadUintPtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *uint `json:"b"` }{A: uptr(1), B: uptr(2)}, }, + { + name: "PtrHeadUintPtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + }{A: uptr(1), B: uptr(2)}, + }, + { + name: "PtrHeadUintPtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + }{A: uptr(1), B: uptr(2)}, + }, + + // PtrHeadUintPtrNilMultiFields { name: "PtrHeadUintPtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *uint `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadUintPtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUintPtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUintNilMultiFields { name: "PtrHeadUintNilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *uint `json:"b"` })(nil), }, + { + name: "PtrHeadUintNilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadUintNilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + })(nil), + }, + + // HeadUintZeroNotRoot { name: "HeadUintZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadUintZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A uint `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUintZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A uint `json:"a,string"` + } + }{}, + }, + + // HeadUintNotRoot { name: "HeadUintNotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A uint `json:"a"` }{A: 1}}, }, + { + name: "HeadUintNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A uint `json:"a,omitempty"` + } + }{A: struct { + A uint `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadUintNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A uint `json:"a,string"` + } + }{A: struct { + A uint `json:"a,string"` + }{A: 1}}, + }, + + // HeadUintPtrNotRoot { name: "HeadUintPtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *uint `json:"a"` }{uptr(1)}}, }, + { + name: "HeadUintPtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *uint `json:"a,omitempty"` + } + }{A: struct { + A *uint `json:"a,omitempty"` + }{uptr(1)}}, + }, + { + name: "HeadUintPtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *uint `json:"a,string"` + } + }{A: struct { + A *uint `json:"a,string"` + }{uptr(1)}}, + }, + + // HeadUintPtrNilNotRoot { name: "HeadUintPtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadUintPtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *uint `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadUintPtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *uint `json:"a,string"` + } + }{}, + }, + + // PtrHeadUintZeroNotRoot { name: "PtrHeadUintZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A uint `json:"a"` })}, }, + { + name: "PtrHeadUintZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A uint `json:"a,omitempty"` + } + }{A: new(struct { + A uint `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadUintZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A uint `json:"a,string"` + } + }{A: new(struct { + A uint `json:"a,string"` + })}, + }, + + // PtrHeadUintNotRoot { name: "PtrHeadUintNotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A uint `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadUintNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A uint `json:"a,omitempty"` + } + }{A: &(struct { + A uint `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadUintNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A uint `json:"a,string"` + } + }{A: &(struct { + A uint `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadUintPtrNotRoot { name: "PtrHeadUintPtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *uint `json:"a"` }{A: uptr(1)})}, }, + { + name: "PtrHeadUintPtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *uint `json:"a,omitempty"` + } + }{A: &(struct { + A *uint `json:"a,omitempty"` + }{A: uptr(1)})}, + }, + { + name: "PtrHeadUintPtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *uint `json:"a,string"` + } + }{A: &(struct { + A *uint `json:"a,string"` + }{A: uptr(1)})}, + }, + + // PtrHeadUintPtrNilNotRoot { name: "PtrHeadUintPtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *uint `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadUintPtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *uint `json:"a,omitempty"` + } + }{A: &(struct { + A *uint `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadUintPtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *uint `json:"a,string"` + } + }{A: &(struct { + A *uint `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadUintNilNotRoot { name: "PtrHeadUintNilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadUintNilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *uint `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadUintNilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *uint `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadUintZeroMultiFieldsNotRoot { name: "HeadUintZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadUintZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A uint `json:"a,omitempty"` + } + B struct { + B uint `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadUintZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A uint `json:"a,string"` + } + B struct { + B uint `json:"b,string"` + } + }{}, + }, + + // HeadUintMultiFieldsNotRoot { name: "HeadUintMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B uint `json:"b"` }{B: 2}}, }, + { + name: "HeadUintMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A uint `json:"a,omitempty"` + } + B struct { + B uint `json:"b,omitempty"` + } + }{A: struct { + A uint `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadUintMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A uint `json:"a,string"` + } + B struct { + B uint `json:"b,string"` + } + }{A: struct { + A uint `json:"a,string"` + }{A: 1}, B: struct { + B uint `json:"b,string"` + }{B: 2}}, + }, + + // HeadUintPtrMultiFieldsNotRoot { name: "HeadUintPtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *uint `json:"b"` }{B: uptr(2)}}, }, + { + name: "HeadUintPtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *uint `json:"a,omitempty"` + } + B struct { + B *uint `json:"b,omitempty"` + } + }{A: struct { + A *uint `json:"a,omitempty"` + }{A: uptr(1)}, B: struct { + B *uint `json:"b,omitempty"` + }{B: uptr(2)}}, + }, + { + name: "HeadUintPtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *uint `json:"a,string"` + } + B struct { + B *uint `json:"b,string"` + } + }{A: struct { + A *uint `json:"a,string"` + }{A: uptr(1)}, B: struct { + B *uint `json:"b,string"` + }{B: uptr(2)}}, + }, + + // HeadUintPtrNilMultiFieldsNotRoot { name: "HeadUintPtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *uint `json:"b"` }{B: nil}}, }, + { + name: "HeadUintPtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *uint `json:"a,omitempty"` + } + B struct { + B *uint `json:"b,omitempty"` + } + }{A: struct { + A *uint `json:"a,omitempty"` + }{A: nil}, B: struct { + B *uint `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadUintPtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *uint `json:"a,string"` + } + B struct { + B *uint `json:"b,string"` + } + }{A: struct { + A *uint `json:"a,string"` + }{A: nil}, B: struct { + B *uint `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadUintZeroMultiFieldsNotRoot { name: "PtrHeadUintZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadUintZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A uint `json:"a,omitempty"` + } + B struct { + B uint `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadUintZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A uint `json:"a,string"` + } + B struct { + B uint `json:"b,string"` + } + }{}, + }, + + // PtrHeadUintMultiFieldsNotRoot { name: "PtrHeadUintMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B uint `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadUintMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A uint `json:"a,omitempty"` + } + B struct { + B uint `json:"b,omitempty"` + } + }{A: struct { + A uint `json:"a,omitempty"` + }{A: 1}, B: struct { + B uint `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadUintMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A uint `json:"a,string"` + } + B struct { + B uint `json:"b,string"` + } + }{A: struct { + A uint `json:"a,string"` + }{A: 1}, B: struct { + B uint `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadUintPtrMultiFieldsNotRoot { name: "PtrHeadUintPtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *uint `json:"b"` }{B: uptr(2)})}, }, + { + name: "PtrHeadUintPtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *uint `json:"a,omitempty"` + } + B *struct { + B *uint `json:"b,omitempty"` + } + }{A: &(struct { + A *uint `json:"a,omitempty"` + }{A: uptr(1)}), B: &(struct { + B *uint `json:"b,omitempty"` + }{B: uptr(2)})}, + }, + { + name: "PtrHeadUintPtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *uint `json:"a,string"` + } + B *struct { + B *uint `json:"b,string"` + } + }{A: &(struct { + A *uint `json:"a,string"` + }{A: uptr(1)}), B: &(struct { + B *uint `json:"b,string"` + }{B: uptr(2)})}, + }, + + // PtrHeadUintPtrNilMultiFieldsNotRoot { name: "PtrHeadUintPtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUintPtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *uint `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUintPtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint `json:"a,string"` + } `json:",string"` + B *struct { + B *uint `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadUintNilMultiFieldsNotRoot { name: "PtrHeadUintNilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadUintNilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint `json:"a,omitempty"` + } + B *struct { + B *uint `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUintNilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint `json:"a,string"` + } + B *struct { + B *uint `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUintDoubleMultiFieldsNotRoot { name: "PtrHeadUintDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B uint `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadUintDoubleMultiFieldsNotRootOmitEmpty", + 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 uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + } + B *struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + } + }{A: &(struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadUintDoubleMultiFieldsNotRootString", + 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 uint `json:"a,string"` + B uint `json:"b,string"` + } + B *struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + } + }{A: &(struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadUintNilDoubleMultiFieldsNotRoot { name: "PtrHeadUintNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUintNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUintNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + } + B *struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUintNilDoubleMultiFieldsNotRoot { name: "PtrHeadUintNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadUintNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + } + B *struct { + A uint `json:"a,omitempty"` + B uint `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUintNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + } + B *struct { + A uint `json:"a,string"` + B uint `json:"b,string"` + } + })(nil), + }, + + // PtrHeadUintPtrDoubleMultiFieldsNotRoot { name: "PtrHeadUintPtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *uint `json:"b"` }{A: uptr(3), B: uptr(4)})}, }, + { + name: "PtrHeadUintPtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + } + B *struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + } + }{A: &(struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + }{A: uptr(1), B: uptr(2)}), B: &(struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + }{A: uptr(3), B: uptr(4)})}, + }, + { + name: "PtrHeadUintPtrDoubleMultiFieldsNotRootString", + 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 *uint `json:"a,string"` + B *uint `json:"b,string"` + } + B *struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + } + }{A: &(struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + }{A: uptr(1), B: uptr(2)}), B: &(struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + }{A: uptr(3), B: uptr(4)})}, + }, + + // PtrHeadUintPtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + } + B *struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadUintPtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + } + B *struct { + A *uint `json:"a,omitempty"` + B *uint `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadUintPtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + } + B *struct { + A *uint `json:"a,string"` + B *uint `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadUint { name: "AnonymousHeadUint", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadUintOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUintOmitEmpty + B uint `json:"b,omitempty"` + }{ + structUintOmitEmpty: structUintOmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadUintString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUintString + B uint `json:"b,string"` + }{ + structUintString: structUintString{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadUint { name: "PtrAnonymousHeadUint", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadUintOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUintOmitEmpty + B uint `json:"b,omitempty"` + }{ + structUintOmitEmpty: &structUintOmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadUintString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUintString + B uint `json:"b,string"` + }{ + structUintString: &structUintString{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadUint { name: "NilPtrAnonymousHeadUint", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadUintOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUintOmitEmpty + B uint `json:"b,omitempty"` + }{ + structUintOmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadUintString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUintString + B uint `json:"b,string"` + }{ + structUintString: nil, + B: 2, + }, + }, + + // AnonymousHeadUintPtr { name: "AnonymousHeadUintPtr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: uptr(2), }, }, + { + name: "AnonymousHeadUintPtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structUintPtrOmitEmpty + B *uint `json:"b,omitempty"` + }{ + structUintPtrOmitEmpty: structUintPtrOmitEmpty{A: uptr(1)}, + B: uptr(2), + }, + }, + { + name: "AnonymousHeadUintPtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structUintPtrString + B *uint `json:"b,string"` + }{ + structUintPtrString: structUintPtrString{A: uptr(1)}, + B: uptr(2), + }, + }, + + // AnonymousHeadUintPtrNil { name: "AnonymousHeadUintPtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: uptr(2), }, }, + { + name: "AnonymousHeadUintPtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structUintPtrOmitEmpty + B *uint `json:"b,omitempty"` + }{ + structUintPtrOmitEmpty: structUintPtrOmitEmpty{A: nil}, + B: uptr(2), + }, + }, + { + name: "AnonymousHeadUintPtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structUintPtrString + B *uint `json:"b,string"` + }{ + structUintPtrString: structUintPtrString{A: nil}, + B: uptr(2), + }, + }, + + // PtrAnonymousHeadUintPtr { name: "PtrAnonymousHeadUintPtr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: uptr(2), }, }, + { + name: "PtrAnonymousHeadUintPtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structUintPtrOmitEmpty + B *uint `json:"b,omitempty"` + }{ + structUintPtrOmitEmpty: &structUintPtrOmitEmpty{A: uptr(1)}, + B: uptr(2), + }, + }, + { + name: "PtrAnonymousHeadUintPtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structUintPtrString + B *uint `json:"b,string"` + }{ + structUintPtrString: &structUintPtrString{A: uptr(1)}, + B: uptr(2), + }, + }, + + // NilPtrAnonymousHeadUintPtr { name: "NilPtrAnonymousHeadUintPtr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: uptr(2), }, }, + { + name: "NilPtrAnonymousHeadUintPtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structUintPtrOmitEmpty + B *uint `json:"b,omitempty"` + }{ + structUintPtrOmitEmpty: nil, + B: uptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadUintPtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structUintPtrString + B *uint `json:"b,string"` + }{ + structUintPtrString: nil, + B: uptr(2), + }, + }, + + // AnonymousHeadUintOnly { name: "AnonymousHeadUintOnly", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structUint: structUint{A: 1}, }, }, + { + name: "AnonymousHeadUintOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUintOmitEmpty + }{ + structUintOmitEmpty: structUintOmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadUintOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUintString + }{ + structUintString: structUintString{A: 1}, + }, + }, + + // PtrAnonymousHeadUintOnly { name: "PtrAnonymousHeadUintOnly", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structUint: &structUint{A: 1}, }, }, + { + name: "PtrAnonymousHeadUintOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUintOmitEmpty + }{ + structUintOmitEmpty: &structUintOmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadUintOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUintString + }{ + structUintString: &structUintString{A: 1}, + }, + }, + + // NilPtrAnonymousHeadUintOnly { name: "NilPtrAnonymousHeadUintOnly", expected: `{}`, @@ -907,6 +2717,32 @@ null structUint: nil, }, }, + { + name: "NilPtrAnonymousHeadUintOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUintOmitEmpty + }{ + structUintOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUintOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUintString + }{ + structUintString: nil, + }, + }, + + // AnonymousHeadUintPtrOnly { name: "AnonymousHeadUintPtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structUintPtr: structUintPtr{A: uptr(1)}, }, }, + { + name: "AnonymousHeadUintPtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structUintPtrOmitEmpty + }{ + structUintPtrOmitEmpty: structUintPtrOmitEmpty{A: uptr(1)}, + }, + }, + { + name: "AnonymousHeadUintPtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structUintPtrString + }{ + structUintPtrString: structUintPtrString{A: uptr(1)}, + }, + }, + + // AnonymousHeadUintPtrNilOnly { name: "AnonymousHeadUintPtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structUintPtr: structUintPtr{A: nil}, }, }, + { + name: "AnonymousHeadUintPtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structUintPtrOmitEmpty + }{ + structUintPtrOmitEmpty: structUintPtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadUintPtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structUintPtrString + }{ + structUintPtrString: structUintPtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadUintPtrOnly { name: "PtrAnonymousHeadUintPtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structUintPtr: &structUintPtr{A: uptr(1)}, }, }, + { + name: "PtrAnonymousHeadUintPtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structUintPtrOmitEmpty + }{ + structUintPtrOmitEmpty: &structUintPtrOmitEmpty{A: uptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadUintPtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structUintPtrString + }{ + structUintPtrString: &structUintPtrString{A: uptr(1)}, + }, + }, + + // NilPtrAnonymousHeadUintPtrOnly { name: "NilPtrAnonymousHeadUintPtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structUintPtr: nil, }, }, + { + name: "NilPtrAnonymousHeadUintPtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUintPtrOmitEmpty + }{ + structUintPtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadUintPtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structUintPtrString + }{ + structUintPtrString: nil, + }, + }, } for _, test := range tests { for _, indent := range []bool{true, false} { @@ -974,6 +2922,10 @@ null if err := enc.Encode(test.data); err != nil { t.Fatalf("%s(htmlEscape:%T): %s: %s", test.name, htmlEscape, test.expected, err) } + stdresult := encodeByEncodingJSON(test.data, indent, htmlEscape) + if buf.String() != stdresult { + t.Errorf("%s(htmlEscape:%T): doesn't compatible with encoding/json. expected %q but got %q", test.name, htmlEscape, stdresult, buf.String()) + } if indent { got := "\n" + buf.String() if got != test.indentExpected { diff --git a/encode_vm.go b/encode_vm.go index 01761cc..435c732 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -2856,7 +2856,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next - case opStructFieldPtrHeadUint: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2873,6 +2872,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUintOnly, opStructFieldHeadUintOnly: p := load(ctxptr, code.idx) b = append(b, '{') @@ -2880,6 +2924,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendUint(b, uint64(e.ptrToUint(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintOnly, opStructFieldHeadOmitEmptyUintOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint(p)) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintOnly, opStructFieldHeadStringTagUintOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2902,6 +2965,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2923,6 +3029,48 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtrOnly: + 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 opStructFieldHeadOmitEmptyUintPtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintPtrOnly: + 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 opStructFieldHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldHeadUintNPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -2957,6 +3105,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintOnly, opStructFieldAnonymousHeadUintOnly: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2967,6 +3154,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUintOnly, opStructFieldAnonymousHeadOmitEmptyUintOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUintOnly, opStructFieldAnonymousHeadStringTagUintOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2985,6 +3199,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3003,6 +3255,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3019,6 +3309,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint8: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint8Only, opStructFieldHeadUint8Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3026,6 +3361,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendUint(b, uint64(e.ptrToUint8(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Only, opStructFieldHeadOmitEmptyUint8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint8(p)) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8Only, opStructFieldHeadStringTagUint8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3048,6 +3402,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3069,6 +3466,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8PtrOnly: + 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 opStructFieldHeadOmitEmptyUint8PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8PtrOnly: + 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 opStructFieldHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint8NPtr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3082,6 +3542,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Only, opStructFieldAnonymousHeadUint8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3092,6 +3591,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Only, opStructFieldAnonymousHeadOmitEmptyUint8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8Only, opStructFieldAnonymousHeadStringTagUint8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3110,6 +3636,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3128,6 +3692,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3144,6 +3746,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint16: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint16Only, opStructFieldHeadUint16Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3151,6 +3798,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendUint(b, uint64(e.ptrToUint16(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Only, opStructFieldHeadOmitEmptyUint16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint16(p)) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16Only, opStructFieldHeadStringTagUint16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3173,6 +3839,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3194,6 +3903,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16PtrOnly: + 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 opStructFieldHeadOmitEmptyUint16PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16PtrOnly: + 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 opStructFieldHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint16NPtr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3207,6 +3979,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Only, opStructFieldAnonymousHeadUint16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3217,6 +4028,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Only, opStructFieldAnonymousHeadOmitEmptyUint16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16Only, opStructFieldAnonymousHeadStringTagUint16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3235,6 +4073,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3253,6 +4129,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3269,6 +4183,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint32: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint32Only, opStructFieldHeadUint32Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3276,6 +4235,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendUint(b, uint64(e.ptrToUint32(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Only, opStructFieldHeadOmitEmptyUint32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint32(p)) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32Only, opStructFieldHeadStringTagUint32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3298,6 +4276,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3319,6 +4340,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32PtrOnly: + 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 opStructFieldHeadOmitEmptyUint32PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32PtrOnly: + 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 opStructFieldHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint32NPtr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3332,6 +4416,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Only, opStructFieldAnonymousHeadUint32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3342,6 +4465,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Only, opStructFieldAnonymousHeadOmitEmptyUint32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32Only, opStructFieldAnonymousHeadStringTagUint32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3360,6 +4510,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3378,6 +4566,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3394,6 +4620,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint64: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint64Only, opStructFieldHeadUint64Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3401,6 +4672,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = appendUint(b, e.ptrToUint64(p)) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Only, opStructFieldHeadOmitEmptyUint64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToUint64(p) + if v != 0 { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64Only, opStructFieldHeadStringTagUint64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3423,6 +4713,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3444,6 +4777,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64PtrOnly: + 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 opStructFieldHeadOmitEmptyUint64PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64PtrOnly: + 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 opStructFieldHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint64NPtr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3457,6 +4853,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Only, opStructFieldAnonymousHeadUint64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3467,6 +4902,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Only, opStructFieldAnonymousHeadOmitEmptyUint64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64Only, opStructFieldAnonymousHeadStringTagUint64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3485,6 +4947,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3503,6 +5003,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -4230,231 +5768,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint8(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint8(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint16(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint16(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = appendUint(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4878,201 +6191,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint: - 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint8: - 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint16: - 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint32: - 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint64: - 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6516,8 +7634,8 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte if v != 0 { b = append(b, code.key...) b = appendUint(b, uint64(v)) - b = appendStructEnd(b) } + b = appendStructEnd(b) code = code.next case opStructEndStringTagUint: ptr := load(ctxptr, code.headIdx) @@ -6538,6 +7656,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUintPtr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUintNPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint8: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -6572,6 +7729,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint8Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint8(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint8NPtr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint16: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -6606,6 +7802,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint16Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint16(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint16NPtr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -6640,6 +7875,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint32Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, uint64(e.ptrToUint32(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint32NPtr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -6659,7 +7933,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = append(b, '"') b = appendStructEnd(b) code = code.next @@ -6674,6 +7948,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint64Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = appendUint(b, e.ptrToUint64(p)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint64NPtr: + 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 = appendUint(b, e.ptrToUint64(p)) + } + b = appendStructEnd(b) + code = code.next case opStructEndFloat32: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 2bdb2e6..a9dcb92 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -2832,6 +2832,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUintOnly, opStructFieldHeadUintOnly: p := load(ctxptr, code.idx) b = append(b, '{') @@ -2839,6 +2884,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendUint(b, uint64(e.ptrToUint(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintOnly, opStructFieldHeadOmitEmptyUintOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintOnly, opStructFieldHeadStringTagUintOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2861,6 +2925,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2882,6 +2989,48 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtrOnly: + 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 opStructFieldHeadOmitEmptyUintPtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintPtrOnly: + 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 opStructFieldHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldHeadUintNPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -2916,6 +3065,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintOnly, opStructFieldAnonymousHeadUintOnly: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -2926,6 +3114,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUintOnly, opStructFieldAnonymousHeadOmitEmptyUintOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUintOnly, opStructFieldAnonymousHeadStringTagUintOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2944,6 +3159,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -2962,6 +3215,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -2978,6 +3269,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint8: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint8Only, opStructFieldHeadUint8Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -2985,6 +3321,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendUint(b, uint64(e.ptrToUint8(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Only, opStructFieldHeadOmitEmptyUint8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint8(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8Only, opStructFieldHeadStringTagUint8Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3007,6 +3362,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3028,6 +3426,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8PtrOnly: + 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 opStructFieldHeadOmitEmptyUint8PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8PtrOnly: + 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 opStructFieldHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint8NPtr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3041,6 +3502,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Only, opStructFieldAnonymousHeadUint8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3051,6 +3551,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Only, opStructFieldAnonymousHeadOmitEmptyUint8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8Only, opStructFieldAnonymousHeadStringTagUint8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3069,6 +3596,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3087,6 +3652,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3103,6 +3706,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint16: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint16Only, opStructFieldHeadUint16Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3110,6 +3758,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendUint(b, uint64(e.ptrToUint16(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Only, opStructFieldHeadOmitEmptyUint16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint16(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16Only, opStructFieldHeadStringTagUint16Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3132,6 +3799,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3153,6 +3863,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16PtrOnly: + 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 opStructFieldHeadOmitEmptyUint16PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16PtrOnly: + 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 opStructFieldHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint16NPtr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3166,6 +3939,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Only, opStructFieldAnonymousHeadUint16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3176,6 +3988,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Only, opStructFieldAnonymousHeadOmitEmptyUint16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16Only, opStructFieldAnonymousHeadStringTagUint16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3194,6 +4033,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3212,6 +4089,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3228,6 +4143,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint32: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint32Only, opStructFieldHeadUint32Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3235,6 +4195,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendUint(b, uint64(e.ptrToUint32(p))) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Only, opStructFieldHeadOmitEmptyUint32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := uint64(e.ptrToUint32(p)) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32Only, opStructFieldHeadStringTagUint32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3257,6 +4236,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3278,6 +4300,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32PtrOnly: + 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 opStructFieldHeadOmitEmptyUint32PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32PtrOnly: + 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 opStructFieldHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint32NPtr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3291,6 +4376,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Only, opStructFieldAnonymousHeadUint32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3301,6 +4425,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Only, opStructFieldAnonymousHeadOmitEmptyUint32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(v)) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32Only, opStructFieldAnonymousHeadStringTagUint32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3319,6 +4470,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3337,6 +4526,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3353,6 +4580,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToUint64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint64: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadUint64Only, opStructFieldHeadUint64Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -3360,6 +4632,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = appendUint(b, e.ptrToUint64(p)) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Only, opStructFieldHeadOmitEmptyUint64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToUint64(p) + if v != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64Only, opStructFieldHeadStringTagUint64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3382,6 +4673,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3403,6 +4737,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64PtrOnly: + 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 opStructFieldHeadOmitEmptyUint64PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64PtrOnly: + 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 opStructFieldHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadUint64NPtr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3416,6 +4813,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Only, opStructFieldAnonymousHeadUint64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3426,6 +4862,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Only, opStructFieldAnonymousHeadOmitEmptyUint64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64Only, opStructFieldAnonymousHeadStringTagUint64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3444,6 +4907,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3462,6 +4963,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -4196,231 +5735,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint8(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint8(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint16(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint16(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, uint64(v)) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToUint64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToUint64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = appendUint(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4844,201 +6158,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint: - 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint8: - 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint16: - 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint32: - 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint64: - 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6523,6 +7642,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUintPtr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUintNPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint8: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -6557,6 +7715,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint8Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint8(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint8NPtr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint16: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -6591,6 +7788,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint16Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint16(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint16NPtr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint32: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -6625,6 +7861,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint32Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, uint64(e.ptrToUint32(p))) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint32NPtr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + } + b = appendStructEnd(b) + code = code.next case opStructEndUint64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -6644,7 +7919,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) b = append(b, '"') - b = appendUint(b, uint64(e.ptrToUint64(ptr+code.offset))) + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = append(b, '"') b = appendStructEnd(b) code = code.next @@ -6659,6 +7934,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyUint64Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = appendUint(b, e.ptrToUint64(p)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndUint64NPtr: + 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 = appendUint(b, e.ptrToUint64(p)) + } + b = appendStructEnd(b) + code = code.next case opStructEndFloat32: 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 a004754..79e64fb 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -3081,6 +3081,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint: + 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.ptrToUint(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUintOnly, opStructFieldHeadUintOnly: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3090,6 +3138,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintOnly, opStructFieldHeadOmitEmptyUintOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintOnly, opStructFieldHeadStringTagUintOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3114,6 +3184,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3137,6 +3254,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtrOnly: + 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 opStructFieldHeadOmitEmptyUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintPtrOnly: + 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 opStructFieldHeadStringTagUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUintNPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3175,6 +3338,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintOnly, opStructFieldAnonymousHeadUintOnly: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3187,6 +3387,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUintOnly, opStructFieldAnonymousHeadOmitEmptyUintOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUintOnly, opStructFieldAnonymousHeadStringTagUintOnly: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3207,6 +3438,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3227,6 +3500,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3245,6 +3560,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint8: + 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.ptrToUint8(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint8: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint8Only, opStructFieldHeadUint8Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3254,6 +3617,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint8(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Only, opStructFieldHeadOmitEmptyUint8Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint8(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8Only, opStructFieldHeadStringTagUint8Only: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3278,6 +3663,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3301,6 +3733,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8PtrOnly: + 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 opStructFieldHeadOmitEmptyUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8PtrOnly: + 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 opStructFieldHeadStringTagUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint8NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3339,6 +3817,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Only, opStructFieldAnonymousHeadUint8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3351,6 +3866,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Only, opStructFieldAnonymousHeadOmitEmptyUint8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8Only, opStructFieldAnonymousHeadStringTagUint8Only: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3371,6 +3917,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3391,6 +3979,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3409,6 +4039,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint16: + 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.ptrToUint16(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint16: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint16Only, opStructFieldHeadUint16Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3418,6 +4096,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint16(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Only, opStructFieldHeadOmitEmptyUint16Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint16(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16Only, opStructFieldHeadStringTagUint16Only: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3442,6 +4142,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3465,6 +4212,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16PtrOnly: + 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 opStructFieldHeadOmitEmptyUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16PtrOnly: + 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 opStructFieldHeadStringTagUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint16NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3503,6 +4296,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Only, opStructFieldAnonymousHeadUint16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3515,6 +4345,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Only, opStructFieldAnonymousHeadOmitEmptyUint16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16Only, opStructFieldAnonymousHeadStringTagUint16Only: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3535,6 +4396,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3555,6 +4458,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3573,6 +4518,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint32: + 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.ptrToUint32(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint32: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint32Only, opStructFieldHeadUint32Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3582,6 +4575,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, uint64(e.ptrToUint32(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Only, opStructFieldHeadOmitEmptyUint32Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint32(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32Only, opStructFieldHeadStringTagUint32Only: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3606,6 +4621,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3629,6 +4691,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32PtrOnly: + 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 opStructFieldHeadOmitEmptyUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32PtrOnly: + 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 opStructFieldHeadStringTagUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint32NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3667,6 +4775,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Only, opStructFieldAnonymousHeadUint32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3679,6 +4824,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Only, opStructFieldAnonymousHeadOmitEmptyUint32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32Only, opStructFieldAnonymousHeadStringTagUint32Only: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3699,6 +4875,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3719,6 +4937,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3737,6 +4997,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint64: + 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.ptrToUint64(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 = appendUint(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint64: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint64Only, opStructFieldHeadUint64Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3746,6 +5054,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = appendUint(b, e.ptrToUint64(p)) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Only, opStructFieldHeadOmitEmptyUint64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToUint64(p) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64Only, opStructFieldHeadStringTagUint64Only: + 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 = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3770,6 +5100,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3793,6 +5170,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64PtrOnly: + 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 opStructFieldHeadOmitEmptyUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64PtrOnly: + 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 opStructFieldHeadStringTagUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint64NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3831,6 +5254,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(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 = appendUint(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Only, opStructFieldAnonymousHeadUint64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3843,6 +5303,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Only, opStructFieldAnonymousHeadOmitEmptyUint64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(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 = appendUint(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64Only, opStructFieldAnonymousHeadStringTagUint64Only: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3863,6 +5354,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3883,6 +5416,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -4307,146 +5882,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint: - 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.ptrToUint(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint8: - 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.ptrToUint8(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint16: - 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.ptrToUint16(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint32: - 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.ptrToUint32(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint64: - 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.ptrToUint64(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 = appendUint(b, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4611,121 +6046,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint: - 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint8: - 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint16: - 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint32: - 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint64: - 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5974,8 +7294,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint: ptr := load(ctxptr, code.headIdx) @@ -5999,6 +7328,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(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 opStructEndStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint8: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -6015,8 +7379,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint8: ptr := load(ctxptr, code.headIdx) @@ -6040,6 +7413,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(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 opStructEndStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint16: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -6056,8 +7464,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint16: ptr := load(ctxptr, code.headIdx) @@ -6081,6 +7498,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(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 opStructEndStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint32: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -6097,8 +7549,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint32: ptr := load(ctxptr, code.headIdx) @@ -6122,6 +7583,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(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 opStructEndStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint64: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -6138,8 +7634,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = appendUint(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 opStructEndStringTagUint64: ptr := load(ctxptr, code.headIdx) @@ -6163,6 +7668,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(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 opStructEndStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat32: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 325275c..091b3f6 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -3081,6 +3081,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint: + 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.ptrToUint(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUintOnly, opStructFieldHeadUintOnly: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3090,6 +3138,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintOnly, opStructFieldHeadOmitEmptyUintOnly: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintOnly, opStructFieldHeadStringTagUintOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3114,6 +3184,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3137,6 +3254,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUintPtrOnly: + 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 opStructFieldHeadOmitEmptyUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUintPtrOnly: + 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 opStructFieldHeadStringTagUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUintNPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3175,6 +3338,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintOnly, opStructFieldAnonymousHeadUintOnly: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3187,6 +3387,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUintOnly, opStructFieldAnonymousHeadOmitEmptyUintOnly: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUintOnly, opStructFieldAnonymousHeadStringTagUintOnly: + 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUintPtr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3207,6 +3438,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUintPtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3227,6 +3500,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUintPtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUintPtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint8: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3245,6 +3560,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint8: + 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.ptrToUint8(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint8: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint8: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint8Only, opStructFieldHeadUint8Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3254,6 +3617,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint8(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Only, opStructFieldHeadOmitEmptyUint8Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint8(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8Only, opStructFieldHeadStringTagUint8Only: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3278,6 +3663,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3301,6 +3733,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint8PtrOnly: + 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 opStructFieldHeadOmitEmptyUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint8PtrOnly: + 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 opStructFieldHeadStringTagUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint8NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3339,6 +3817,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Only, opStructFieldAnonymousHeadUint8Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3351,6 +3866,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Only, opStructFieldAnonymousHeadOmitEmptyUint8Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint8(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint8Only, opStructFieldAnonymousHeadStringTagUint8Only: + 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint8Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3371,6 +3917,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint8PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3391,6 +3979,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint8PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint8PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint8(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint16: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3409,6 +4039,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint16: + 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.ptrToUint16(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint16: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint16: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint16Only, opStructFieldHeadUint16Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3418,6 +4096,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint16(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Only, opStructFieldHeadOmitEmptyUint16Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint16(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16Only, opStructFieldHeadStringTagUint16Only: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3442,6 +4142,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3465,6 +4212,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint16PtrOnly: + 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 opStructFieldHeadOmitEmptyUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint16PtrOnly: + 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 opStructFieldHeadStringTagUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint16NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3503,6 +4296,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Only, opStructFieldAnonymousHeadUint16Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3515,6 +4345,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Only, opStructFieldAnonymousHeadOmitEmptyUint16Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint16(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint16Only, opStructFieldAnonymousHeadStringTagUint16Only: + 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint16Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3535,6 +4396,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint16PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3555,6 +4458,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint16PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint16PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint16(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3573,6 +4518,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint32: + 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.ptrToUint32(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint32: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint32Only, opStructFieldHeadUint32Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3582,6 +4575,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, uint64(e.ptrToUint32(p))) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Only, opStructFieldHeadOmitEmptyUint32Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := uint64(e.ptrToUint32(p)) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32Only, opStructFieldHeadStringTagUint32Only: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3606,6 +4621,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3629,6 +4691,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint32PtrOnly: + 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 opStructFieldHeadOmitEmptyUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint32PtrOnly: + 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 opStructFieldHeadStringTagUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint32NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3667,6 +4775,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Only, opStructFieldAnonymousHeadUint32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3679,6 +4824,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Only, opStructFieldAnonymousHeadOmitEmptyUint32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint32(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 = appendUint(b, uint64(v)) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint32Only, opStructFieldAnonymousHeadStringTagUint32Only: + 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3699,6 +4875,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3719,6 +4937,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint32PtrOnly: + 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 = appendUint(b, uint64(e.ptrToUint32(p+code.offset))) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3737,6 +4997,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyUint64: + 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.ptrToUint64(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 = appendUint(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagUint64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagUint64: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadUint64Only, opStructFieldHeadUint64Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -3746,6 +5054,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, e.ptrToUint64(p)) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Only, opStructFieldHeadOmitEmptyUint64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToUint64(p) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = appendUint(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64Only, opStructFieldHeadStringTagUint64Only: + 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 = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3770,6 +5100,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3793,6 +5170,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyUint64PtrOnly: + 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 opStructFieldHeadOmitEmptyUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagUint64PtrOnly: + 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 opStructFieldHeadStringTagUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadUint64NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -3831,6 +5254,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(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 = appendUint(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Only, opStructFieldAnonymousHeadUint64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -3843,6 +5303,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Only, opStructFieldAnonymousHeadOmitEmptyUint64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToUint64(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 = appendUint(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagUint64Only, opStructFieldAnonymousHeadStringTagUint64Only: + 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadUint64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -3863,6 +5354,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadUint64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -3883,6 +5416,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagUint64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagUint64PtrOnly: + 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 = appendUint(b, e.ptrToUint64(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -4307,146 +5882,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint: - 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.ptrToUint(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint8: - 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.ptrToUint8(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint16: - 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.ptrToUint16(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint32: - 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.ptrToUint32(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 = appendUint(b, uint64(v)) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyUint64: - 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.ptrToUint64(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 = appendUint(b, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -4611,121 +6046,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagUint: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint: - 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 = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint8: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint8: - 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 = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint16: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint16: - 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 = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint32: - 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 = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagUint64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagUint64: - 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 = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagFloat32: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -5974,8 +7294,17 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint: ptr := load(ctxptr, code.headIdx) @@ -5999,6 +7328,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(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 opStructEndStringTagUintPtr: + 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 = appendUint(b, uint64(e.ptrToUint(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint8: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -6015,8 +7379,17 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint8: ptr := load(ctxptr, code.headIdx) @@ -6040,6 +7413,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(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 opStructEndStringTagUint8Ptr: + 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 = appendUint(b, uint64(e.ptrToUint8(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint16: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -6056,8 +7464,17 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint16: ptr := load(ctxptr, code.headIdx) @@ -6081,6 +7498,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(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 opStructEndStringTagUint16Ptr: + 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 = appendUint(b, uint64(e.ptrToUint16(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint32: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -6097,8 +7549,17 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = appendUint(b, uint64(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 opStructEndStringTagUint32: ptr := load(ctxptr, code.headIdx) @@ -6122,6 +7583,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(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 opStructEndStringTagUint32Ptr: + 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 = appendUint(b, uint64(e.ptrToUint32(p))) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndUint64: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -6130,15 +7626,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = appendUint(b, e.ptrToUint64(ptr+code.offset)) b = e.appendStructEndIndent(b, code.indent-1) code = code.next - case opStructEndStringTagUint64: - ptr := load(ctxptr, code.headIdx) - b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = appendUint(b, e.ptrToUint64(ptr+code.offset)) - b = append(b, '"') - b = e.appendStructEndIndent(b, code.indent-1) - code = code.next case opStructEndOmitEmptyUint64: ptr := load(ctxptr, code.headIdx) v := e.ptrToUint64(ptr + code.offset) @@ -6147,7 +7634,25 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = appendUint(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 opStructEndStringTagUint64: + ptr := load(ctxptr, code.headIdx) + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ', '"') + b = appendUint(b, e.ptrToUint64(ptr+code.offset)) + b = append(b, '"') b = e.appendStructEndIndent(b, code.indent-1) code = code.next case opStructEndUint64Ptr: @@ -6163,6 +7668,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(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 opStructEndStringTagUint64Ptr: + 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 = appendUint(b, e.ptrToUint64(p)) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat32: b = e.encodeIndent(b, code.indent) b = append(b, code.key...)