Skip to content

Commit

Permalink
clientMessage crete buffer offset fix
Browse files Browse the repository at this point in the history
  • Loading branch information
asimarslan committed Feb 18, 2016
1 parent 02a9f9d commit bed4c6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public boolean readFrom(ByteBuffer src) {
//we don't have even the frame length ready
return false;
}
frameLength = Bits.readIntL(src.array(), 0);
frameLength = Bits.readIntL(src.array(), src.position());
if (USE_UNSAFE) {
wrap(new UnsafeBuffer(new byte[frameLength]), 0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
public class ClientMessageAccumulatorTest {


private static final byte[] BYTE_DATA = new byte[] { 24, 0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0, 0, 0, 0, 0 };
private static final byte[] BYTE_DATA = new byte[] { 0, 0, 24, 0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0 ,0, 0, 0, 0, 0, 0, 0 };
private static final int OFFSET = 2;

@Before
public void setUp() {
Expand All @@ -39,13 +40,14 @@ public void tearDown() {
public void shouldAccumulateClientMessageCorrectly() {
ClientMessage accumulator = ClientMessage.create();
final ByteBuffer inBuffer = ByteBuffer.wrap(BYTE_DATA);
inBuffer.position(OFFSET);
accumulator.readFrom(inBuffer);

final ByteBuffer byteBuffer = accumulatedByteBuffer(accumulator.buffer(), accumulator.index());
assertEquals(0, byteBuffer.position());
assertEquals(accumulator.getFrameLength(), byteBuffer.limit());

for (int i = 0; i < byteBuffer.limit(); i++) {
for (int i = OFFSET; i < byteBuffer.limit(); i++) {
assertEquals(BYTE_DATA[i], byteBuffer.get());
}
assertTrue(accumulator.isComplete());
Expand Down

0 comments on commit bed4c6c

Please sign in to comment.