Skip to content

Commit

Permalink
fix: array size byte offset
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Dec 9, 2024
1 parent f442db6 commit 2b7dcc8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/codecs/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class ArrayCodec {
};
}
else {
this.$$size = (value) => {
this.$$size = (value, byteOffset) => {
let size = 4;
for (const element of value) {
size += this.$$elementCodec.size(element, size);
size += this.$$elementCodec.size(element, size + byteOffset);
}
return size;
};
Expand Down Expand Up @@ -157,7 +157,7 @@ class ArrayCodec {
};
}
else {
this.$$size = (value) => {
this.$$size = (value, byteOffset) => {
let size = 0;
// let the environment report
if (!value[Symbol.iterator]) {
Expand All @@ -166,7 +166,7 @@ class ArrayCodec {
let protocol = value[Symbol.iterator]();
let result = protocol.next();
for (let i = 0; i < length; ++i) {
size += this.$$elementCodec.size(result.value);
size += this.$$elementCodec.size(result.value, size + byteOffset);
result = protocol.next();
}
return size;
Expand Down

0 comments on commit 2b7dcc8

Please sign in to comment.