Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-09-22 02:19:49 +03:00
parent 047c791f3b
commit cfd576d197

View File

@ -39,16 +39,17 @@ func (c *jsonpbCodec) Marshal(v interface{}, opts ...codec.Option) ([]byte, erro
case *codec.Frame: case *codec.Frame:
return m.Data, nil return m.Data, nil
case proto.Message: case proto.Message:
if nv, nerr := rutil.StructFieldByTag(m, codec.DefaultTagName, flattenTag); nerr == nil {
if nm, ok := nv.(proto.Message); ok {
m = nm
}
}
options := c.opts options := c.opts
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
if nv, nerr := rutil.StructFieldByTag(m, options.TagName, flattenTag); nerr == nil {
if nm, ok := nv.(proto.Message); ok {
m = nm
}
}
marshalOptions := DefaultMarshalOptions marshalOptions := DefaultMarshalOptions
if options.Context != nil { if options.Context != nil {
if f, ok := options.Context.Value(marshalOptionsKey{}).(jsonpb.MarshalOptions); ok { if f, ok := options.Context.Value(marshalOptionsKey{}).(jsonpb.MarshalOptions); ok {
@ -72,17 +73,17 @@ func (c *jsonpbCodec) Unmarshal(d []byte, v interface{}, opts ...codec.Option) e
m.Data = d m.Data = d
return nil return nil
case proto.Message: case proto.Message:
if nv, nerr := rutil.StructFieldByTag(m, codec.DefaultTagName, flattenTag); nerr == nil {
if nm, ok := nv.(proto.Message); ok {
m = nm
}
}
options := c.opts options := c.opts
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
if nv, nerr := rutil.StructFieldByTag(m, options.TagName, flattenTag); nerr == nil {
if nm, ok := nv.(proto.Message); ok {
m = nm
}
}
unmarshalOptions := DefaultUnmarshalOptions unmarshalOptions := DefaultUnmarshalOptions
if options.Context != nil { if options.Context != nil {
if f, ok := options.Context.Value(unmarshalOptionsKey{}).(jsonpb.UnmarshalOptions); ok { if f, ok := options.Context.Value(unmarshalOptionsKey{}).(jsonpb.UnmarshalOptions); ok {