[#120] protogen: Marshal 64-bit integers as strings

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-10-01 13:50:43 +03:00
parent d94b9c6d0d
commit b06dad731c
10 changed files with 92 additions and 30 deletions

View file

@ -125,7 +125,9 @@ func (x *Decimal) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"value\":" const prefix string = "\"value\":"
out.RawString(prefix) out.RawString(prefix)
out.Int64(x.Value) out.RawByte('"')
out.Buffer.Buf = strconv.AppendInt(out.Buffer.Buf, x.Value, 10)
out.RawByte('"')
} }
} }
{ {

View file

@ -1423,7 +1423,9 @@ func (x *BearerToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"exp\":" const prefix string = "\"exp\":"
out.RawString(prefix) 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\":" const prefix string = "\"nbf\":"
out.RawString(prefix) 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\":" const prefix string = "\"iat\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.Iat) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Iat, 10)
out.RawByte('"')
} }
} }
out.RawByte('}') out.RawByte('}')

View file

@ -2081,7 +2081,9 @@ func (x *Netmap) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"epoch\":" const prefix string = "\"epoch\":"
out.RawString(prefix) 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\":" const prefix string = "\"currentEpoch\":"
out.RawString(prefix) 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\":" const prefix string = "\"magicNumber\":"
out.RawString(prefix) 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\":" const prefix string = "\"msPerBlock\":"
out.RawString(prefix) out.RawString(prefix)
out.Int64(x.MsPerBlock) out.RawByte('"')
out.Buffer.Buf = strconv.AppendInt(out.Buffer.Buf, x.MsPerBlock, 10)
out.RawByte('"')
} }
} }
{ {

View file

@ -5612,7 +5612,9 @@ func (x *Range) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"offset\":" const prefix string = "\"offset\":"
out.RawString(prefix) 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\":" const prefix string = "\"length\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.Length) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Length, 10)
out.RawByte('"')
} }
} }
out.RawByte('}') out.RawByte('}')

View file

@ -327,7 +327,9 @@ func (x *ShortHeader) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"creationEpoch\":" const prefix string = "\"creationEpoch\":"
out.RawString(prefix) 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\":" const prefix string = "\"payloadLength\":"
out.RawString(prefix) 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\":" const prefix string = "\"creationEpoch\":"
out.RawString(prefix) 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\":" const prefix string = "\"payloadLength\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.PayloadLength) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.PayloadLength, 10)
out.RawByte('"')
} }
} }
{ {

View file

@ -141,7 +141,9 @@ func (x *CreateRequest_Body) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"expiration\":" const prefix string = "\"expiration\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.Expiration) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Expiration, 10)
out.RawByte('"')
} }
} }
out.RawByte('}') out.RawByte('}')

View file

@ -877,7 +877,9 @@ func (x *SessionToken_Body_TokenLifetime) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"exp\":" const prefix string = "\"exp\":"
out.RawString(prefix) 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\":" const prefix string = "\"nbf\":"
out.RawString(prefix) 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\":" const prefix string = "\"iat\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.Iat) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Iat, 10)
out.RawByte('"')
} }
} }
out.RawByte('}') out.RawByte('}')
@ -1987,7 +1993,9 @@ func (x *RequestMetaHeader) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"epoch\":" const prefix string = "\"epoch\":"
out.RawString(prefix) 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\":" const prefix string = "\"magicNumber\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.MagicNumber) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.MagicNumber, 10)
out.RawByte('"')
} }
} }
out.RawByte('}') out.RawByte('}')
@ -2408,7 +2418,9 @@ func (x *ResponseMetaHeader) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"epoch\":" const prefix string = "\"epoch\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.Epoch) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.Epoch, 10)
out.RawByte('"')
} }
} }
{ {

View file

@ -152,7 +152,9 @@ func (x *Tombstone) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"expirationEpoch\":" const prefix string = "\"expirationEpoch\":"
out.RawString(prefix) out.RawString(prefix)
out.Uint64(x.ExpirationEpoch) out.RawByte('"')
out.Buffer.Buf = strconv.AppendUint(out.Buffer.Buf, x.ExpirationEpoch, 10)
out.RawByte('"')
} }
} }
{ {

View file

@ -647,7 +647,9 @@ func (x *Primitives) MarshalEasyJSON(out *jwriter.Writer) {
} }
const prefix string = "\"fieldF\":" const prefix string = "\"fieldF\":"
out.RawString(prefix) 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\":" const prefix string = "\"fieldG\":"
out.RawString(prefix) 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\":" const prefix string = "\"fieldI\":"
out.RawString(prefix) 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 { if i != 0 {
out.RawByte(',') 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(']') out.RawByte(']')
} }
@ -1467,7 +1475,9 @@ func (x *RepPrimitives) MarshalEasyJSON(out *jwriter.Writer) {
if i != 0 { if i != 0 {
out.RawByte(',') 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(']') out.RawByte(']')
} }
@ -1486,7 +1496,9 @@ func (x *RepPrimitives) MarshalEasyJSON(out *jwriter.Writer) {
if i != 0 { if i != 0 {
out.RawByte(',') 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(']') out.RawByte(']')
} }

View file

@ -231,9 +231,15 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
template = "out.Uint32(%s)" template = "out.Uint32(%s)"
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: 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: 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: case protoreflect.FloatKind:
template = "out.Float32(%s)" template = "out.Float32(%s)"
case protoreflect.DoubleKind: case protoreflect.DoubleKind: