use of org.apache.qpid.server.protocol.v1_0.codec.ValueHandler in project qpid-broker-j by apache.
the class ValueHandlerTest method performTest.
private void performTest(final byte type, final byte[] encodedBytes, ValueHandler valueHandler) {
QpidByteBuffer qbb = QpidByteBuffer.wrap(encodedBytes);
try {
valueHandler.parse(qbb);
fail(String.format("AmqpErrorException is expected for %#02x", type));
} catch (AmqpErrorException e) {
assertEquals(String.format("Unexpected error code for %#02x", type), AmqpError.DECODE_ERROR, e.getError().getCondition());
} catch (Exception e) {
fail(String.format("Unexpected exception for %#02x: %s", type, e));
}
}
use of org.apache.qpid.server.protocol.v1_0.codec.ValueHandler in project qpid-broker-j by apache.
the class ArrayTypeConstructor method construct.
@Override
public Object[] construct(final QpidByteBuffer in, final ValueHandler handler) throws AmqpErrorException {
int size = read(in);
long remaining = in.remaining();
if (remaining < (long) size) {
throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Insufficient data to decode array - requires %d octects, only %d remaining.", size, remaining);
}
List<Object> rval;
int count = read(in);
TypeConstructor t = handler.readConstructor(in);
rval = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
rval.add(t.construct(in, handler));
}
long expectedRemaining = remaining - size;
long unconsumedBytes = in.remaining() - expectedRemaining;
if (unconsumedBytes > 0) {
final String msg = String.format("Array incorrectly encoded, %d bytes remaining after decoding %d elements", unconsumedBytes, count);
throw new AmqpErrorException(AmqpError.DECODE_ERROR, msg);
} else if (unconsumedBytes < 0) {
final String msg = String.format("Array incorrectly encoded, %d bytes beyond provided size consumed after decoding %d elements", -unconsumedBytes, count);
throw new AmqpErrorException(AmqpError.DECODE_ERROR, msg);
}
if (rval.size() == 0) {
return null;
} else {
return rval.toArray((Object[]) Array.newInstance(rval.get(0).getClass(), rval.size()));
}
}
use of org.apache.qpid.server.protocol.v1_0.codec.ValueHandler in project qpid-broker-j by apache.
the class FrameHandlerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_valueHandler = new ValueHandler(AMQPDescribedTypeRegistry.newInstance());
}
use of org.apache.qpid.server.protocol.v1_0.codec.ValueHandler in project qpid-broker-j by apache.
the class SymbolTypeConstructor method construct.
@Override
public Symbol construct(final QpidByteBuffer in, final ValueHandler handler) throws AmqpErrorException {
int size;
if (!in.hasRemaining(getSize())) {
throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
}
if (getSize() == 1) {
size = in.getUnsignedByte();
} else {
size = in.getInt();
}
if (!in.hasRemaining(size)) {
throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
}
byte[] data = new byte[size];
in.get(data);
final BinaryString binaryStr = new BinaryString(data);
Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
if (symbolVal == null) {
symbolVal = Symbol.valueOf(new String(data, ASCII));
SYMBOL_MAP.putIfAbsent(binaryStr, symbolVal);
}
return symbolVal;
}
use of org.apache.qpid.server.protocol.v1_0.codec.ValueHandler in project qpid-broker-j by apache.
the class AbstractSection method decode.
private S decode(DescribedTypeConstructor<S> constructor) {
try (QpidByteBuffer input = getEncodedForm()) {
int originalPosition = input.position();
int describedByte = input.get();
if (describedByte != ValueHandler.DESCRIBED_TYPE) {
throw new ConnectionScopedRuntimeException("Cannot decode section", new AmqpErrorException(AmqpError.DECODE_ERROR, "Not a described type."));
}
ValueHandler handler = new ValueHandler(TYPE_REGISTRY);
try {
Object descriptor = handler.parse(input);
return constructor.construct(descriptor, input, originalPosition, handler).construct(input, handler);
} catch (AmqpErrorException e) {
throw new ConnectionScopedRuntimeException("Cannot decode section", e);
}
}
}
Aggregations