Skip to content

Commit 6e75891

Browse files
author
Matthias Radestock
committed
implement extended table field types
1 parent 1fc425c commit 6e75891

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

src/com/rabbitmq/client/impl/MethodArgumentReader.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,30 @@ public final String readShortstr()
103103
return readShortstr(this.in);
104104
}
105105

106-
/** Public API - convenience method - reads a long string argument from a DataInputStream. */
107-
public static final LongString readLongstr(final DataInputStream in)
106+
/** Public API - convenience method - reads a 32-bit-length-prefix
107+
* byte vector from a DataInputStream.
108+
*/
109+
public static final byte[] readBytes(final DataInputStream in)
108110
throws IOException
109111
{
110112
final long contentLength = unsignedExtend(in.readInt());
111113
if(contentLength < Integer.MAX_VALUE) {
112114
final byte [] buffer = new byte[(int)contentLength];
113115
in.readFully(buffer);
114-
115-
return LongStringHelper.asLongString(buffer);
116-
}
116+
return buffer;
117+
} else {
117118
throw new UnsupportedOperationException
118-
("Very long strings not currently supported");
119+
("Very long byte vectors and strings not currently supported");
120+
}
121+
}
122+
123+
/** Public API - convenience method - reads a long string argument
124+
* from a DataInputStream.
125+
*/
126+
public static final LongString readLongstr(final DataInputStream in)
127+
throws IOException
128+
{
129+
return LongStringHelper.asLongString(readBytes(in));
119130
}
120131

121132
/** Public API - reads a long string argument. */
@@ -206,6 +217,30 @@ public static final Map<String, Object> readTable(DataInputStream in)
206217
case 'F':
207218
value = readTable(tableIn);
208219
break;
220+
case 'b':
221+
value = tableIn.readByte();
222+
break;
223+
case 'd':
224+
value = tableIn.readDouble();
225+
break;
226+
case 'f':
227+
value = tableIn.readFloat();
228+
break;
229+
case 'l':
230+
value = tableIn.readLong();
231+
break;
232+
case 's':
233+
value = tableIn.readShort();
234+
break;
235+
case 't':
236+
value = tableIn.readBoolean();
237+
break;
238+
case 'x':
239+
value = readBytes(tableIn);
240+
break;
241+
case 'V':
242+
value = null;
243+
break;
209244
default:
210245
throw new MalformedFrameException
211246
("Unrecognised type in table");

src/com/rabbitmq/client/impl/MethodArgumentWriter.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,38 @@ else if(value instanceof Map) {
203203
// (not even a little respect)
204204
writeTable((Map<String, Object>) value);
205205
}
206+
else if (value instanceof Byte) {
207+
writeOctet('b');
208+
out.writeByte((Byte)value);
209+
}
210+
else if(value instanceof Double) {
211+
writeOctet('d');
212+
out.writeDouble((Double)value);
213+
}
214+
else if(value instanceof Float) {
215+
writeOctet('f');
216+
out.writeFloat((Float)value);
217+
}
218+
else if(value instanceof Long) {
219+
writeOctet('l');
220+
out.writeLong((Long)value);
221+
}
222+
else if(value instanceof Short) {
223+
writeOctet('s');
224+
out.writeShort((Short)value);
225+
}
226+
else if(value instanceof Boolean) {
227+
writeOctet('t');
228+
out.writeBoolean((Boolean)value);
229+
}
230+
else if(value instanceof byte[]) {
231+
writeOctet('x');
232+
writeLong(((byte[])value).length);
233+
out.write((byte[])value);
234+
}
235+
else if(value == null) {
236+
writeOctet('V');
237+
}
206238
else {
207239
throw new IllegalArgumentException
208240
("Invalid value type: " + value.getClass().getName()

0 commit comments

Comments
 (0)