Class: Reader

Reader

Wire format reader using Uint8Array if available, otherwise Array.

new Reader(buffer)

Constructs a new reader instance using the specified buffer.

Name Type Description
buffer Uint8Array

Buffer to read from

Members

buf { Uint8Array }

Read buffer.

len { number }

Read buffer length.

pos { number }

Read buffer position.

Methods

Reader.create(buffer){ Reader | BufferReader }

Creates a new reader using the specified buffer.

Name Type Description
buffer Uint8Array | Buffer

Buffer to read from

Throws:
Type Description
Error

If buffer is not a valid buffer

Returns:
Type Description
Reader | BufferReader A BufferReader if buffer is a Buffer, otherwise a Reader

bool(){ boolean }

Reads a varint as a boolean.

Returns:
Type Description
boolean Value read

bytes(){ Uint8Array }

Reads a sequence of bytes preceeded by its length as a varint.

Returns:
Type Description
Uint8Array Value read

double(){ number }

Reads a double (64 bit float) as a number.

Returns:
Type Description
number Value read

fixed32(){ number }

Reads fixed 32 bits as an unsigned 32 bit integer.

Returns:
Type Description
number Value read

fixed64(){ Long }

Reads fixed 64 bits.

Returns:
Type Description
Long Value read

float(){ number }

Reads a float (32 bit) as a number.

Returns:
Type Description
number Value read

int32(){ number }

Reads a varint as a signed 32 bit value.

Returns:
Type Description
number Value read

Reads a varint as a signed 64 bit value.

Returns:
Type Description
Long Value read

sfixed32(){ number }

Reads fixed 32 bits as a signed 32 bit integer.

Returns:
Type Description
number Value read

sfixed64(){ Long }

Reads zig-zag encoded fixed 64 bits.

Returns:
Type Description
Long Value read

sint32(){ number }

Reads a zig-zag encoded varint as a signed 32 bit value.

Returns:
Type Description
number Value read

sint64(){ Long }

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

Returns:
Type Description
Long Value read

skip(length){ Reader }

Skips the specified number of bytes if specified, otherwise skips a varint.

Name Type Description
length number optional

Length if known, otherwise a varint is assumed

Returns:
Type Description
Reader this

skipType(wireType){ Reader }

Skips the next element of the specified wire type.

Name Type Description
wireType number

Wire type received

Returns:
Type Description
Reader this

string(){ string }

Reads a string preceeded by its byte length as a varint.

Returns:
Type Description
string Value read

uint32(){ number }

Reads a varint as an unsigned 32 bit value.

Returns:
Type Description
number Value read

uint64(){ Long }

Reads a varint as an unsigned 64 bit value.

Returns:
Type Description
Long Value read