Class: Writer

Writer

Wire format writer using Uint8Array if available, otherwise Array.

new Writer()

Constructs a new writer instance.

Members

Operations head.

len { number }

Current length.

states { Object | null }

Linked forked states.

tail { Object }

Operations tail

Methods

Writer.alloc(size){ Uint8Array }

Allocates a buffer of the specified size.

Name Type Description
size number

Buffer size

Returns:
Type Description
Uint8Array Buffer

Writer.create(){ BufferWriter | Writer }

Creates a new writer.

Returns:
Type Description
BufferWriter | Writer A BufferWriter when Buffers are supported, otherwise a Writer

bool(value){ Writer }

Writes a boolish value as a varint.

Name Type Description
value boolean

Value to write

Returns:
Type Description
Writer this

bytes(value){ Writer }

Writes a sequence of bytes.

Name Type Description
value Uint8Array | string

Buffer or base64 encoded string to write

Returns:
Type Description
Writer this

double(value){ Writer }

Writes a double (64 bit float).

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

finish(){ Uint8Array }

Finishes the write operation.

Returns:
Type Description
Uint8Array Finished buffer

fixed32(value){ Writer }

Writes an unsigned 32 bit value as fixed 32 bits.

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

fixed64(value){ Writer }

Writes an unsigned 64 bit value as fixed 64 bits.

Name Type Description
value Long | number | string

Value to write

Throws:
Type Description
TypeError

If value is a string and no long library is present.

Returns:
Type Description
Writer this

float(value){ Writer }

Writes a float (32 bit).

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

Forks this writer's state by pushing it to a stack.
Calling reset or ldelim resets the writer to the previous state.

Returns:
Type Description
Writer this

int32(value){ Writer }

Writes a signed 32 bit value as a varint.

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

int64(value){ Writer }

Writes a signed 64 bit value as a varint.

Name Type Description
value Long | number | string

Value to write

Throws:
Type Description
TypeError

If value is a string and no long library is present.

Returns:
Type Description
Writer this

Resets to the last state and appends the fork state's current write length as a varint followed by its operations.

Returns:
Type Description
Writer this

Resets this instance to the last state.

Returns:
Type Description
Writer this

sfixed32(value){ Writer }

Writes a signed 32 bit value as fixed 32 bits.

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

sfixed64(value){ Writer }

Writes a signed 64 bit value as fixed 64 bits.

Name Type Description
value Long | number | string

Value to write

Throws:
Type Description
TypeError

If value is a string and no long library is present.

Returns:
Type Description
Writer this

sint32(value){ Writer }

Writes a 32 bit value as a varint, zig-zag encoded.

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

sint64(value){ Writer }

Writes a signed 64 bit value as a varint, zig-zag encoded.

Name Type Description
value Long | number | string

Value to write

Throws:
Type Description
TypeError

If value is a string and no long library is present.

Returns:
Type Description
Writer this

string(value){ Writer }

Writes a string.

Name Type Description
value string

Value to write

Returns:
Type Description
Writer this

uint32(value){ Writer }

Writes an unsigned 32 bit value as a varint.

Name Type Description
value number

Value to write

Returns:
Type Description
Writer this

uint64(value){ Writer }

Writes an unsigned 64 bit value as a varint.

Name Type Description
value Long | number | string

Value to write

Throws:
Type Description
TypeError

If value is a string and no long library is present.

Returns:
Type Description
Writer this