Skip to content

Commit c0d8d4f

Browse files
committed
Parse ByteBufs correctly if no array is available.
1 parent 4849b02 commit c0d8d4f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/com/github/brainlag/nsq/frames/MessageFrame.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public void setData(byte[] bytes) {
1818
timestamp = buf.readLong();
1919
attempts = buf.readShort();
2020
buf.readBytes(messageId);
21-
messageBody = buf.readBytes(buf.readableBytes()).array();
21+
if (buf.hasArray()) {
22+
messageBody = buf.readBytes(buf.readableBytes()).array();
23+
} else {
24+
byte[] array = new byte[buf.readableBytes()];
25+
buf.readBytes(array);
26+
messageBody = array;
27+
}
2228
}
2329

2430
public long getTimestamp() {

src/main/java/com/github/brainlag/nsq/netty/NSQDecoder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
2626
}
2727
frame.setSize(size);
2828
ByteBuf bytes = in.readBytes(frame.getSize() - 4); //subtract 4 because the frame id is included
29-
frame.setData(bytes.array());
29+
if (bytes.hasArray()) {
30+
frame.setData(bytes.array());
31+
} else {
32+
byte[] array = new byte[bytes.readableBytes()];
33+
bytes.readBytes(array);
34+
frame.setData(array);
35+
}
3036
out.add(frame);
3137
}
3238

0 commit comments

Comments
 (0)