Search in sources :

Example 1 with BBEncoder

use of org.apache.qpid.server.protocol.v0_10.transport.BBEncoder in project qpid-broker-j by apache.

the class ListToAmqpListConverter method toMimeContent.

@Override
public byte[] toMimeContent(final List list) {
    BBEncoder encoder = new BBEncoder(1024);
    encoder.writeList(list);
    final ByteBuffer buf = encoder.buffer();
    int remaining = buf.remaining();
    byte[] data = new byte[remaining];
    buf.get(data);
    return data;
}
Also used : BBEncoder(org.apache.qpid.server.protocol.v0_10.transport.BBEncoder) ByteBuffer(java.nio.ByteBuffer)

Example 2 with BBEncoder

use of org.apache.qpid.server.protocol.v0_10.transport.BBEncoder in project qpid-broker-j by apache.

the class MapToAmqpMapConverter method toMimeContent.

@Override
public byte[] toMimeContent(final Map map) {
    BBEncoder encoder = new BBEncoder(1024);
    encoder.writeMap(map);
    final ByteBuffer buf = encoder.buffer();
    int remaining = buf.remaining();
    byte[] data = new byte[remaining];
    buf.get(data);
    return data;
}
Also used : BBEncoder(org.apache.qpid.server.protocol.v0_10.transport.BBEncoder) ByteBuffer(java.nio.ByteBuffer)

Example 3 with BBEncoder

use of org.apache.qpid.server.protocol.v0_10.transport.BBEncoder in project qpid-broker-j by apache.

the class Disassembler method method.

private void method(Method method, SegmentType type) {
    BBEncoder enc = _encoder.get();
    enc.init();
    enc.writeUint16(method.getEncodedType());
    if (type == SegmentType.COMMAND) {
        if (method.isSync()) {
            enc.writeUint16(0x0101);
        } else {
            enc.writeUint16(0x0100);
        }
    }
    method.write(enc);
    int methodLimit = enc.position();
    byte flags = FIRST_SEG;
    boolean payload = method.hasPayload();
    if (!payload) {
        flags |= LAST_SEG;
    }
    int headerLimit = -1;
    if (payload) {
        final Header hdr = method.getHeader();
        if (hdr != null) {
            if (hdr.getDeliveryProperties() != null) {
                enc.writeStruct32(hdr.getDeliveryProperties());
            }
            if (hdr.getMessageProperties() != null) {
                enc.writeStruct32(hdr.getMessageProperties());
            }
            if (hdr.getNonStandardProperties() != null) {
                for (Struct st : hdr.getNonStandardProperties()) {
                    enc.writeStruct32(st);
                }
            }
        }
        headerLimit = enc.position();
    }
    synchronized (_sendlock) {
        ByteBuffer buf = enc.underlyingBuffer();
        buf.flip();
        ByteBuffer copy = ByteBuffer.allocate(buf.remaining());
        copy.put(buf.duplicate());
        copy.flip();
        final ByteBuffer methodBuf = view(copy, 0, methodLimit);
        fragment(flags, type, method, methodBuf);
        if (payload) {
            QpidByteBuffer qpidByteBuffer = method.getBody();
            ByteBuffer body = null;
            if (qpidByteBuffer != null) {
                body = ByteBuffer.allocate(qpidByteBuffer.remaining());
                qpidByteBuffer.copyTo(body);
                body.flip();
            }
            ByteBuffer headerBuf = view(copy, methodLimit, headerLimit);
            fragment(body == null ? LAST_SEG : 0x0, SegmentType.HEADER, method, headerBuf);
            if (body != null) {
                fragment(LAST_SEG, SegmentType.BODY, method, body.duplicate());
            }
        }
    }
}
Also used : BBEncoder(org.apache.qpid.server.protocol.v0_10.transport.BBEncoder) ProtocolHeader(org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct)

Example 4 with BBEncoder

use of org.apache.qpid.server.protocol.v0_10.transport.BBEncoder in project qpid-broker-j by apache.

the class Interaction method copyPerformative.

private <T extends Method> T copyPerformative(final T src) {
    T dst = (T) Method.create(src.getStructType());
    final BBEncoder encoder = new BBEncoder(4096);
    encoder.init();
    src.write(encoder);
    ByteBuffer buffer = encoder.buffer();
    final BBDecoder decoder = new BBDecoder();
    decoder.init(buffer);
    dst.read(decoder);
    dst.setChannel(src.getChannel());
    if (src.getHeader() != null) {
        Header srcHeader = src.getHeader();
        MessageProperties dstMessageProperties = null;
        DeliveryProperties dstDeliveryProperties = null;
        if (srcHeader.getMessageProperties() != null) {
            MessageProperties properties = srcHeader.getMessageProperties();
            dstMessageProperties = new MessageProperties();
            encoder.init();
            properties.write(encoder);
            decoder.init(encoder.buffer());
            dstMessageProperties.read(decoder);
        }
        if (srcHeader.getDeliveryProperties() != null) {
            DeliveryProperties properties = srcHeader.getDeliveryProperties();
            dstDeliveryProperties = new DeliveryProperties();
            encoder.init();
            properties.write(encoder);
            decoder.init(encoder.buffer());
            dstDeliveryProperties.read(decoder);
        }
        if (dstMessageProperties != null || dstDeliveryProperties != null) {
            dst.setHeader(new Header(dstDeliveryProperties, dstMessageProperties));
        }
    }
    if (src.getBody() != null) {
        dst.setBody(src.getBody());
    }
    return dst;
}
Also used : BBEncoder(org.apache.qpid.server.protocol.v0_10.transport.BBEncoder) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) ByteBuffer(java.nio.ByteBuffer) BBDecoder(org.apache.qpid.server.protocol.v0_10.transport.BBDecoder)

Aggregations

ByteBuffer (java.nio.ByteBuffer)4 BBEncoder (org.apache.qpid.server.protocol.v0_10.transport.BBEncoder)4 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 BBDecoder (org.apache.qpid.server.protocol.v0_10.transport.BBDecoder)1 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)1 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)1 ProtocolHeader (org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader)1 Struct (org.apache.qpid.server.protocol.v0_10.transport.Struct)1