From baa49ae0573cddf2387a29f1fc4e5b0947d6ef47 Mon Sep 17 00:00:00 2001 From: Adrian Witas Date: Tue, 2 Jun 2020 10:38:19 -0700 Subject: [PATCH] updated udf --- udf/protobuf.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/udf/protobuf.go b/udf/protobuf.go index c67784e1..de18b18f 100644 --- a/udf/protobuf.go +++ b/udf/protobuf.go @@ -20,7 +20,6 @@ import ( type ProtoCodec struct { registry *msgregistry.MessageRegistry msgType string - convertToLowerCamel bool } func (c *ProtoCodec) AsMessage(msgType string, data []byte) (interface{}, error) { @@ -63,18 +62,21 @@ func (c *ProtoCodec) AsBinary(msgType string, msg interface{}) ([]byte, error) { if err != nil { return nil, err } - if c.convertToLowerCamel { + + + protoMsg := dynamic.NewMessage(msgDescriptor) + err = protoMsg.UnmarshalJSON(data) + if err != nil { data, err = c.toLowerCamel(err, data) if err != nil { err = errors.Wrapf(err, "failed to convert to lowerCase fields") return nil, err } - } - protoMsg := dynamic.NewMessage(msgDescriptor) - err = protoMsg.UnmarshalJSON(data) - if err != nil { - err = errors.Wrapf(err, "failed to UnmarshalJSON") - return nil, err + err = protoMsg.UnmarshalJSON(data) + if err != nil { + err = errors.Wrapf(err, "failed to UnmarshalJSON") + return nil, err + } } return protoMsg.Marshal() } @@ -115,7 +117,6 @@ func NewProtoCodec(schemaFile, importPath string, msgType string, lowercaseKey b return &ProtoCodec{ registry: registry, msgType: msgType, - convertToLowerCamel: lowercaseKey, }, nil }