Skip to content

RUST-1111 Support deserializing RawBson from Bson #331

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

Conversation

patrickfreed
Copy link
Contributor

RUST-1111

This PR adds support to the Bson-based deserializer (used in bson::from_bson and bson::from_document) for deserializing the owned raw BSON types, namely RawBson, RawDocumentBuf, and RawArrayBuf.

@@ -529,7 +529,7 @@ impl Bson {
/// This function mainly used for [extended JSON format](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
// TODO RUST-426: Investigate either removing this from the serde implementation or unifying
// with the extended JSON implementation.
pub(crate) fn into_extended_document(self) -> Document {
pub(crate) fn into_extended_document(self, rawbson: bool) -> Document {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rather than implementing various MapAccess structs, the Bson deserializer instead converts things into their "extended document" form and then uses a single MapAccess implementation to walk over the resultant document. The changes here modify this method to create the documents in the form that the raw BSON types expect where necessary.

/// Hint provided to the deserializer via `deserialize_newtype_struct` as to the type of thing
/// being deserialized.
#[derive(Debug, Clone, Copy)]
enum DeserializerHint {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was originally just used in the raw deserializer, but now that the non-raw deserializer needs to interpret these hints, I've moved it to the top level of the de module.

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

looks good, just a small typo fix

/// - deserializing a `T` from the raw BSON version of `expected_doc` produces `expected_value`
/// - deserializing a `Document` from the raw BSON version of `expected_doc` produces
/// `expected_doc`
/// - serializering `expected_value` to BSON bytes matches the raw BSON bytes of `expected_doc`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// - serializering `expected_value` to BSON bytes matches the raw BSON bytes of `expected_doc`
/// - serializing `expected_value` to BSON bytes matches the raw BSON bytes of `expected_doc`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"serializer-ing" lol, fixed

@patrickfreed patrickfreed force-pushed the RUST-1111/deserialize-owned-raw-bson branch from 5e04426 to 0eba63f Compare December 3, 2021 22:27
@patrickfreed patrickfreed merged commit fa97946 into mongodb:master Dec 3, 2021
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.

3 participants