Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify msgpack decode option to return strings for appropriate types #116

Merged
merged 2 commits into from Jan 6, 2019

Conversation

paddybyers
Copy link
Member

Copy link
Contributor

@gernest gernest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the tests are passing. I see a nasty panic on the ci logs.

panic: interface conversion: interface {} is string, not []uint8 [recovered]
	panic: interface conversion: interface {} is string, not []uint8

Also

    // RawToString controls how raw bytes are decoded into a nil interface{}.
    RawToString bool

Now we really dont want this behavior. I considered this before and decided it should not be used because strings in go are utf-8 meaning this will mangle any raw bytes encoded in msgpack.

@paddybyers
Copy link
Member Author

Now we really dont want this behavior. I considered this before and decided it should not be used because strings in go are utf-8 meaning this will mangle any raw bytes encoded in msgpack.

OK, but I think you're misreading the intent of the option. In older msgpack versions there was no distinction between binary and string values, and they were labelled as a single "raw" type. Then the spec was changed to introduce separate string and binary types, and there was a migration path where the legacy "raw" types could be interpreted as either a string or binary value. See https://github.com/msgpack/msgpack/blob/master/spec.md#upgrading-messagepack-specification

This option in the library affects the decoding of various opcode ranges, particularly the opcodes that were historically raw types. The opcode for the "client1" member in the message data was 0xa6, which is in the FixStr range (see https://github.com/ugorji/go/blob/master/codec/msgpack.go#L38) - our msgpack encoder in the Ably system correctly uses this opcode for short fixed-length strings, so we need these decoded as strings. The RawToString option controls this - see https://github.com/ugorji/go/blob/master/codec/msgpack.go#L520. It does not mean that every binary type is decoded to string type; the binary opcodes are all unconditionally decoded to bytes - see https://github.com/ugorji/go/blob/master/codec/msgpack.go#L528.

@paddybyers
Copy link
Member Author

Please make sure the tests are passing. I see a nasty panic on the ci logs.

panic: interface conversion: interface {} is string, not []uint8 [recovered]
panic: interface conversion: interface {} is string, not []uint8

Agreed, I need to look at this.

@paddybyers
Copy link
Member Author

I see a nasty panic on the ci logs.

panic: interface conversion: interface {} is string, not []uint8 [recovered]
panic: interface conversion: interface {} is string, not []uint8

See eb6dba9: this was an error in the test, incorrectly expecting some members of decoded messages to have []byte type.

Copy link
Contributor

@gernest gernest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paddybyers paddybyers merged commit 118c3ed into develop Jan 6, 2019
@QuintinWillison QuintinWillison deleted the fix-msgpack-string-handling branch February 11, 2020 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants