use of org.apache.qpid.server.protocol.v0_10.transport.ProtocolEvent in project qpid-broker-j by apache.
the class FrameEncoder method encode.
@Override
public ByteBuffer encode(final Object msg) {
if (msg instanceof ProtocolEvent) {
final List<ByteBuffer> buffers = new ArrayList<>();
final AtomicInteger totalSize = new AtomicInteger();
Disassembler disassembler = new Disassembler(new ByteBufferSender() {
@Override
public boolean isDirectBufferPreferred() {
return false;
}
@Override
public void send(final QpidByteBuffer msg) {
int remaining = msg.remaining();
byte[] data = new byte[remaining];
ByteBuffer byteBuffer = ByteBuffer.wrap(data);
msg.get(data);
buffers.add(byteBuffer);
totalSize.addAndGet(remaining);
}
@Override
public void flush() {
}
@Override
public void close() {
}
}, 512);
disassembler.send((ProtocolEvent) msg);
ByteBuffer data = ByteBuffer.allocate(totalSize.get());
for (ByteBuffer buffer : buffers) {
data.put(buffer);
}
data.flip();
return data;
}
return null;
}
Aggregations