Skip to content

Format display #9

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

Merged
merged 4 commits into from
Jul 27, 2015
Merged

Format display #9

merged 4 commits into from
Jul 27, 2015

Conversation

saghm
Copy link
Contributor

@saghm saghm commented Jul 23, 2015

For the logging functionality in the MongoDB driver, we need to be able to print out documents in the format that they would appear in the shell. The ability to print the documents in a readable format would be useful for almost anyone using BSON, though.

@zonyitoo
Copy link
Contributor

One comment: the Binary type may be printed with rustc_serialize::hex.

@saghm
Copy link
Contributor Author

saghm commented Jul 26, 2015

It doesn't seem to get the correct result when I use ToHex to convert the binary data. I think it might just convert each hex number to its string equivalent (e.g. 74 converts to "74" rather than to "t").

@zonyitoo
Copy link
Contributor

Indeed. Then I think this line

format!("BinData({}, \"{}\")", u8::from(t), string)

could be modified to

format!("BinData({}, \"{:?}\")", u8::from(t), string)

@saghm
Copy link
Contributor Author

saghm commented Jul 27, 2015

I just took another look at how the MongoDB shell prints out the binary values, and it's actually much stranger than I thought (for instance, both "hello---" and "hello___" get printed out as "helloAAA", and I really have no clue why). Trying to emulate this properly would be much more work than I originally thought would be, so I think it's probably better to just go with your to_hex() suggestion and just print out the raw number.

zonyitoo added a commit that referenced this pull request Jul 27, 2015
@zonyitoo zonyitoo merged commit 1c1fcca into mongodb:master Jul 27, 2015
@zonyitoo
Copy link
Contributor

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants