mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-04-24 15:02:37 +00:00
Change also fixed64 format to be a number in JSON output
This commit is contained in:
parent
9233a902f4
commit
ba917c03ca
@ -302,18 +302,14 @@ func (e encoder) marshalSingular(val protoreflect.Value, fd protoreflect.FieldDe
|
|||||||
return errors.InvalidUTF8(string(fd.FullName()))
|
return errors.InvalidUTF8(string(fd.FullName()))
|
||||||
}
|
}
|
||||||
|
|
||||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind, protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||||
// 64-bit and 32-bit integers are written out as JSON number.
|
// 64-bit and 32-bit integers are written out as JSON number.
|
||||||
e.WriteInt(val.Int())
|
e.WriteInt(val.Int())
|
||||||
|
|
||||||
case protoreflect.Uint64Kind, protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind, protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||||
// 64-bit and 32-bit unsigned integers are written out as JSON number.
|
// 64-bit and 32-bit unsigned integers are written out as JSON number.
|
||||||
e.WriteUint(val.Uint())
|
e.WriteUint(val.Uint())
|
||||||
|
|
||||||
case protoreflect.Sfixed64Kind, protoreflect.Fixed64Kind:
|
|
||||||
// 64-bit fixed are written out as JSON string.
|
|
||||||
e.WriteString(val.String())
|
|
||||||
|
|
||||||
case protoreflect.FloatKind:
|
case protoreflect.FloatKind:
|
||||||
// Encoder.WriteFloat handles the special numbers NaN and infinites.
|
// Encoder.WriteFloat handles the special numbers NaN and infinites.
|
||||||
e.WriteFloat(val.Float(), 32)
|
e.WriteFloat(val.Float(), 32)
|
||||||
|
@ -80,9 +80,9 @@ func TestMarshal(t *testing.T) {
|
|||||||
"optSint32": 0,
|
"optSint32": 0,
|
||||||
"optSint64": 0,
|
"optSint64": 0,
|
||||||
"optFixed32": 0,
|
"optFixed32": 0,
|
||||||
"optFixed64": "0",
|
"optFixed64": 0,
|
||||||
"optSfixed32": 0,
|
"optSfixed32": 0,
|
||||||
"optSfixed64": "0",
|
"optSfixed64": 0,
|
||||||
"optFloat": 0,
|
"optFloat": 0,
|
||||||
"optDouble": 0,
|
"optDouble": 0,
|
||||||
"optBytes": "",
|
"optBytes": "",
|
||||||
@ -141,7 +141,7 @@ func TestMarshal(t *testing.T) {
|
|||||||
"optUint64": 3735928559,
|
"optUint64": 3735928559,
|
||||||
"optSint32": -1001,
|
"optSint32": -1001,
|
||||||
"optSint64": -65535,
|
"optSint64": -65535,
|
||||||
"optFixed64": "64",
|
"optFixed64": 64,
|
||||||
"optSfixed32": -32,
|
"optSfixed32": -32,
|
||||||
"optFloat": 1.02,
|
"optFloat": 1.02,
|
||||||
"optDouble": 1.234,
|
"optDouble": 1.234,
|
||||||
@ -741,7 +741,7 @@ func TestMarshal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: `{
|
want: `{
|
||||||
"reqBool": false,
|
"reqBool": false,
|
||||||
"reqSfixed64": "0",
|
"reqSfixed64": 0,
|
||||||
"reqDouble": 1.23,
|
"reqDouble": 1.23,
|
||||||
"reqString": "hello",
|
"reqString": "hello",
|
||||||
"reqEnum": "ONE"
|
"reqEnum": "ONE"
|
||||||
@ -759,7 +759,7 @@ func TestMarshal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: `{
|
want: `{
|
||||||
"reqBool": false,
|
"reqBool": false,
|
||||||
"reqSfixed64": "0",
|
"reqSfixed64": 0,
|
||||||
"reqDouble": 1.23,
|
"reqDouble": 1.23,
|
||||||
"reqString": "hello",
|
"reqString": "hello",
|
||||||
"reqEnum": "ONE"
|
"reqEnum": "ONE"
|
||||||
@ -776,7 +776,7 @@ func TestMarshal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: `{
|
want: `{
|
||||||
"reqBool": false,
|
"reqBool": false,
|
||||||
"reqSfixed64": "0",
|
"reqSfixed64": 0,
|
||||||
"reqDouble": 1.23,
|
"reqDouble": 1.23,
|
||||||
"reqString": "hello",
|
"reqString": "hello",
|
||||||
"reqEnum": "ONE",
|
"reqEnum": "ONE",
|
||||||
@ -1655,9 +1655,9 @@ func TestMarshal(t *testing.T) {
|
|||||||
"sSint32": 0,
|
"sSint32": 0,
|
||||||
"sSint64": 0,
|
"sSint64": 0,
|
||||||
"sFixed32": 0,
|
"sFixed32": 0,
|
||||||
"sFixed64": "0",
|
"sFixed64": 0,
|
||||||
"sSfixed32": 0,
|
"sSfixed32": 0,
|
||||||
"sSfixed64": "0",
|
"sSfixed64": 0,
|
||||||
"sFloat": 0,
|
"sFloat": 0,
|
||||||
"sDouble": 0,
|
"sDouble": 0,
|
||||||
"sBytes": "",
|
"sBytes": "",
|
||||||
@ -1966,9 +1966,9 @@ func TestMarshal(t *testing.T) {
|
|||||||
"sSint32": 0,
|
"sSint32": 0,
|
||||||
"sSint64": 0,
|
"sSint64": 0,
|
||||||
"sFixed32": 0,
|
"sFixed32": 0,
|
||||||
"sFixed64": "0",
|
"sFixed64": 0,
|
||||||
"sSfixed32": 0,
|
"sSfixed32": 0,
|
||||||
"sSfixed64": "0",
|
"sSfixed64": 0,
|
||||||
"sFloat": 0,
|
"sFloat": 0,
|
||||||
"sDouble": 0,
|
"sDouble": 0,
|
||||||
"sBytes": "",
|
"sBytes": "",
|
||||||
@ -2232,9 +2232,9 @@ func TestMarshal(t *testing.T) {
|
|||||||
"sSint32": 0,
|
"sSint32": 0,
|
||||||
"sSint64": 0,
|
"sSint64": 0,
|
||||||
"sFixed32": 0,
|
"sFixed32": 0,
|
||||||
"sFixed64": "0",
|
"sFixed64": 0,
|
||||||
"sSfixed32": 0,
|
"sSfixed32": 0,
|
||||||
"sSfixed64": "0",
|
"sSfixed64": 0,
|
||||||
"sFloat": 0,
|
"sFloat": 0,
|
||||||
"sDouble": 0,
|
"sDouble": 0,
|
||||||
"sBytes": "",
|
"sBytes": "",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user