Class: BufferWriter

BufferWriter

Wire format writer using node buffers.

new BufferWriter()

Constructs a new buffer writer instance.

Extends

Members

Operations head.

len { number }

Current length.

states { Object | null }

Linked forked states.

tail { Object }

Operations tail

Methods

inherited bool(value){ Writer }

Writes a boolish value as a varint.

Parameters:
value boolean

Value to write

Returns:
Writer this

Writes a sequence of bytes.

Parameters:
value Uint8Array | string

Buffer or base64 encoded string to write

Returns:
Writer this

inherited double(value){ Writer }

Writes a double (64 bit float).

Parameters:
value number

Value to write

Returns:
Writer this

finish(){ Buffer }

Finishes the write operation.

Returns:
Buffer Finished buffer

inherited finishInto(buf, offset){ T }

Finishes the write operation, writing into the provided buffer.
The caller must ensure that buf has enough space starting at offset
to hold Writer#len bytes.

Parameters:
buf T

Target buffer

offset number 0 optional

Offset to start writing at

Returns:
T The provided buffer

inherited fixed32(value){ Writer }

Writes an unsigned 32 bit value as fixed 32 bits.

Parameters:
value number

Value to write

Returns:
Writer this

inherited fixed64(value){ Writer }

Writes an unsigned 64 bit value as fixed 64 bits.

Parameters:
value Long | number | string

Value to write

Throws:
TypeError

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

Returns:
Writer this

inherited float(value){ Writer }

Writes a float (32 bit).

Parameters:
value number

Value to write

Returns:
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:
Writer this

inherited int32(value){ Writer }

Writes a signed 32 bit value as a varint.

Parameters:
value number

Value to write

Returns:
Writer this

inherited int64(value){ Writer }

Writes a signed 64 bit value as a varint.

Parameters:
value Long | number | string

Value to write

Throws:
TypeError

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

Returns:
Writer this

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

Returns:
Writer this

Writes raw bytes without a tag or length prefix.

Parameters:
value Uint8Array

Raw bytes

Returns:
BufferWriter this

Resets this instance to the last state.

Returns:
Writer this

inherited sfixed32(value){ Writer }

Writes a signed 32 bit value as fixed 32 bits.

Parameters:
value number

Value to write

Returns:
Writer this

inherited sfixed64(value){ Writer }

Writes a signed 64 bit value as fixed 64 bits.

Parameters:
value Long | number | string

Value to write

Throws:
TypeError

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

Returns:
Writer this

inherited sint32(value){ Writer }

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

Parameters:
value number

Value to write

Returns:
Writer this

inherited sint64(value){ Writer }

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

Parameters:
value Long | number | string

Value to write

Throws:
TypeError

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

Returns:
Writer this

inherited string(value){ Writer }

Writes a string.

Parameters:
value string

Value to write

Returns:
Writer this

inherited uint32(value){ Writer }

Writes an unsigned 32 bit value as a varint.

Parameters:
value number

Value to write

Returns:
Writer this

inherited uint64(value){ Writer }

Writes an unsigned 64 bit value as a varint.

Parameters:
value Long | number | string

Value to write

Throws:
TypeError

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

Returns:
Writer this

BufferWriter.alloc(size){ Buffer }

Allocates a buffer of the specified size.

Parameters:
size number

Buffer size

Returns:
Buffer Buffer