the MessageBuffer constructor that takes a ByteBuffer behaves wrongly if the supplied byte buffer only occupies a subset of the backing array, it ignores the bytebuffer subset, and just looks at the entire backing array. e.g. this test demonstrates the problem
@test
public void testWrappedByteBuffer() {
byte [] d = {10,11,12,13,14,15,16,17,18,19};
ByteBuffer subset = ByteBuffer.wrap(d, 2, 2);
MessageBuffer mb = MessageBuffer.wrap(subset);
Assert.assertEquals(12, mb.getByte(0)); // fails returns 10
Assert.assertEquals(2, mb.size()); // fails return 10
}
The code seems to assume that ByteBuffer.array() returns an array of just the current Buffer contents, but in fact it returns the entire backing array.
the MessageBuffer constructor that takes a ByteBuffer behaves wrongly if the supplied byte buffer only occupies a subset of the backing array, it ignores the bytebuffer subset, and just looks at the entire backing array. e.g. this test demonstrates the problem
@test
public void testWrappedByteBuffer() {
byte [] d = {10,11,12,13,14,15,16,17,18,19};
ByteBuffer subset = ByteBuffer.wrap(d, 2, 2);
MessageBuffer mb = MessageBuffer.wrap(subset);
Assert.assertEquals(12, mb.getByte(0)); // fails returns 10
Assert.assertEquals(2, mb.size()); // fails return 10
}
The code seems to assume that ByteBuffer.array() returns an array of just the current Buffer contents, but in fact it returns the entire backing array.