mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
implement packet parser
This commit is contained in:
parent
bba89fd4f1
commit
7d97745783
1 changed files with 22 additions and 0 deletions
22
src/packet.js
Normal file
22
src/packet.js
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue