Class PacketCodec

java.lang.Object
org.tinyradius.packet.util.PacketCodec

public class PacketCodec
extends java.lang.Object
To encode/decode packets to/from Datagram.

A dictionary is required in constructor to avoid passing in dictionary on every conversion - in typical use cases, only one instance of this class will be required as the server/proxy/client will be using one Dictionary.

  • Method Summary

    Modifier and Type Method Description
    static RadiusRequest fromDatagramRequest​(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram)
    Reads a request from the given input stream and creates an appropriate RadiusPacket/subclass.
    static RadiusResponse fromDatagramResponse​(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram)
    Reads a response from the given input stream and creates an appropriate RadiusPacket/subclass.
    static io.netty.buffer.ByteBuf toByteBuf​(RadiusPacket packet)  
    static io.netty.channel.socket.DatagramPacket toDatagram​(RadiusPacket packet, java.net.InetSocketAddress recipient)  
    static io.netty.channel.socket.DatagramPacket toDatagram​(RadiusPacket packet, java.net.InetSocketAddress recipient, java.net.InetSocketAddress sender)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toDatagram

      public static io.netty.channel.socket.DatagramPacket toDatagram​(RadiusPacket packet, java.net.InetSocketAddress recipient) throws RadiusPacketException
      Parameters:
      packet - packet to convert
      recipient - destination socket
      Returns:
      converted DatagramPacket
      Throws:
      RadiusPacketException - if packet could not be encoded/serialized to datagram
    • toDatagram

      public static io.netty.channel.socket.DatagramPacket toDatagram​(RadiusPacket packet, java.net.InetSocketAddress recipient, java.net.InetSocketAddress sender) throws RadiusPacketException
      Parameters:
      packet - packet to convert
      recipient - destination socket
      sender - source socket, nullable
      Returns:
      converted DatagramPacket
      Throws:
      RadiusPacketException - if packet could not be encoded/serialized to datagram
    • toByteBuf

      public static io.netty.buffer.ByteBuf toByteBuf​(RadiusPacket packet) throws RadiusPacketException
      Throws:
      RadiusPacketException
    • fromDatagramRequest

      public static RadiusRequest fromDatagramRequest​(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram) throws RadiusPacketException
      Reads a request from the given input stream and creates an appropriate RadiusPacket/subclass.

      Decodes the encrypted fields and attributes of the packet, and checks authenticator if appropriate.

      Parameters:
      dictionary - dictionary to use for attributes
      datagram - DatagramPacket to read packet from
      Returns:
      new RadiusPacket object
      Throws:
      RadiusPacketException - malformed packet
    • fromDatagramResponse

      public static RadiusResponse fromDatagramResponse​(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram) throws RadiusPacketException
      Reads a response from the given input stream and creates an appropriate RadiusPacket/subclass.

      Decodes the encrypted fields and attributes of the packet, and checks authenticator if appropriate.

      Parameters:
      dictionary - dictionary to use for attributes
      datagram - DatagramPacket to read packet from
      Returns:
      new RadiusPacket object
      Throws:
      RadiusPacketException - malformed packet