new Writer()
Constructs a new writer instance.
Members
-
head { Object }
-
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 sizenumber 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 valueboolean Value to write
Returns:
Type Description Writer this -
bytes(value){ Writer }
-
Writes a sequence of bytes.
Name Type Description valueUint8Array | 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 valuenumber 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 valuenumber Value to write
Returns:
Type Description Writer this -
fixed64(value){ Writer }
-
Writes an unsigned 64 bit value as fixed 64 bits.
Name Type Description valueLong | number | string Value to write
Throws:
Type Description TypeError If
valueis a string and no long library is present.Returns:
Type Description Writer this -
float(value){ Writer }
-
Writes a float (32 bit).
Name Type Description valuenumber Value to write
Returns:
Type Description Writer this -
fork(){ Writer }
-
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 valuenumber Value to write
Returns:
Type Description Writer this -
int64(value){ Writer }
-
Writes a signed 64 bit value as a varint.
Name Type Description valueLong | number | string Value to write
Throws:
Type Description TypeError If
valueis a string and no long library is present.Returns:
Type Description Writer this -
ldelim(){ Writer }
-
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 -
reset(){ Writer }
-
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 valuenumber Value to write
Returns:
Type Description Writer this -
sfixed64(value){ Writer }
-
Writes a signed 64 bit value as fixed 64 bits.
Name Type Description valueLong | number | string Value to write
Throws:
Type Description TypeError If
valueis 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 valuenumber 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 valueLong | number | string Value to write
Throws:
Type Description TypeError If
valueis a string and no long library is present.Returns:
Type Description Writer this -
string(value){ Writer }
-
Writes a string.
Name Type Description valuestring Value to write
Returns:
Type Description Writer this -
uint32(value){ Writer }
-
Writes an unsigned 32 bit value as a varint.
Name Type Description valuenumber Value to write
Returns:
Type Description Writer this -
uint64(value){ Writer }
-
Writes an unsigned 64 bit value as a varint.
Name Type Description valueLong | number | string Value to write
Throws:
Type Description TypeError If
valueis a string and no long library is present.Returns:
Type Description Writer this