mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-19 01:30:24 -04:00
Added stringArray datatype
This commit is contained in:
parent
5f6abad700
commit
4a366d75b5
1 changed files with 39 additions and 0 deletions
|
@ -497,6 +497,7 @@ var types = {
|
||||||
'intVector': [readIntVector, IntVectorWriter],
|
'intVector': [readIntVector, IntVectorWriter],
|
||||||
'byteVector': [readByteVector, ByteVectorWriter],
|
'byteVector': [readByteVector, ByteVectorWriter],
|
||||||
'byteVectorArray': [readByteVectorArray, ByteVectorArrayWriter],
|
'byteVectorArray': [readByteVectorArray, ByteVectorArrayWriter],
|
||||||
|
'stringArray': [readStringArray, StringArrayWriter],
|
||||||
};
|
};
|
||||||
|
|
||||||
function ByteArray32Writer(value) {
|
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) {
|
function readIntArray8(buffer, offset) {
|
||||||
var results = readByte(buffer, offset);
|
var results = readByte(buffer, offset);
|
||||||
if (! results) return null;
|
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) {
|
function readShort(buffer, offset) {
|
||||||
if (offset + 2 > buffer.length) return null;
|
if (offset + 2 > buffer.length) return null;
|
||||||
var value = buffer.readInt16BE(offset);
|
var value = buffer.readInt16BE(offset);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue