implement packet parser

This commit is contained in:
liamcottle 2025-02-15 21:41:10 +13:00
parent bba89fd4f1
commit 7d97745783

22
src/packet.js Normal file
View file

@ -0,0 +1,22 @@
import BufferReader from "./buffer_reader.js";
class Packet {
constructor(header, path, payload) {
this.header = header;
this.path = path;
this.payload = payload;
}
static fromBytes(bytes) {
const bufferReader = new BufferReader(bytes);
const header = bufferReader.readByte();
const pathLen = bufferReader.readInt8();
const path = bufferReader.readBytes(pathLen);
const payload = bufferReader.readRemainingBytes();
return new Packet(header, path, payload);
}
}
export default Packet;