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

How to determinate whether a value is string or binary #39

Closed
darkl opened this issue Sep 8, 2014 · 4 comments
Labels

Comments

@darkl
Copy link

@darkl darkl commented Sep 8, 2014

Hi @yfakariya
From my understanding, MsgPack 5 supports distinction between string values to binary values.

How can I determinate what have I read from the stream?

I tried this code

MemoryStream stream = new MemoryStream();
Packer packer = Packer.Create(stream);
packer.PackBinary(new byte[16]);
stream.Position = 0;

Unpacker unpacker = Unpacker.Create(stream);
unpacker.Read();
Type type = unpacker.LastReadData.UnderlyingType; // string?

But it tells me a string was written.
Thanks

@yfakariya yfakariya added the question label Sep 9, 2014
@yfakariya

This comment has been minimized.

Copy link
Member

@yfakariya yfakariya commented Sep 9, 2014

Hi, @darkl

You can enable 'new protocol' specifying PackerCompatibilityOptions.None to Packer.Create method or SerializationContext.CompatibilityOptions.PackerCompatibilityOptions property. It is intended behavior to interop old bindings. Note that Unpacker always handle bin types.

@darkl

This comment has been minimized.

Copy link
Author

@darkl darkl commented Sep 9, 2014

Hi @yfakariya
Thanks for your response,
I tried your suggestion and I still get String as the underlying type:

Here's the code

MemoryStream stream = new MemoryStream();
Packer packer = Packer.Create(stream, PackerCompatibilityOptions.None);
packer.PackBinary(new byte[16]);
stream.Position = 0;

Unpacker unpacker = Unpacker.Create(stream);
unpacker.Read();
Type type = unpacker.LastReadData.UnderlyingType; // string?
@yfakariya

This comment has been minimized.

Copy link
Member

@yfakariya yfakariya commented Sep 10, 2014

Hi @darkl

I recognized the issue. Unpacker certainly recognize new binary type, but it handles it as raw type. It should always treat binary type as byte[], so I will fix it. Thanks!

@yfakariya yfakariya added the bug label Sep 10, 2014
@darkl

This comment has been minimized.

Copy link
Author

@darkl darkl commented Sep 10, 2014

Thanks @yfakariya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.