Skip to content

Commit 6391c39

Browse files
committed
Use fixed length for dimensions count in vector images for Oracle Database 23ai
1 parent bf7f16c commit 6391c39

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

lib/impl/datahandlers/constants.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ module.exports = {
3535
TNS_VECTOR_VERSION: 0,
3636

3737
// vector flags
38-
TNS_VECTOR_FLAG_DIM_UINT8: 0x0001,
39-
TNS_VECTOR_FLAG_DIM_UINT32: 0x0002,
40-
TNS_VECTOR_FLAG_NORMSRC: 0x0040,
41-
TNS_VECTOR_FLAG_NORM: 0x0008,
38+
TNS_VECTOR_FLAG_NORMSRC: 0x0010,
39+
TNS_VECTOR_FLAG_NORM: 0x0002,
4240

4341
// base JSON constants
4442
TNS_JSON_MAGIC_BYTE_1: 0xff,

lib/impl/datahandlers/vector.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ class VectorDecoder extends BaseBuffer {
5454
errors.throwErr(errors.ERR_VECTOR_VERSION_NOT_SUPPORTED, version);
5555
const flags = this.readUInt16BE();
5656
const vectorFormat = this.readUInt8();
57-
let numElements;
58-
if (flags & constants.TNS_VECTOR_FLAG_DIM_UINT8) {
59-
numElements = this.readUInt8();
60-
} else if (flags & constants.TNS_VECTOR_FLAG_DIM_UINT32) {
61-
numElements = this.readUInt32BE();
62-
} else {
63-
numElements = this.readUInt16BE();
64-
}
57+
const numElements = this.readUInt32BE();
6558
let elementSize, result;
6659
if (vectorFormat === constants.VECTOR_FORMAT_FLOAT32) {
6760
elementSize = 4;
@@ -117,27 +110,15 @@ class VectorEncoder extends GrowableBuffer {
117110
}
118111

119112
// Let server generate the norm (TNS_VECTOR_FLAG_NORMSRC)
120-
let flags = constants.TNS_VECTOR_FLAG_NORM
113+
const flags = constants.TNS_VECTOR_FLAG_NORM
121114
| constants.TNS_VECTOR_FLAG_NORMSRC;
122-
const numElements = value.length;
123-
if (numElements < 256) {
124-
flags |= constants.TNS_VECTOR_FLAG_DIM_UINT8;
125-
} else if (numElements > 65535) {
126-
flags |= constants.TNS_VECTOR_FLAG_DIM_UINT32;
127-
}
128115

129116
// write header
130117
this.writeUInt8(constants.TNS_VECTOR_MAGIC_BYTE);
131118
this.writeUInt8(constants.TNS_VECTOR_VERSION);
132119
this.writeUInt16BE(flags);
133120
this.writeUInt8(vectorFormat);
134-
if (numElements < 256) {
135-
this.writeUInt8(numElements);
136-
} else if (numElements < 65536) {
137-
this.writeUInt16BE(numElements);
138-
} else {
139-
this.writeUInt32BE(numElements);
140-
}
121+
this.writeUInt32BE(value.length);
141122
this.reserveBytes(8);
142123

143124
// write data

0 commit comments

Comments
 (0)