diff --git a/src/core/communication/codec/BinaryReader.ts b/src/core/communication/codec/BinaryReader.ts index 0f7ab479..4ff2b469 100644 --- a/src/core/communication/codec/BinaryReader.ts +++ b/src/core/communication/codec/BinaryReader.ts @@ -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; diff --git a/src/core/communication/codec/evawire/EvaWireDataWrapper.ts b/src/core/communication/codec/evawire/EvaWireDataWrapper.ts index 42e76c0f..50a7a68b 100644 --- a/src/core/communication/codec/evawire/EvaWireDataWrapper.ts +++ b/src/core/communication/codec/evawire/EvaWireDataWrapper.ts @@ -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(); diff --git a/src/core/communication/messages/IMessageDataWrapper.ts b/src/core/communication/messages/IMessageDataWrapper.ts index 4a75eed9..87337b8a 100644 --- a/src/core/communication/messages/IMessageDataWrapper.ts +++ b/src/core/communication/messages/IMessageDataWrapper.ts @@ -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;