2023-10-24 12:04:07 +01:00
|
|
|
// Copyright (c) Holly Stubbs (tgpholly) - Licensed under MIT
|
|
|
|
// Check LICENSE in repository root for more information.
|
|
|
|
|
2023-04-28 16:47:02 +01:00
|
|
|
import { IReader } from "./IReader";
|
2023-07-28 10:25:08 +01:00
|
|
|
import { ReaderBase } from "../base/ReaderBase";
|
2023-04-28 16:47:02 +01:00
|
|
|
|
|
|
|
export class ReaderLE extends ReaderBase implements IReader {
|
|
|
|
public readShort() {
|
|
|
|
const value = this.buffer.readInt16LE(this.offset);
|
|
|
|
this.offset += 2
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readUShort() {
|
|
|
|
const value = this.buffer.readUInt16LE(this.offset);
|
|
|
|
this.offset += 2
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readInt() {
|
|
|
|
const value = this.buffer.readInt32LE(this.offset);
|
|
|
|
this.offset += 4;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readUInt() {
|
|
|
|
const value = this.buffer.readUInt32LE(this.offset);
|
|
|
|
this.offset += 4;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readLong() {
|
|
|
|
const value = this.buffer.readBigInt64LE(this.offset);
|
|
|
|
this.offset += 8;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readULong() {
|
2024-11-26 15:08:21 +00:00
|
|
|
const value = this.buffer.readBigUInt64LE(this.offset);
|
2023-04-28 16:47:02 +01:00
|
|
|
this.offset += 8;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readFloat() {
|
|
|
|
const value = this.buffer.readFloatLE(this.offset);
|
|
|
|
this.offset += 4;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readDouble() {
|
|
|
|
const value = this.buffer.readDoubleLE(this.offset);
|
|
|
|
this.offset += 8;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2024-11-26 15:08:21 +00:00
|
|
|
public readUString() {
|
2024-01-01 22:23:16 +00:00
|
|
|
const length = this.readUShort();
|
2023-04-28 16:47:02 +01:00
|
|
|
let text:string = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
text += String.fromCharCode(this.readUByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2024-11-26 15:08:21 +00:00
|
|
|
|
|
|
|
public readString() {
|
|
|
|
const length = this.readShort();
|
|
|
|
let text:string = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
text += String.fromCharCode(this.readByte());
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2024-01-01 22:23:16 +00:00
|
|
|
|
2024-11-26 15:08:21 +00:00
|
|
|
public readUString16() {
|
2023-04-28 16:47:02 +01:00
|
|
|
const length = this.readUShort();
|
|
|
|
let text:string = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
2024-01-01 22:23:16 +00:00
|
|
|
text += String.fromCharCode(this.readUShort());
|
2023-04-28 16:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2023-05-02 10:10:47 +01:00
|
|
|
|
2024-11-26 15:08:21 +00:00
|
|
|
public readString16() {
|
|
|
|
const length = this.readShort();
|
|
|
|
let text:string = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
text += String.fromCharCode(this.readShort());
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2024-01-01 22:23:16 +00:00
|
|
|
public readShortsAsString(shortsToRead:number) {
|
|
|
|
let text = "";
|
|
|
|
|
|
|
|
for (let i = 0; i < shortsToRead; i++) {
|
2023-05-02 10:10:47 +01:00
|
|
|
text += String.fromCharCode(this.readUShort());
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
2024-12-16 10:20:28 +00:00
|
|
|
|
|
|
|
public readArbInt(length: number) {
|
|
|
|
const value = this.buffer.readIntLE(this.offset, length);
|
|
|
|
this.offset += length;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public readArbUInt(length: number) {
|
|
|
|
const value = this.buffer.readUIntLE(this.offset, length);
|
|
|
|
this.offset += length;
|
|
|
|
return value;
|
|
|
|
}
|
2023-04-28 16:47:02 +01:00
|
|
|
}
|