Search in sources :

Example 1 with BBDecoder

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

the class Assembler method assemble.

private void assemble(Frame frame, ByteBuffer segment) {
    BBDecoder dec = _decoder.get();
    dec.init(segment);
    int channel = frame.getChannel();
    Method command;
    switch(frame.getType()) {
        case CONTROL:
            int controlType = dec.readUint16();
            Method control = Method.create(controlType);
            control.read(dec);
            emit(channel, control);
            break;
        case COMMAND:
            int commandType = dec.readUint16();
            // read in the session header, right now we don't use it
            int hdr = dec.readUint16();
            command = Method.create(commandType);
            command.setSync((0x0001 & hdr) != 0);
            command.read(dec);
            if (command.hasPayload() && !frame.isLastSegment()) {
                setIncompleteCommand(channel, command);
            } else {
                emit(channel, command);
            }
            break;
        case HEADER:
            command = getIncompleteCommand(channel);
            List<Struct> structs = null;
            DeliveryProperties deliveryProps = null;
            MessageProperties messageProps = null;
            while (dec.hasRemaining()) {
                Struct struct = dec.readStruct32();
                if (struct instanceof DeliveryProperties && deliveryProps == null) {
                    deliveryProps = (DeliveryProperties) struct;
                } else if (struct instanceof MessageProperties && messageProps == null) {
                    messageProps = (MessageProperties) struct;
                } else {
                    if (structs == null) {
                        structs = new ArrayList<>(2);
                    }
                    structs.add(struct);
                }
            }
            command.setHeader(new Header(deliveryProps, messageProps, structs));
            if (frame.isLastSegment()) {
                setIncompleteCommand(channel, null);
                emit(channel, command);
            }
            break;
        case BODY:
            command = getIncompleteCommand(channel);
            command.setBody(QpidByteBuffer.wrap(segment));
            setIncompleteCommand(channel, null);
            emit(channel, command);
            break;
        default:
            throw new IllegalStateException("unknown frame type: " + frame.getType());
    }
    dec.releaseBuffer();
}
Also used : ProtocolHeader(org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ArrayList(java.util.ArrayList) Method(org.apache.qpid.server.protocol.v0_10.transport.Method) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) BBDecoder(org.apache.qpid.server.protocol.v0_10.transport.BBDecoder) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct)

Example 2 with BBDecoder

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

the class AmqpMapToMapConverter method toObject.

@Override
public Map toObject(final byte[] data) {
    if (data == null || data.length == 0) {
        return Collections.emptyMap();
    }
    BBDecoder decoder = new BBDecoder();
    decoder.init(ByteBuffer.wrap(data));
    return decoder.readMap();
}
Also used : BBDecoder(org.apache.qpid.server.protocol.v0_10.transport.BBDecoder)

Example 3 with BBDecoder

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

the class AmqpListToListConverter method toObject.

@Override
public List toObject(final byte[] data) {
    if (data == null || data.length == 0) {
        return Collections.emptyList();
    }
    BBDecoder decoder = new BBDecoder();
    decoder.init(ByteBuffer.wrap(data));
    return decoder.readList();
}
Also used : BBDecoder(org.apache.qpid.server.protocol.v0_10.transport.BBDecoder)

Example 4 with BBDecoder

use of org.apache.qpid.server.protocol.v0_10.transport.BBDecoder 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

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