[#120] protogen: Marshal enum as string

Be compatible with protojson.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-10-01 09:42:40 +03:00
parent f812b1ae5b
commit 805da79319
9 changed files with 121 additions and 20 deletions

View file

@ -288,7 +288,12 @@ func (x *Filter) MarshalEasyJSON(out *jwriter.Writer) {
{
const prefix string = ",\"op\":"
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\":"
@ -572,7 +577,12 @@ func (x *Selector) MarshalEasyJSON(out *jwriter.Writer) {
{
const prefix string = ",\"clause\":"
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\":"
@ -1627,7 +1637,12 @@ func (x *NodeInfo) MarshalEasyJSON(out *jwriter.Writer) {
{
const prefix string = ",\"state\":"
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('}')
}