Skip to content

Commit

Permalink
updated udf
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Jun 2, 2020
1 parent f0bc6e1 commit baa49ae
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions udf/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -115,7 +117,6 @@ func NewProtoCodec(schemaFile, importPath string, msgType string, lowercaseKey b
return &ProtoCodec{
registry: registry,
msgType: msgType,
convertToLowerCamel: lowercaseKey,
}, nil

}
Expand Down

0 comments on commit baa49ae

Please sign in to comment.