class PacketDecoder extends MessageToMessageDecoder<DatagramPacket> {

    public DiscoveryEvent decodeMessage(ChannelHandlerContext ctx, byte[] encoded, InetSocketAddress sender) {
        try {
            PeerDiscoveryMessage msg = MessageDecoder.decode(encoded);
            return new DiscoveryEvent(msg, sender);
        } catch (Exception e) {
            logger.error("Exception processing inbound message from {} : {}", ctx.channel().remoteAddress(), Hex.toHexString(encoded), e);
            throw e;
        }
    }

}