Skip to content

Commit

Permalink
Merge pull request #48 from cloudstruct/feature/message-use-raw-cbor
Browse files Browse the repository at this point in the history
Reuse raw CBOR from message if present
  • Loading branch information
agaffney authored Mar 20, 2022
2 parents 1670124 + a631882 commit d14ed3d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ func (p *Protocol) SendMessage(msg Message, isResponse bool) error {
if err != nil {
return fmt.Errorf("%s: error sending message: %s", p.config.Name, err)
}
data, err := utils.CborEncode(msg)
if err != nil {
return err
// Get raw CBOR from message
data := msg.Cbor()
// If message has no raw CBOR, encode the message
if data == nil {
var err error
data, err = utils.CborEncode(msg)
if err != nil {
return err
}
}
segment := muxer.NewSegment(p.config.ProtocolId, data, isResponse)
p.sendChan <- segment
Expand Down

0 comments on commit d14ed3d

Please sign in to comment.