Class UDP

  • All Implemented Interfaces:
    IPacket

    public class UDP
    extends BasePacket
    Representation of a UDP packet.
    • Field Detail

      • PORT_DESERIALIZER_MAP

        public static final java.util.Map<java.lang.Integer,​Deserializer<? extends IPacket>> PORT_DESERIALIZER_MAP
      • sourcePort

        protected int sourcePort
      • destinationPort

        protected int destinationPort
      • length

        protected short length
      • checksum

        protected short checksum
    • Constructor Detail

      • UDP

        public UDP()
    • Method Detail

      • getSourcePort

        public int getSourcePort()
        Returns:
        the sourcePort
      • setSourcePort

        public UDP setSourcePort​(int sourcePort)
        Parameters:
        sourcePort - the sourcePort to set (16 bits unsigned integer)
        Returns:
        this
      • getDestinationPort

        public int getDestinationPort()
        Returns:
        the destinationPort
      • setDestinationPort

        public UDP setDestinationPort​(int destinationPort)
        Parameters:
        destinationPort - the destinationPort to set (16 bits unsigned integer)
        Returns:
        this
      • getLength

        public short getLength()
        Returns:
        the length
      • getChecksum

        public short getChecksum()
        Returns:
        the checksum
      • setChecksum

        public UDP setChecksum​(short checksum)
        Parameters:
        checksum - the checksum to set
        Returns:
        this
      • resetChecksum

        public void resetChecksum()
        Description copied from interface: IPacket
        Reset any checksum as needed, and call resetChecksum on all parents.
        Specified by:
        resetChecksum in interface IPacket
        Overrides:
        resetChecksum in class BasePacket
      • serialize

        public byte[] serialize()
        Serializes the packet. Will compute and set the following fields if they are set to specific values at the time serialize is called: -checksum : 0 -length : 0
        Returns:
        a byte[] containing this packet and payloads
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class BasePacket
      • deserializer

        public static Deserializer<UDP> deserializer()
        Deserializer function for UDP packets.
        Returns:
        deserializer function
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object