fnbr
Version:
A library to interact with Epic Games' Fortnite HTTP and XMPP services
136 lines • 3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Represents a writer for binary data used for tournament replays
* @private
*/
class BinaryWriter {
/**
* @param buffer The buffer
*/
constructor(buffer) {
this.buffer = buffer;
this.offset = 0;
}
/**
* Skip bytes
*/
skip(count) {
this.offset += count;
return this;
}
/**
* Change the current buffer offset
*/
goto(offset) {
this.offset = offset;
return this;
}
/**
* Write an int8
*/
writeInt8(value) {
this.buffer.writeInt8(value, this.offset);
this.offset += 1;
return this;
}
/**
* Write a uint8
*/
writeUInt8(value) {
this.buffer.writeUInt8(value, this.offset);
this.offset += 1;
return this;
}
/**
* Write an int16
*/
writeInt16(value) {
this.buffer.writeInt16LE(value, this.offset);
this.offset += 2;
return this;
}
/**
* Write a uint16
*/
writeUInt16(value) {
this.buffer.writeUInt16LE(value, this.offset);
this.offset += 2;
return this;
}
/**
* Write an int32
*/
writeInt32(value) {
this.buffer.writeInt32LE(value, this.offset);
this.offset += 4;
return this;
}
/**
* Write a uint32
*/
writeUInt32(value) {
this.buffer.writeUInt32LE(value, this.offset);
this.offset += 4;
return this;
}
/**
* Write an int64
*/
writeInt64(value) {
this.buffer.writeBigInt64LE(value, this.offset);
this.offset += 8;
return this;
}
/**
* Write a uint64
*/
writeUInt64(value) {
this.buffer.writeBigUInt64LE(value, this.offset);
this.offset += 8;
return this;
}
/**
* Write a float32
*/
writeFloat32(value) {
this.buffer.writeFloatLE(value, this.offset);
this.offset += 4;
return this;
}
/**
* Write a string
*/
writeString(value, encoding = 'utf8') {
this.writeInt32(encoding === 'utf8' ? value.length + 1 : -(value.length + 1));
this.writeBytes(Buffer.from(value, encoding));
this.skip(encoding === 'utf8' ? 1 : 2);
return this;
}
/**
* Write a boolean
*/
writeBool(value) {
this.writeInt32(value === true ? 1 : 0);
return this;
}
/**
* Write multiple bytes
*/
writeBytes(value) {
value.forEach((b, i) => {
this.buffer[this.offset + i] = b;
});
this.offset += value.byteLength;
return this;
}
/**
* Write 16 bytes as a hex string
*/
writeId(value) {
this.writeBytes(Buffer.from(Buffer.from(value).toString('hex')));
return this;
}
}
exports.default = BinaryWriter;
//# sourceMappingURL=BinaryWriter.js.map