Interface Packet

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Packet.Builder
      This interface is designed to be implemented by builder classes for packet objects.
      static interface  Packet.Header
      The interface representing a packet's header.
    • Method Summary

      Modifier and Type Method Description
      default <T extends Packet>
      boolean
      contains​(java.lang.Class<T> clazz)
      Returns true if this packet is or its payload includes an object of specified packet class; false otherwise.
      default <T extends Packet>
      T
      get​(java.lang.Class<T> clazz)
      Traverses this packet and its payload to find an object of the specified packet class and returns the object.
      Packet.Builder getBuilder()
      Returns a new Builder object populated with this object's fields' values.
      Packet.Header getHeader()
      Returns the Header object representing this packet's header.
      default Packet getLowerLayerOf​(java.lang.Class<? extends Packet> clazz)
      Returns the outer packet object of a packet object get(clazz) returns.
      Packet getPayload()
      Returns the Packet object representing this packet's payload.
      byte[] getRawData()
      Returns this packet's raw data.
      default java.util.Iterator<Packet> iterator()  
      int length()
      Returns the packet length in bytes.
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • getHeader

        Packet.Header getHeader()
        Returns the Header object representing this packet's header.
        Returns:
        the Header object representing this packet's header. May be null if the header doesn't exist
      • getPayload

        Packet getPayload()
        Returns the Packet object representing this packet's payload.
        Returns:
        the Packet object representing this packet's payload. May be null if the payload doesn't exist
      • length

        int length()
        Returns the packet length in bytes.
        Returns:
        the length of the byte stream of the packet represented by this object in bytes
      • getRawData

        byte[] getRawData()
        Returns this packet's raw data.
        Returns:
        this packet's raw data, namely the byte stream which is actually sent through real network
      • iterator

        default java.util.Iterator<Packet> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Packet>
      • get

        default <T extends Packet> T get​(java.lang.Class<T> clazz)
        Traverses this packet and its payload to find an object of the specified packet class and returns the object. If there are more than one objects of the specified class in this object, this method returns the most outer one of them.
        Type Parameters:
        T - packet
        Parameters:
        clazz - the packet class of the object to get
        Returns:
        a packet object if found; otherwise null
      • getLowerLayerOf

        default Packet getLowerLayerOf​(java.lang.Class<? extends Packet> clazz)
        Returns the outer packet object of a packet object get(clazz) returns.
        Parameters:
        clazz - the packet class of the object whose outer packet object is what you want to get
        Returns:
        a packet object if found; otherwise null
      • contains

        default <T extends Packet> boolean contains​(java.lang.Class<T> clazz)
        Returns true if this packet is or its payload includes an object of specified packet class; false otherwise.
        Type Parameters:
        T - packet
        Parameters:
        clazz - the packet class of the object to search for
        Returns:
        true if this packet is or its payload includes an object of specified packet class; false otherwise
      • getBuilder

        Packet.Builder getBuilder()
        Returns a new Builder object populated with this object's fields' values.
        Returns:
        a new Builder object populated with this object's fields values