Skip to main content

BcsWriter

@iota/bcs


@iota/bcs / BcsWriter

Class: BcsWriter

Defined in: writer.ts:36

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

Defined in: writer.ts:43

Parameters​

__namedParameters?​

BcsWriterOptions = {}

Returns​

BcsWriter

Methods​

[iterator]()​

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

Defined in: writer.ts:189

Adds support for iterations over the object.

Returns​

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


shift()​

shift(bytes): this

Defined in: writer.ts:80

Shift current cursor position by bytes.

Parameters​

bytes​

number

Number of bytes to

Returns​

this

Self for possible chaining.


toBytes()​

toBytes(): Uint8Array

Defined in: writer.ts:200

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

Returns​

Uint8Array

Resulting bcs.


toString()​

toString(encoding): string

Defined in: writer.ts:208

Represent data as 'hex' or 'base64'

Parameters​

encoding​

Encoding

Encoding to use: 'base64' or 'hex'

Returns​

string


write128()​

write128(value): this

Defined in: writer.ts:142

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

Parameters​

value​

number | bigint

Value to write.

Returns​

this


write16()​

write16(value): this

Defined in: writer.ts:111

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

Parameters​

value​

number | bigint

Value to write.

Returns​

this


write256()​

write256(value): this

Defined in: writer.ts:153

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

Parameters​

value​

number | bigint

Value to write.

Returns​

this


write32()​

write32(value): this

Defined in: writer.ts:121

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

Parameters​

value​

number | bigint

Value to write.

Returns​

this


write64()​

write64(value): this

Defined in: writer.ts:131

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

Parameters​

value​

number | bigint

Value to write.

Returns​

this


write8()​

write8(value): this

Defined in: writer.ts:89

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

Parameters​

value​

number | bigint

Value to write.

Returns​

this


writeBytes()​

writeBytes(bytes): this

Defined in: writer.ts:99

Write a byte array into the buffer and shift cursor position by the number of bytes written.

Parameters​

bytes​

Uint8Array

Bytes to write.

Returns​

this


writeULEB()​

writeULEB(value): this

Defined in: writer.ts:164

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

Defined in: writer.ts:176

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