Skip to content

Commit 43d2c7b

Browse files
DRIVERS-3123 Require ignored bits in BSON binary vector PACKED_BITS to be zero. (#1783)
1 parent dc08180 commit 43d2c7b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

source/bson-binary-vector/bson-binary-vector.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Drivers MUST validate vector metadata and raise an error if any invariant is vio
184184

185185
- Padding MUST be 0 for all dtypes where padding doesn’t apply, and MUST be within \[0, 7\] for PACKED_BIT.
186186
- A PACKED_BIT vector MUST NOT be empty if padding is in the range \[1, 7\].
187+
- For a PACKED_BIT vector, ignored bits must be zero.
187188
- When unpacking binary data into a FLOAT32 Vector structure, the length of the binary data following the dtype and
188189
padding MUST be a multiple of 4 bytes.
189190

@@ -237,16 +238,26 @@ See the [README](tests/README.md) for tests.
237238
## FAQ
238239

239240
- What MongoDB Server version does this apply to?
241+
240242
- Files in the "specifications" repository have no version scheme. They are not tied to a MongoDB server version.
243+
241244
- In PACKED_BIT, why would one choose to use integers in \[0, 256)?
245+
242246
- This follows a well-established precedent for packing binary-valued arrays into bytes (8 bits), This technique is
243247
widely used across different fields, such as data compression, communication protocols, and file formats, where
244248
you want to store or transmit binary data more efficiently by grouping 8 bits into a single byte (uint8). For an
245249
example in Python, see
246250
[numpy.unpackbits](https://numpy.org/doc/2.0/reference/generated/numpy.unpackbits.html#numpy.unpackbits).
247251

252+
- In PACKED_BIT, why are ignored bits required to be zero?
253+
254+
- To ensure the same data representation has the same encoding. For drivers supporting comparison operations, this
255+
avoids comparing different unused bits.
256+
248257
## Changelog
249258

259+
- 2025-04-08: In PACKED_BIT vectors, ignored bits must be zero.
260+
250261
- 2025-03-07: Update tests to use Extended JSON representation of +/-Infinity. (DRIVERS-3095)
251262

252263
- 2025-02-04: Update validation for decoding into a FLOAT32 vector.

source/bson-binary-vector/tests/packed_bit.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,32 @@
2121
"canonical_bson": "1600000005766563746F7200040000000910007F0700"
2222
},
2323
{
24-
"description": "Empty Vector PACKED_BIT",
24+
"description": "PACKED_BIT with padding",
2525
"valid": true,
26-
"vector": [],
26+
"vector": [127, 8],
2727
"dtype_hex": "0x10",
2828
"dtype_alias": "PACKED_BIT",
29-
"padding": 0,
30-
"canonical_bson": "1400000005766563746F72000200000009100000"
29+
"padding": 3,
30+
"canonical_bson": "1600000005766563746F7200040000000910037F0800"
3131
},
3232
{
33-
"description": "PACKED_BIT with padding",
34-
"valid": true,
33+
"description": "PACKED_BIT with inconsistent padding",
34+
"valid": false,
3535
"vector": [127, 7],
3636
"dtype_hex": "0x10",
3737
"dtype_alias": "PACKED_BIT",
3838
"padding": 3,
3939
"canonical_bson": "1600000005766563746F7200040000000910037F0700"
4040
},
41+
{
42+
"description": "Empty Vector PACKED_BIT",
43+
"valid": true,
44+
"vector": [],
45+
"dtype_hex": "0x10",
46+
"dtype_alias": "PACKED_BIT",
47+
"padding": 0,
48+
"canonical_bson": "1400000005766563746F72000200000009100000"
49+
},
4150
{
4251
"description": "Overflow Vector PACKED_BIT",
4352
"valid": false,

0 commit comments

Comments
 (0)