forked from TrueCloudLab/frostfs-api-go
[#120] protogen: Marshal enum as string
Be compatible with protojson. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
f812b1ae5b
commit
805da79319
9 changed files with 121 additions and 20 deletions
35
acl/grpc/types_frostfs.pb.go
generated
35
acl/grpc/types_frostfs.pb.go
generated
|
@ -356,12 +356,22 @@ func (x *EACLRecord_Filter) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"headerType\":"
|
const prefix string = ",\"headerType\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.HeaderType))
|
v := int32(x.HeaderType)
|
||||||
|
if vv, ok := HeaderType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"matchType\":"
|
const prefix string = ",\"matchType\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.MatchType))
|
v := int32(x.MatchType)
|
||||||
|
if vv, ok := MatchType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"key\":"
|
const prefix string = ",\"key\":"
|
||||||
|
@ -570,7 +580,12 @@ func (x *EACLRecord_Target) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"role\":"
|
const prefix string = ",\"role\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Role))
|
v := int32(x.Role)
|
||||||
|
if vv, ok := Role_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"keys\":"
|
const prefix string = ",\"keys\":"
|
||||||
|
@ -812,12 +827,22 @@ func (x *EACLRecord) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"operation\":"
|
const prefix string = ",\"operation\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Operation))
|
v := int32(x.Operation)
|
||||||
|
if vv, ok := Operation_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"action\":"
|
const prefix string = ",\"action\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.Action))
|
v := int32(x.Action)
|
||||||
|
if vv, ok := Action_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"filters\":"
|
const prefix string = ",\"filters\":"
|
||||||
|
|
7
ape/grpc/types_frostfs.pb.go
generated
7
ape/grpc/types_frostfs.pb.go
generated
|
@ -159,7 +159,12 @@ func (x *ChainTarget) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"type\":"
|
const prefix string = ",\"type\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Type))
|
v := int32(x.Type)
|
||||||
|
if vv, ok := TargetType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"name\":"
|
const prefix string = ",\"name\":"
|
||||||
|
|
21
netmap/grpc/types_frostfs.pb.go
generated
21
netmap/grpc/types_frostfs.pb.go
generated
|
@ -288,7 +288,12 @@ func (x *Filter) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"op\":"
|
const prefix string = ",\"op\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.Op))
|
v := int32(x.Op)
|
||||||
|
if vv, ok := Operation_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"value\":"
|
const prefix string = ",\"value\":"
|
||||||
|
@ -572,7 +577,12 @@ func (x *Selector) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"clause\":"
|
const prefix string = ",\"clause\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.Clause))
|
v := int32(x.Clause)
|
||||||
|
if vv, ok := Clause_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"attribute\":"
|
const prefix string = ",\"attribute\":"
|
||||||
|
@ -1627,7 +1637,12 @@ func (x *NodeInfo) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"state\":"
|
const prefix string = ",\"state\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.State))
|
v := int32(x.State)
|
||||||
|
if vv, ok := NodeInfo_State_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out.RawByte('}')
|
out.RawByte('}')
|
||||||
}
|
}
|
||||||
|
|
21
object/grpc/service_frostfs.pb.go
generated
21
object/grpc/service_frostfs.pb.go
generated
|
@ -4117,7 +4117,12 @@ func (x *SearchRequest_Body_Filter) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"matchType\":"
|
const prefix string = ",\"matchType\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.MatchType))
|
v := int32(x.MatchType)
|
||||||
|
if vv, ok := MatchType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"key\":"
|
const prefix string = ",\"key\":"
|
||||||
|
@ -6246,7 +6251,12 @@ func (x *GetRangeHashRequest_Body) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"type\":"
|
const prefix string = ",\"type\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.Type))
|
v := int32(x.Type)
|
||||||
|
if vv, ok := grpc.ChecksumType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out.RawByte('}')
|
out.RawByte('}')
|
||||||
}
|
}
|
||||||
|
@ -6659,7 +6669,12 @@ func (x *GetRangeHashResponse_Body) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"type\":"
|
const prefix string = ",\"type\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Type))
|
v := int32(x.Type)
|
||||||
|
if vv, ok := grpc.ChecksumType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"hashList\":"
|
const prefix string = ",\"hashList\":"
|
||||||
|
|
14
object/grpc/types_frostfs.pb.go
generated
14
object/grpc/types_frostfs.pb.go
generated
|
@ -323,7 +323,12 @@ func (x *ShortHeader) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"objectType\":"
|
const prefix string = ",\"objectType\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.ObjectType))
|
v := int32(x.ObjectType)
|
||||||
|
if vv, ok := ObjectType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"payloadLength\":"
|
const prefix string = ",\"payloadLength\":"
|
||||||
|
@ -1659,7 +1664,12 @@ func (x *Header) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"objectType\":"
|
const prefix string = ",\"objectType\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.ObjectType))
|
v := int32(x.ObjectType)
|
||||||
|
if vv, ok := ObjectType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"homomorphicHash\":"
|
const prefix string = ",\"homomorphicHash\":"
|
||||||
|
|
14
refs/grpc/types_frostfs.pb.go
generated
14
refs/grpc/types_frostfs.pb.go
generated
|
@ -933,7 +933,12 @@ func (x *Signature) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"scheme\":"
|
const prefix string = ",\"scheme\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.Scheme))
|
v := int32(x.Scheme)
|
||||||
|
if vv, ok := SignatureScheme_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out.RawByte('}')
|
out.RawByte('}')
|
||||||
}
|
}
|
||||||
|
@ -1270,7 +1275,12 @@ func (x *Checksum) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"type\":"
|
const prefix string = ",\"type\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Type))
|
v := int32(x.Type)
|
||||||
|
if vv, ok := ChecksumType_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"sum\":"
|
const prefix string = ",\"sum\":"
|
||||||
|
|
14
session/grpc/types_frostfs.pb.go
generated
14
session/grpc/types_frostfs.pb.go
generated
|
@ -362,7 +362,12 @@ func (x *ObjectSessionContext) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"verb\":"
|
const prefix string = ",\"verb\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Verb))
|
v := int32(x.Verb)
|
||||||
|
if vv, ok := ObjectSessionContext_Verb_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"target\":"
|
const prefix string = ",\"target\":"
|
||||||
|
@ -600,7 +605,12 @@ func (x *ContainerSessionContext) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"verb\":"
|
const prefix string = ",\"verb\":"
|
||||||
out.RawString(prefix[1:])
|
out.RawString(prefix[1:])
|
||||||
out.Int32(int32(x.Verb))
|
v := int32(x.Verb)
|
||||||
|
if vv, ok := ContainerSessionContext_Verb_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const prefix string = ",\"wildcard\":"
|
const prefix string = ",\"wildcard\":"
|
||||||
|
|
7
util/proto/test/custom/test_frostfs.pb.go
generated
7
util/proto/test/custom/test_frostfs.pb.go
generated
|
@ -614,7 +614,12 @@ func (x *Primitives) MarshalEasyJSON(out *jwriter.Writer) {
|
||||||
{
|
{
|
||||||
const prefix string = ",\"fieldH\":"
|
const prefix string = ",\"fieldH\":"
|
||||||
out.RawString(prefix)
|
out.RawString(prefix)
|
||||||
out.Int32(int32(x.FieldH))
|
v := int32(x.FieldH)
|
||||||
|
if vv, ok := Primitives_SomeEnum_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch xx := x.FieldM.(type) {
|
switch xx := x.FieldM.(type) {
|
||||||
case *Primitives_FieldMa:
|
case *Primitives_FieldMa:
|
||||||
|
|
|
@ -195,7 +195,13 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin
|
||||||
case protoreflect.BoolKind:
|
case protoreflect.BoolKind:
|
||||||
template = "out.Bool(%s)"
|
template = "out.Bool(%s)"
|
||||||
case protoreflect.EnumKind:
|
case protoreflect.EnumKind:
|
||||||
template = "out.Int32(int32(%s))"
|
enumType := fieldType(g, f).String()
|
||||||
|
template = `v := int32(%s)
|
||||||
|
if vv, ok := ` + enumType + `_name[v]; ok {
|
||||||
|
out.String(vv)
|
||||||
|
} else {
|
||||||
|
out.Int32(v)
|
||||||
|
}`
|
||||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||||
template = "out.Int32(%s)"
|
template = "out.Int32(%s)"
|
||||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||||
|
|
Loading…
Add table
Reference in a new issue