mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-31 06:12:34 +00:00
35 lines
679 B
JavaScript
35 lines
679 B
JavaScript
|
|
class EmptyObject {
|
|
|
|
|
|
static PROTOCOL_ID = 0;
|
|
|
|
protocolId() {
|
|
return EmptyObject.PROTOCOL_ID;
|
|
}
|
|
|
|
static write(buffer, packet) {
|
|
if (packet === null) {
|
|
buffer.writeInt(0);
|
|
return;
|
|
}
|
|
buffer.writeInt(-1);
|
|
}
|
|
|
|
static read(buffer) {
|
|
const length = buffer.readInt();
|
|
if (length === 0) {
|
|
return null;
|
|
}
|
|
const beforeReadIndex = buffer.getReadOffset();
|
|
const packet = new EmptyObject();
|
|
|
|
if (length > 0) {
|
|
buffer.setReadOffset(beforeReadIndex + length);
|
|
}
|
|
return packet;
|
|
}
|
|
|
|
}
|
|
export default EmptyObject;
|