diff --git a/.idea/prettier.xml b/.idea/prettier.xml new file mode 100644 index 0000000..0c83ac4 --- /dev/null +++ b/.idea/prettier.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/package.json b/package.json index f1b4cf0..338f13e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "@btc-vision/bsi-binary", - "version": "1.0.1", + "version": "1.0.2", "description": "", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/src/buffer/BinaryReader.ts b/src/buffer/BinaryReader.ts index c5bd66d..18449d6 100644 --- a/src/buffer/BinaryReader.ts +++ b/src/buffer/BinaryReader.ts @@ -145,11 +145,12 @@ export class BinaryReader { return value; } - public readU32(): u32 { + public readU32(le: boolean = true): u32 { this.verifyEnd(this.currentOffset + 4); - const value = this.buffer.getUint32(this.currentOffset, true); + const value = this.buffer.getUint32(this.currentOffset, le); this.currentOffset += 4; + return value; } @@ -217,7 +218,7 @@ export class BinaryReader { } public readSelector(): Selector { - return this.readU32(); + return this.readU32(false); } public readStringWithLength(): string { diff --git a/src/buffer/BinaryWriter.ts b/src/buffer/BinaryWriter.ts index da7d947..3e41f47 100644 --- a/src/buffer/BinaryWriter.ts +++ b/src/buffer/BinaryWriter.ts @@ -1,4 +1,3 @@ -import { BinaryReader } from './BinaryReader.js'; import { Address, ADDRESS_BYTE_LENGTH, @@ -16,6 +15,7 @@ import { } from './types/math.js'; import { BufferHelper } from '../utils/BufferHelper'; +import { BinaryReader } from './BinaryReader'; export class BinaryWriter { private currentOffset: u32 = 0; @@ -34,9 +34,9 @@ export class BinaryWriter { this.currentOffset += 2; } - public writeU32(value: u32): void { + public writeU32(value: u32, le: boolean = true): void { this.allocSafe(4); - this.buffer.setUint32(this.currentOffset, value, true); + this.buffer.setUint32(this.currentOffset, value, le); this.currentOffset += 4; } @@ -46,7 +46,7 @@ export class BinaryWriter { } public writeSelector(value: Selector): void { - this.writeU32(value); + this.writeU32(value, false); } public writeBoolean(value: boolean): void {