You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 23:16:20 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { IBinaryReader } from '@nitrots/api';
|
||||
|
||||
export class BinaryReader implements IBinaryReader
|
||||
{
|
||||
private _position: number;
|
||||
private _dataView: DataView;
|
||||
|
||||
constructor(buffer: ArrayBuffer)
|
||||
{
|
||||
this._position = 0;
|
||||
this._dataView = new DataView(buffer);
|
||||
}
|
||||
|
||||
public readBytes(length: number): IBinaryReader
|
||||
{
|
||||
const buffer = new BinaryReader(this._dataView.buffer.slice(this._position, this._position + length));
|
||||
|
||||
this._position += length;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public readByte(): number
|
||||
{
|
||||
const byte = this._dataView.getInt8(this._position);
|
||||
|
||||
this._position++;
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
public readShort(): number
|
||||
{
|
||||
const short = this._dataView.getInt16(this._position);
|
||||
|
||||
this._position += 2;
|
||||
|
||||
return short;
|
||||
}
|
||||
|
||||
public readInt(): number
|
||||
{
|
||||
const int = this._dataView.getInt32(this._position);
|
||||
|
||||
this._position += 4;
|
||||
|
||||
return int;
|
||||
}
|
||||
|
||||
public readFloat(): number
|
||||
{
|
||||
const float = this._dataView.getFloat32(this._position);
|
||||
|
||||
this._position += 4;
|
||||
|
||||
return float;
|
||||
}
|
||||
|
||||
public readDouble(): number
|
||||
{
|
||||
const double = this._dataView.getFloat64(this._position);
|
||||
|
||||
this._position += 8;
|
||||
|
||||
return double;
|
||||
}
|
||||
|
||||
public remaining(): number
|
||||
{
|
||||
return this._dataView.byteLength - this._position;
|
||||
}
|
||||
|
||||
public toString(encoding?: string): string
|
||||
{
|
||||
return new TextDecoder().decode(this._dataView.buffer);
|
||||
}
|
||||
|
||||
public toArrayBuffer(): ArrayBuffer
|
||||
{
|
||||
return this._dataView.buffer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user