From 0e7e77078dc9daa1b69677b0a0a3ed2e1eaa2fca Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 1 Oct 2024 13:50:43 +0300 Subject: [PATCH] [#120] protogen: Marshal 64-bit integers as strings Signed-off-by: Evgenii Stratonikov --- accounting/grpc/types_frostfs.pb.go | 4 +++- acl/grpc/types_frostfs.pb.go | 12 +++++++++--- netmap/grpc/types_frostfs.pb.go | 16 +++++++++++---- object/grpc/service_frostfs.pb.go | 8 ++++++-- object/grpc/types_frostfs.pb.go | 16 +++++++++++---- session/grpc/service_frostfs.pb.go | 4 +++- session/grpc/types_frostfs.pb.go | 24 +++++++++++++++++------ tombstone/grpc/types_frostfs.pb.go | 4 +++- util/proto/test/custom/test_frostfs.pb.go | 24 +++++++++++++++++------ util/protogen/internalgengo/json.go | 10 ++++++++-- 10 files changed, 92 insertions(+), 30 deletions(-) diff --git a/accounting/grpc/types_frostfs.pb.go b/accounting/grpc/types_frostfs.pb.go index 438cd03..8585583 100644 --- a/accounting/grpc/types_frostfs.pb.go +++ b/accounting/grpc/types_frostfs.pb.go @@ -125,7 +125,9 @@ func (x *Decimal) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"value\":" out.RawString(prefix) - out.Int64(x.Value) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendInt(out.Buffer.Buf, x.Value, 10) + out.RawByte('"') } } { diff --git a/acl/grpc/types_frostfs.pb.go b/acl/grpc/types_frostfs.pb.go index 6ebaf63..1ba6c53 100644 --- a/acl/grpc/types_frostfs.pb.go +++ b/acl/grpc/types_frostfs.pb.go @@ -1423,7 +1423,9 @@ func (x *BearerToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"exp\":" out.RawString(prefix) - out.Uint64(x.Exp) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Exp, 10) + out.RawByte('"') } } { @@ -1435,7 +1437,9 @@ func (x *BearerToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"nbf\":" out.RawString(prefix) - out.Uint64(x.Nbf) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Nbf, 10) + out.RawByte('"') } } { @@ -1447,7 +1451,9 @@ func (x *BearerToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"iat\":" out.RawString(prefix) - out.Uint64(x.Iat) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Iat, 10) + out.RawByte('"') } } out.RawByte('}') diff --git a/netmap/grpc/types_frostfs.pb.go b/netmap/grpc/types_frostfs.pb.go index 24b7575..a4b10f9 100644 --- a/netmap/grpc/types_frostfs.pb.go +++ b/netmap/grpc/types_frostfs.pb.go @@ -2081,7 +2081,9 @@ func (x *Netmap) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"epoch\":" out.RawString(prefix) - out.Uint64(x.Epoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Epoch, 10) + out.RawByte('"') } } { @@ -2655,7 +2657,9 @@ func (x *NetworkInfo) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"currentEpoch\":" out.RawString(prefix) - out.Uint64(x.CurrentEpoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.CurrentEpoch, 10) + out.RawByte('"') } } { @@ -2667,7 +2671,9 @@ func (x *NetworkInfo) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"magicNumber\":" out.RawString(prefix) - out.Uint64(x.MagicNumber) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.MagicNumber, 10) + out.RawByte('"') } } { @@ -2679,7 +2685,9 @@ func (x *NetworkInfo) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"msPerBlock\":" out.RawString(prefix) - out.Int64(x.MsPerBlock) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendInt(out.Buffer.Buf, x.MsPerBlock, 10) + out.RawByte('"') } } { diff --git a/object/grpc/service_frostfs.pb.go b/object/grpc/service_frostfs.pb.go index 0130ee3..f934f3b 100644 --- a/object/grpc/service_frostfs.pb.go +++ b/object/grpc/service_frostfs.pb.go @@ -5612,7 +5612,9 @@ func (x *Range) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"offset\":" out.RawString(prefix) - out.Uint64(x.Offset) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Offset, 10) + out.RawByte('"') } } { @@ -5624,7 +5626,9 @@ func (x *Range) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"length\":" out.RawString(prefix) - out.Uint64(x.Length) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Length, 10) + out.RawByte('"') } } out.RawByte('}') diff --git a/object/grpc/types_frostfs.pb.go b/object/grpc/types_frostfs.pb.go index bc246cf..0ee939a 100644 --- a/object/grpc/types_frostfs.pb.go +++ b/object/grpc/types_frostfs.pb.go @@ -327,7 +327,9 @@ func (x *ShortHeader) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"creationEpoch\":" out.RawString(prefix) - out.Uint64(x.CreationEpoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.CreationEpoch, 10) + out.RawByte('"') } } { @@ -368,7 +370,9 @@ func (x *ShortHeader) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"payloadLength\":" out.RawString(prefix) - out.Uint64(x.PayloadLength) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.PayloadLength, 10) + out.RawByte('"') } } { @@ -1882,7 +1886,9 @@ func (x *Header) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"creationEpoch\":" out.RawString(prefix) - out.Uint64(x.CreationEpoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.CreationEpoch, 10) + out.RawByte('"') } } { @@ -1894,7 +1900,9 @@ func (x *Header) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"payloadLength\":" out.RawString(prefix) - out.Uint64(x.PayloadLength) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.PayloadLength, 10) + out.RawByte('"') } } { diff --git a/session/grpc/service_frostfs.pb.go b/session/grpc/service_frostfs.pb.go index 71a6a41..c71325a 100644 --- a/session/grpc/service_frostfs.pb.go +++ b/session/grpc/service_frostfs.pb.go @@ -141,7 +141,9 @@ func (x *CreateRequest_Body) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"expiration\":" out.RawString(prefix) - out.Uint64(x.Expiration) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Expiration, 10) + out.RawByte('"') } } out.RawByte('}') diff --git a/session/grpc/types_frostfs.pb.go b/session/grpc/types_frostfs.pb.go index 1b6a664..e18c1ab 100644 --- a/session/grpc/types_frostfs.pb.go +++ b/session/grpc/types_frostfs.pb.go @@ -877,7 +877,9 @@ func (x *SessionToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"exp\":" out.RawString(prefix) - out.Uint64(x.Exp) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Exp, 10) + out.RawByte('"') } } { @@ -889,7 +891,9 @@ func (x *SessionToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"nbf\":" out.RawString(prefix) - out.Uint64(x.Nbf) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Nbf, 10) + out.RawByte('"') } } { @@ -901,7 +905,9 @@ func (x *SessionToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"iat\":" out.RawString(prefix) - out.Uint64(x.Iat) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Iat, 10) + out.RawByte('"') } } out.RawByte('}') @@ -1987,7 +1993,9 @@ func (x *RequestMetaHeader) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"epoch\":" out.RawString(prefix) - out.Uint64(x.Epoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Epoch, 10) + out.RawByte('"') } } { @@ -2066,7 +2074,9 @@ func (x *RequestMetaHeader) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"magicNumber\":" out.RawString(prefix) - out.Uint64(x.MagicNumber) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.MagicNumber, 10) + out.RawByte('"') } } out.RawByte('}') @@ -2408,7 +2418,9 @@ func (x *ResponseMetaHeader) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"epoch\":" out.RawString(prefix) - out.Uint64(x.Epoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Epoch, 10) + out.RawByte('"') } } { diff --git a/tombstone/grpc/types_frostfs.pb.go b/tombstone/grpc/types_frostfs.pb.go index 0971045..e5b67d5 100644 --- a/tombstone/grpc/types_frostfs.pb.go +++ b/tombstone/grpc/types_frostfs.pb.go @@ -152,7 +152,9 @@ func (x *Tombstone) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"expirationEpoch\":" out.RawString(prefix) - out.Uint64(x.ExpirationEpoch) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.ExpirationEpoch, 10) + out.RawByte('"') } } { diff --git a/util/proto/test/custom/test_frostfs.pb.go b/util/proto/test/custom/test_frostfs.pb.go index 15e77af..3804e46 100644 --- a/util/proto/test/custom/test_frostfs.pb.go +++ b/util/proto/test/custom/test_frostfs.pb.go @@ -647,7 +647,9 @@ func (x *Primitives) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"fieldF\":" out.RawString(prefix) - out.Int64(x.FieldF) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendInt(out.Buffer.Buf, x.FieldF, 10) + out.RawByte('"') } } { @@ -659,7 +661,9 @@ func (x *Primitives) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"fieldG\":" out.RawString(prefix) - out.Uint64(x.FieldG) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.FieldG, 10) + out.RawByte('"') } } { @@ -671,7 +675,9 @@ func (x *Primitives) MarshalEasyJSON(out *jwriter.Writer) { } const prefix string = "\"fieldI\":" out.RawString(prefix) - out.Uint64(x.FieldI) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.FieldI, 10) + out.RawByte('"') } } { @@ -1448,7 +1454,9 @@ func (x *RepPrimitives) MarshalEasyJSON(out *jwriter.Writer) { if i != 0 { out.RawByte(',') } - out.Int64(x.FieldE[i]) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendInt(out.Buffer.Buf, x.FieldE[i], 10) + out.RawByte('"') } out.RawByte(']') } @@ -1467,7 +1475,9 @@ func (x *RepPrimitives) MarshalEasyJSON(out *jwriter.Writer) { if i != 0 { out.RawByte(',') } - out.Uint64(x.FieldF[i]) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.FieldF[i], 10) + out.RawByte('"') } out.RawByte(']') } @@ -1486,7 +1496,9 @@ func (x *RepPrimitives) MarshalEasyJSON(out *jwriter.Writer) { if i != 0 { out.RawByte(',') } - out.Uint64(x.FieldFu[i]) + out.RawByte('"') + out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.FieldFu[i], 10) + out.RawByte('"') } out.RawByte(']') } diff --git a/util/protogen/internalgengo/json.go b/util/protogen/internalgengo/json.go index 606a9ff..3254d1b 100644 --- a/util/protogen/internalgengo/json.go +++ b/util/protogen/internalgengo/json.go @@ -231,9 +231,15 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: template = "out.Uint32(%s)" case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - template = "out.Int64(%s)" + g.P("out.RawByte('\"')") + g.P("out.Buffer.Buf = ", strconvPackage.Ident("AppendInt"), "(out.Buffer.Buf, ", selector, ", 10)") + g.P("out.RawByte('\"')") + return case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - template = "out.Uint64(%s)" + g.P("out.RawByte('\"')") + g.P("out.Buffer.Buf = ", strconvPackage.Ident("AppendUint"), "(out.Buffer.Buf, ", selector, ", 10)") + g.P("out.RawByte('\"')") + return case protoreflect.FloatKind: template = "out.Float32(%s)" case protoreflect.DoubleKind: