mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-11-22 23:50:52 +01:00
Add readFloat
This commit is contained in:
parent
b32d877462
commit
486ad29450
@ -9,15 +9,6 @@ export class BinaryReader
|
||||
this._dataView = new DataView(buffer);
|
||||
}
|
||||
|
||||
public readByte(): number
|
||||
{
|
||||
const byte = this._dataView.getInt8(this._position);
|
||||
|
||||
this._position++;
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
public readBytes(length: number): BinaryReader
|
||||
{
|
||||
const buffer = new BinaryReader(this._dataView.buffer.slice(this._position, this._position + length));
|
||||
@ -27,6 +18,15 @@ export class BinaryReader
|
||||
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);
|
||||
@ -36,15 +36,6 @@ export class BinaryReader
|
||||
return short;
|
||||
}
|
||||
|
||||
public readDouble(): number
|
||||
{
|
||||
const double = this._dataView.getFloat64(this._position);
|
||||
|
||||
this._position += 8;
|
||||
|
||||
return double;
|
||||
}
|
||||
|
||||
public readInt(): number
|
||||
{
|
||||
const int = this._dataView.getInt32(this._position);
|
||||
@ -54,6 +45,24 @@ export class BinaryReader
|
||||
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;
|
||||
|
@ -12,13 +12,6 @@ export class EvaWireDataWrapper implements IMessageDataWrapper
|
||||
this._buffer = buffer;
|
||||
}
|
||||
|
||||
public readByte(): number
|
||||
{
|
||||
if(!this._buffer) return -1;
|
||||
|
||||
return this._buffer.readByte();
|
||||
}
|
||||
|
||||
public readBytes(length: number): BinaryReader
|
||||
{
|
||||
if(!this._buffer) return null;
|
||||
@ -26,6 +19,13 @@ export class EvaWireDataWrapper implements IMessageDataWrapper
|
||||
return this._buffer.readBytes(length);
|
||||
}
|
||||
|
||||
public readByte(): number
|
||||
{
|
||||
if(!this._buffer) return -1;
|
||||
|
||||
return this._buffer.readByte();
|
||||
}
|
||||
|
||||
public readBoolean(): boolean
|
||||
{
|
||||
return (this.readByte() === 1);
|
||||
@ -38,13 +38,6 @@ export class EvaWireDataWrapper implements IMessageDataWrapper
|
||||
return this._buffer.readShort();
|
||||
}
|
||||
|
||||
public readDouble(): number
|
||||
{
|
||||
if(!this._buffer) return -1;
|
||||
|
||||
return this._buffer.readDouble();
|
||||
}
|
||||
|
||||
public readInt(): number
|
||||
{
|
||||
if(!this._buffer) return -1;
|
||||
@ -52,6 +45,20 @@ export class EvaWireDataWrapper implements IMessageDataWrapper
|
||||
return this._buffer.readInt();
|
||||
}
|
||||
|
||||
public readFloat(): number
|
||||
{
|
||||
if(!this._buffer) return -1;
|
||||
|
||||
return this._buffer.readFloat();
|
||||
}
|
||||
|
||||
public readDouble(): number
|
||||
{
|
||||
if(!this._buffer) return -1;
|
||||
|
||||
return this._buffer.readDouble();
|
||||
}
|
||||
|
||||
public readString(): string
|
||||
{
|
||||
const length = this.readShort();
|
||||
|
@ -6,8 +6,9 @@ export interface IMessageDataWrapper
|
||||
readBytes(length: number): BinaryReader;
|
||||
readBoolean(): boolean;
|
||||
readShort(): number;
|
||||
readDouble(): number;
|
||||
readInt(): number;
|
||||
readFloat(): number;
|
||||
readDouble(): number;
|
||||
readString(): string;
|
||||
header: number;
|
||||
bytesAvailable: boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user