QubicTypeScript

BinaryReader

Reads typed little-endian values from a Uint8Array sequentially.

BinaryReader

Reads typed values from a Uint8Array sequentially. Each read method advances an internal cursor. All integers are decoded little-endian, matching the Qubic wire format.

Most applications should use readField from the payload codec instead. BinaryReader is for custom wire formats or protocol extensions that don't fit the payload codec's field model.

import { BinaryReader } from "@qubic.org/tx"

const reader = new BinaryReader(frame)

const sessionId = reader.readUint32()  // 42
const balance = reader.readInt64()     // 100_000_000n
const flags = reader.readUint8()       // 3

console.log(reader.bytesRead)      // 13
console.log(reader.bytesRemaining) // 0

Constructor

new BinaryReader(bytes: Uint8Array)
ParameterTypeDescription
bytesUint8ArrayThe buffer to read from

Methods

MethodReturnsDescription
readBytes(length)Uint8ArrayReads length bytes at the current position
readUint8()numberReads an unsigned 8-bit integer
readUint16()numberReads an unsigned 16-bit integer (LE)
readUint32()numberReads an unsigned 32-bit integer (LE)
readInt64()bigintReads a signed 64-bit integer (LE)
readUint64()bigintReads an unsigned 64-bit integer (LE)

Properties

PropertyTypeDescription
bytesReadnumberNumber of bytes consumed so far
bytesRemainingnumberNumber of bytes left in the buffer

On this page