in client/src/main/java/org/apache/qpid/transport/network/Disassembler.java [116:189]
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());
ByteBufferUtils.copyTo(buf, copy);
copy.flip();
final ByteBuffer methodBuf = ByteBufferUtils.view(copy,0, methodLimit);
fragment(flags, type, method, methodBuf);
if (payload)
{
ByteBuffer body = method.getBody();
ByteBuffer headerBuf = ByteBufferUtils.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());
}
}
}
}