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

feat: Deserialize binary as JSON array #1247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ThetaSinner
Copy link

I'm using rmp_serde with serde_json. I want to be able to do something like:

let binary = vec![196, 39, 132, 41, 36, 231, 196, 82, 19, 131, 98, 76, 183, 39, 96, 20, 116, 59, 218, 195, 4, 22, 240, 167, 37, 50, 187, 162, 63, 216, 103, 212, 34, 103, 224, 154, 209, 255, 101, 36, 57];
let t: serde_json::Value = rmp_serde::from_slice(&binary).unwrap();
assert!(matches!(t, serde_json::Value::Array(_)));

It's not a perfect round trip if you try to reverse it because in the other direction this would now serialize as a msgpack array rather than binary data. At least in this direction, I believe it's reasonable to represent binary data as a numeric array.

@ThetaSinner
Copy link
Author

I had a go at writing a test for this. Without a Deserializer that will request deserializing binary, I don't think this code can be reached. serde_json won't do that so I'd need some other Deserializer. I'm up for adding one in a test if that's a useful thing to do?

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.

1 participant