java.lang.Object
org.photonvision.common.dataflow.structures.Packet

public class Packet extends Object
A packet that holds byte-packed data to be sent over NetworkTables.
  • Field Details

  • Constructor Details

    • Packet

      public Packet(int size)
      Constructs an empty packet. This buffer will dynamically expand if we need more data space.
      Parameters:
      size - The size of the packet buffer.
    • Packet

      public Packet(byte[] data)
      Constructs a packet with the given data.
      Parameters:
      data - The packet data.
  • Method Details

    • clear

      public void clear()
      Clears the packet and resets the read and write positions.
    • getNumBytesWritten

      public int getNumBytesWritten()
    • getNumBytesRead

      public int getNumBytesRead()
    • getSize

      public int getSize()
    • getWrittenDataCopy

      public byte[] getWrittenDataCopy()
      Returns a copy of only the packet data we've actually written to so far.
      Returns:
      The packet data.
    • setData

      public void setData(byte[] data)
      Sets the packet data.
      Parameters:
      data - The packet data.
    • encode

      public void encode(byte src)
      Encodes the byte into the packet.
      Parameters:
      src - The byte to encode.
    • encode

      public void encode(short src)
      Encodes the short into the packet.
      Parameters:
      src - The short to encode.
    • encode

      public void encode(int src)
      Encodes the integer into the packet.
      Parameters:
      src - The integer to encode.
    • encode

      public void encode(float src)
      Encodes the float into the packet.
      Parameters:
      src - The float to encode.
    • encode

      public void encode(long data)
      Encodes the double into the packet.
      Parameters:
      data - The double to encode.
    • encode

      public void encode(double src)
      Encodes the double into the packet.
      Parameters:
      src - The double to encode.
    • encode

      public void encode(boolean src)
      Encodes the boolean into the packet.
      Parameters:
      src - The boolean to encode.
    • encode

      public void encode(List<Short> data)
    • encode

      public <T extends PhotonStructSerializable<T>> void encode(T data)
    • encodeList

      public <T extends PhotonStructSerializable<T>> void encodeList(List<T> data)
      Encode a list of serializable structs. Lists are stored as [uint8 length, [length many] data structs]
      Type Parameters:
      T - the class this list will be packing
      Parameters:
      data -
    • encodeOptional

      public <T extends PhotonStructSerializable<T>> void encodeOptional(Optional<T> data)
    • decodeByte

      public byte decodeByte()
      Returns a decoded byte from the packet.
      Returns:
      A decoded byte from the packet.
    • decodeInt

      public int decodeInt()
      Returns a decoded int from the packet.
      Returns:
      A decoded int from the packet.
    • decodeLong

      public long decodeLong()
    • decodeDouble

      public double decodeDouble()
      Returns a decoded double from the packet.
      Returns:
      A decoded double from the packet.
    • decodeFloat

      public float decodeFloat()
      Returns a decoded float from the packet.
      Returns:
      A decoded float from the packet.
    • decodeBoolean

      public boolean decodeBoolean()
      Returns a decoded boolean from the packet.
      Returns:
      A decoded boolean from the packet.
    • encode

      public void encode(double[] data)
    • decodeDoubleArray

      public double[] decodeDoubleArray(int len)
    • decodeShort

      public short decodeShort()
    • decodeList

      public <T extends PhotonStructSerializable<T>> List<T> decodeList(PacketSerde<T> serde)
      Decode a list of serializable structs. Lists are stored as [uint8 length, [length many] data structs]. Because java sucks, we need to take the serde ref directly
      Type Parameters:
      T -
      Parameters:
      serde -
    • decodeOptional

      public <T extends PhotonStructSerializable<T>> Optional<T> decodeOptional(PacketSerde<T> serde)
    • decodeShortList

      public List<Short> decodeShortList()
    • decode

      public <T extends PhotonStructSerializable<T>> T decode(PhotonStructSerializable<T> t)