use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class BasicContentHeaderProperties method decode.
private void decode(QpidByteBuffer buffer) throws AMQFrameDecodingException {
if ((_propertyFlags & (CONTENT_TYPE_MASK)) != 0) {
_contentType = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & ENCODING_MASK) != 0) {
_encoding = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & HEADERS_MASK) != 0) {
long length = buffer.getUnsignedInt();
try (QpidByteBuffer buf = buffer.view(0, (int) length)) {
_headers = new FieldTable(buf);
}
buffer.position(buffer.position() + (int) length);
}
if ((_propertyFlags & DELIVERY_MODE_MASK) != 0) {
_deliveryMode = buffer.get();
}
if ((_propertyFlags & PRIORITY_MASK) != 0) {
_priority = buffer.get();
}
if ((_propertyFlags & CORRELATION_ID_MASK) != 0) {
_correlationId = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & REPLY_TO_MASK) != 0) {
_replyTo = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & EXPIRATION_MASK) != 0) {
_expiration = EncodingUtils.readLongAsShortString(buffer);
}
if ((_propertyFlags & MESSAGE_ID_MASK) != 0) {
_messageId = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & TIMESTAMP_MASK) != 0) {
_timestamp = buffer.getLong();
}
if ((_propertyFlags & TYPE_MASK) != 0) {
_type = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & USER_ID_MASK) != 0) {
_userId = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & APPLICATION_ID_MASK) != 0) {
_appId = AMQShortString.readAMQShortString(buffer);
}
if ((_propertyFlags & CLUSTER_ID_MASK) != 0) {
_clusterId = AMQShortString.readAMQShortString(buffer);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class BasicContentHeaderProperties method populatePropertiesFromBuffer.
public synchronized void populatePropertiesFromBuffer(QpidByteBuffer buffer, int propertyFlags, int size) throws AMQFrameDecodingException {
_propertyFlags = propertyFlags;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Property flags: " + _propertyFlags);
}
if (_encodedForm != null) {
_encodedForm.dispose();
}
_encodedForm = buffer.view(0, size);
try (QpidByteBuffer byteBuffer = _encodedForm.slice()) {
decode(byteBuffer);
}
buffer.position(buffer.position() + size);
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AMQDecoderTest method testDecodeWithManyBuffers.
public void testDecodeWithManyBuffers() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
Random random = new Random();
final byte[] payload = new byte[2048];
random.nextBytes(payload);
final AMQBody body = new ContentBody(ByteBuffer.wrap(payload));
AMQFrame frame = new AMQFrame(1, body);
TestSender sender = new TestSender();
frame.writePayload(sender);
ByteBuffer allData = combine(sender.getSentBuffers());
for (int i = 0; i < allData.remaining(); i++) {
byte[] minibuf = new byte[1];
minibuf[0] = allData.get(i);
_decoder.decodeBuffer(ByteBuffer.wrap(minibuf));
}
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
if (frames.get(0) instanceof AMQFrame) {
assertEquals(ContentBody.TYPE, ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
ContentBody decodedBody = (ContentBody) ((AMQFrame) frames.get(0)).getBodyFrame();
byte[] bodyBytes;
try (QpidByteBuffer payloadBuffer = decodedBody.getPayload()) {
bodyBytes = new byte[payloadBuffer.remaining()];
payloadBuffer.get(bodyBytes);
}
assertTrue("Body was corrupted", Arrays.equals(payload, bodyBytes));
} else {
fail("decode was not a frame");
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class AMQDecoderTest method combine.
private static ByteBuffer combine(Collection<QpidByteBuffer> bufs) {
if (bufs == null || bufs.isEmpty()) {
return EMPTY_BYTE_BUFFER;
} else {
int size = 0;
boolean isDirect = false;
for (QpidByteBuffer buf : bufs) {
size += buf.remaining();
isDirect = isDirect || buf.isDirect();
}
ByteBuffer combined = isDirect ? ByteBuffer.allocateDirect(size) : ByteBuffer.allocate(size);
for (QpidByteBuffer buf : bufs) {
buf.copyTo(combined);
}
combined.flip();
return combined;
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class ClientDecoder method decodeBuffer.
public void decodeBuffer(ByteBuffer incomingBuffer) throws AMQFrameDecodingException, AMQProtocolVersionException {
if (_incompleteBuffer == null) {
QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(incomingBuffer);
final int required = decode(qpidByteBuffer);
if (required != 0) {
_incompleteBuffer = QpidByteBuffer.allocate(qpidByteBuffer.remaining() + required);
_incompleteBuffer.put(qpidByteBuffer);
}
qpidByteBuffer.dispose();
} else {
if (incomingBuffer.remaining() < _incompleteBuffer.remaining()) {
_incompleteBuffer.put(incomingBuffer);
} else {
_incompleteBuffer.flip();
final QpidByteBuffer aggregatedBuffer = QpidByteBuffer.allocate(_incompleteBuffer.remaining() + incomingBuffer.remaining());
aggregatedBuffer.put(_incompleteBuffer);
aggregatedBuffer.put(incomingBuffer);
aggregatedBuffer.flip();
final int required = decode(aggregatedBuffer);
_incompleteBuffer.dispose();
if (required != 0) {
_incompleteBuffer = QpidByteBuffer.allocate(aggregatedBuffer.remaining() + required);
_incompleteBuffer.put(aggregatedBuffer);
} else {
_incompleteBuffer = null;
}
aggregatedBuffer.dispose();
}
}
// post-condition: assert(!incomingBuffer.hasRemaining());
}
Aggregations