Closed
Description
After calling writeCString
on a buffer with data already in it, the offset
is set to the length of the string + 1, instead of offset
+ length + 1.
Code to reproduce:
var str = "This is a test string.";
var body = new ByteBuffer(BUFFER_MAX_SIZE, ByteBuffer.LITTLE_ENDIAN);
body.writeUint32(55555); // 4 bytes, offset = 4
body.writeUint16(1234); // 2 bytes, offset = 6
body.writeCString(str); // 23 bytes, offset should = 29
body.writeUint32(123456); // 4 bytes, offset should = 33
console.log("Expected offset: %d, actual: %d", 4 + 2 + str.length + 1 + 4, body.offset); // Expected offset: 33, actual: 27
body.flip();
console.log("Uint32: %d, Uint16: %d string: %s, Uint32: %d", body.readUint32(), body.readUint16(), body.readCString(), body.readUint32()); // Uint32: 55555, Uint16: 1234 string: This is a test st@?☺, Uint32: 46
Metadata
Metadata
Assignees
Labels
No labels