27 lines
519 B
JavaScript
27 lines
519 B
JavaScript
import {Encoder, Decoder} from '@msgpack/msgpack';
|
|
|
|
const decoder = new Decoder();
|
|
const encoder = new Encoder();
|
|
|
|
export default class Packet {
|
|
|
|
static decode(view) {
|
|
return decoder.decode(new DataView(view.buffer, view.byteOffset + 2, view.byteLength - 2));
|
|
}
|
|
|
|
static encode(payload) {
|
|
encoder.pos = 2;
|
|
encoder.doEncode(payload)
|
|
return new DataView(encoder.bytes.buffer, 0, encoder.pos);
|
|
}
|
|
|
|
static pack(payload) {
|
|
return payload;
|
|
}
|
|
|
|
static unpack(packed) {
|
|
return packed;
|
|
}
|
|
|
|
}
|