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();
}
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();
}
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();
}
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;
}
Aggregations