import MqttPacket from './MqttPacket' ; export default class PacketReader { packet : MqttPacket ; pos : number = 0 ; constructor ( packet ) { this . packet = packet ; } readU8 ( ) { const res = this . packet . content . readUInt8 ( this . pos ) ; this . pos += 1 ; return res ; } readU16 ( ) { const res = this . packet . content . readUInt16BE ( this . pos ) ; this . pos += 2 ; return res ; } readData ( ) { const size = this . readU16 ( ) ; const res = this . packet . content . slice ( this . pos , size + 2 ) ; this . pos += size ; return res ; } readRaw ( ) { const res = this . packet . content . slice ( this . pos , this . packet . content . length ) ; this . pos = this . packet . content . length ; return res ; } }