Skip to content

@temporary-escape/mod-sdk / CborVisitor

Class: CborVisitor ​

Defined in: cbor.ts:233

Streaming cursor over a CBOR encoded buffer (guest side, no host calls).

Every as* method consumes exactly one CBOR item: it reads the current item and moves the cursor past it. Containers are entered with enterMap / enterArray and closed with leave. The get* methods are read-only peeks that do not move the cursor.

The numeric coercions mirror Engine::Cbor::Visitor / Adapter on the C++ side: asU8 reads a CBOR simple value, asU64/asI64 accept both integer major types, and asFloat/asDouble accept floats, integers and simple values.

Constructors ​

Constructor ​

ts
new CborVisitor(buffer: Uint8Array): CborVisitor;

Defined in: cbor.ts:234

Parameters ​

ParameterType
bufferUint8Array

Returns ​

CborVisitor

Methods ​

asBool() ​

ts
asBool(): bool;

Defined in: cbor.ts:431

Returns ​

bool


asBytes() ​

ts
asBytes(): Uint8Array;

Defined in: cbor.ts:467

Returns ​

Uint8Array


asDouble() ​

ts
asDouble(): number;

Defined in: cbor.ts:520

Returns ​

number


asFloat() ​

ts
asFloat(): number;

Defined in: cbor.ts:487

Returns ​

number


asI64() ​

ts
asI64(): number;

Defined in: cbor.ts:423

Returns ​

number


asString() ​

ts
asString(): string;

Defined in: cbor.ts:448

Returns ​

string


asU64() ​

ts
asU64(): number;

Defined in: cbor.ts:415

Returns ​

number


asU8() ​

ts
asU8(): number;

Defined in: cbor.ts:396

Returns ​

number


enterArray() ​

ts
enterArray(): void;

Defined in: cbor.ts:358

Enters the current array. Must be paired with leave().

Returns ​

void


enterMap() ​

ts
enterMap(): void;

Defined in: cbor.ts:340

Enters the current map. Must be paired with leave().

Returns ​

void


expectTag() ​

ts
expectTag(tag: number): void;

Defined in: cbor.ts:325

Verifies the current tag and consumes it, leaving the cursor on the value.

Parameters ​

ParameterType
tagnumber

Returns ​

void


getArraySize() ​

ts
getArraySize(): number;

Defined in: cbor.ts:295

Number of items of the current array (definite length only).

Returns ​

number


getMapSize() ​

ts
getMapSize(): number;

Defined in: cbor.ts:277

Number of key/value pairs of the current map (definite length only).

Returns ​

number


getTag() ​

ts
getTag(): number;

Defined in: cbor.ts:313

The tag number of the current item (does not consume the tag).

Returns ​

number


getType() ​

ts
getType(): CborType;

Defined in: cbor.ts:258

The major type of the item the cursor is currently pointing at.

Returns ​

CborType


isEnd() ​

ts
isEnd(): bool;

Defined in: cbor.ts:263

True when the current container has no more items.

Returns ​

bool


leave() ​

ts
leave(): void;

Defined in: cbor.ts:376

Closes the container opened by the matching enterMap/enterArray.

Returns ​

void


fromRaw() ​

ts
static fromRaw(dataStart: number, length: number): CborVisitor;

Defined in: cbor.ts:249

Wraps a raw (dataStart, length) region of guest memory without copying. Used to decode a buffer the host allocated directly in the guest's linear memory (see the canonical-ABI helpers in ./abi). The caller owns the buffer and must keep it alive for the visitor's lifetime.

Parameters ​

ParameterType
dataStartnumber
lengthnumber

Returns ​

CborVisitor