SrtpDecoder extends MessageToMessageDecoder<SrtpPacket> { @Override protected void decode(ChannelHandlerContext ctx, SrtpPacket msg, List<Object> out) throws Exception { byte[] rawData = msg.getRawData(); byte[] decoded = this.decoder.reverseTransform(rawData, 0, rawData.length); if(decoded == null || decoded.length == 0) { log.warn("Channel " + ctx.channel().localAddress() + " could not decode incoming SRTP packet."); } else { msg.wrap(decoded); out.add((RtpPacket) msg); } } SrtpDecoder(PacketTransformer decoder);   }
@Test public void testDecode() { final SrtpPacket srtpPacket = mock(SrtpPacket.class); final PacketTransformer transformer = mock(PacketTransformer.class); final SrtpDecoder decoder = new SrtpDecoder(transformer); final EmbeddedChannel channel = new EmbeddedChannel(decoder); final byte[] encodedPayload = "encoded".getBytes(); final byte[] decodedPayload = "decoded".getBytes(); when(srtpPacket.getRawData()).thenReturn(encodedPayload); when(transformer.reverseTransform(encodedPayload, 0, encodedPayload.length)).thenReturn(decodedPayload); channel.writeInbound(srtpPacket); Object inboundObject = channel.readInbound(); verify(transformer).reverseTransform(eq(encodedPayload), any(Integer.class), any(Integer.class)); verify(srtpPacket).wrap(decodedPayload); assertNotNull(inboundObject); assertTrue(inboundObject instanceof RtpPacket); }