-
Notifications
You must be signed in to change notification settings - Fork 0
/
AOctet.java
35 lines (29 loc) · 920 Bytes
/
AOctet.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
//Class represeting a type in AMQP, such as long-string, short-string, long, long-long etc
//Inherited by other subclasses
public class AOctet extends AMQPNativeType {
int value;
//Constructor
AOctet(ByteArrayBuffer byteArrayBuffer) throws InvalidTypeException {
if (byteArrayBuffer.length() < 1) throw new InvalidTypeException("AOctet too short input");
this.type = AMQPNativeType.Type.OCTET;
this.value = byteArrayBuffer.pop(1).toInt();
}
//Constructor
AOctet(int value) {
this.type = AMQPNativeType.Type.OCTET;
this.value = value;
}
public int toInt() {
return value;
}
//Encode data type to wire
public ByteArrayBuffer toWire() {
//A long is 8 bytes, cut the 7 MSB to get the octet
ByteArrayBuffer ret = new ByteArrayBuffer(ByteArrayBuffer.longToBytes(value));
ret.pop(7);
return ret;
}
public String toString() {
return "" + value;
}
};