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