mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
parse extra packet types
This commit is contained in:
parent
1d88787c92
commit
26888c8fcf
4 changed files with 81 additions and 6 deletions
|
|
@ -105,12 +105,31 @@ class Packet {
|
|||
|
||||
parsePayload() {
|
||||
switch(this.getPayloadType()){
|
||||
case Packet.PAYLOAD_TYPE_PATH: return this.parsePayloadTypePath();
|
||||
case Packet.PAYLOAD_TYPE_REQ: return this.parsePayloadTypeReq();
|
||||
case Packet.PAYLOAD_TYPE_RESPONSE: return this.parsePayloadTypeResponse();
|
||||
case Packet.PAYLOAD_TYPE_TXT_MSG: return this.parsePayloadTypeTxtMsg();
|
||||
case Packet.PAYLOAD_TYPE_ACK: return this.parsePayloadTypeAck();
|
||||
case Packet.PAYLOAD_TYPE_ANON_REQ: return this.parsePayloadTypeAnonReq();
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
parsePayloadTypePath() {
|
||||
|
||||
// parse bytes
|
||||
const bufferReader = new BufferReader(this.payload);
|
||||
const dest = bufferReader.readByte();
|
||||
const src = bufferReader.readByte();
|
||||
// todo other fields
|
||||
|
||||
return {
|
||||
src: src,
|
||||
dest: dest,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
parsePayloadTypeReq() {
|
||||
|
||||
// parse bytes
|
||||
|
|
@ -127,12 +146,57 @@ class Packet {
|
|||
|
||||
}
|
||||
|
||||
parsePayloadTypeResponse() {
|
||||
|
||||
// parse bytes
|
||||
const bufferReader = new BufferReader(this.payload);
|
||||
const dest = bufferReader.readByte();
|
||||
const src = bufferReader.readByte();
|
||||
// todo other fields
|
||||
|
||||
return {
|
||||
src: src,
|
||||
dest: dest,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
parsePayloadTypeTxtMsg() {
|
||||
|
||||
// parse bytes
|
||||
const bufferReader = new BufferReader(this.payload);
|
||||
const dest = bufferReader.readByte();
|
||||
const src = bufferReader.readByte();
|
||||
// todo other fields
|
||||
|
||||
return {
|
||||
src: src,
|
||||
dest: dest,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
parsePayloadTypeAck() {
|
||||
return {
|
||||
ack_code: this.payload,
|
||||
};
|
||||
}
|
||||
|
||||
parsePayloadTypeAnonReq() {
|
||||
|
||||
// parse bytes
|
||||
const bufferReader = new BufferReader(this.payload);
|
||||
const dest = bufferReader.readByte();
|
||||
const srcPublicKey = bufferReader.readBytes(32);
|
||||
// todo other fields
|
||||
|
||||
return {
|
||||
src: srcPublicKey,
|
||||
dest: dest,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Packet;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue