List of usage examples for io.netty.channel DefaultAddressedEnvelope DefaultAddressedEnvelope
public DefaultAddressedEnvelope(M message, A recipient, A sender)
From source file:sas.systems.imflux.network.udp.UdpDataPacketDecoder.java
License:Apache License
/** * Decodes a {@link DatagramPacket} to a {@link DataPacket} wrapped into an {@link AddressedEnvelope} to allow multicast on * the used {@link SocketChannel}. /*from w w w .ja va2 s. c o m*/ * * @param ctx The context of the ChannelHandler * @param message the message which should be encoded * @param out a list where all messages are written to */ @Override protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception { final ByteBuf content = msg.content(); final SocketAddress sender = msg.sender(); final SocketAddress recipient = msg.recipient(); try { final DataPacket dataPacket = DataPacket.decode(content); final AddressedEnvelope<DataPacket, SocketAddress> newMsg = new DefaultAddressedEnvelope<DataPacket, SocketAddress>( dataPacket, recipient, sender); out.add(newMsg); } catch (Exception e) { LOG.debug("Failed to decode RTP packet.", e); } }
From source file:sas.systems.imflux.network.udp.UdpDataPacketEncoder.java
License:Apache License
/** * Encodes a {@link DataPacket} wrapped into an {@link AddressedEnvelope} in a {@link ByteBuf} also wrapped into an * {@link AddressedEnvelope}. If the {@link DataPacket}'s content is not empty it is added, otherwise an empty ByteBuf * is added to the AddressedEnvelope.//www . j a v a2 s. c om * * @param ctx The context of the ChannelHandler * @param message the message which should be encoded * @param out a list where all messages are written to */ @Override protected void encode(ChannelHandlerContext ctx, AddressedEnvelope<DataPacket, SocketAddress> msg, List<Object> out) throws Exception { // encode CompountControlPacket here and forward destination (recipient) of the packet final DataPacket dataPacket = msg.content(); final SocketAddress recipient = msg.recipient(); final SocketAddress sender = ctx.channel().localAddress(); final ByteBuf buffer; if (dataPacket.getDataSize() == 0) { buffer = Unpooled.EMPTY_BUFFER; } else { buffer = dataPacket.encode(); } final AddressedEnvelope<ByteBuf, SocketAddress> newMsg = new DefaultAddressedEnvelope<ByteBuf, SocketAddress>( buffer, recipient, sender); out.add(newMsg); }