Package edu.wpi.first.util.struct
Class StructBuffer<T>
java.lang.Object
edu.wpi.first.util.struct.StructBuffer<T>
- Type Parameters:
T- Object type.
Reusable buffer for serialization/deserialization to/from a raw struct.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> StructBuffer<T>Returns a StructBuffer for the given struct.Gets the struct object of the stored type.Gets the type string.read(byte[] buf) Deserializes a value from a byte array, creating a new object.read(byte[] buf, int start, int len) Deserializes a value from a byte array, creating a new object.read(ByteBuffer buf) Deserializes a value from a ByteBuffer, creating a new object.T[]readArray(byte[] buf) Deserializes an array of values from a byte array, creating an array of new objects.T[]readArray(byte[] buf, int start, int len) Deserializes an array of values from a byte array, creating an array of new objects.T[]readArray(ByteBuffer buf) Deserializes an array of values from a ByteBuffer, creating an array of new objects.voidDeserializes a value from a byte array into a mutable object.voidDeserializes a value from a byte array into a mutable object.voidreadInto(T out, ByteBuffer buf) Deserializes a value from a ByteBuffer into a mutable object.voidreserve(int nelem) Ensures sufficient buffer space is available for the given number of elements.Serializes a value to a ByteBuffer.writeArray(Collection<T> values) Serializes a collection of values to a ByteBuffer.writeArray(T[] values) Serializes an array of values to a ByteBuffer.
-
Method Details
-
create
Returns a StructBuffer for the given struct.- Type Parameters:
T- Object type.- Parameters:
struct- A struct.- Returns:
- A StructBuffer for the given struct.
-
getStruct
Gets the struct object of the stored type.- Returns:
- struct object
-
getTypeString
Gets the type string.- Returns:
- type string
-
reserve
Ensures sufficient buffer space is available for the given number of elements.- Parameters:
nelem- number of elements
-
write
Serializes a value to a ByteBuffer. The returned ByteBuffer is a direct byte buffer with the position set to the end of the serialized data.- Parameters:
value- value- Returns:
- byte buffer
-
read
Deserializes a value from a byte array, creating a new object.- Parameters:
buf- byte arraystart- starting location within byte arraylen- length of serialized data- Returns:
- new object
-
read
Deserializes a value from a byte array, creating a new object.- Parameters:
buf- byte array- Returns:
- new object
-
read
Deserializes a value from a ByteBuffer, creating a new object.- Parameters:
buf- byte buffer- Returns:
- new object
-
readInto
Deserializes a value from a byte array into a mutable object.- Parameters:
out- object (will be updated with deserialized contents)buf- byte arraystart- starting location within byte arraylen- length of serialized data- Throws:
UnsupportedOperationException- if T is immutable
-
readInto
Deserializes a value from a byte array into a mutable object.- Parameters:
out- object (will be updated with deserialized contents)buf- byte array- Throws:
UnsupportedOperationException- if T is immutable
-
readInto
Deserializes a value from a ByteBuffer into a mutable object.- Parameters:
out- object (will be updated with deserialized contents)buf- byte buffer- Throws:
UnsupportedOperationException- if T is immutable
-
writeArray
Serializes a collection of values to a ByteBuffer. The returned ByteBuffer is a direct byte buffer with the position set to the end of the serialized data.- Parameters:
values- values- Returns:
- byte buffer
-
writeArray
Serializes an array of values to a ByteBuffer. The returned ByteBuffer is a direct byte buffer with the position set to the end of the serialized data.- Parameters:
values- values- Returns:
- byte buffer
-
readArray
Deserializes an array of values from a byte array, creating an array of new objects.- Parameters:
buf- byte arraystart- starting location within byte arraylen- length of serialized data- Returns:
- new object array
-
readArray
Deserializes an array of values from a byte array, creating an array of new objects.- Parameters:
buf- byte array- Returns:
- new object array
-
readArray
Deserializes an array of values from a ByteBuffer, creating an array of new objects.- Parameters:
buf- byte buffer- Returns:
- new object array
-