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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the packet and resets the read and write positions.<T extends PhotonStructSerializable<T>>
TbooleanReturns a decoded boolean from the packet.byteReturns a decoded byte from the packet.doubleReturns a decoded double from the packet.double[]decodeDoubleArray(int len) floatReturns a decoded float from the packet.intReturns 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) shortvoidencode(boolean src) Encodes the boolean into the packet.voidencode(byte src) Encodes the byte into the packet.voidencode(double src) Encodes the double into the packet.voidencode(double[] data) voidencode(float src) Encodes the float into the packet.voidencode(int src) Encodes the integer into the packet.voidencode(long data) Encodes the double into the packet.voidencode(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) intintintgetSize()byte[]Returns a copy of only the packet data we've actually written to so far.voidsetData(byte[] data) Sets the packet data.
-
Field Details
-
SOFT_MAX_ARRAY_LENGTH
- See Also:
-
-
Constructor Details
-
Packet
Constructs an empty packet. This buffer will dynamically expand if we need more data space.- Parameters:
size- The size of the packet buffer.
-
Packet
Constructs a packet with the given data.- Parameters:
data- The packet data.
-
-
Method Details
-
clear
Clears the packet and resets the read and write positions. -
getNumBytesWritten
-
getNumBytesRead
-
getSize
-
getWrittenDataCopy
Returns a copy of only the packet data we've actually written to so far.- Returns:
- The packet data.
-
setData
Sets the packet data.- Parameters:
data- The packet data.
-
encode
Encodes the byte into the packet.- Parameters:
src- The byte to encode.
-
encode
Encodes the short into the packet.- Parameters:
src- The short to encode.
-
encode
Encodes the integer into the packet.- Parameters:
src- The integer to encode.
-
encode
Encodes the float into the packet.- Parameters:
src- The float to encode.
-
encode
Encodes the double into the packet.- Parameters:
data- The double to encode.
-
encode
Encodes the double into the packet.- Parameters:
src- The double to encode.
-
encode
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
Returns a decoded byte from the packet.- Returns:
- A decoded byte from the packet.
-
decodeInt
Returns a decoded int from the packet.- Returns:
- A decoded int from the packet.
-
decodeLong
-
decodeDouble
Returns a decoded double from the packet.- Returns:
- A decoded double from the packet.
-
decodeFloat
Returns a decoded float from the packet.- Returns:
- A decoded float from the packet.
-
decodeBoolean
Returns a decoded boolean from the packet.- Returns:
- A decoded boolean from the packet.
-
encode
-
decodeDoubleArray
-
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
-