mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-27 13:14:41 -04:00
Added stringArray datatype
This commit is contained in:
parent
5f6abad700
commit
4a366d75b5
@ -497,6 +497,7 @@ var types = {
|
||||
'intVector': [readIntVector, IntVectorWriter],
|
||||
'byteVector': [readByteVector, ByteVectorWriter],
|
||||
'byteVectorArray': [readByteVectorArray, ByteVectorArrayWriter],
|
||||
'stringArray': [readStringArray, StringArrayWriter],
|
||||
};
|
||||
|
||||
function ByteArray32Writer(value) {
|
||||
@ -677,6 +678,24 @@ ByteVectorArrayWriter.prototype.write = function(buffer, offset) {
|
||||
});
|
||||
}
|
||||
|
||||
function StringArrayWriter(value) {
|
||||
this.value = value;
|
||||
this.size = 2;
|
||||
for (var i = 0; i < this.value.length; ++i) {
|
||||
this.value[i] = stringWriter = new StringWriter(this.value[i]);
|
||||
this.size += stringWriter.size;
|
||||
}
|
||||
}
|
||||
|
||||
StringArrayWriter.prototype.write = function(buffer, offset) {
|
||||
buffer.writeInt16BE(this.value.length, offset);
|
||||
offset += 2;
|
||||
this.value.forEach(function(stringWriter) {
|
||||
stringWriter.write(buffer, offset);
|
||||
offset += stringWriter.size;
|
||||
});
|
||||
}
|
||||
|
||||
function readIntArray8(buffer, offset) {
|
||||
var results = readByte(buffer, offset);
|
||||
if (! results) return null;
|
||||
@ -954,6 +973,26 @@ function readSlotArray (buffer, offset) {
|
||||
};
|
||||
}
|
||||
|
||||
function readStringArray (buffer, offset) {
|
||||
var results = readShort(buffer, offset);
|
||||
if (! results) return null;
|
||||
var count = results.value;
|
||||
var cursor = offset + results.size;
|
||||
|
||||
var stringArray = [];
|
||||
for (var i = 0; i < count; ++i) {
|
||||
results = readString(buffer, cursor);
|
||||
if (! results) return null;
|
||||
stringArray.push(results.value);
|
||||
cursor += results.size;
|
||||
}
|
||||
|
||||
return {
|
||||
value: stringArray,
|
||||
size: cursor - offset,
|
||||
};
|
||||
}
|
||||
|
||||
function readShort(buffer, offset) {
|
||||
if (offset + 2 > buffer.length) return null;
|
||||
var value = buffer.readInt16BE(offset);
|
||||
|
Loading…
x
Reference in New Issue
Block a user