Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const BINARY_SUBTYPE_UUID_OLD: u8 = 0x03;
const BINARY_SUBTYPE_UUID: u8 = 0x04;
const BINARY_SUBTYPE_MD5: u8 = 0x05;
const BINARY_SUBTYPE_ENCRYPTED: u8 = 0x06;
const BINARY_SUBTYPE_COLUMN: u8 = 0x07;
const BINARY_SUBTYPE_USER_DEFINED: u8 = 0x80;

/// All available BSON element types.
Expand Down Expand Up @@ -151,6 +152,7 @@ pub enum BinarySubtype {
Uuid,
Md5,
Encrypted,
Column,
UserDefined(u8),
Reserved(u8),
}
Expand All @@ -166,6 +168,7 @@ impl From<BinarySubtype> for u8 {
BinarySubtype::Uuid => BINARY_SUBTYPE_UUID,
BinarySubtype::Md5 => BINARY_SUBTYPE_MD5,
BinarySubtype::Encrypted => BINARY_SUBTYPE_ENCRYPTED,
BinarySubtype::Column => BINARY_SUBTYPE_COLUMN,
BinarySubtype::UserDefined(x) => x,
BinarySubtype::Reserved(x) => x,
}
Expand All @@ -183,6 +186,7 @@ impl From<u8> for BinarySubtype {
BINARY_SUBTYPE_UUID => BinarySubtype::Uuid,
BINARY_SUBTYPE_MD5 => BinarySubtype::Md5,
BINARY_SUBTYPE_ENCRYPTED => BinarySubtype::Encrypted,
BINARY_SUBTYPE_COLUMN => BinarySubtype::Column,
_ if t < BINARY_SUBTYPE_USER_DEFINED => BinarySubtype::Reserved(t),
_ => BinarySubtype::UserDefined(t),
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/binary_subtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn from_u8() {
// Check the endpoints of the defined, reserved, and user-defined subtype ranges.
assert_eq!(BinarySubtype::from(0x00), BinarySubtype::Generic);
assert_eq!(BinarySubtype::from(0x06), BinarySubtype::Encrypted);
assert_eq!(BinarySubtype::from(0x07), BinarySubtype::Reserved(0x07));
assert_eq!(BinarySubtype::from(0x07), BinarySubtype::Column);
assert_eq!(BinarySubtype::from(0x7F), BinarySubtype::Reserved(0x7F));
assert_eq!(BinarySubtype::from(0x80), BinarySubtype::UserDefined(0x80));
assert_eq!(BinarySubtype::from(0xFF), BinarySubtype::UserDefined(0xFF));
Expand Down