Skip to content

Commit 84c1cbc

Browse files
author
Steve Powell
committed
Some speculative additions to valueWriter/Reader and Frame for real arrays.
1 parent 0ae1115 commit 84c1cbc

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ else if(value instanceof byte[]) {
328328
else if(value instanceof List) {
329329
acc += 4 + arraySize((List<?>)value);
330330
}
331+
else if(value instanceof Object[]) {
332+
acc += 4 + arraySize((Object[])value);
333+
}
331334
else if(value == null) {
332335
}
333336
else {
@@ -346,6 +349,17 @@ public static long arraySize(List<?> values)
346349
}
347350
return acc;
348351
}
352+
353+
/** Computes the AMQP wire-protocol length of an encoded field-array */
354+
public static long arraySize(Object[] values)
355+
throws UnsupportedEncodingException
356+
{
357+
long acc = 0;
358+
for (Object value : values) {
359+
acc += fieldValueSize(value);
360+
}
361+
return acc;
362+
}
349363

350364
/** Computes the AMQP wire-protocol length of a protocol-encoded long string. */
351365
private static int longStrSize(String str)

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,43 @@ else if(value instanceof List) {
189189
writeOctet('A');
190190
writeArray((List<?>)value);
191191
}
192+
else if(value instanceof Object[]) {
193+
writeOctet('A');
194+
writeArray((Object[])value);
195+
}
192196
else {
193197
throw new IllegalArgumentException
194198
("Invalid value type: " + value.getClass().getName());
195199
}
196200
}
197201

198202
public void writeArray(List<?> value)
199-
throws IOException
200-
{
201-
if (value==null) {
202-
out.write(0);
203+
throws IOException
204+
{
205+
if (value==null) {
206+
out.write(0);
207+
}
208+
else {
209+
out.writeInt((int)Frame.arraySize(value));
210+
for (Object item : value) {
211+
writeFieldValue(item);
203212
}
204-
else {
205-
out.writeInt((int)Frame.arraySize(value));
206-
for (Object item : value) {
207-
writeFieldValue(item);
208-
}
213+
}
214+
}
215+
216+
public void writeArray(Object[] value)
217+
throws IOException
218+
{
219+
if (value==null) {
220+
out.write(0);
221+
}
222+
else {
223+
out.writeInt((int)Frame.arraySize(value));
224+
for (Object item : value) {
225+
writeFieldValue(item);
209226
}
210227
}
228+
}
211229

212230
/** Public API - encodes an octet from an int. */
213231
public final void writeOctet(int octet)

0 commit comments

Comments
 (0)