Skip to content

Instantly share code, notes, and snippets.

View oshothebig's full-sized avatar

Sho Shimizu oshothebig

  • Preferred Networks, Inc.
  • Tokyo, Japan
View GitHub Profile
private static class OpenFlowEncoder extends OneToOneEncoder {
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (msg instanceof OFMessage) {
OFMessage response = (OFMessage) msg;
// may have an bad effect on performance
ByteBuffer buffer = ByteBuffer.allocate(response.getLength());
response.writeTo(buffer);
buffer.flip();
return ChannelBuffers.wrappedBuffer(buffer);
private static class OpenFlowDecoder extends OneToOneDecoder {
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (!(msg instanceof ChannelBuffer)) {
return msg;
}
ChannelBuffer channelBuffer = (ChannelBuffer)msg;
ByteBuffer byteBuffer = channelBuffer.toByteBuffer();
List<OFMessage> messages = factory.parseMessages(byteBuffer);