-
Notifications
You must be signed in to change notification settings - Fork 0
/
RequestMessage.java
36 lines (29 loc) · 942 Bytes
/
RequestMessage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class RequestMessage extends ActualMessage {
private int index;
public RequestMessage(int index) throws IOException {
super(5, MessageType.request);
this.index = index;
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(intToByteArray(this.length));
out.write(this.msType.getMessageType());
out.write(intToByteArray(this.index));
this.msBytes = out.toByteArray();
out.close();
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public static byte[] intToByteArray(int a) {
return new byte[] {
(byte) ((a >> 24) & 0xFF),
(byte) ((a >> 16) & 0xFF),
(byte) ((a >> 8) & 0xFF),
(byte) (a & 0xFF)
};
}
}