-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubAckMessage.java
More file actions
33 lines (30 loc) · 1021 Bytes
/
SubAckMessage.java
File metadata and controls
33 lines (30 loc) · 1021 Bytes
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
public class SubAckMessage {
int byteIdentifier;
Integer returnCode;
byte[] message = new byte[5];
public SubAckMessage(int byteIdentifier, int returnCode) {
this.byteIdentifier = byteIdentifier;
this.returnCode = returnCode;
generateMessage();
}
private static byte[] intToByteArray(int packetId) {
return new byte[] {
(byte)(packetId>> 8),
(byte) packetId};
}
private void generateMessage(){
// Always the same fixed header
Integer firstByte = 64;
Integer secondByte = 2;
Integer lastByte = 0;
message[0] = firstByte.byteValue();
message[1] = secondByte.byteValue();
byte[] byteIdentifierByte = intToByteArray(byteIdentifier);
message[2] = byteIdentifierByte[0];
message[3] = byteIdentifierByte[1];
message[4] = returnCode.byteValue();
}
public byte[] getMessage() {
return message;
}
}