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
| Parameter | Type |
|---|---|
__namedParameters | BcsWriterOptions |
Returns
BcsWriter
Methods
shift()
shift(bytes): this;
Shift current cursor position by bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
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
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | Value to write. |
Returns
this
write16()
write16(value): this;
Write a U16 value into a buffer and shift cursor position by 2.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | Value to write. |
Returns
this
write32()
write32(value): this;
Write a U32 value into a buffer and shift cursor position by 4.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | Value to write. |
Returns
this
write64()
write64(value): this;
Write a U64 value into a buffer and shift cursor position by 8.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | Value to write. |
Returns
this
write128()
write128(value): this;
Write a U128 value into a buffer and shift cursor position by 16.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | Value to write. |
Returns
this
write256()
write256(value): this;
Write a U256 value into a buffer and shift cursor position by 16.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | bigint | Value 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
| Parameter | Type | Description |
|---|---|---|
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
| Parameter | Type | Description |
|---|---|---|
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
| Parameter | Type | Description |
|---|---|---|
encoding | Encoding | Encoding to use: 'base64' or 'hex' |
Returns
string