strings obey lang

This commit is contained in:
Moon Man 2024-01-28 12:12:26 -05:00
parent 9ae7e46855
commit c8cba3c45e
2 changed files with 8 additions and 7 deletions

7
dist/bert.js vendored
View File

@ -335,8 +335,9 @@ export class Bert {
}; };
}; };
decode_string = (buffer) => { decode_string = (buffer) => {
const size = this.bytesToInt(buffer, 2, true); const sizeLen = this.convention == Lang.ELIXIR ? 4 : 2;
buffer = buffer.subarray(2); const size = this.bytesToInt(buffer, sizeLen, true);
buffer = buffer.subarray(sizeLen);
return { return {
value: buffer.toString("utf8", 0, size), value: buffer.toString("utf8", 0, size),
rest: buffer.subarray(size), rest: buffer.subarray(size),
@ -345,7 +346,7 @@ export class Bert {
decode_list = (buffer) => { decode_list = (buffer) => {
const arr = []; const arr = [];
const size = this.bytesToInt(buffer, 4, true); const size = this.bytesToInt(buffer, 4, true);
buffer = Buffer.from(buffer, 4); buffer = buffer.subarray(4);
for (let i = 0; i < size; ++i) { for (let i = 0; i < size; ++i) {
const el = this.#decode(buffer); const el = this.#decode(buffer);
arr.push(el.value); arr.push(el.value);

View File

@ -391,9 +391,9 @@ export class Bert {
}; };
decode_string = (buffer: Buffer) => { decode_string = (buffer: Buffer) => {
const size = this.bytesToInt(buffer, 2, true); const sizeLen = this.convention == Lang.ELIXIR ? 4 : 2;
const size = this.bytesToInt(buffer, sizeLen, true);
buffer = buffer.subarray(2); buffer = buffer.subarray(sizeLen);
return { return {
value: buffer.toString("utf8", 0, size), value: buffer.toString("utf8", 0, size),
@ -404,7 +404,7 @@ export class Bert {
decode_list = (buffer: Buffer) => { decode_list = (buffer: Buffer) => {
const arr = []; const arr = [];
const size = this.bytesToInt(buffer, 4, true); const size = this.bytesToInt(buffer, 4, true);
buffer = Buffer.from(buffer, 4); buffer = buffer.subarray(4);
for (let i = 0; i < size; ++i) { for (let i = 0; i < size; ++i) {
const el = this.#decode(buffer); const el = this.#decode(buffer);