Static
fromThe buffer to read from.
Create a hazel reader from a string.
The created reader.
const reader = HazelReader.from("weakeyes", "utf8");
The string to read from.
Create a hazel reader from a number array.
The created reader.
const reader = HazelReader.from([5, 6, 7, 8]);
The byte array to read from.
Read a specified number of bytes.
const reader = HazelReader.from("030201);
const message = reader.bytes(2);
console.log(message.buffer); // => <Buffer 03 02>
The number of bytes to read.
Check whether two hazel buffers contain the same information.
Whether or not the hazel writers are the same.
const writer = HazelWriter.alloc(2);
writer.uint8(21);
writer.uint8(69);
const writer2 = HazelWriter.alloc(2);
writer.uint8(21);
writer.uint8(69);
console.log(writer.compare(writer2)); // => true
writer2.uint8(90);
console.log(writer.compare(writer2)); // => false
The other hazel writer to check.
Move the cursor to a position.
The writer.
const writer = HazelWriter.alloc(12);
writer.goto(5);
console.log(writer.cursor); // => 5
The position to move to.
Skip a speciied number of bytes.
The writer.
const writer = HazelWriter.alloc(12);
writer.skip(3);
writer.skip(2);
writer.skip(5);
console.log(writer.cursor); // => 10
Read an object list from the buffer.
const reader = HazelReader.from([5, 6, 7, 8]);
const items = reader.list(reader => reader.uint8());
console.log(items); // => [5, 6, 7, 8];
The length of the list.
The function accepting a single reader to use for reading data.
Read a list of deserializable objects from the reader.
An array of deserialized objects.
The object class to read.
Rest
...args: GetDeserializeArgs<K>Read a hazel message.
The message that was read.
const reader = HazelReader.from("0005010a0a0a0a0a");
const [ tag, mreader ] = reader.message();
console.log(tag, mreader.size); // => 1 5
Read a deserializable object from the reader.
The deserialized data.
The object class to read.
Rest
...args: GetDeserializeArgs<K>The buffer that the writer or reader is targeting.
const writer = HazelWriter.alloc(6);
console.log(writer; // => <HazelBuffer [00] 00 00 00 00 00>
The current position of the writer or reader.
const writer = HazelWriter.alloc(2);
writer.uint16(4);
console.log(writer.cursor); // => 2
The number of bytes left in the writer or reader.
const writer = HazelWriter.alloc(6);
writer.uint16(4);
console.log(writer.left); // => 4
The size of the buffer that the writer or reader is targeting.
const writer = HazelWriter.alloc(6);
console.log(writer.size); // => 6
Generated using TypeDoc
Create a hazel reader from a buffer.
Returns
The created reader.
Example