@Test public void testList() throws Exception { OFMessageEncoder encoder = new OFMessageEncoder(); MockOfMessage message1 = new MockOfMessage(); MockOfMessage message2 = new MockOfMessage(); MockOfMessage message3 = new MockOfMessage(); List<MockOfMessage> messages = ImmutableList.of(message1, message2, message3); ChannelBuffer returnedChannel = (ChannelBuffer) encoder.encode(null, null, messages); assertThat(returnedChannel, notNullValue()); byte[] channelBytes = returnedChannel.array(); String expectedListMessage = "message1 message2 message3 "; String listMessage = (new String(channelBytes, StandardCharsets.UTF_8)) .substring(0, expectedListMessage.length()); assertThat(listMessage, is(expectedListMessage)); }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof List)) { return msg; } @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>) msg; ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); for (OFMessage ofm : msglist) { if (ofm != null) { ofm.writeTo(buf); } } return buf; }
OFMessageEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof List)) { return msg; } @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>) msg; ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); for (OFMessage ofm : msglist) { if (ofm != null) { ofm.writeTo(buf); } } return buf; } }
OFMessageEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof List)) { return msg; } @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>) msg; ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); for (OFMessage ofm : msglist) { if (ofm != null) { ofm.writeTo(buf); } } return buf; }  }
OFMessageEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof List)) { return msg; } @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>) msg; ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); for (OFMessage ofm : msglist) { if (ofm != null) { ofm.writeTo(buf); } } return buf; }   }
OFMessageEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof List)) { return msg; } @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>) msg; ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); for (OFMessage ofm : msglist) { if (ofm != null) { ofm.writeTo(buf); } } return buf; }    }