-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALongUInt.java
More file actions
41 lines (33 loc) · 1.03 KB
/
ALongUInt.java
File metadata and controls
41 lines (33 loc) · 1.03 KB
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
37
38
39
40
41
//Class represeting a type in AMQP, such as long-string, short-string, long, long-long etc
//Inherited by other subclasses
public class ALongUInt extends AMQPNativeType {
long value;
//Constructor
ALongUInt(ByteArrayBuffer byteArrayBuffer) throws InvalidTypeException {
if (byteArrayBuffer.length() < 4) throw new InvalidTypeException("Invalid type length");
this.type = AMQPNativeType.Type.LONG_UINT;
this.buffer = byteArrayBuffer.pop(4);
//Convert data from wire to value
this.value = ByteArrayBuffer.bytesToLong(this.buffer.get());
}
ALongUInt(long value) {
this.type = AMQPNativeType.Type.LONG_UINT;
this.value = value;
}
public long toLong() {
return value;
}
public String toString() {
return "" + value;
}
//Encode data type to wire
public ByteArrayBuffer toWire() {
//A long is 8 bytes, cut the 4 MSB
ByteArrayBuffer ret = new ByteArrayBuffer(ByteArrayBuffer.longToBytes(value));
ret.pop(4);
return ret;
}
public int toInt() {
return (int) value;
}
};