Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed problem with writeu32 #3

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.1",
"version": "1.0.2",
"description": "",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
7 changes: 4 additions & 3 deletions src/buffer/BinaryReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -217,7 +218,7 @@ export class BinaryReader {
}

public readSelector(): Selector {
return this.readU32();
return this.readU32(false);
}

public readStringWithLength(): string {
Expand Down
8 changes: 4 additions & 4 deletions src/buffer/BinaryWriter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BinaryReader } from './BinaryReader.js';
import {
Address,
ADDRESS_BYTE_LENGTH,
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -46,7 +46,7 @@ export class BinaryWriter {
}

public writeSelector(value: Selector): void {
this.writeU32(value);
this.writeU32(value, false);
}

public writeBoolean(value: boolean): void {
Expand Down
Loading