[#120] protogen: Unmarshal stringified integers from JSON
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
eeb754c327
commit
d94b9c6d0d
13 changed files with 19 additions and 4 deletions
BIN
accounting/grpc/types_frostfs.pb.go
generated
BIN
accounting/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
acl/grpc/types_frostfs.pb.go
generated
BIN
acl/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
container/grpc/types_frostfs.pb.go
generated
BIN
container/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/types_frostfs.pb.go
generated
BIN
netmap/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
object/grpc/service_frostfs.pb.go
generated
BIN
object/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
object/grpc/types_frostfs.pb.go
generated
BIN
object/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
refs/grpc/types_frostfs.pb.go
generated
BIN
refs/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
session/grpc/service_frostfs.pb.go
generated
BIN
session/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
session/grpc/types_frostfs.pb.go
generated
BIN
session/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
status/grpc/types_frostfs.pb.go
generated
BIN
status/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
tombstone/grpc/types_frostfs.pb.go
generated
BIN
tombstone/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
Binary file not shown.
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue