Class Packet
java.lang.Object
org.photonvision.common.dataflow.structures.Packet
A packet that holds byte-packed data to be sent over NetworkTables.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the packet and resets the read and write positions.<T extends PhotonStructSerializable<T>>
Tboolean
Returns a decoded boolean from the packet.byte
Returns a decoded byte from the packet.double
Returns a decoded double from the packet.double[]
decodeDoubleArray
(int len) float
Returns a decoded float from the packet.int
Returns a decoded int from the packet.<T extends PhotonStructSerializable<T>>
List<T>decodeList
(PacketSerde<T> serde) Decode a list of serializable structs.long
<T extends PhotonStructSerializable<T>>
Optional<T>decodeOptional
(PacketSerde<T> serde) short
void
encode
(boolean src) Encodes the boolean into the packet.void
encode
(byte src) Encodes the byte into the packet.void
encode
(double src) Encodes the double into the packet.void
encode
(double[] data) void
encode
(float src) Encodes the float into the packet.void
encode
(int src) Encodes the integer into the packet.void
encode
(long data) Encodes the double into the packet.void
encode
(short src) Encodes the short into the packet.void
<T extends PhotonStructSerializable<T>>
voidencode
(T data) <T extends PhotonStructSerializable<T>>
voidencodeList
(List<T> data) Encode a list of serializable structs.<T extends PhotonStructSerializable<T>>
voidencodeOptional
(Optional<T> data) int
int
int
getSize()
byte[]
Returns a copy of only the packet data we've actually written to so far.void
setData
(byte[] data) Sets the packet data.
-
Field Details
-
SOFT_MAX_ARRAY_LENGTH
public static final int SOFT_MAX_ARRAY_LENGTH- See Also:
-
-
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
-
encode
-
encodeList
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
-
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
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
-
decodeShortList
-
decode
-