mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 13:45:37 -04:00
Merge pull request #349 from deathcap/compressnbt
[WIP] Compress compressedNbt on write
This commit is contained in:
commit
35bc9282bc
@ -73,14 +73,27 @@ function writeCompressedNbt(value, buffer, offset) {
|
|||||||
buffer.writeInt16BE(-1,offset);
|
buffer.writeInt16BE(-1,offset);
|
||||||
return offset+2;
|
return offset+2;
|
||||||
}
|
}
|
||||||
buffer.writeInt16BE(sizeOfNbt(value),offset);
|
const nbtBuffer = new Buffer(sizeOfNbt(value));
|
||||||
return nbt.proto.write(value,buffer,offset+2,"nbt");
|
nbt.proto.write(value,nbtBuffer,0,"nbt");
|
||||||
|
|
||||||
|
const compressedNbt = zlib.gzipSync(nbtBuffer); // TODO: async
|
||||||
|
compressedNbt.writeUInt8(0, 9); // clear the OS field to match MC
|
||||||
|
|
||||||
|
buffer.writeInt16BE(compressedNbt.length,offset);
|
||||||
|
compressedNbt.copy(buffer,offset+2);
|
||||||
|
return offset+2+compressedNbt.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sizeOfCompressedNbt(value) {
|
function sizeOfCompressedNbt(value) {
|
||||||
if(value==undefined)
|
if(value==undefined)
|
||||||
return 2;
|
return 2;
|
||||||
return 2+nbt.proto.sizeOf(value,"nbt");
|
|
||||||
|
const nbtBuffer = new Buffer(sizeOfNbt(value,"nbt"));
|
||||||
|
nbt.proto.write(value,nbtBuffer,0,"nbt");
|
||||||
|
|
||||||
|
const compressedNbt = zlib.gzipSync(nbtBuffer); // TODO: async
|
||||||
|
|
||||||
|
return 2+compressedNbt.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user