-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMQPNativeType.java
More file actions
69 lines (56 loc) · 1.88 KB
/
AMQPNativeType.java
File metadata and controls
69 lines (56 loc) · 1.88 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//Class represeting a type in AMQP, such as long-string, short-string, long, long-long etc
//Inherited by other subclasses
public class AMQPNativeType {
//(Some) native AMQP types
public enum Type {
OCTET, //1 byte
SHORT_UINT, //2 bytes
LONG_UINT, //4 bytes
LONGLONG_UINT, //8 bytes
SHORT_STRING, //OCTET + String
LONG_STRING, // LONG_UINT (4 bytes) + String
TIMESTAMP, //8 bytes, unix TS
FIELD_TABLE, //LONG_UINT (4 bytes) + Table data
FIELD_ARRAY, //LONG_UINT (4 bytes) + Array data
FIELD_VALUE_PAIR, //SHORT_STRING + OCTET type + Field data
BOOLEAN, //1 byte, 0x00 = false, otherwise = true
SHORTSHORT_INT, //1 byte
SHORTSHORT_UINT, //1 byte
}
//Raw data
public ByteArrayBuffer buffer;
public Type type;
//Constructor
//AMQPNativeType() throws InvalidTypeException {}
//Encode data type to wire
public ByteArrayBuffer toWire() {
return new ByteArrayBuffer();
}
//Returns a ByteArrayBuffer of the expected field type,
//i.e S for Long String and s for Short String
//Throws InvalidTypeException if cannot be included in a field table
public ByteArrayBuffer getFieldTableType() throws InvalidTypeException {
if (type == Type.LONG_STRING) {
return new ByteArrayBuffer((byte) 'S');
}
if (type == Type.BOOLEAN) {
return new ByteArrayBuffer((byte) 't');
}
if (type == Type.FIELD_TABLE) {
return new ByteArrayBuffer((byte) 'F');
}
if (type == Type.SHORT_STRING) {
return new ByteArrayBuffer((byte) 's');
}
if (type == Type.FIELD_ARRAY) {
return new ByteArrayBuffer((byte) 'A');
}
if (type == Type.SHORT_UINT) {
return new ByteArrayBuffer((byte) 'u');
}
if (type == Type.LONG_UINT) {
return new ByteArrayBuffer((byte) 'i');
}
throw new InvalidTypeException("Cannot encode native type to Field Table: " + type.name());
}
};