Open amnonbc opened 1 year ago
➤ Automation for Jira commented:
The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3196
➤ Amnon Cohen commented:
The problem is in the codec, as you can see in this failing test:
func TestSmallByteData(t *testing.T) {
src := []byte("abc")
encodedBytes, err := ablyutil.MarshalMsgpack(src)
assert.NoError(t, err)
var decoded interface{}
err = ablyutil.UnmarshalMsgpack(encodedBytes, &decoded)
assert.NoError(t, err)
assert.IsType(t, src, decoded)
}
func TestUnmarshallByte(t *testing.T) {
buf := []byte{
0xc4, // bin8
2, // len
'a', 'a', // bytes
}
var target interface{}
err := UnmarshalMsgpack(buf, &target)
require.NoError(t, err)
assert.IsType(t, []byte{}, target,
"bin8 should be decoded as []byte, but instead we got %T", target)
}
In github.com/ugorji/go/codec@v1.1.9/msgpack.go:494
case bd == mpBin8, bd == mpBin16, bd == mpBin32:
fauxUnionReadRawBytes(d, &d.d, n, d.h.RawToString)
which calls
func fauxUnionReadRawBytes(dr decDriver, d *Decoder, n *fauxUnion, rawToString bool) {
if rawToString {
n.v = valueTypeString
n.s = string(dr.DecodeBytes(d.b[:], true))
} else {
n.v = valueTypeBytes
n.l = dr.DecodeBytes(nil, false)
}
}
I added a bug report to https://github.com/ugorji/go/issues/387
See https://github.com/ably/ably-go/pull/581 as a sample fix.
The code below send a message of type
[]byte
. But the subscriber receives the message of typestring
.https://go.dev/play/p/VUqZbF7B6Wv
According to the Spec (RSL6a) All messages received will be decoded automatically based on the encoding field and the payloads will be converted into the format they were originally sent using i.e. binary, string, or JSON
In this case the message was sent as
[]byte
so should have been received as as[]byte
.┆Issue is synchronized with this Jira Task by Unito