Skip to content

Commit

Permalink
Fix #79 messages sent as byte slice should be recieved as byte slice.
Browse files Browse the repository at this point in the history
  • Loading branch information
amnonbc committed Jan 4, 2023
1 parent a65d852 commit 10a80f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion ably/internal/ablyutil/msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var handle codec.MsgpackHandle
func init() {
handle.Raw = true
handle.WriteExt = true
handle.RawToString = true
}

// UnmarshalMsgpack decodes the MessagePack-encoded data and stores the result in the
Expand Down
25 changes: 25 additions & 0 deletions ably/proto_protocol_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,33 @@ import (
"github.com/ably/ably-go/ably/internal/ablyutil"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestMsgpackEncodesBytesAsBytes(t *testing.T) {
msg := ably.Message{Data: []byte("abc")}

encoded, err := ablyutil.MarshalMsgpack(msg)
assert.NoError(t, err)

var decodedMsg ably.Message
err = ablyutil.UnmarshalMsgpack(encoded, &decodedMsg)
require.NoError(t, err)
assert.IsType(t, []byte{}, decodedMsg.Data)
}

func TestMsgpackEncodesStringAsString(t *testing.T) {
msg := ably.Message{Data: "abc"}

encoded, err := ablyutil.MarshalMsgpack(msg)
assert.NoError(t, err)

var decodedMsg ably.Message
err = ablyutil.UnmarshalMsgpack(encoded, &decodedMsg)
require.NoError(t, err)
assert.IsType(t, "", decodedMsg.Data)
}

// TestProtocolMessageEncodeZeroSerials tests that zero-valued serials are
// explicitly encoded into msgpack (as required by the realtime API)
func TestProtocolMessageEncodeZeroSerials(t *testing.T) {
Expand Down

0 comments on commit 10a80f7

Please sign in to comment.