From d1cfcb0450530f196da58606232d62a5d07e41de Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Tue, 19 Jan 2021 20:41:14 +0900 Subject: [PATCH] Add test cases for float32/float64 type --- cover_float32_test.go | 1952 +++++++++++++++++++++++++++++++++++ cover_float64_test.go | 1952 +++++++++++++++++++++++++++++++++++ encode_vm.go | 962 +++++++++++++---- encode_vm_escaped.go | 964 +++++++++++++---- encode_vm_escaped_indent.go | 926 ++++++++++++++--- encode_vm_indent.go | 926 ++++++++++++++--- 6 files changed, 7069 insertions(+), 613 deletions(-) diff --git a/cover_float32_test.go b/cover_float32_test.go index 0c17ed4..785a54e 100644 --- a/cover_float32_test.go +++ b/cover_float32_test.go @@ -12,9 +12,22 @@ func TestCoverFloat32(t *testing.T) { type structFloat32 struct { A float32 `json:"a"` } + type structFloat32OmitEmpty struct { + A float32 `json:"a,omitempty"` + } + type structFloat32String struct { + A float32 `json:"a,string"` + } + type structFloat32Ptr struct { A *float32 `json:"a"` } + type structFloat32PtrOmitEmpty struct { + A *float32 `json:"a,omitempty"` + } + type structFloat32PtrString struct { + A *float32 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverFloat32(t *testing.T) { indentExpected string data interface{} }{ + // HeadFloat32Zero { name: "HeadFloat32Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverFloat32(t *testing.T) { A float32 `json:"a"` }{}, }, + { + name: "HeadFloat32ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A float32 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadFloat32ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A float32 `json:"a,string"` + }{}, + }, + + // HeadFloat32 { name: "HeadFloat32", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverFloat32(t *testing.T) { A float32 `json:"a"` }{A: 1}, }, + { + name: "HeadFloat32OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A float32 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadFloat32String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A float32 `json:"a,string"` + }{A: 1}, + }, + + // HeadFloat32Ptr { name: "HeadFloat32Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverFloat32(t *testing.T) { A *float32 `json:"a"` }{A: float32ptr(1)}, }, + { + name: "HeadFloat32PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *float32 `json:"a,omitempty"` + }{A: float32ptr(1)}, + }, + { + name: "HeadFloat32PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *float32 `json:"a,string"` + }{A: float32ptr(1)}, + }, + + // HeadFloat32PtrNil { name: "HeadFloat32PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverFloat32(t *testing.T) { A *float32 `json:"a"` }{A: nil}, }, + { + name: "HeadFloat32PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *float32 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadFloat32PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *float32 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadFloat32Zero { name: "PtrHeadFloat32Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverFloat32(t *testing.T) { A float32 `json:"a"` }{}, }, + { + name: "PtrHeadFloat32ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A float32 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadFloat32ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A float32 `json:"a,string"` + }{}, + }, + + // PtrHeadFloat32 { name: "PtrHeadFloat32", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverFloat32(t *testing.T) { A float32 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadFloat32OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A float32 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadFloat32String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A float32 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadFloat32Ptr { name: "PtrHeadFloat32Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverFloat32(t *testing.T) { A *float32 `json:"a"` }{A: float32ptr(1)}, }, + { + name: "PtrHeadFloat32PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *float32 `json:"a,omitempty"` + }{A: float32ptr(1)}, + }, + { + name: "PtrHeadFloat32PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *float32 `json:"a,string"` + }{A: float32ptr(1)}, + }, + + // PtrHeadFloat32PtrNil { name: "PtrHeadFloat32PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverFloat32(t *testing.T) { A *float32 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadFloat32PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *float32 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadFloat32PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *float32 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadFloat32Nil { name: "PtrHeadFloat32Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *float32 `json:"a"` })(nil), }, + { + name: "PtrHeadFloat32NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float32 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadFloat32NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float32 `json:"a,string"` + })(nil), + }, + + // HeadFloat32ZeroMultiFields { name: "HeadFloat32ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B float32 `json:"b"` }{}, }, + { + name: "HeadFloat32ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadFloat32ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + }{}, + }, + + // HeadFloat32MultiFields { name: "HeadFloat32MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B float32 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadFloat32MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadFloat32MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadFloat32PtrMultiFields { name: "HeadFloat32PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *float32 `json:"b"` }{A: float32ptr(1), B: float32ptr(2)}, }, + { + name: "HeadFloat32PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + }{A: float32ptr(1), B: float32ptr(2)}, + }, + { + name: "HeadFloat32PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + }{A: float32ptr(1), B: float32ptr(2)}, + }, + + // HeadFloat32PtrNilMultiFields { name: "HeadFloat32PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *float32 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadFloat32PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadFloat32PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadFloat32ZeroMultiFields { name: "PtrHeadFloat32ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B float32 `json:"b"` }{}, }, + { + name: "PtrHeadFloat32ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadFloat32ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + }{}, + }, + + // PtrHeadFloat32MultiFields { name: "PtrHeadFloat32MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B float32 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadFloat32MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadFloat32MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadFloat32PtrMultiFields { name: "PtrHeadFloat32PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *float32 `json:"b"` }{A: float32ptr(1), B: float32ptr(2)}, }, + { + name: "PtrHeadFloat32PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + }{A: float32ptr(1), B: float32ptr(2)}, + }, + { + name: "PtrHeadFloat32PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + }{A: float32ptr(1), B: float32ptr(2)}, + }, + + // PtrHeadFloat32PtrNilMultiFields { name: "PtrHeadFloat32PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *float32 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat32PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat32PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadFloat32NilMultiFields { name: "PtrHeadFloat32NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *float32 `json:"b"` })(nil), }, + { + name: "PtrHeadFloat32NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadFloat32NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + })(nil), + }, + + // HeadFloat32ZeroNotRoot { name: "HeadFloat32ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadFloat32ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A float32 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadFloat32ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A float32 `json:"a,string"` + } + }{}, + }, + + // HeadFloat32NotRoot { name: "HeadFloat32NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A float32 `json:"a"` }{A: 1}}, }, + { + name: "HeadFloat32NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A float32 `json:"a,omitempty"` + } + }{A: struct { + A float32 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadFloat32NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A float32 `json:"a,string"` + } + }{A: struct { + A float32 `json:"a,string"` + }{A: 1}}, + }, + + // HeadFloat32PtrNotRoot { name: "HeadFloat32PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *float32 `json:"a"` }{float32ptr(1)}}, }, + { + name: "HeadFloat32PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *float32 `json:"a,omitempty"` + } + }{A: struct { + A *float32 `json:"a,omitempty"` + }{float32ptr(1)}}, + }, + { + name: "HeadFloat32PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *float32 `json:"a,string"` + } + }{A: struct { + A *float32 `json:"a,string"` + }{float32ptr(1)}}, + }, + + // HeadFloat32PtrNilNotRoot { name: "HeadFloat32PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadFloat32PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *float32 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadFloat32PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *float32 `json:"a,string"` + } + }{}, + }, + + // PtrHeadFloat32ZeroNotRoot { name: "PtrHeadFloat32ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A float32 `json:"a"` })}, }, + { + name: "PtrHeadFloat32ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A float32 `json:"a,omitempty"` + } + }{A: new(struct { + A float32 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadFloat32ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A float32 `json:"a,string"` + } + }{A: new(struct { + A float32 `json:"a,string"` + })}, + }, + + // PtrHeadFloat32NotRoot { name: "PtrHeadFloat32NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A float32 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadFloat32NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A float32 `json:"a,omitempty"` + } + }{A: &(struct { + A float32 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadFloat32NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A float32 `json:"a,string"` + } + }{A: &(struct { + A float32 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadFloat32PtrNotRoot { name: "PtrHeadFloat32PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *float32 `json:"a"` }{A: float32ptr(1)})}, }, + { + name: "PtrHeadFloat32PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *float32 `json:"a,omitempty"` + } + }{A: &(struct { + A *float32 `json:"a,omitempty"` + }{A: float32ptr(1)})}, + }, + { + name: "PtrHeadFloat32PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *float32 `json:"a,string"` + } + }{A: &(struct { + A *float32 `json:"a,string"` + }{A: float32ptr(1)})}, + }, + + // PtrHeadFloat32PtrNilNotRoot { name: "PtrHeadFloat32PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *float32 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadFloat32PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *float32 `json:"a,omitempty"` + } + }{A: &(struct { + A *float32 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadFloat32PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *float32 `json:"a,string"` + } + }{A: &(struct { + A *float32 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadFloat32NilNotRoot { name: "PtrHeadFloat32NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadFloat32NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *float32 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadFloat32NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *float32 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadFloat32ZeroMultiFieldsNotRoot { name: "HeadFloat32ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadFloat32ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A float32 `json:"a,omitempty"` + } + B struct { + B float32 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadFloat32ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A float32 `json:"a,string"` + } + B struct { + B float32 `json:"b,string"` + } + }{}, + }, + + // HeadFloat32MultiFieldsNotRoot { name: "HeadFloat32MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B float32 `json:"b"` }{B: 2}}, }, + { + name: "HeadFloat32MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A float32 `json:"a,omitempty"` + } + B struct { + B float32 `json:"b,omitempty"` + } + }{A: struct { + A float32 `json:"a,omitempty"` + }{A: 1}, B: struct { + B float32 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadFloat32MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A float32 `json:"a,string"` + } + B struct { + B float32 `json:"b,string"` + } + }{A: struct { + A float32 `json:"a,string"` + }{A: 1}, B: struct { + B float32 `json:"b,string"` + }{B: 2}}, + }, + + // HeadFloat32PtrMultiFieldsNotRoot { name: "HeadFloat32PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *float32 `json:"b"` }{B: float32ptr(2)}}, }, + { + name: "HeadFloat32PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *float32 `json:"a,omitempty"` + } + B struct { + B *float32 `json:"b,omitempty"` + } + }{A: struct { + A *float32 `json:"a,omitempty"` + }{A: float32ptr(1)}, B: struct { + B *float32 `json:"b,omitempty"` + }{B: float32ptr(2)}}, + }, + { + name: "HeadFloat32PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *float32 `json:"a,string"` + } + B struct { + B *float32 `json:"b,string"` + } + }{A: struct { + A *float32 `json:"a,string"` + }{A: float32ptr(1)}, B: struct { + B *float32 `json:"b,string"` + }{B: float32ptr(2)}}, + }, + + // HeadFloat32PtrNilMultiFieldsNotRoot { name: "HeadFloat32PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *float32 `json:"b"` }{B: nil}}, }, + { + name: "HeadFloat32PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *float32 `json:"a,omitempty"` + } + B struct { + B *float32 `json:"b,omitempty"` + } + }{A: struct { + A *float32 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *float32 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadFloat32PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *float32 `json:"a,string"` + } + B struct { + B *float32 `json:"b,string"` + } + }{A: struct { + A *float32 `json:"a,string"` + }{A: nil}, B: struct { + B *float32 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadFloat32ZeroMultiFieldsNotRoot { name: "PtrHeadFloat32ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadFloat32ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A float32 `json:"a,omitempty"` + } + B struct { + B float32 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadFloat32ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A float32 `json:"a,string"` + } + B struct { + B float32 `json:"b,string"` + } + }{}, + }, + + // PtrHeadFloat32MultiFieldsNotRoot { name: "PtrHeadFloat32MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B float32 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadFloat32MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A float32 `json:"a,omitempty"` + } + B struct { + B float32 `json:"b,omitempty"` + } + }{A: struct { + A float32 `json:"a,omitempty"` + }{A: 1}, B: struct { + B float32 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadFloat32MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A float32 `json:"a,string"` + } + B struct { + B float32 `json:"b,string"` + } + }{A: struct { + A float32 `json:"a,string"` + }{A: 1}, B: struct { + B float32 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadFloat32PtrMultiFieldsNotRoot { name: "PtrHeadFloat32PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *float32 `json:"b"` }{B: float32ptr(2)})}, }, + { + name: "PtrHeadFloat32PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *float32 `json:"a,omitempty"` + } + B *struct { + B *float32 `json:"b,omitempty"` + } + }{A: &(struct { + A *float32 `json:"a,omitempty"` + }{A: float32ptr(1)}), B: &(struct { + B *float32 `json:"b,omitempty"` + }{B: float32ptr(2)})}, + }, + { + name: "PtrHeadFloat32PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *float32 `json:"a,string"` + } + B *struct { + B *float32 `json:"b,string"` + } + }{A: &(struct { + A *float32 `json:"a,string"` + }{A: float32ptr(1)}), B: &(struct { + B *float32 `json:"b,string"` + }{B: float32ptr(2)})}, + }, + + // PtrHeadFloat32PtrNilMultiFieldsNotRoot { name: "PtrHeadFloat32PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat32PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *float32 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *float32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat32PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *float32 `json:"a,string"` + } `json:",string"` + B *struct { + B *float32 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadFloat32NilMultiFieldsNotRoot { name: "PtrHeadFloat32NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadFloat32NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float32 `json:"a,omitempty"` + } + B *struct { + B *float32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadFloat32NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float32 `json:"a,string"` + } + B *struct { + B *float32 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadFloat32DoubleMultiFieldsNotRoot { name: "PtrHeadFloat32DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B float32 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadFloat32DoubleMultiFieldsNotRootOmitEmpty", + 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 float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + } + B *struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + } + }{A: &(struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadFloat32DoubleMultiFieldsNotRootString", + 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 float32 `json:"a,string"` + B float32 `json:"b,string"` + } + B *struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + } + }{A: &(struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadFloat32NilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat32NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat32NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat32NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + } + B *struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadFloat32NilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat32NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadFloat32NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + } + B *struct { + A float32 `json:"a,omitempty"` + B float32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadFloat32NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + } + B *struct { + A float32 `json:"a,string"` + B float32 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadFloat32PtrDoubleMultiFieldsNotRoot { name: "PtrHeadFloat32PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *float32 `json:"b"` }{A: float32ptr(3), B: float32ptr(4)})}, }, + { + name: "PtrHeadFloat32PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + } + B *struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + } + }{A: &(struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + }{A: float32ptr(1), B: float32ptr(2)}), B: &(struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + }{A: float32ptr(3), B: float32ptr(4)})}, + }, + { + name: "PtrHeadFloat32PtrDoubleMultiFieldsNotRootString", + 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 *float32 `json:"a,string"` + B *float32 `json:"b,string"` + } + B *struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + } + }{A: &(struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + }{A: float32ptr(1), B: float32ptr(2)}), B: &(struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + }{A: float32ptr(3), B: float32ptr(4)})}, + }, + + // PtrHeadFloat32PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + } + B *struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadFloat32PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + } + B *struct { + A *float32 `json:"a,omitempty"` + B *float32 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadFloat32PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + } + B *struct { + A *float32 `json:"a,string"` + B *float32 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadFloat32 { name: "AnonymousHeadFloat32", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadFloat32OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structFloat32OmitEmpty + B float32 `json:"b,omitempty"` + }{ + structFloat32OmitEmpty: structFloat32OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadFloat32String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structFloat32String + B float32 `json:"b,string"` + }{ + structFloat32String: structFloat32String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadFloat32 { name: "PtrAnonymousHeadFloat32", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadFloat32OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structFloat32OmitEmpty + B float32 `json:"b,omitempty"` + }{ + structFloat32OmitEmpty: &structFloat32OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadFloat32String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structFloat32String + B float32 `json:"b,string"` + }{ + structFloat32String: &structFloat32String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadFloat32 { name: "NilPtrAnonymousHeadFloat32", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadFloat32OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structFloat32OmitEmpty + B float32 `json:"b,omitempty"` + }{ + structFloat32OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadFloat32String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structFloat32String + B float32 `json:"b,string"` + }{ + structFloat32String: nil, + B: 2, + }, + }, + + // AnonymousHeadFloat32Ptr { name: "AnonymousHeadFloat32Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: float32ptr(2), }, }, + { + name: "AnonymousHeadFloat32PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structFloat32PtrOmitEmpty + B *float32 `json:"b,omitempty"` + }{ + structFloat32PtrOmitEmpty: structFloat32PtrOmitEmpty{A: float32ptr(1)}, + B: float32ptr(2), + }, + }, + { + name: "AnonymousHeadFloat32PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structFloat32PtrString + B *float32 `json:"b,string"` + }{ + structFloat32PtrString: structFloat32PtrString{A: float32ptr(1)}, + B: float32ptr(2), + }, + }, + + // AnonymousHeadFloat32PtrNil { name: "AnonymousHeadFloat32PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: float32ptr(2), }, }, + { + name: "AnonymousHeadFloat32PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structFloat32PtrOmitEmpty + B *float32 `json:"b,omitempty"` + }{ + structFloat32PtrOmitEmpty: structFloat32PtrOmitEmpty{A: nil}, + B: float32ptr(2), + }, + }, + { + name: "AnonymousHeadFloat32PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structFloat32PtrString + B *float32 `json:"b,string"` + }{ + structFloat32PtrString: structFloat32PtrString{A: nil}, + B: float32ptr(2), + }, + }, + + // PtrAnonymousHeadFloat32Ptr { name: "PtrAnonymousHeadFloat32Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: float32ptr(2), }, }, + { + name: "PtrAnonymousHeadFloat32PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structFloat32PtrOmitEmpty + B *float32 `json:"b,omitempty"` + }{ + structFloat32PtrOmitEmpty: &structFloat32PtrOmitEmpty{A: float32ptr(1)}, + B: float32ptr(2), + }, + }, + { + name: "PtrAnonymousHeadFloat32PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structFloat32PtrString + B *float32 `json:"b,string"` + }{ + structFloat32PtrString: &structFloat32PtrString{A: float32ptr(1)}, + B: float32ptr(2), + }, + }, + + // NilPtrAnonymousHeadFloat32Ptr { name: "NilPtrAnonymousHeadFloat32Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: float32ptr(2), }, }, + { + name: "NilPtrAnonymousHeadFloat32PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structFloat32PtrOmitEmpty + B *float32 `json:"b,omitempty"` + }{ + structFloat32PtrOmitEmpty: nil, + B: float32ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadFloat32PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structFloat32PtrString + B *float32 `json:"b,string"` + }{ + structFloat32PtrString: nil, + B: float32ptr(2), + }, + }, + + // AnonymousHeadFloat32Only { name: "AnonymousHeadFloat32Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structFloat32: structFloat32{A: 1}, }, }, + { + name: "AnonymousHeadFloat32OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structFloat32OmitEmpty + }{ + structFloat32OmitEmpty: structFloat32OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadFloat32OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structFloat32String + }{ + structFloat32String: structFloat32String{A: 1}, + }, + }, + + // PtrAnonymousHeadFloat32Only { name: "PtrAnonymousHeadFloat32Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structFloat32: &structFloat32{A: 1}, }, }, + { + name: "PtrAnonymousHeadFloat32OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structFloat32OmitEmpty + }{ + structFloat32OmitEmpty: &structFloat32OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadFloat32OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structFloat32String + }{ + structFloat32String: &structFloat32String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadFloat32Only { name: "NilPtrAnonymousHeadFloat32Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structFloat32: nil, }, }, + { + name: "NilPtrAnonymousHeadFloat32OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat32OmitEmpty + }{ + structFloat32OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadFloat32OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat32String + }{ + structFloat32String: nil, + }, + }, + + // AnonymousHeadFloat32PtrOnly { name: "AnonymousHeadFloat32PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structFloat32Ptr: structFloat32Ptr{A: float32ptr(1)}, }, }, + { + name: "AnonymousHeadFloat32PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structFloat32PtrOmitEmpty + }{ + structFloat32PtrOmitEmpty: structFloat32PtrOmitEmpty{A: float32ptr(1)}, + }, + }, + { + name: "AnonymousHeadFloat32PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structFloat32PtrString + }{ + structFloat32PtrString: structFloat32PtrString{A: float32ptr(1)}, + }, + }, + + // AnonymousHeadFloat32PtrNilOnly { name: "AnonymousHeadFloat32PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structFloat32Ptr: structFloat32Ptr{A: nil}, }, }, + { + name: "AnonymousHeadFloat32PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structFloat32PtrOmitEmpty + }{ + structFloat32PtrOmitEmpty: structFloat32PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadFloat32PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structFloat32PtrString + }{ + structFloat32PtrString: structFloat32PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadFloat32PtrOnly { name: "PtrAnonymousHeadFloat32PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structFloat32Ptr: &structFloat32Ptr{A: float32ptr(1)}, }, }, + { + name: "PtrAnonymousHeadFloat32PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structFloat32PtrOmitEmpty + }{ + structFloat32PtrOmitEmpty: &structFloat32PtrOmitEmpty{A: float32ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadFloat32PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structFloat32PtrString + }{ + structFloat32PtrString: &structFloat32PtrString{A: float32ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadFloat32PtrOnly { name: "NilPtrAnonymousHeadFloat32PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structFloat32Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadFloat32PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat32PtrOmitEmpty + }{ + structFloat32PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadFloat32PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat32PtrString + }{ + structFloat32PtrString: 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_float64_test.go b/cover_float64_test.go index 3841254..3d2c14e 100644 --- a/cover_float64_test.go +++ b/cover_float64_test.go @@ -12,9 +12,22 @@ func TestCoverFloat64(t *testing.T) { type structFloat64 struct { A float64 `json:"a"` } + type structFloat64OmitEmpty struct { + A float64 `json:"a,omitempty"` + } + type structFloat64String struct { + A float64 `json:"a,string"` + } + type structFloat64Ptr struct { A *float64 `json:"a"` } + type structFloat64PtrOmitEmpty struct { + A *float64 `json:"a,omitempty"` + } + type structFloat64PtrString struct { + A *float64 `json:"a,string"` + } tests := []struct { name string @@ -22,6 +35,7 @@ func TestCoverFloat64(t *testing.T) { indentExpected string data interface{} }{ + // HeadFloat64Zero { name: "HeadFloat64Zero", expected: `{"a":0}`, @@ -34,6 +48,30 @@ func TestCoverFloat64(t *testing.T) { A float64 `json:"a"` }{}, }, + { + name: "HeadFloat64ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A float64 `json:"a,omitempty"` + }{}, + }, + { + name: "HeadFloat64ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: struct { + A float64 `json:"a,string"` + }{}, + }, + + // HeadFloat64 { name: "HeadFloat64", expected: `{"a":1}`, @@ -46,6 +84,32 @@ func TestCoverFloat64(t *testing.T) { A float64 `json:"a"` }{A: 1}, }, + { + name: "HeadFloat64OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A float64 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "HeadFloat64String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A float64 `json:"a,string"` + }{A: 1}, + }, + + // HeadFloat64Ptr { name: "HeadFloat64Ptr", expected: `{"a":1}`, @@ -58,6 +122,32 @@ func TestCoverFloat64(t *testing.T) { A *float64 `json:"a"` }{A: float64ptr(1)}, }, + { + name: "HeadFloat64PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + A *float64 `json:"a,omitempty"` + }{A: float64ptr(1)}, + }, + { + name: "HeadFloat64PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + A *float64 `json:"a,string"` + }{A: float64ptr(1)}, + }, + + // HeadFloat64PtrNil { name: "HeadFloat64PtrNil", expected: `{"a":null}`, @@ -70,6 +160,30 @@ func TestCoverFloat64(t *testing.T) { A *float64 `json:"a"` }{A: nil}, }, + { + name: "HeadFloat64PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *float64 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "HeadFloat64PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + A *float64 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadFloat64Zero { name: "PtrHeadFloat64Zero", expected: `{"a":0}`, @@ -82,6 +196,30 @@ func TestCoverFloat64(t *testing.T) { A float64 `json:"a"` }{}, }, + { + name: "PtrHeadFloat64ZeroOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A float64 `json:"a,omitempty"` + }{}, + }, + { + name: "PtrHeadFloat64ZeroString", + expected: `{"a":"0"}`, + indentExpected: ` +{ + "a": "0" +} +`, + data: &struct { + A float64 `json:"a,string"` + }{}, + }, + + // PtrHeadFloat64 { name: "PtrHeadFloat64", expected: `{"a":1}`, @@ -94,6 +232,32 @@ func TestCoverFloat64(t *testing.T) { A float64 `json:"a"` }{A: 1}, }, + { + name: "PtrHeadFloat64OmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A float64 `json:"a,omitempty"` + }{A: 1}, + }, + { + name: "PtrHeadFloat64String", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A float64 `json:"a,string"` + }{A: 1}, + }, + + // PtrHeadFloat64Ptr { name: "PtrHeadFloat64Ptr", expected: `{"a":1}`, @@ -106,6 +270,32 @@ func TestCoverFloat64(t *testing.T) { A *float64 `json:"a"` }{A: float64ptr(1)}, }, + { + name: "PtrHeadFloat64PtrOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: &struct { + A *float64 `json:"a,omitempty"` + }{A: float64ptr(1)}, + }, + { + name: "PtrHeadFloat64PtrString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: &struct { + A *float64 `json:"a,string"` + }{A: float64ptr(1)}, + }, + + // PtrHeadFloat64PtrNil { name: "PtrHeadFloat64PtrNil", expected: `{"a":null}`, @@ -118,6 +308,30 @@ func TestCoverFloat64(t *testing.T) { A *float64 `json:"a"` }{A: nil}, }, + { + name: "PtrHeadFloat64PtrNilOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *float64 `json:"a,omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadFloat64PtrNilString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: &struct { + A *float64 `json:"a,string"` + }{A: nil}, + }, + + // PtrHeadFloat64Nil { name: "PtrHeadFloat64Nil", expected: `null`, @@ -128,6 +342,28 @@ null A *float64 `json:"a"` })(nil), }, + { + name: "PtrHeadFloat64NilOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float64 `json:"a,omitempty"` + })(nil), + }, + { + name: "PtrHeadFloat64NilString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float64 `json:"a,string"` + })(nil), + }, + + // HeadFloat64ZeroMultiFields { name: "HeadFloat64ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -142,6 +378,33 @@ null B float64 `json:"b"` }{}, }, + { + name: "HeadFloat64ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + }{}, + }, + { + name: "HeadFloat64ZeroMultiFields", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + }{}, + }, + + // HeadFloat64MultiFields { name: "HeadFloat64MultiFields", expected: `{"a":1,"b":2}`, @@ -156,6 +419,36 @@ null B float64 `json:"b"` }{A: 1, B: 2}, }, + { + name: "HeadFloat64MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "HeadFloat64MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // HeadFloat64PtrMultiFields { name: "HeadFloat64PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -170,6 +463,36 @@ null B *float64 `json:"b"` }{A: float64ptr(1), B: float64ptr(2)}, }, + { + name: "HeadFloat64PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + }{A: float64ptr(1), B: float64ptr(2)}, + }, + { + name: "HeadFloat64PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + }{A: float64ptr(1), B: float64ptr(2)}, + }, + + // HeadFloat64PtrNilMultiFields { name: "HeadFloat64PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -184,6 +507,33 @@ null B *float64 `json:"b"` }{A: nil, B: nil}, }, + { + name: "HeadFloat64PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "HeadFloat64PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadFloat64ZeroMultiFields { name: "PtrHeadFloat64ZeroMultiFields", expected: `{"a":0,"b":0}`, @@ -198,6 +548,33 @@ null B float64 `json:"b"` }{}, }, + { + name: "PtrHeadFloat64ZeroMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + }{}, + }, + { + name: "PtrHeadFloat64ZeroMultiFieldsString", + expected: `{"a":"0","b":"0"}`, + indentExpected: ` +{ + "a": "0", + "b": "0" +} +`, + data: &struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + }{}, + }, + + // PtrHeadFloat64MultiFields { name: "PtrHeadFloat64MultiFields", expected: `{"a":1,"b":2}`, @@ -212,6 +589,36 @@ null B float64 `json:"b"` }{A: 1, B: 2}, }, + { + name: "PtrHeadFloat64MultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + }{A: 1, B: 2}, + }, + { + name: "PtrHeadFloat64MultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + }{A: 1, B: 2}, + }, + + // PtrHeadFloat64PtrMultiFields { name: "PtrHeadFloat64PtrMultiFields", expected: `{"a":1,"b":2}`, @@ -226,6 +633,36 @@ null B *float64 `json:"b"` }{A: float64ptr(1), B: float64ptr(2)}, }, + { + name: "PtrHeadFloat64PtrMultiFieldsOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: &struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + }{A: float64ptr(1), B: float64ptr(2)}, + }, + { + name: "PtrHeadFloat64PtrMultiFieldsString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: &struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + }{A: float64ptr(1), B: float64ptr(2)}, + }, + + // PtrHeadFloat64PtrNilMultiFields { name: "PtrHeadFloat64PtrNilMultiFields", expected: `{"a":null,"b":null}`, @@ -240,6 +677,33 @@ null B *float64 `json:"b"` }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat64PtrNilMultiFieldsOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat64PtrNilMultiFieldsString", + expected: `{"a":null,"b":null}`, + indentExpected: ` +{ + "a": null, + "b": null +} +`, + data: &struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + }{A: nil, B: nil}, + }, + + // PtrHeadFloat64NilMultiFields { name: "PtrHeadFloat64NilMultiFields", expected: `null`, @@ -251,6 +715,30 @@ null B *float64 `json:"b"` })(nil), }, + { + name: "PtrHeadFloat64NilMultiFieldsOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + })(nil), + }, + { + name: "PtrHeadFloat64NilMultiFieldsString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + })(nil), + }, + + // HeadFloat64ZeroNotRoot { name: "HeadFloat64ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -267,6 +755,38 @@ null } }{}, }, + { + name: "HeadFloat64ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A float64 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadFloat64ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A struct { + A float64 `json:"a,string"` + } + }{}, + }, + + // HeadFloat64NotRoot { name: "HeadFloat64NotRoot", expected: `{"A":{"a":1}}`, @@ -285,6 +805,44 @@ null A float64 `json:"a"` }{A: 1}}, }, + { + name: "HeadFloat64NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A float64 `json:"a,omitempty"` + } + }{A: struct { + A float64 `json:"a,omitempty"` + }{A: 1}}, + }, + { + name: "HeadFloat64NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A float64 `json:"a,string"` + } + }{A: struct { + A float64 `json:"a,string"` + }{A: 1}}, + }, + + // HeadFloat64PtrNotRoot { name: "HeadFloat64PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -303,6 +861,44 @@ null A *float64 `json:"a"` }{float64ptr(1)}}, }, + { + name: "HeadFloat64PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A struct { + A *float64 `json:"a,omitempty"` + } + }{A: struct { + A *float64 `json:"a,omitempty"` + }{float64ptr(1)}}, + }, + { + name: "HeadFloat64PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A struct { + A *float64 `json:"a,string"` + } + }{A: struct { + A *float64 `json:"a,string"` + }{float64ptr(1)}}, + }, + + // HeadFloat64PtrNilNotRoot { name: "HeadFloat64PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -319,6 +915,38 @@ null } }{}, }, + { + name: "HeadFloat64PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A struct { + A *float64 `json:"a,omitempty"` + } + }{}, + }, + { + name: "HeadFloat64PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A struct { + A *float64 `json:"a,string"` + } + }{}, + }, + + // PtrHeadFloat64ZeroNotRoot { name: "PtrHeadFloat64ZeroNotRoot", expected: `{"A":{"a":0}}`, @@ -337,6 +965,42 @@ null A float64 `json:"a"` })}, }, + { + name: "PtrHeadFloat64ZeroNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A float64 `json:"a,omitempty"` + } + }{A: new(struct { + A float64 `json:"a,omitempty"` + })}, + }, + { + name: "PtrHeadFloat64ZeroNotRootString", + expected: `{"A":{"a":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + } +} +`, + data: struct { + A *struct { + A float64 `json:"a,string"` + } + }{A: new(struct { + A float64 `json:"a,string"` + })}, + }, + + // PtrHeadFloat64NotRoot { name: "PtrHeadFloat64NotRoot", expected: `{"A":{"a":1}}`, @@ -355,6 +1019,44 @@ null A float64 `json:"a"` }{A: 1})}, }, + { + name: "PtrHeadFloat64NotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A float64 `json:"a,omitempty"` + } + }{A: &(struct { + A float64 `json:"a,omitempty"` + }{A: 1})}, + }, + { + name: "PtrHeadFloat64NotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A float64 `json:"a,string"` + } + }{A: &(struct { + A float64 `json:"a,string"` + }{A: 1})}, + }, + + // PtrHeadFloat64PtrNotRoot { name: "PtrHeadFloat64PtrNotRoot", expected: `{"A":{"a":1}}`, @@ -373,6 +1075,44 @@ null A *float64 `json:"a"` }{A: float64ptr(1)})}, }, + { + name: "PtrHeadFloat64PtrNotRootOmitEmpty", + expected: `{"A":{"a":1}}`, + indentExpected: ` +{ + "A": { + "a": 1 + } +} +`, + data: struct { + A *struct { + A *float64 `json:"a,omitempty"` + } + }{A: &(struct { + A *float64 `json:"a,omitempty"` + }{A: float64ptr(1)})}, + }, + { + name: "PtrHeadFloat64PtrNotRootString", + expected: `{"A":{"a":"1"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + } +} +`, + data: struct { + A *struct { + A *float64 `json:"a,string"` + } + }{A: &(struct { + A *float64 `json:"a,string"` + }{A: float64ptr(1)})}, + }, + + // PtrHeadFloat64PtrNilNotRoot { name: "PtrHeadFloat64PtrNilNotRoot", expected: `{"A":{"a":null}}`, @@ -391,6 +1131,42 @@ null A *float64 `json:"a"` }{A: nil})}, }, + { + name: "PtrHeadFloat64PtrNilNotRootOmitEmpty", + expected: `{"A":{}}`, + indentExpected: ` +{ + "A": {} +} +`, + data: struct { + A *struct { + A *float64 `json:"a,omitempty"` + } + }{A: &(struct { + A *float64 `json:"a,omitempty"` + }{A: nil})}, + }, + { + name: "PtrHeadFloat64PtrNilNotRootString", + expected: `{"A":{"a":null}}`, + indentExpected: ` +{ + "A": { + "a": null + } +} +`, + data: struct { + A *struct { + A *float64 `json:"a,string"` + } + }{A: &(struct { + A *float64 `json:"a,string"` + }{A: nil})}, + }, + + // PtrHeadFloat64NilNotRoot { name: "PtrHeadFloat64NilNotRoot", expected: `{"A":null}`, @@ -405,6 +1181,34 @@ null } }{A: nil}, }, + { + name: "PtrHeadFloat64NilNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + A *struct { + A *float64 `json:"a,omitempty"` + } `json:",omitempty"` + }{A: nil}, + }, + { + name: "PtrHeadFloat64NilNotRootString", + expected: `{"A":null}`, + indentExpected: ` +{ + "A": null +} +`, + data: struct { + A *struct { + A *float64 `json:"a,string"` + } `json:",string"` + }{A: nil}, + }, + + // HeadFloat64ZeroMultiFieldsNotRoot { name: "HeadFloat64ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -427,6 +1231,48 @@ null } }{}, }, + { + name: "HeadFloat64ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A float64 `json:"a,omitempty"` + } + B struct { + B float64 `json:"b,omitempty"` + } + }{}, + }, + { + name: "HeadFloat64ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: struct { + A struct { + A float64 `json:"a,string"` + } + B struct { + B float64 `json:"b,string"` + } + }{}, + }, + + // HeadFloat64MultiFieldsNotRoot { name: "HeadFloat64MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -453,6 +1299,60 @@ null B float64 `json:"b"` }{B: 2}}, }, + { + name: "HeadFloat64MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A float64 `json:"a,omitempty"` + } + B struct { + B float64 `json:"b,omitempty"` + } + }{A: struct { + A float64 `json:"a,omitempty"` + }{A: 1}, B: struct { + B float64 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "HeadFloat64MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A float64 `json:"a,string"` + } + B struct { + B float64 `json:"b,string"` + } + }{A: struct { + A float64 `json:"a,string"` + }{A: 1}, B: struct { + B float64 `json:"b,string"` + }{B: 2}}, + }, + + // HeadFloat64PtrMultiFieldsNotRoot { name: "HeadFloat64PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -479,6 +1379,60 @@ null B *float64 `json:"b"` }{B: float64ptr(2)}}, }, + { + name: "HeadFloat64PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: struct { + A struct { + A *float64 `json:"a,omitempty"` + } + B struct { + B *float64 `json:"b,omitempty"` + } + }{A: struct { + A *float64 `json:"a,omitempty"` + }{A: float64ptr(1)}, B: struct { + B *float64 `json:"b,omitempty"` + }{B: float64ptr(2)}}, + }, + { + name: "HeadFloat64PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: struct { + A struct { + A *float64 `json:"a,string"` + } + B struct { + B *float64 `json:"b,string"` + } + }{A: struct { + A *float64 `json:"a,string"` + }{A: float64ptr(1)}, B: struct { + B *float64 `json:"b,string"` + }{B: float64ptr(2)}}, + }, + + // HeadFloat64PtrNilMultiFieldsNotRoot { name: "HeadFloat64PtrNilMultiFieldsNotRoot", expected: `{"A":{"a":null},"B":{"b":null}}`, @@ -505,6 +1459,56 @@ null B *float64 `json:"b"` }{B: nil}}, }, + { + name: "HeadFloat64PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: struct { + A struct { + A *float64 `json:"a,omitempty"` + } + B struct { + B *float64 `json:"b,omitempty"` + } + }{A: struct { + A *float64 `json:"a,omitempty"` + }{A: nil}, B: struct { + B *float64 `json:"b,omitempty"` + }{B: nil}}, + }, + { + name: "HeadFloat64PtrNilMultiFieldsNotRootString", + expected: `{"A":{"a":null},"B":{"b":null}}`, + indentExpected: ` +{ + "A": { + "a": null + }, + "B": { + "b": null + } +} +`, + data: struct { + A struct { + A *float64 `json:"a,string"` + } + B struct { + B *float64 `json:"b,string"` + } + }{A: struct { + A *float64 `json:"a,string"` + }{A: nil}, B: struct { + B *float64 `json:"b,string"` + }{B: nil}}, + }, + + // PtrHeadFloat64ZeroMultiFieldsNotRoot { name: "PtrHeadFloat64ZeroMultiFieldsNotRoot", expected: `{"A":{"a":0},"B":{"b":0}}`, @@ -527,6 +1531,48 @@ null } }{}, }, + { + name: "PtrHeadFloat64ZeroMultiFieldsNotRootOmitEmpty", + expected: `{"A":{},"B":{}}`, + indentExpected: ` +{ + "A": {}, + "B": {} +} +`, + data: &struct { + A struct { + A float64 `json:"a,omitempty"` + } + B struct { + B float64 `json:"b,omitempty"` + } + }{}, + }, + { + name: "PtrHeadFloat64ZeroMultiFieldsNotRootString", + expected: `{"A":{"a":"0"},"B":{"b":"0"}}`, + indentExpected: ` +{ + "A": { + "a": "0" + }, + "B": { + "b": "0" + } +} +`, + data: &struct { + A struct { + A float64 `json:"a,string"` + } + B struct { + B float64 `json:"b,string"` + } + }{}, + }, + + // PtrHeadFloat64MultiFieldsNotRoot { name: "PtrHeadFloat64MultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -553,6 +1599,60 @@ null B float64 `json:"b"` }{B: 2}}, }, + { + name: "PtrHeadFloat64MultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A struct { + A float64 `json:"a,omitempty"` + } + B struct { + B float64 `json:"b,omitempty"` + } + }{A: struct { + A float64 `json:"a,omitempty"` + }{A: 1}, B: struct { + B float64 `json:"b,omitempty"` + }{B: 2}}, + }, + { + name: "PtrHeadFloat64MultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A struct { + A float64 `json:"a,string"` + } + B struct { + B float64 `json:"b,string"` + } + }{A: struct { + A float64 `json:"a,string"` + }{A: 1}, B: struct { + B float64 `json:"b,string"` + }{B: 2}}, + }, + + // PtrHeadFloat64PtrMultiFieldsNotRoot { name: "PtrHeadFloat64PtrMultiFieldsNotRoot", expected: `{"A":{"a":1},"B":{"b":2}}`, @@ -579,6 +1679,60 @@ null B *float64 `json:"b"` }{B: float64ptr(2)})}, }, + { + name: "PtrHeadFloat64PtrMultiFieldsNotRootOmitEmpty", + expected: `{"A":{"a":1},"B":{"b":2}}`, + indentExpected: ` +{ + "A": { + "a": 1 + }, + "B": { + "b": 2 + } +} +`, + data: &struct { + A *struct { + A *float64 `json:"a,omitempty"` + } + B *struct { + B *float64 `json:"b,omitempty"` + } + }{A: &(struct { + A *float64 `json:"a,omitempty"` + }{A: float64ptr(1)}), B: &(struct { + B *float64 `json:"b,omitempty"` + }{B: float64ptr(2)})}, + }, + { + name: "PtrHeadFloat64PtrMultiFieldsNotRootString", + expected: `{"A":{"a":"1"},"B":{"b":"2"}}`, + indentExpected: ` +{ + "A": { + "a": "1" + }, + "B": { + "b": "2" + } +} +`, + data: &struct { + A *struct { + A *float64 `json:"a,string"` + } + B *struct { + B *float64 `json:"b,string"` + } + }{A: &(struct { + A *float64 `json:"a,string"` + }{A: float64ptr(1)}), B: &(struct { + B *float64 `json:"b,string"` + }{B: float64ptr(2)})}, + }, + + // PtrHeadFloat64PtrNilMultiFieldsNotRoot { name: "PtrHeadFloat64PtrNilMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -597,6 +1751,41 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat64PtrNilMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *float64 `json:"a,omitempty"` + } `json:",omitempty"` + B *struct { + B *float64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat64PtrNilMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *float64 `json:"a,string"` + } `json:",string"` + B *struct { + B *float64 `json:"b,string"` + } `json:",string"` + }{A: nil, B: nil}, + }, + + // PtrHeadFloat64NilMultiFieldsNotRoot { name: "PtrHeadFloat64NilMultiFieldsNotRoot", expected: `null`, @@ -612,6 +1801,38 @@ null } })(nil), }, + { + name: "PtrHeadFloat64NilMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float64 `json:"a,omitempty"` + } + B *struct { + B *float64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadFloat64NilMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float64 `json:"a,string"` + } + B *struct { + B *float64 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadFloat64DoubleMultiFieldsNotRoot { name: "PtrHeadFloat64DoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -644,6 +1865,72 @@ null B float64 `json:"b"` }{A: 3, B: 4})}, }, + { + name: "PtrHeadFloat64DoubleMultiFieldsNotRootOmitEmpty", + 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 float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + } + B *struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + } + }{A: &(struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + }{A: 1, B: 2}), B: &(struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + }{A: 3, B: 4})}, + }, + { + name: "PtrHeadFloat64DoubleMultiFieldsNotRootString", + 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 float64 `json:"a,string"` + B float64 `json:"b,string"` + } + B *struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + } + }{A: &(struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + }{A: 1, B: 2}), B: &(struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + }{A: 3, B: 4})}, + }, + + // PtrHeadFloat64NilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat64NilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -664,6 +1951,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + } + B *struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadFloat64NilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat64NilDoubleMultiFieldsNotRoot", expected: `null`, @@ -681,6 +2007,42 @@ null } })(nil), }, + { + name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + } + B *struct { + A float64 `json:"a,omitempty"` + B float64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadFloat64NilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + } + B *struct { + A float64 `json:"a,string"` + B float64 `json:"b,string"` + } + })(nil), + }, + + // PtrHeadFloat64PtrDoubleMultiFieldsNotRoot { name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRoot", expected: `{"A":{"a":1,"b":2},"B":{"a":3,"b":4}}`, @@ -713,6 +2075,72 @@ null B *float64 `json:"b"` }{A: float64ptr(3), B: float64ptr(4)})}, }, + { + name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRootOmitEmpty", + 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 *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + } + B *struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + } + }{A: &(struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + }{A: float64ptr(1), B: float64ptr(2)}), B: &(struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + }{A: float64ptr(3), B: float64ptr(4)})}, + }, + { + name: "PtrHeadFloat64PtrDoubleMultiFieldsNotRootString", + 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 *float64 `json:"a,string"` + B *float64 `json:"b,string"` + } + B *struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + } + }{A: &(struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + }{A: float64ptr(1), B: float64ptr(2)}), B: &(struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + }{A: float64ptr(3), B: float64ptr(4)})}, + }, + + // PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot", expected: `{"A":null,"B":null}`, @@ -733,6 +2161,45 @@ null } }{A: nil, B: nil}, }, + { + name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: &struct { + A *struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + } `json:",omitempty"` + B *struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + } `json:",omitempty"` + }{A: nil, B: nil}, + }, + { + name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootString", + expected: `{"A":null,"B":null}`, + indentExpected: ` +{ + "A": null, + "B": null +} +`, + data: &struct { + A *struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + } + B *struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + } + }{A: nil, B: nil}, + }, + + // PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot { name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRoot", expected: `null`, @@ -750,6 +2217,42 @@ null } })(nil), }, + { + name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootOmitEmpty", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + } + B *struct { + A *float64 `json:"a,omitempty"` + B *float64 `json:"b,omitempty"` + } + })(nil), + }, + { + name: "PtrHeadFloat64PtrNilDoubleMultiFieldsNotRootString", + expected: `null`, + indentExpected: ` +null +`, + data: (*struct { + A *struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + } + B *struct { + A *float64 `json:"a,string"` + B *float64 `json:"b,string"` + } + })(nil), + }, + + // AnonymousHeadFloat64 { name: "AnonymousHeadFloat64", expected: `{"a":1,"b":2}`, @@ -767,6 +2270,42 @@ null B: 2, }, }, + { + name: "AnonymousHeadFloat64OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structFloat64OmitEmpty + B float64 `json:"b,omitempty"` + }{ + structFloat64OmitEmpty: structFloat64OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "AnonymousHeadFloat64String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structFloat64String + B float64 `json:"b,string"` + }{ + structFloat64String: structFloat64String{A: 1}, + B: 2, + }, + }, + + // PtrAnonymousHeadFloat64 { name: "PtrAnonymousHeadFloat64", expected: `{"a":1,"b":2}`, @@ -784,6 +2323,42 @@ null B: 2, }, }, + { + name: "PtrAnonymousHeadFloat64OmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structFloat64OmitEmpty + B float64 `json:"b,omitempty"` + }{ + structFloat64OmitEmpty: &structFloat64OmitEmpty{A: 1}, + B: 2, + }, + }, + { + name: "PtrAnonymousHeadFloat64String", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structFloat64String + B float64 `json:"b,string"` + }{ + structFloat64String: &structFloat64String{A: 1}, + B: 2, + }, + }, + + // NilPtrAnonymousHeadFloat64 { name: "NilPtrAnonymousHeadFloat64", expected: `{"b":2}`, @@ -800,6 +2375,40 @@ null B: 2, }, }, + { + name: "NilPtrAnonymousHeadFloat64OmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structFloat64OmitEmpty + B float64 `json:"b,omitempty"` + }{ + structFloat64OmitEmpty: nil, + B: 2, + }, + }, + { + name: "NilPtrAnonymousHeadFloat64String", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structFloat64String + B float64 `json:"b,string"` + }{ + structFloat64String: nil, + B: 2, + }, + }, + + // AnonymousHeadFloat64Ptr { name: "AnonymousHeadFloat64Ptr", expected: `{"a":1,"b":2}`, @@ -817,6 +2426,42 @@ null B: float64ptr(2), }, }, + { + name: "AnonymousHeadFloat64PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + structFloat64PtrOmitEmpty + B *float64 `json:"b,omitempty"` + }{ + structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: float64ptr(1)}, + B: float64ptr(2), + }, + }, + { + name: "AnonymousHeadFloat64PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + structFloat64PtrString + B *float64 `json:"b,string"` + }{ + structFloat64PtrString: structFloat64PtrString{A: float64ptr(1)}, + B: float64ptr(2), + }, + }, + + // AnonymousHeadFloat64PtrNil { name: "AnonymousHeadFloat64PtrNil", expected: `{"a":null,"b":2}`, @@ -834,6 +2479,41 @@ null B: float64ptr(2), }, }, + { + name: "AnonymousHeadFloat64PtrNilOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + structFloat64PtrOmitEmpty + B *float64 `json:"b,omitempty"` + }{ + structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: nil}, + B: float64ptr(2), + }, + }, + { + name: "AnonymousHeadFloat64PtrNilString", + expected: `{"a":null,"b":"2"}`, + indentExpected: ` +{ + "a": null, + "b": "2" +} +`, + data: struct { + structFloat64PtrString + B *float64 `json:"b,string"` + }{ + structFloat64PtrString: structFloat64PtrString{A: nil}, + B: float64ptr(2), + }, + }, + + // PtrAnonymousHeadFloat64Ptr { name: "PtrAnonymousHeadFloat64Ptr", expected: `{"a":1,"b":2}`, @@ -851,6 +2531,42 @@ null B: float64ptr(2), }, }, + { + name: "PtrAnonymousHeadFloat64PtrOmitEmpty", + expected: `{"a":1,"b":2}`, + indentExpected: ` +{ + "a": 1, + "b": 2 +} +`, + data: struct { + *structFloat64PtrOmitEmpty + B *float64 `json:"b,omitempty"` + }{ + structFloat64PtrOmitEmpty: &structFloat64PtrOmitEmpty{A: float64ptr(1)}, + B: float64ptr(2), + }, + }, + { + name: "PtrAnonymousHeadFloat64PtrString", + expected: `{"a":"1","b":"2"}`, + indentExpected: ` +{ + "a": "1", + "b": "2" +} +`, + data: struct { + *structFloat64PtrString + B *float64 `json:"b,string"` + }{ + structFloat64PtrString: &structFloat64PtrString{A: float64ptr(1)}, + B: float64ptr(2), + }, + }, + + // NilPtrAnonymousHeadFloat64Ptr { name: "NilPtrAnonymousHeadFloat64Ptr", expected: `{"b":2}`, @@ -867,6 +2583,40 @@ null B: float64ptr(2), }, }, + { + name: "NilPtrAnonymousHeadFloat64PtrOmitEmpty", + expected: `{"b":2}`, + indentExpected: ` +{ + "b": 2 +} +`, + data: struct { + *structFloat64PtrOmitEmpty + B *float64 `json:"b,omitempty"` + }{ + structFloat64PtrOmitEmpty: nil, + B: float64ptr(2), + }, + }, + { + name: "NilPtrAnonymousHeadFloat64PtrString", + expected: `{"b":"2"}`, + indentExpected: ` +{ + "b": "2" +} +`, + data: struct { + *structFloat64PtrString + B *float64 `json:"b,string"` + }{ + structFloat64PtrString: nil, + B: float64ptr(2), + }, + }, + + // AnonymousHeadFloat64Only { name: "AnonymousHeadFloat64Only", expected: `{"a":1}`, @@ -881,6 +2631,36 @@ null structFloat64: structFloat64{A: 1}, }, }, + { + name: "AnonymousHeadFloat64OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structFloat64OmitEmpty + }{ + structFloat64OmitEmpty: structFloat64OmitEmpty{A: 1}, + }, + }, + { + name: "AnonymousHeadFloat64OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structFloat64String + }{ + structFloat64String: structFloat64String{A: 1}, + }, + }, + + // PtrAnonymousHeadFloat64Only { name: "PtrAnonymousHeadFloat64Only", expected: `{"a":1}`, @@ -895,6 +2675,36 @@ null structFloat64: &structFloat64{A: 1}, }, }, + { + name: "PtrAnonymousHeadFloat64OnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structFloat64OmitEmpty + }{ + structFloat64OmitEmpty: &structFloat64OmitEmpty{A: 1}, + }, + }, + { + name: "PtrAnonymousHeadFloat64OnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structFloat64String + }{ + structFloat64String: &structFloat64String{A: 1}, + }, + }, + + // NilPtrAnonymousHeadFloat64Only { name: "NilPtrAnonymousHeadFloat64Only", expected: `{}`, @@ -907,6 +2717,32 @@ null structFloat64: nil, }, }, + { + name: "NilPtrAnonymousHeadFloat64OnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat64OmitEmpty + }{ + structFloat64OmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadFloat64OnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat64String + }{ + structFloat64String: nil, + }, + }, + + // AnonymousHeadFloat64PtrOnly { name: "AnonymousHeadFloat64PtrOnly", expected: `{"a":1}`, @@ -921,6 +2757,36 @@ null structFloat64Ptr: structFloat64Ptr{A: float64ptr(1)}, }, }, + { + name: "AnonymousHeadFloat64PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + structFloat64PtrOmitEmpty + }{ + structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: float64ptr(1)}, + }, + }, + { + name: "AnonymousHeadFloat64PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + structFloat64PtrString + }{ + structFloat64PtrString: structFloat64PtrString{A: float64ptr(1)}, + }, + }, + + // AnonymousHeadFloat64PtrNilOnly { name: "AnonymousHeadFloat64PtrNilOnly", expected: `{"a":null}`, @@ -935,6 +2801,34 @@ null structFloat64Ptr: structFloat64Ptr{A: nil}, }, }, + { + name: "AnonymousHeadFloat64PtrNilOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + structFloat64PtrOmitEmpty + }{ + structFloat64PtrOmitEmpty: structFloat64PtrOmitEmpty{A: nil}, + }, + }, + { + name: "AnonymousHeadFloat64PtrNilOnlyString", + expected: `{"a":null}`, + indentExpected: ` +{ + "a": null +} +`, + data: struct { + structFloat64PtrString + }{ + structFloat64PtrString: structFloat64PtrString{A: nil}, + }, + }, + + // PtrAnonymousHeadFloat64PtrOnly { name: "PtrAnonymousHeadFloat64PtrOnly", expected: `{"a":1}`, @@ -949,6 +2843,36 @@ null structFloat64Ptr: &structFloat64Ptr{A: float64ptr(1)}, }, }, + { + name: "PtrAnonymousHeadFloat64PtrOnlyOmitEmpty", + expected: `{"a":1}`, + indentExpected: ` +{ + "a": 1 +} +`, + data: struct { + *structFloat64PtrOmitEmpty + }{ + structFloat64PtrOmitEmpty: &structFloat64PtrOmitEmpty{A: float64ptr(1)}, + }, + }, + { + name: "PtrAnonymousHeadFloat64PtrOnlyString", + expected: `{"a":"1"}`, + indentExpected: ` +{ + "a": "1" +} +`, + data: struct { + *structFloat64PtrString + }{ + structFloat64PtrString: &structFloat64PtrString{A: float64ptr(1)}, + }, + }, + + // NilPtrAnonymousHeadFloat64PtrOnly { name: "NilPtrAnonymousHeadFloat64PtrOnly", expected: `{}`, @@ -961,6 +2885,30 @@ null structFloat64Ptr: nil, }, }, + { + name: "NilPtrAnonymousHeadFloat64PtrOnlyOmitEmpty", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat64PtrOmitEmpty + }{ + structFloat64PtrOmitEmpty: nil, + }, + }, + { + name: "NilPtrAnonymousHeadFloat64PtrOnlyString", + expected: `{}`, + indentExpected: ` +{} +`, + data: struct { + *structFloat64PtrString + }{ + structFloat64PtrString: 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 435c732..e0eb98e 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -5057,6 +5057,51 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToFloat32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = encodeFloat32(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat32: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadFloat32Only, opStructFieldHeadFloat32Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -5064,6 +5109,25 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeFloat32(b, e.ptrToFloat32(p)) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Only, opStructFieldHeadOmitEmptyFloat32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToFloat32(p) + if v != 0 { + b = append(b, code.key...) + b = encodeFloat32(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32Only, opStructFieldHeadStringTagFloat32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5086,6 +5150,49 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5107,6 +5214,69 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat32PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32PtrOnly: + 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 opStructFieldHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadFloat32NPtr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5120,6 +5290,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = encodeFloat32(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Only, opStructFieldAnonymousHeadFloat32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5130,6 +5339,33 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Only, opStructFieldAnonymousHeadOmitEmptyFloat32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = encodeFloat32(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Only, opStructFieldAnonymousHeadStringTagFloat32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5148,6 +5384,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5166,6 +5440,44 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5186,6 +5498,58 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = append(b, '"') + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadFloat64Only, opStructFieldHeadFloat64Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -5197,6 +5561,32 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeFloat64(b, v) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Only, opStructFieldHeadOmitEmptyFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToFloat64(p) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.key...) + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64Only, opStructFieldHeadStringTagFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + b = append(b, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5223,6 +5613,57 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat64Ptr: + 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...) + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5248,6 +5689,81 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat64PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.key...) + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64PtrOnly: + 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 opStructFieldHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadFloat64NPtr: + 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 { + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5265,6 +5781,53 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Only, opStructFieldAnonymousHeadFloat64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5279,6 +5842,41 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Only, opStructFieldAnonymousHeadOmitEmptyFloat64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Only, opStructFieldAnonymousHeadStringTagFloat64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.key...) + b = append(b, '"') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5301,6 +5899,52 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64Ptr: + 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...) + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5323,6 +5967,52 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.key...) + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.key...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadString: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5768,102 +6458,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToFloat32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = encodeFloat32(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToFloat32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.key...) - b = encodeFloat32(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToFloat64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = encodeFloat64(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToFloat64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = encodeFloat64(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6191,92 +6785,6 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat32: - 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.key...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -8021,6 +8529,45 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyFloat32Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + b = encodeFloat32(b, e.ptrToFloat32(p)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndFloat32NPtr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + } + b = appendStructEnd(b) + code = code.next case opStructEndFloat64: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) @@ -8072,6 +8619,57 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte b = encodeFloat64(b, v) b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyFloat64Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.key...) + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndFloat64NPtr: + 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 { + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = appendStructEnd(b) + code = code.next case opStructEndString: ptr := load(ctxptr, code.headIdx) b = append(b, code.key...) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index a9dcb92..5eca5b2 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -5017,6 +5017,51 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToFloat32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat32: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadFloat32Only, opStructFieldHeadFloat32Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -5024,6 +5069,25 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeFloat32(b, e.ptrToFloat32(p)) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Only, opStructFieldHeadOmitEmptyFloat32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToFloat32(p) + if v != 0 { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32Only, opStructFieldHeadStringTagFloat32Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5046,6 +5110,49 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5067,6 +5174,69 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat32PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32PtrOnly: + 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 opStructFieldHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadFloat32NPtr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat32: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5080,6 +5250,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Only, opStructFieldAnonymousHeadFloat32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5090,6 +5299,33 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Only, opStructFieldAnonymousHeadOmitEmptyFloat32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Only, opStructFieldAnonymousHeadStringTagFloat32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5108,6 +5344,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5126,6 +5400,44 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + b = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5146,6 +5458,58 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + b = encodeNull(b) + b = encodeComma(b) + code = code.end.next + } else { + b = append(b, '{') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = append(b, '"') + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrHeadFloat64Only, opStructFieldHeadFloat64Only: p := load(ctxptr, code.idx) b = append(b, '{') @@ -5157,6 +5521,32 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeFloat64(b, v) b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Only, opStructFieldHeadOmitEmptyFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + v := e.ptrToFloat64(p) + if v != 0 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = append(b, code.escapedKey...) + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64Only, opStructFieldHeadStringTagFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + b = append(b, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5183,6 +5573,57 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat64Ptr: + 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...) + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5208,6 +5649,81 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat64PtrOnly: + b = append(b, '{') + p := load(ctxptr, code.idx) + if p != 0 { + b = append(b, code.escapedKey...) + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64PtrOnly: + 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 opStructFieldHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, '{') + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next + case opStructFieldHeadFloat64NPtr: + 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 { + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5225,6 +5741,53 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Only, opStructFieldAnonymousHeadFloat64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5239,6 +5802,41 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Only, opStructFieldAnonymousHeadOmitEmptyFloat64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Only, opStructFieldAnonymousHeadStringTagFloat64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + b = append(b, code.escapedKey...) + b = append(b, '"') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5261,6 +5859,52 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64Ptr: + 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...) + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5283,6 +5927,52 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = encodeComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.nextField + } else { + b = append(b, code.escapedKey...) + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + b = append(b, code.escapedKey...) + if p == 0 { + b = encodeNull(b) + } else { + b = append(b, '"') + v := e.ptrToFloat64(p + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeComma(b) + code = code.next case opStructFieldPtrHeadString: p := load(ctxptr, code.idx) if p == 0 { @@ -5454,7 +6144,7 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) case opStructFieldHeadBoolOnly: ptr := load(ctxptr, code.idx) b = append(b, '{') - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = encodeBool(b, e.ptrToBool(ptr+code.offset)) b = encodeComma(b) code = code.next @@ -5735,102 +6425,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToFloat32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = encodeFloat32(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToFloat32(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - b = append(b, code.escapedKey...) - b = encodeFloat32(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToFloat64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = encodeFloat64(b, v) - b = encodeComma(b) - code = code.next - } - } - case opStructFieldPtrAnonymousHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToFloat64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = encodeFloat64(b, v) - b = encodeComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6158,92 +6752,6 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) code = code.next store(ctxptr, code.idx, ptr+code.offset) } - case opStructFieldPtrHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat32: - 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - b = encodeNull(b) - b = encodeComma(b) - code = code.end.next - } else { - b = append(b, '{') - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } - case opStructFieldPtrAnonymousHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldAnonymousHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr == 0 { - code = code.end.next - } else { - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = append(b, code.escapedKey...) - b = append(b, '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -8007,6 +8515,45 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) } b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyFloat32Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + b = encodeFloat32(b, e.ptrToFloat32(p)) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndFloat32NPtr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + } + b = appendStructEnd(b) + code = code.next case opStructEndFloat64: ptr := load(ctxptr, code.headIdx) b = append(b, code.escapedKey...) @@ -8058,6 +8605,57 @@ func (e *Encoder) runEscaped(ctx *encodeRuntimeContext, b []byte, code *opcode) b = encodeFloat64(b, v) b = appendStructEnd(b) code = code.next + case opStructEndOmitEmptyFloat64Ptr: + ptr := load(ctxptr, code.headIdx) + p := e.ptrToPtr(ptr + code.offset) + if p != 0 { + b = append(b, code.escapedKey...) + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = appendStructEnd(b) + code = code.next + case opStructEndStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = appendStructEnd(b) + code = code.next + case opStructEndFloat64NPtr: + 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 { + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = appendStructEnd(b) + code = code.next case opStructEndString: 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 79e64fb..33fade2 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -972,7 +972,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) @@ -1451,7 +1451,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) @@ -1930,7 +1930,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) @@ -2409,7 +2409,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) @@ -2888,7 +2888,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, e.ptrToInt64(ptr+code.offset)) @@ -3367,7 +3367,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) @@ -3846,7 +3846,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) @@ -4325,7 +4325,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) @@ -4804,7 +4804,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) @@ -5283,7 +5283,7 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.key...) + b = append(b, code.escapedKey...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, e.ptrToUint64(ptr+code.offset)) @@ -5476,6 +5476,54 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat32: + 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.ptrToFloat32(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 = encodeFloat32(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat32: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadFloat32Only, opStructFieldHeadFloat32Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -5485,6 +5533,28 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeFloat32(b, e.ptrToFloat32(p)) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Only, opStructFieldHeadOmitEmptyFloat32Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToFloat32(p) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat32(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32Only, opStructFieldHeadStringTagFloat32Only: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5509,6 +5579,53 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5532,6 +5649,52 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32PtrOnly: + 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 opStructFieldHeadStringTagFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadFloat32NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -5570,6 +5733,43 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(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 = encodeFloat32(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Only, opStructFieldAnonymousHeadFloat32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5582,6 +5782,37 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Only, opStructFieldAnonymousHeadOmitEmptyFloat32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(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 = encodeFloat32(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Only, opStructFieldAnonymousHeadStringTagFloat32Only: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5602,6 +5833,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5622,6 +5895,48 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5644,6 +5959,61 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat64: + 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.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat64: + 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, ' ', '"') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadFloat64Only, opStructFieldHeadFloat64Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -5657,6 +6027,35 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeFloat64(b, v) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Only, opStructFieldHeadOmitEmptyFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64Only, opStructFieldHeadStringTagFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.escapedKey...) + b = append(b, ' ', '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5685,6 +6084,61 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat64Ptr: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5712,6 +6166,60 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat64PtrOnly: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64PtrOnly: + 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 opStructFieldHeadStringTagFloat64PtrOnly: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadFloat64NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -5758,6 +6266,50 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64: + 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, '"') + v := e.ptrToFloat64(ptr) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Only, opStructFieldAnonymousHeadFloat64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5774,6 +6326,45 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Only, opStructFieldAnonymousHeadOmitEmptyFloat64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.escapedKey...) + b = append(b, ' ') + v := e.ptrToFloat64(ptr) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Only, opStructFieldAnonymousHeadStringTagFloat64Only: + 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, '"') + v := e.ptrToFloat64(ptr) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5798,6 +6389,56 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64Ptr: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5822,6 +6463,56 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64PtrOnly: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64PtrOnly: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadString: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5882,65 +6573,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat32: - 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.ptrToFloat32(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 = encodeFloat32(b, v) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat64: - 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.ptrToFloat64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent+1) - b = append(b, code.escapedKey...) - b = append(b, ' ') - b = encodeFloat64(b, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6046,56 +6678,6 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat32: - 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat64: - 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') - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent+1) - b = append(b, code.escapedKey...) - b = append(b, ' ', '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -7719,8 +8301,17 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op b = append(b, code.escapedKey...) b = append(b, ' ') b = encodeFloat32(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 opStructEndStringTagFloat32: ptr := load(ctxptr, code.headIdx) @@ -7744,6 +8335,41 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(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 opStructEndStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat64: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) @@ -7760,15 +8386,24 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op ptr := load(ctxptr, code.headIdx) v := e.ptrToFloat64(ptr + code.offset) if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) b = append(b, ' ') + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } b = encodeFloat64(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 opStructEndStringTagFloat64: ptr := load(ctxptr, code.headIdx) @@ -7800,6 +8435,49 @@ func (e *Encoder) runEscapedIndent(ctx *encodeRuntimeContext, b []byte, code *op } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat64Ptr: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(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 opStructEndStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndString: b = e.encodeIndent(b, code.indent) b = append(b, code.escapedKey...) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index 091b3f6..c46942f 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -972,7 +972,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt(ptr+code.offset))) @@ -1451,7 +1451,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt8(ptr+code.offset))) @@ -1930,7 +1930,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt16(ptr+code.offset))) @@ -2409,7 +2409,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, int64(e.ptrToInt32(ptr+code.offset))) @@ -2888,7 +2888,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendInt(b, e.ptrToInt64(ptr+code.offset)) @@ -3367,7 +3367,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint(ptr+code.offset))) @@ -3846,7 +3846,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint8(ptr+code.offset))) @@ -4325,7 +4325,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint16(ptr+code.offset))) @@ -4804,7 +4804,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, uint64(e.ptrToUint32(ptr+code.offset))) @@ -5283,7 +5283,7 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.end.next } else { b = e.encodeIndent(b, code.indent) - b = append(b, code.escapedKey...) + b = append(b, code.key...) b = append(b, ' ') b = append(b, '"') b = appendUint(b, e.ptrToUint64(ptr+code.offset)) @@ -5476,6 +5476,54 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat32: + 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.ptrToFloat32(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 = encodeFloat32(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat32: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat32: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadFloat32Only, opStructFieldHeadFloat32Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -5485,6 +5533,28 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeFloat32(b, e.ptrToFloat32(p)) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Only, opStructFieldHeadOmitEmptyFloat32Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToFloat32(p) + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat32(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32Only, opStructFieldHeadStringTagFloat32Only: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5509,6 +5579,53 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5532,6 +5649,52 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat32PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat32PtrOnly: + 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 opStructFieldHeadStringTagFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadFloat32NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -5570,6 +5733,43 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(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 = encodeFloat32(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Only, opStructFieldAnonymousHeadFloat32Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5582,6 +5782,37 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Only, opStructFieldAnonymousHeadOmitEmptyFloat32Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat32(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 = encodeFloat32(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Only, opStructFieldAnonymousHeadStringTagFloat32Only: + 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat32Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5602,6 +5833,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat32PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5622,6 +5895,48 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat32PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat32PtrOnly: + 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 = encodeFloat32(b, e.ptrToFloat32(p+code.offset)) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat64: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5644,6 +5959,61 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadOmitEmptyFloat64: + 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.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrHeadStringTagFloat64: + ptr := load(ctxptr, code.idx) + if ptr != 0 { + store(ctxptr, code.idx, e.ptrToPtr(ptr)) + } + fallthrough + case opStructFieldHeadStringTagFloat64: + 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, ' ', '"') + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrHeadFloat64Only, opStructFieldHeadFloat64Only: p := load(ctxptr, code.idx) b = append(b, '{', '\n') @@ -5657,6 +6027,35 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeFloat64(b, v) b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Only, opStructFieldHeadOmitEmptyFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + if v != 0 { + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64Only, opStructFieldHeadStringTagFloat64Only: + p := load(ctxptr, code.idx) + b = append(b, '{', '\n') + b = e.encodeIndent(b, code.indent+1) + b = append(b, code.key...) + b = append(b, ' ', '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5685,6 +6084,61 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadOmitEmptyFloat64Ptr: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + } + case opStructFieldPtrHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5712,6 +6166,60 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrHeadOmitEmptyFloat64PtrOnly: + 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 opStructFieldHeadOmitEmptyFloat64PtrOnly: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + } + code = code.next + case opStructFieldPtrHeadStringTagFloat64PtrOnly: + 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 opStructFieldHeadStringTagFloat64PtrOnly: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldHeadFloat64NPtr: p := load(ctxptr, code.idx) if p == 0 { @@ -5758,6 +6266,50 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64: + 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, '"') + v := e.ptrToFloat64(ptr) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Only, opStructFieldAnonymousHeadFloat64Only: ptr := load(ctxptr, code.idx) if ptr == 0 { @@ -5774,6 +6326,45 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Only, opStructFieldAnonymousHeadOmitEmptyFloat64Only: + ptr := load(ctxptr, code.idx) + if ptr == 0 { + code = code.end.next + } else { + v := e.ptrToFloat64(ptr + code.offset) + if v == 0 { + code = code.nextField + } else { + b = e.encodeIndent(b, code.indent) + b = append(b, code.key...) + b = append(b, ' ') + v := e.ptrToFloat64(ptr) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Only, opStructFieldAnonymousHeadStringTagFloat64Only: + 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, '"') + v := e.ptrToFloat64(ptr) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + b = encodeIndentComma(b) + code = code.next + } case opStructFieldPtrAnonymousHeadFloat64Ptr: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5798,6 +6389,56 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64Ptr: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64Ptr: + store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrAnonymousHeadFloat64PtrOnly: p := load(ctxptr, code.idx) if p == 0 { @@ -5822,6 +6463,56 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = encodeIndentComma(b) code = code.next + case opStructFieldPtrAnonymousHeadOmitEmptyFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadOmitEmptyFloat64PtrOnly: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = encodeIndentComma(b) + code = code.next + } + case opStructFieldPtrAnonymousHeadStringTagFloat64PtrOnly: + p := load(ctxptr, code.idx) + if p == 0 { + code = code.end.next + break + } + store(ctxptr, code.idx, e.ptrToPtr(p)) + fallthrough + case opStructFieldAnonymousHeadStringTagFloat64PtrOnly: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = encodeIndentComma(b) + code = code.next case opStructFieldPtrHeadString: store(ctxptr, code.idx, e.ptrToPtr(load(ctxptr, code.idx))) fallthrough @@ -5882,65 +6573,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = encodeIndentComma(b) code = code.next } - case opStructFieldPtrHeadOmitEmptyFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat32: - 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.ptrToFloat32(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 = encodeFloat32(b, v) - b = encodeIndentComma(b) - code = code.next - } - } - case opStructFieldPtrHeadOmitEmptyFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadOmitEmptyFloat64: - 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.ptrToFloat64(ptr + code.offset) - if v == 0 { - code = code.nextField - } else { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent+1) - b = append(b, code.key...) - b = append(b, ' ') - b = encodeFloat64(b, v) - b = encodeIndentComma(b) - code = code.next - } - } case opStructFieldPtrHeadOmitEmptyString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -6046,56 +6678,6 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( code = code.next store(ctxptr, code.idx, p) } - case opStructFieldPtrHeadStringTagFloat32: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat32: - 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 = encodeFloat32(b, e.ptrToFloat32(ptr+code.offset)) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } - case opStructFieldPtrHeadStringTagFloat64: - ptr := load(ctxptr, code.idx) - if ptr != 0 { - store(ctxptr, code.idx, e.ptrToPtr(ptr)) - } - fallthrough - case opStructFieldHeadStringTagFloat64: - 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') - v := e.ptrToFloat64(ptr + code.offset) - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } - b = e.encodeIndent(b, code.indent+1) - b = append(b, code.key...) - b = append(b, ' ', '"') - b = encodeFloat64(b, v) - b = append(b, '"') - b = encodeIndentComma(b) - code = code.next - } case opStructFieldPtrHeadStringTagString: ptr := load(ctxptr, code.idx) if ptr != 0 { @@ -7719,8 +8301,17 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( b = append(b, code.key...) b = append(b, ' ') b = encodeFloat32(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 opStructEndStringTagFloat32: ptr := load(ctxptr, code.headIdx) @@ -7744,6 +8335,41 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(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 opStructEndStringTagFloat32Ptr: + 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 = encodeFloat32(b, e.ptrToFloat32(p)) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndFloat64: b = e.encodeIndent(b, code.indent) b = append(b, code.key...) @@ -7760,15 +8386,24 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( ptr := load(ctxptr, code.headIdx) v := e.ptrToFloat64(ptr + code.offset) if v != 0 { - if math.IsInf(v, 0) || math.IsNaN(v) { - return nil, errUnsupportedFloat(v) - } b = e.encodeIndent(b, code.indent) b = append(b, code.key...) b = append(b, ' ') + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } b = encodeFloat64(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 opStructEndStringTagFloat64: ptr := load(ctxptr, code.headIdx) @@ -7800,6 +8435,49 @@ func (e *Encoder) runIndent(ctx *encodeRuntimeContext, b []byte, code *opcode) ( } b = e.appendStructEndIndent(b, code.indent-1) code = code.next + case opStructEndOmitEmptyFloat64Ptr: + 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, ' ') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(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 opStructEndStringTagFloat64Ptr: + 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, '"') + v := e.ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + b = append(b, '"') + } + b = e.appendStructEndIndent(b, code.indent-1) + code = code.next case opStructEndString: b = e.encodeIndent(b, code.indent) b = append(b, code.key...)