Skip to content

BinaryWriter

new BinaryWriter(encodeUtf8?): BinaryWriter

(text) => Uint8Array

BinaryWriter

bool(value): this

Write a bool value, a variant.

boolean

this


bytes(value): this

Write a bytes value, length-delimited arbitrary data.

Uint8Array

this


double(value): this

Write a double value, a 64-bit floating point number.

number

this


finish(): Uint8Array

Return all bytes written and reset this writer.

Uint8Array


fixed32(value): this

Write a fixed32 value, an unsigned, fixed-length 32-bit integer.

number

this


fixed64(value): this

Write a fixed64 value, an unsigned, fixed-length 64 bit integer.

string | number | bigint

this


float(value): this

Write a float value, 32-bit floating point number.

number

this


fork(): this

Start a new fork for length-delimited data like a message or a packed repeated field.

Must be joined later with join().

this


int32(value): this

Write a int32 value, a signed 32 bit varint.

number

this


int64(value): this

Write a int64 value, a signed 64-bit varint.

string | number | bigint

this


join(): this

Join the last fork. Write its length and bytes, then return to the previous state.

this


raw(chunk): this

Write a chunk of raw bytes.

Uint8Array

this


sfixed32(value): this

Write a sfixed32 value, a signed, fixed-length 32-bit integer.

number

this


sfixed64(value): this

Write a fixed64 value, a signed, fixed-length 64-bit integer.

string | number | bigint

this


sint32(value): this

Write a sint32 value, a signed, zigzag-encoded 32-bit varint.

number

this


sint64(value): this

Write a sint64 value, a signed, zig-zag-encoded 64-bit varint.

string | number | bigint

this


string(value): this

Write a string value, length-delimited data converted to UTF-8 text.

string

this


tag(fieldNo, type): this

Writes a tag (field number and wire type).

Equivalent to uint32( (fieldNo << 3 | type) >>> 0 ).

Generated code should compute the tag ahead of time and call uint32().

number

WireType

this


uint32(value): this

Write a uint32 value, an unsigned 32 bit varint.

number

this


uint64(value): this

Write a uint64 value, an unsigned 64-bit varint.

string | number | bigint

this