Skip to content

Commit

Permalink
Added read address array
Browse files Browse the repository at this point in the history
  • Loading branch information
BlobMaster41 committed Jul 5, 2024
1 parent aef5150 commit 3c69890
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "@btc-vision/bsi-binary",
"version": "1.0.26",
"version": "1.0.27",
"author": "BlobMaster41",
"description": "OPNet official buffer serialization and deserialization library",
"main": "build/index.js",
Expand Down
11 changes: 11 additions & 0 deletions src/buffer/BinaryReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export class BinaryReader {
return events;
}

public readAddressArray(): Address[] {
const length = this.readU16();
const result: Address[] = new Array<Address>(length);

for (let i = 0; i < length; i++) {
result[i] = this.readAddress();
}

return result;
}

public readEvent(): NetEvent {
const eventType = this.readStringWithLength();
const eventDataSelector = this.readU64();
Expand Down
10 changes: 10 additions & 0 deletions src/buffer/BinaryWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ export class BinaryWriter {
this.writeBytes(value);
}

public writeAddressArray(value: Address[]): void {
if(value.length > 65535) throw new Error('Array size is too large');

this.writeU16(value.length);

for (let i = 0; i < value.length; i++) {
this.writeAddress(value[i]);
}
}

private fromAddress(value: Address): Uint8Array {
if (value.length > ADDRESS_BYTE_LENGTH) {
throw new Error('Address is too long');
Expand Down

0 comments on commit 3c69890

Please sign in to comment.