Static
allocThe number of bytes to allocate.
Begin writing a new length & tag message.
The writer.
const writer = HazelWriter.alloc(4);
writer.begin(5);
writer.uint8(0x45);
writer.end();
The tag of the message.
Write a true or false value.
The writer.
const writer = HazelWriter.alloc(4);
writer.bool(true);
writer.bool(false);
The value to write.
Write a single unsigned byte.
The writer.
const writer = HazelWriter.alloc(1);
writer.byte(69);
The value to write. (Between 0 and 255 inclusive.)
Write non-length-prefixed bytes.
The writer.
const writer = HazelWriter.alloc(5);
writer.bytes("Hello");
The bytes to write to the buffer.
Clone the message writer to a new writer with a separate buffer.
The new message writer.
const writer = HazelWriter.alloc(2);
writer.uint8(32);
writer.uint8(12);
const cloned = writer.clone();
cloned.uint8(90);
console.log(writer); // => <HazelBuffer 20 0c [ ]>
console.log(cloned); // => <HazelBuffer 20 0c 5a [ ]>
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.
End writing an opened message.
The writer.
const writer = HazelWriter.alloc(4);
writer.begin(5);
writer.uint8(0x45);
writer.end();
Expand the writer by the number of bytes required to write a value. Won't reallocate if there are enough bytes remaining.
The writer.
const writer = HazelWriter.alloc(6);
writer.expand(2); // The cursor is at 0, since there is 2 bytes remaining, the size remains at 6.
console.log(writer.size); // => 6
writer.expand(8); // There is not 8 bytes remaining so the writer buffer is reallocated to 8.
console.log(writer.size); // => 8
The number of bytes required to write a value.
Write an IEEE 754 floating point number.
The writer.
const writer = HazelWriter.alloc(8);
writer.float(54.32);
writer.float(21.69420);
The value to write.
Optional
be: booleanMove 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.
Write a signed 16-bit integer value.
The writer.
const writer = HazelWriter.alloc(4);
writer.int16(-3452);
writer.int16(1933);
The value to write. (Between -32767 and 32767 inclusive.)
Optional
be: booleanWrite a signed 32-bit integer value.
The writer.
const writer = HazelWriter.alloc(8);
writer.int32(-432423);
writer.int32(1212112);
The value to write. (Between -2147483647 and 2147483647 inclusive.)
Optional
be: booleanWrite a signed 64-bit integer value.
The writer.
const writer = HazelWriter.alloc(8);
writer.int64(-432423);
The value to write. (Between -2147483647 and 2147483647 inclusive.)
Optional
be: booleanWrite a signed 8-bit integer value.
The writer.
const writer = HazelWriter.alloc(4);
writer.int8(-120);
writer.int8(68);
The value to write. (Between -127 and 127 inclusive.)
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
Write an object list from the buffer.
The writer.
const nums = [5, 6, 7, 8];
const reader = HazelReader.alloc(0);
const items = reader.list(nums, (item, writer) => writer.uint8(item));
console.log(items); // => [5, 6, 7, 8];
The length of the list.
Optional
fn: ListWriter<T>The function accepting a single reader to use for reading data.
Write a list of serializable objects to the writer.
The writer.
const writer = HazelWriter.alloc(0);
writer.write(players.map(player => player.control));
The objects to write.
Rest
...args: GetSerializeArgs<K>Reallocate the the number of bytes in the writer.
The writer.
const writer = HazelWriter.alloc(4);
writer.realloc(8);
console.log(writer.size); // => 8
The size to reallocate to.
Write a single signed byte.
The writer.
const writer = HazelWriter.alloc(1);
writer.byte(-32);
The value to write. (Between -127 and 127 inclusive.)
Write an unsigned 16-bit integer value.
The writer.
const writer = HazelWriter.alloc(4);
writer.uint16(5342);
writer.uint16(256);
The value to write. (Between 0 and 65535 inclusive.)
Optional
be: booleanWrite an unsigned 32-bit integer value.
The writer.
const writer = HazelWriter.alloc(8);
writer.uint32(6764774);
writer.uint32(12314352);
The value to write. (Between 0 and 4294967295 inclusive.)
Optional
be: booleanWrite an unsigned 64-bit integer value.
The writer.
const writer = HazelWriter.alloc(8);
writer.uint64(6764774);
The value to write. (Between 0 and 18446744073709552000 inclusive.)
Optional
be: booleanWrite an unsigned 8-bit integer value.
The writer.
const writer = HazelWriter.alloc(1);
writer.uint8(54);
The value to write. (Between 0 and 255 inclusive.)
Write a serializable object to the writer.
The writer.
const writer = HazelWriter.alloc(0);
writer.write(player.control);
The object to write.
Rest
...args: GetSerializeArgs<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
Allocate a message writer with a buffer of the specified number of bytes.
Returns
The message writer writing to the allocated bytes.
Example