File tree Expand file tree Collapse file tree 5 files changed +35
-25
lines changed
source/bson-binary-vector Expand file tree Collapse file tree 5 files changed +35
-25
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,8 @@ Drivers MUST validate vector metadata and raise an error if any invariant is vio
184
184
185
185
- Padding MUST be 0 for all dtypes where padding doesn’t apply, and MUST be within \[ 0, 7\] for PACKED_BIT.
186
186
- A PACKED_BIT vector MUST NOT be empty if padding is in the range \[ 1, 7\] .
187
+ - When unpacking binary data into a FLOAT32 Vector structure, the length of the binary data following the dtype and
188
+ padding MUST be a multiple of 4 bytes.
187
189
188
190
Drivers MUST perform this validation when a numeric vector and padding are provided through the API, and when unpacking
189
191
binary data (BSON or similar) into a Vector structure.
@@ -242,3 +244,9 @@ See the [README](tests/README.md) for tests.
242
244
you want to store or transmit binary data more efficiently by grouping 8 bits into a single byte (uint8). For an
243
245
example in Python, see
244
246
[ numpy.unpackbits] ( https://numpy.org/doc/2.0/reference/generated/numpy.unpackbits.html#numpy.unpackbits ) .
247
+
248
+ ## Changelog
249
+
250
+ - 2025-02-04: Update validation for decoding into a FLOAT32 vector.
251
+
252
+ - 2024-11-01: BSON Binary Subtype 9 accepted DRIVERS-2926 (#1708 )
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ Each JSON file contains three top-level keys.
29
29
30
30
- ` description ` : string describing the test.
31
31
- ` valid ` : boolean indicating if the vector, dtype, and padding should be considered a valid input.
32
- - ` vector ` : list of numbers
32
+ - ` vector ` : (required if valid is true) list of numbers
33
33
- ` dtype_hex ` : string defining the data type in hex (e.g. "0x10", "0x27")
34
34
- ` dtype_alias ` : (optional) string defining the data dtype, perhaps as Enum.
35
35
- ` padding ` : (optional) integer for byte padding. Defaults to 0.
@@ -50,7 +50,10 @@ MUST assert that the input float array is the same after encoding and decoding.
50
50
51
51
#### To prove correct in an invalid case (` valid:false ` ), one MUST
52
52
53
- - raise an exception when attempting to encode a document from the numeric values, dtype, and padding.
53
+ - if the vector field is present, raise an exception when attempting to encode a document from the numeric values,
54
+ dtype, and padding.
55
+ - if the canonical_bson field is present, raise an exception when attempting to deserialize it into the corresponding
56
+ numeric values, as the field contains corrupted data.
54
57
55
58
## FAQ
56
59
Original file line number Diff line number Diff line change 44
44
"vector" : [127.0 , 7.0 ],
45
45
"dtype_hex" : " 0x27" ,
46
46
"dtype_alias" : " FLOAT32" ,
47
- "padding" : 3
47
+ "padding" : 3 ,
48
+ "canonical_bson" : " 1C00000005766563746F72000A0000000927030000FE420000E04000"
49
+ },
50
+ {
51
+ "description" : " Insufficient vector data with 3 bytes FLOAT32" ,
52
+ "valid" : false ,
53
+ "dtype_hex" : " 0x27" ,
54
+ "dtype_alias" : " FLOAT32" ,
55
+ "canonical_bson" : " 1700000005766563746F7200050000000927002A2A2A00"
56
+ },
57
+ {
58
+ "description" : " Insufficient vector data with 5 bytes FLOAT32" ,
59
+ "valid" : false ,
60
+ "dtype_hex" : " 0x27" ,
61
+ "dtype_alias" : " FLOAT32" ,
62
+ "canonical_bson" : " 1900000005766563746F7200070000000927002A2A2A2A2A00"
48
63
}
49
64
]
50
65
}
51
-
Original file line number Diff line number Diff line change 42
42
"vector" : [127 , 7 ],
43
43
"dtype_hex" : " 0x03" ,
44
44
"dtype_alias" : " INT8" ,
45
- "padding" : 3
45
+ "padding" : 3 ,
46
+ "canonical_bson" : " 1600000005766563746F7200040000000903037F0700"
46
47
},
47
48
{
48
49
"description" : " INT8 with float inputs" ,
54
55
}
55
56
]
56
57
}
57
-
Original file line number Diff line number Diff line change 8
8
"vector" : [],
9
9
"dtype_hex" : " 0x10" ,
10
10
"dtype_alias" : " PACKED_BIT" ,
11
- "padding" : 1
11
+ "padding" : 1 ,
12
+ "canonical_bson" : " 1400000005766563746F72000200000009100100"
12
13
},
13
14
{
14
15
"description" : " Simple Vector PACKED_BIT" ,
61
62
"dtype_alias" : " PACKED_BIT" ,
62
63
"padding" : 0
63
64
},
64
- {
65
- "description" : " Padding specified with no vector data PACKED_BIT" ,
66
- "valid" : false ,
67
- "vector" : [],
68
- "dtype_hex" : " 0x10" ,
69
- "dtype_alias" : " PACKED_BIT" ,
70
- "padding" : 1
71
- },
72
65
{
73
66
"description" : " Exceeding maximum padding PACKED_BIT" ,
74
67
"valid" : false ,
75
68
"vector" : [1 ],
76
69
"dtype_hex" : " 0x10" ,
77
70
"dtype_alias" : " PACKED_BIT" ,
78
- "padding" : 8
71
+ "padding" : 8 ,
72
+ "canonical_bson" : " 1500000005766563746F7200030000000910080100"
79
73
},
80
74
{
81
75
"description" : " Negative padding PACKED_BIT" ,
84
78
"dtype_hex" : " 0x10" ,
85
79
"dtype_alias" : " PACKED_BIT" ,
86
80
"padding" : -1
87
- },
88
- {
89
- "description" : " Vector with float values PACKED_BIT" ,
90
- "valid" : false ,
91
- "vector" : [127.5 ],
92
- "dtype_hex" : " 0x10" ,
93
- "dtype_alias" : " PACKED_BIT" ,
94
- "padding" : 0
95
81
}
96
82
]
97
83
}
98
-
You can’t perform that action at this time.
0 commit comments