Home Reference Source
import {NiceBuffer} from 'jvm/lib/core/parsers/NiceBuffer.js'
public class | source

NiceBuffer

Wraps Node's Buffer class by providing smart defaults specific to the JVM's binary format.

Constructor Summary

Public Constructor
public

constructor(buffer: Buffer)

Instantiates a new instance

Member Summary

Public Members
public

buffer: Buffer

public

Maps size constants to their respective method names.

public

Current position in buffer.

Method Summary

Public Methods
public

Reads an unsigned 8bit Integer from the buffer.

public

int(): Number

Reads an unsigned 32bit Integer from the buffer in Big Endian format.

public

move(len: Number): Number

Moves the offset used when reading/writing bytes by a relative amount.

public

read(len: Number): Number | Buffer

Reads an arbitrary amount of bytes from the buffer.

public

readStruct(struct: *): *

public

Reads an unsigned 16bit Integer from the buffer in Big Endian format.

public

slice(len: Number): Buffer

Slice a Buffer of bytes from the buffer of a specified length at the current position.

public

write(bytes: Array<Number>)

Writes an array of bytes to the current position in the buffer.

public

Writes a single ubyte to the current position in the buffer.

public

Writes a uint to the current position in the buffer in Big Endian format.

public

Writes a ushort to the current position in the buffer in Big Endian format.

Public Constructors

public constructor(buffer: Buffer) source

Instantiates a new instance

Params:

NameTypeAttributeDescription
buffer Buffer

normal Node Buffer object

Public Members

public buffer: Buffer source

public lengthMap: Object source

Maps size constants to their respective method names.

public pos: Number source

Current position in buffer.

Public Methods

public byte(): Number source

Reads an unsigned 8bit Integer from the buffer.

Return:

Number

ubyte

public int(): Number source

Reads an unsigned 32bit Integer from the buffer in Big Endian format.

Return:

Number

uint

public move(len: Number): Number source

Moves the offset used when reading/writing bytes by a relative amount.

Params:

NameTypeAttributeDescription
len Number

Relative offset to move

Return:

Number

The position before the offset is added to it. Behavior is similar to position++ rather than ++position.

public read(len: Number): Number | Buffer source

Reads an arbitrary amount of bytes from the buffer. If the length matches one of the SIZE_ prefixed constants also declared in this class, it will instead decode the bytes into an unsigned integer of that size.

Params:

NameTypeAttributeDescription
len Number

Number of bytes to read.

Return:

Number | Buffer

public readStruct(struct: *): * source

Params:

NameTypeAttributeDescription
struct *

Return:

*

public short(): Number source

Reads an unsigned 16bit Integer from the buffer in Big Endian format.

Return:

Number

ushort

public slice(len: Number): Buffer source

Slice a Buffer of bytes from the buffer of a specified length at the current position.

Params:

NameTypeAttributeDescription
len Number

Number of bytes to slice

Return:

Buffer

public write(bytes: Array<Number>) source

Writes an array of bytes to the current position in the buffer.

Params:

NameTypeAttributeDescription
bytes Array<Number>

an array of bytes

public writeByte(val: Number) source

Writes a single ubyte to the current position in the buffer.

Params:

NameTypeAttributeDescription
val Number

public writeInt(val: Number) source

Writes a uint to the current position in the buffer in Big Endian format.

Params:

NameTypeAttributeDescription
val Number

public writeShort(val: Number) source

Writes a ushort to the current position in the buffer in Big Endian format.

Params:

NameTypeAttributeDescription
val Number