|
4 | 4 | import io.netty.buffer.Unpooled; |
5 | 5 |
|
6 | 6 | public class MessageFrame extends NSQFrame { |
7 | | - private long timestamp; |
8 | | - private int attempts; |
9 | | - private byte[] messageId = new byte[16]; |
10 | | - private byte[] messageBody; |
11 | | - |
12 | | - @Override |
13 | | - public void setData(byte[] bytes) { |
14 | | - //parse the bytes |
15 | | - super.setData(bytes); |
| 7 | + private long timestamp; |
| 8 | + private int attempts; |
| 9 | + private byte[] messageId = new byte[16]; |
| 10 | + private byte[] messageBody; |
| 11 | + |
| 12 | + @Override |
| 13 | + public void setData(byte[] bytes) { |
| 14 | + //parse the bytes |
| 15 | + super.setData(bytes); |
16 | 16 |
|
17 | 17 | ByteBuf buf = Unpooled.wrappedBuffer(bytes); |
18 | | - timestamp = buf.readLong(); |
19 | | - attempts = buf.readShort(); |
20 | | - buf.readBytes(messageId); |
21 | | - ByteBuf messageBodyBuf = buf.readBytes(buf.readableBytes()); |
22 | | - if (messageBodyBuf.hasArray()) { |
23 | | - messageBody = messageBodyBuf.array(); |
24 | | - } else { |
25 | | - byte[] array = new byte[messageBodyBuf.readableBytes()]; |
26 | | - messageBodyBuf.readBytes(array); |
27 | | - messageBody = array; |
28 | | - } |
29 | | - } |
30 | | - |
31 | | - public long getTimestamp() { |
32 | | - return timestamp; |
33 | | - } |
34 | | - |
35 | | - public int getAttempts() { |
36 | | - return attempts; |
37 | | - } |
38 | | - |
39 | | - public byte[] getMessageId() { |
40 | | - return messageId; |
41 | | - } |
42 | | - |
43 | | - public byte[] getMessageBody() { |
44 | | - return messageBody; |
45 | | - } |
| 18 | + timestamp = buf.readLong(); |
| 19 | + attempts = buf.readShort(); |
| 20 | + buf.readBytes(messageId); |
| 21 | + ByteBuf messageBodyBuf = buf.readBytes(buf.readableBytes()); |
| 22 | + if (messageBodyBuf.hasArray()) { |
| 23 | + messageBody = messageBodyBuf.array(); |
| 24 | + } else { |
| 25 | + byte[] array = new byte[messageBodyBuf.readableBytes()]; |
| 26 | + messageBodyBuf.readBytes(array); |
| 27 | + messageBody = array; |
| 28 | + } |
| 29 | + buf.release(); |
| 30 | + messageBodyBuf.release(); |
| 31 | + } |
| 32 | + |
| 33 | + public long getTimestamp() { |
| 34 | + return timestamp; |
| 35 | + } |
| 36 | + |
| 37 | + public int getAttempts() { |
| 38 | + return attempts; |
| 39 | + } |
| 40 | + |
| 41 | + public byte[] getMessageId() { |
| 42 | + return messageId; |
| 43 | + } |
| 44 | + |
| 45 | + public byte[] getMessageBody() { |
| 46 | + return messageBody; |
| 47 | + } |
46 | 48 |
|
47 | 49 | } |
0 commit comments