Skip to main content

Class: BcsWriter

Set of methods that allows data encoding/decoding as standalone BCS value or a part of a composed structure/vector.

Constructors

Constructor

new BcsWriter(__namedParameters?): BcsWriter

Parameters

__namedParameters?

BcsWriterOptions = {}

Returns

BcsWriter

Methods

shift()

shift(bytes): this

Shift current cursor position by bytes.

Parameters

bytes

number

Number of bytes to

Returns

this

Self for possible chaining.


write8()

write8(value): this

Write a U8 value into a buffer and shift cursor position by 1.

Parameters

value

Value to write.

number | bigint

Returns

this


write16()

write16(value): this

Write a U16 value into a buffer and shift cursor position by 2.

Parameters

value

Value to write.

number | bigint

Returns

this


write32()

write32(value): this

Write a U32 value into a buffer and shift cursor position by 4.

Parameters

value

Value to write.

number | bigint

Returns

this


write64()

write64(value): this

Write a U64 value into a buffer and shift cursor position by 8.

Parameters

value

Value to write.

number | bigint

Returns

this


write128()

write128(value): this

Write a U128 value into a buffer and shift cursor position by 16.

Parameters

value

Value to write.

number | bigint

Returns

this


write256()

write256(value): this

Write a U256 value into a buffer and shift cursor position by 16.

Parameters

value

Value to write.

number | bigint

Returns

this


writeULEB()

writeULEB(value): this

Write a ULEB value into a buffer and shift cursor position by number of bytes written.

Parameters

value

number

Value to write.

Returns

this


writeVec()

writeVec(vector, cb): this

Write a vector into a buffer by first writing the vector length and then calling a callback on each passed value.

Parameters

vector

any[]

Array of elements to write.

cb

(writer, el, i, len) => void

Callback to call on each element of the vector.

Returns

this


[iterator]()

[iterator](): Iterator<number, Iterable<number, any, any>>

Adds support for iterations over the object.

Returns

Iterator<number, Iterable<number, any, any>>


toBytes()

toBytes(): Uint8Array

Get underlying buffer taking only value bytes (in case initial buffer size was bigger).

Returns

Uint8Array

Resulting bcs.


toString()

toString(encoding): string

Represent data as 'hex' or 'base64'

Parameters

encoding

Encoding

Encoding to use: 'base64' or 'hex'

Returns

string