-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALongLongUInt.java
More file actions
44 lines (35 loc) · 1.1 KB
/
ALongLongUInt.java
File metadata and controls
44 lines (35 loc) · 1.1 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
42
43
44
//Long long unsigned int
//Does not actually hold 64 (unsigned) bits, so this is limited to 63 bits precision
//Could be resolved by using BigInteger
public class ALongLongUInt extends AMQPNativeType {
long value;
//Constructor
ALongLongUInt(ByteArrayBuffer byteArrayBuffer) throws InvalidTypeException {
if (byteArrayBuffer.length() < 8) throw new InvalidTypeException("Invalid type length");
this.type = AMQPNativeType.Type.LONGLONG_UINT;
this.buffer = byteArrayBuffer.pop(8);
//Convert data from wire to value
this.value = ByteArrayBuffer.bytesToLong(this.buffer.get());
}
ALongLongUInt(long value) {
this.type = AMQPNativeType.Type.LONGLONG_UINT;
this.value = value;
}
ALongLongUInt(int value) {
this.type = AMQPNativeType.Type.LONGLONG_UINT;
this.value = (long) value;
}
public long toLong() {
return value;
}
public String toString() {
return "" + value;
}
//Encode data type to wire
public ByteArrayBuffer toWire() {
return new ByteArrayBuffer(ByteArrayBuffer.longToBytes(value));
}
public int toInt() {
return (int) value;
}
};