Search in sources :

Example 86 with QpidByteBuffer

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);
    }
}
Also used : FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 87 with QpidByteBuffer

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);
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 88 with QpidByteBuffer

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");
    }
}
Also used : AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) Random(java.util.Random) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) AMQBody(org.apache.qpid.server.protocol.v0_8.transport.AMQBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 89 with QpidByteBuffer

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;
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 90 with QpidByteBuffer

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());
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)185 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)61 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)61 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)30 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)29 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)29 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)29 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)28 ArrayList (java.util.ArrayList)22 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)20 Test (org.junit.Test)13 MapToJmsMapMessage (org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage)12 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 ByteBuffer (java.nio.ByteBuffer)8 LinkedHashMap (java.util.LinkedHashMap)8 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)8