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

ParameterType
__namedParametersBcsWriterOptions

Returns

BcsWriter

Methods

shift()

shift(bytes): this;

Shift current cursor position by bytes.

Parameters

ParameterTypeDescription
bytesnumberNumber 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

ParameterTypeDescription
valuenumber | bigintValue to write.

Returns

this


write16()

write16(value): this;

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

Parameters

ParameterTypeDescription
valuenumber | bigintValue to write.

Returns

this


write32()

write32(value): this;

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

Parameters

ParameterTypeDescription
valuenumber | bigintValue to write.

Returns

this


write64()

write64(value): this;

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

Parameters

ParameterTypeDescription
valuenumber | bigintValue to write.

Returns

this


write128()

write128(value): this;

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

Parameters

ParameterTypeDescription
valuenumber | bigintValue to write.

Returns

this


write256()

write256(value): this;

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

Parameters

ParameterTypeDescription
valuenumber | bigintValue to write.

Returns

this


writeULEB()

writeULEB(value): this;

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

Parameters

ParameterTypeDescription
valuenumberValue 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

ParameterTypeDescription
vectorany[]Array of elements to write.
cb(writer, el, i, len) => voidCallback 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

ParameterTypeDescription
encodingEncodingEncoding to use: 'base64' or 'hex'

Returns

string