-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABoolean.java
More file actions
33 lines (26 loc) · 858 Bytes
/
ABoolean.java
File metadata and controls
33 lines (26 loc) · 858 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 ABoolean extends AMQPNativeType {
boolean value;
//Constructor
ABoolean(ByteArrayBuffer byteArrayBuffer) throws InvalidTypeException {
if (byteArrayBuffer.length() < 1) throw new InvalidTypeException("Invalid type length");
this.type = AMQPNativeType.Type.BOOLEAN;
this.buffer = byteArrayBuffer.pop(1);
value = (buffer.toInt() != 0); //C-style values, 0=false, else=true
}
ABoolean(boolean value) {
this.type = AMQPNativeType.Type.BOOLEAN;
this.value = value;
}
//Get boolean value
public boolean toBool() {
return value;
}
//Encode data type to wire
public ByteArrayBuffer toWire() {
if (value) return new ByteArrayBuffer(new byte[]{0x01}); //True
return new ByteArrayBuffer(new byte[]{0x00}); //False
}
public String toString() {
return value ? "True" : "False";
}
};