mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
update to new protodef
This commit is contained in:
parent
4806e48aff
commit
b2b8ad2372
2 changed files with 24 additions and 7 deletions
|
@ -45,7 +45,7 @@
|
|||
"buffer-equal": "1.0.0",
|
||||
"minecraft-data": "^0.19.1",
|
||||
"prismarine-nbt": "0.2.0",
|
||||
"protodef": "0.2.5",
|
||||
"protodef": "0.3.0",
|
||||
"readable-stream": "^2.0.5",
|
||||
"ursa-purejs": "0.0.3",
|
||||
"uuid-1345": "^0.99.6",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const [readVarInt, writeVarInt, sizeOfVarInt] = require("protodef").types.varint;
|
||||
const {PartialReadError} = require("protodef").utils;
|
||||
const Transform = require("readable-stream").Transform;
|
||||
|
||||
module.exports.createSplitter = function() {
|
||||
|
@ -47,13 +48,29 @@ class Splitter extends Transform {
|
|||
}
|
||||
|
||||
let offset = 0;
|
||||
|
||||
let { value, size, error } = readVarInt(this.buffer, offset) || { error: "Not enough data" };
|
||||
while (!error && this.buffer.length >= offset + size + value)
|
||||
let value, size, error;
|
||||
try {
|
||||
({ value, size, error } = readVarInt(this.buffer, offset));
|
||||
}
|
||||
catch(e) {
|
||||
if(!(e instanceof PartialReadError)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
while (this.buffer.length >= offset + size + value)
|
||||
{
|
||||
this.push(this.buffer.slice(offset + size, offset + size + value));
|
||||
offset += size + value;
|
||||
({ value, size, error } = readVarInt(this.buffer, offset) || { error: "Not enough data" });
|
||||
try {
|
||||
this.push(this.buffer.slice(offset + size, offset + size + value));
|
||||
offset += size + value;
|
||||
({value, size, error} = readVarInt(this.buffer, offset));
|
||||
}
|
||||
catch(e) {
|
||||
if(e instanceof PartialReadError) {
|
||||
break;
|
||||
}
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
this.buffer = this.buffer.slice(offset);
|
||||
return cb();
|
||||
|
|
Loading…
Reference in a new issue