[#120] protogen: Unmarshal stringified integers from JSON

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

View file

@ -11,6 +11,7 @@ import (
easyproto "github.com/VictoriaMetrics/easyproto" easyproto "github.com/VictoriaMetrics/easyproto"
jlexer "github.com/mailru/easyjson/jlexer" jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter" jwriter "github.com/mailru/easyjson/jwriter"
strconv "strconv"
) )
type Decimal struct { type Decimal struct {
@ -170,13 +171,29 @@ func (x *Decimal) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "value": case "value":
{ {
var f int64 var f int64
f = in.Int64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseInt(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := int64(v)
f = pv
x.Value = f x.Value = f
} }
case "precision": case "precision":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Precision = f x.Precision = f
} }
} }

View file

@ -1481,19 +1481,43 @@ func (x *BearerToken_Body_TokenLifetime) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "exp": case "exp":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Exp = f x.Exp = f
} }
case "nbf": case "nbf":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Nbf = f x.Nbf = f
} }
case "iat": case "iat":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Iat = f x.Iat = f
} }
} }

View file

@ -13,6 +13,7 @@ import (
easyproto "github.com/VictoriaMetrics/easyproto" easyproto "github.com/VictoriaMetrics/easyproto"
jlexer "github.com/mailru/easyjson/jlexer" jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter" jwriter "github.com/mailru/easyjson/jwriter"
strconv "strconv"
) )
type Container_Attribute struct { type Container_Attribute struct {
@ -517,7 +518,15 @@ func (x *Container) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "basicACL": case "basicACL":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.BasicAcl = f x.BasicAcl = f
} }
case "attributes": case "attributes":

View file

@ -703,7 +703,15 @@ func (x *Selector) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "count": case "count":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Count = f x.Count = f
} }
case "clause": case "clause":
@ -970,7 +978,15 @@ func (x *Replica) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "count": case "count":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Count = f x.Count = f
} }
case "selector": case "selector":
@ -982,13 +998,29 @@ func (x *Replica) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "ecDataCount": case "ecDataCount":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.EcDataCount = f x.EcDataCount = f
} }
case "ecParityCount": case "ecParityCount":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.EcParityCount = f x.EcParityCount = f
} }
} }
@ -1306,7 +1338,15 @@ func (x *PlacementPolicy) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "containerBackupFactor": case "containerBackupFactor":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.ContainerBackupFactor = f x.ContainerBackupFactor = f
} }
case "selectors": case "selectors":
@ -2094,7 +2134,15 @@ func (x *Netmap) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "epoch": case "epoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Epoch = f x.Epoch = f
} }
case "nodes": case "nodes":
@ -2677,19 +2725,43 @@ func (x *NetworkInfo) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "currentEpoch": case "currentEpoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.CurrentEpoch = f x.CurrentEpoch = f
} }
case "magicNumber": case "magicNumber":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.MagicNumber = f x.MagicNumber = f
} }
case "msPerBlock": case "msPerBlock":
{ {
var f int64 var f int64
f = in.Int64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseInt(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := int64(v)
f = pv
x.MsPerBlock = f x.MsPerBlock = f
} }
case "networkConfig": case "networkConfig":

View file

@ -1508,7 +1508,15 @@ func (x *PutRequest_Body_Init) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []uint32 var list []uint32
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }
@ -4815,7 +4823,15 @@ func (x *SearchRequest_Body) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "version": case "version":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Version = f x.Version = f
} }
case "filters": case "filters":
@ -5642,13 +5658,29 @@ func (x *Range) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "offset": case "offset":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Offset = f x.Offset = f
} }
case "length": case "length":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Length = f x.Length = f
} }
} }
@ -7823,7 +7855,15 @@ func (x *PutSingleRequest_Body) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []uint32 var list []uint32
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }

View file

@ -433,7 +433,15 @@ func (x *ShortHeader) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "creationEpoch": case "creationEpoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.CreationEpoch = f x.CreationEpoch = f
} }
case "ownerID": case "ownerID":
@ -468,7 +476,15 @@ func (x *ShortHeader) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "payloadLength": case "payloadLength":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.PayloadLength = f x.PayloadLength = f
} }
case "payloadHash": case "payloadHash":
@ -1408,19 +1424,43 @@ func (x *Header_EC) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "index": case "index":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Index = f x.Index = f
} }
case "total": case "total":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Total = f x.Total = f
} }
case "headerLength": case "headerLength":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.HeaderLength = f x.HeaderLength = f
} }
case "header": case "header":
@ -2005,13 +2045,29 @@ func (x *Header) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "creationEpoch": case "creationEpoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.CreationEpoch = f x.CreationEpoch = f
} }
case "payloadLength": case "payloadLength":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.PayloadLength = f x.PayloadLength = f
} }
case "payloadHash": case "payloadHash":
@ -2777,13 +2833,29 @@ func (x *ECInfo_Chunk) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "index": case "index":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Index = f x.Index = f
} }
case "total": case "total":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Total = f x.Total = f
} }
} }

View file

@ -835,13 +835,29 @@ func (x *Version) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "major": case "major":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Major = f x.Major = f
} }
case "minor": case "minor":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Minor = f x.Minor = f
} }
} }

View file

@ -12,6 +12,7 @@ import (
easyproto "github.com/VictoriaMetrics/easyproto" easyproto "github.com/VictoriaMetrics/easyproto"
jlexer "github.com/mailru/easyjson/jlexer" jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter" jwriter "github.com/mailru/easyjson/jwriter"
strconv "strconv"
) )
type CreateRequest_Body struct { type CreateRequest_Body struct {
@ -181,7 +182,15 @@ func (x *CreateRequest_Body) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "expiration": case "expiration":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Expiration = f x.Expiration = f
} }
} }

View file

@ -935,19 +935,43 @@ func (x *SessionToken_Body_TokenLifetime) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "exp": case "exp":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Exp = f x.Exp = f
} }
case "nbf": case "nbf":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Nbf = f x.Nbf = f
} }
case "iat": case "iat":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Iat = f x.Iat = f
} }
} }
@ -2083,13 +2107,29 @@ func (x *RequestMetaHeader) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "epoch": case "epoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Epoch = f x.Epoch = f
} }
case "ttl": case "ttl":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Ttl = f x.Ttl = f
} }
case "xHeaders": case "xHeaders":
@ -2130,7 +2170,15 @@ func (x *RequestMetaHeader) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "magicNumber": case "magicNumber":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.MagicNumber = f x.MagicNumber = f
} }
} }
@ -2456,13 +2504,29 @@ func (x *ResponseMetaHeader) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "epoch": case "epoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.Epoch = f x.Epoch = f
} }
case "ttl": case "ttl":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Ttl = f x.Ttl = f
} }
case "xHeaders": case "xHeaders":

View file

@ -425,7 +425,15 @@ func (x *Status_Detail) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "id": case "id":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Id = f x.Id = f
} }
case "value": case "value":
@ -645,7 +653,15 @@ func (x *Status) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "code": case "code":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.Code = f x.Code = f
} }
case "message": case "message":

View file

@ -12,6 +12,7 @@ import (
easyproto "github.com/VictoriaMetrics/easyproto" easyproto "github.com/VictoriaMetrics/easyproto"
jlexer "github.com/mailru/easyjson/jlexer" jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter" jwriter "github.com/mailru/easyjson/jwriter"
strconv "strconv"
) )
type Tombstone struct { type Tombstone struct {
@ -216,7 +217,15 @@ func (x *Tombstone) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "expirationEpoch": case "expirationEpoch":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.ExpirationEpoch = f x.ExpirationEpoch = f
} }
case "splitID": case "splitID":

View file

@ -175,7 +175,15 @@ func (x *Primitives_Aux) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "innerField": case "innerField":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.InnerField = f x.InnerField = f
} }
} }
@ -797,31 +805,71 @@ func (x *Primitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "fieldD": case "fieldD":
{ {
var f int32 var f int32
f = in.Int32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseInt(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := int32(v)
f = pv
x.FieldD = f x.FieldD = f
} }
case "fieldE": case "fieldE":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.FieldE = f x.FieldE = f
} }
case "fieldF": case "fieldF":
{ {
var f int64 var f int64
f = in.Int64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseInt(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := int64(v)
f = pv
x.FieldF = f x.FieldF = f
} }
case "fieldG": case "fieldG":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.FieldG = f x.FieldG = f
} }
case "fieldI": case "fieldI":
{ {
var f uint64 var f uint64
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
x.FieldI = f x.FieldI = f
} }
case "fieldJ": case "fieldJ":
@ -833,7 +881,15 @@ func (x *Primitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "fieldK": case "fieldK":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.FieldK = f x.FieldK = f
} }
case "fieldH": case "fieldH":
@ -871,7 +927,15 @@ func (x *Primitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
x.FieldM = xx x.FieldM = xx
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
xx.FieldMe = f xx.FieldMe = f
} }
case "fieldAux": case "fieldAux":
@ -1039,7 +1103,15 @@ func (x *RepPrimitives_Aux) UnmarshalEasyJSON(in *jlexer.Lexer) {
case "innerField": case "innerField":
{ {
var f uint32 var f uint32
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
x.InnerField = f x.InnerField = f
} }
} }
@ -1498,7 +1570,15 @@ func (x *RepPrimitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []int32 var list []int32
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Int32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseInt(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := int32(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }
@ -1511,7 +1591,15 @@ func (x *RepPrimitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []uint32 var list []uint32
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Uint32() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 32)
if err != nil {
in.AddError(err)
return
}
pv := uint32(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }
@ -1524,7 +1612,15 @@ func (x *RepPrimitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []int64 var list []int64
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Int64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseInt(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := int64(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }
@ -1537,7 +1633,15 @@ func (x *RepPrimitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []uint64 var list []uint64
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }
@ -1550,7 +1654,15 @@ func (x *RepPrimitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
var list []uint64 var list []uint64
in.Delim('[') in.Delim('[')
for !in.IsDelim(']') { for !in.IsDelim(']') {
f = in.Uint64() r := in.JsonNumber()
n := r.String()
v, err := strconv.ParseUint(n, 10, 64)
if err != nil {
in.AddError(err)
return
}
pv := uint64(v)
f = pv
list = append(list, f) list = append(list, f)
in.WantComma() in.WantComma()
} }

View file

@ -59,6 +59,17 @@ func emitJSONUnmarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
g.P("}") g.P("}")
} }
func emitJSONParseInteger(g *protogen.GeneratedFile, ident string, method string, bitSize int, typ string) {
g.P("r := in.JsonNumber()")
g.P("n := r.String()")
g.P("v, err := ", strconvPackage.Ident(method), "(n, 10, ", bitSize, ")")
g.P("if err != nil {")
g.P(" in.AddError(err)")
g.P(" return")
g.P("}")
g.P(ident, " := ", typ, "(v)")
}
func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) { func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) {
g.P("{") g.P("{")
defer g.P("}") defer g.P("}")
@ -100,13 +111,17 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string
}`) }`)
template = "%s = parsedValue" template = "%s = parsedValue"
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
template = "%s = in.Int32()" emitJSONParseInteger(g, "pv", "ParseInt", 32, "int32")
template = "%s = pv"
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
template = "%s = in.Uint32()" emitJSONParseInteger(g, "pv", "ParseUint", 32, "uint32")
template = "%s = pv"
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
template = "%s = in.Int64()" emitJSONParseInteger(g, "pv", "ParseInt", 64, "int64")
template = "%s = pv"
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
template = "%s = in.Uint64()" emitJSONParseInteger(g, "pv", "ParseUint", 64, "uint64")
template = "%s = pv"
case protoreflect.FloatKind: case protoreflect.FloatKind:
template = "%s = in.Float32()" template = "%s = in.Float32()"
case protoreflect.DoubleKind: case protoreflect.DoubleKind: