-
Notifications
You must be signed in to change notification settings - Fork 144
RUST-871 Support direct serialization to BSON bytes #279
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
patrickfreed
merged 21 commits into
mongodb:master
from
patrickfreed:RUST-871/raw-serialize
Jul 28, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8a4d9f6
initial impl working
patrickfreed 82fb936
corpus, code w scope not working
patrickfreed 123a102
wip custom stuff
patrickfreed 67b195d
datetime binary oid symbol done
patrickfreed c15cb01
checkpoint
patrickfreed 586038d
wip
patrickfreed 9e5894a
corpus working
patrickfreed db62358
move doc serializer to own file
patrickfreed 48143e8
move value serializer to its own file
patrickfreed a8595b1
various cleanup
patrickfreed b041228
wip serde tests
patrickfreed 88aeaeb
fix serde tests
patrickfreed efe2867
lossless decimal128 serialization via bytes
patrickfreed d9ccb01
various cleanup
patrickfreed 7b9eb51
add u2i tests to serde-tests
patrickfreed 3617b48
add docstrings
patrickfreed acfd4bc
cleanup
patrickfreed d2b2212
unify binary serialization impls
patrickfreed 4ce6913
inline everything
patrickfreed a55c519
fix fmt in serde-tests
patrickfreed f512590
remove bson::to_writer
patrickfreed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,15 @@ version = "0.1.0" | |
authors = ["Kevin Yeh <[email protected]>"] | ||
edition = "2018" | ||
|
||
[features] | ||
u2i = ["bson/u2i"] | ||
decimal128 = ["bson/decimal128"] | ||
|
||
[dependencies] | ||
bson = { path = "..", features = ["decimal128"] } | ||
bson = { path = ".." } | ||
serde = { version = "1.0", features = ["derive"] } | ||
pretty_assertions = "0.6.1" | ||
hex = "0.4.2" | ||
|
||
[lib] | ||
name = "serde_tests" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
//! BSON definition | ||
|
||
use std::{ | ||
convert::TryFrom, | ||
convert::{TryFrom, TryInto}, | ||
fmt::{self, Debug, Display, Formatter}, | ||
}; | ||
|
||
|
@@ -698,6 +698,20 @@ impl Bson { | |
} | ||
} | ||
|
||
["$numberDecimalBytes"] => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unintuitively, this function is used in the existing serializer to convert between the intermediate serialized form (i.e. and "extended document") and the final serialized form. Now that decimal128 can serialize this way, this needed to be updated to interpret it. |
||
if let Ok(bytes) = doc.get_binary_generic("$numberDecimalBytes") { | ||
if let Ok(b) = bytes.clone().try_into() { | ||
#[cfg(not(feature = "decimal128"))] | ||
return Bson::Decimal128(Decimal128 { bytes: b }); | ||
|
||
#[cfg(feature = "decimal128")] | ||
unsafe { | ||
return Bson::Decimal128(Decimal128::from_raw_bytes_le(b)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
["$binary"] => { | ||
if let Some(binary) = Binary::from_extended_doc(&doc) { | ||
return Bson::Binary(binary); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than the serde tests being their own task in evergreen, I updated each of the other tasks to run it too with their associated feature flags on.