INNER CODE UNIT · TypeScript
validateBinaryVector
mongodb/js-bson · src/binary.ts:516
export function validateBinaryVector(vector: Binary): void {
if (vector.sub_type !== Binary.SUBTYPE_VECTOR) return;
const size = vector.position;
// NOTE: Validation is only applied to **KNOWN** vector types
// If a new datatype is introduced, a future version of the library will need to add validation
const datatype = vector.buffer[0];
// NOTE: We do not enable noUncheckedIndexedAccess so TS believes this is always number
// a Binary vector may be empty, in which case the padding is undefined
// this possible value is tolerable for our validation checks
const padding: number | undefined = vector.buffer[1];
if (
(datatype === Binary.VECTOR_TYPE.Float32 || datatype === Binary.VECTOR_TYPE.Int8) &&
padding !== 0
) {