Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions source/bson-binary-vector/bson-binary-vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Drivers MUST validate vector metadata and raise an error if any invariant is vio

- Padding MUST be 0 for all dtypes where padding doesn’t apply, and MUST be within \[0, 7\] for PACKED_BIT.
- A PACKED_BIT vector MUST NOT be empty if padding is in the range \[1, 7\].
- For a PACKED_BIT vector, bits lower than the given padding (those ignored) must be zero.
Copy link

Choose a reason for hiding this comment

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

For what it's worth, it could be helpful adding some specificity about bit order here since the description is correct only if bits are interpreted in the opposite order used for packed_bit encoding. (packed_bit is otherwise MSB first, but this is referring to the LSB as 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to. Would you please suggest a short alternative? Any longer description that you'd like to make should be done in a new PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest rewording to avoid "lower":

Suggested change
- For a PACKED_BIT vector, bits lower than the given padding (those ignored) must be zero.
- For a PACKED_BIT vector, ignored bits must be zero.

I expect the phrase "The least-significant bits are ignored." above clarifies which bits are ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @kevinAlbs. Updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this for Encoding and Decoding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. That's what we came to, and exceptions are thrown in the Python implementation in both cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, it's specified a few lines after:
Drivers MUST perform this validation when...

- When unpacking binary data into a FLOAT32 Vector structure, the length of the binary data following the dtype and
padding MUST be a multiple of 4 bytes.

Expand Down
25 changes: 17 additions & 8 deletions source/bson-binary-vector/tests/packed_bit.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,39 @@
{
"description": "Simple Vector PACKED_BIT",
"valid": true,
"vector": [127, 7],
"vector": [127, 8],
"dtype_hex": "0x10",
"dtype_alias": "PACKED_BIT",
"padding": 0,
"canonical_bson": "1600000005766563746F7200040000000910007F0700"
"canonical_bson": "1600000005766563746F7200040000000910007F0800"
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
"canonical_bson": "1600000005766563746F7200040000000910007F0800"
"canonical_bson": "1600000005766563746F7200040000000910007F0700"

},
{
"description": "Empty Vector PACKED_BIT",
"description": "PACKED_BIT with padding",
"valid": true,
"vector": [],
"vector": [127, 8],
"dtype_hex": "0x10",
"dtype_alias": "PACKED_BIT",
"padding": 0,
"canonical_bson": "1400000005766563746F72000200000009100000"
"padding": 3,
"canonical_bson": "1600000005766563746F7200040000000910037F0800"
},
{
"description": "PACKED_BIT with padding",
"valid": true,
"description": "PACKED_BIT with inconsistent padding",
"valid": false,
"vector": [127, 7],
"dtype_hex": "0x10",
"dtype_alias": "PACKED_BIT",
"padding": 3,
"canonical_bson": "1600000005766563746F7200040000000910037F0700"
},
{
"description": "Empty Vector PACKED_BIT",
"valid": true,
"vector": [],
"dtype_hex": "0x10",
"dtype_alias": "PACKED_BIT",
"padding": 0,
"canonical_bson": "1400000005766563746F72000200000009100000"
},
{
"description": "Overflow Vector PACKED_BIT",
"valid": false,
Expand Down
Loading