Package edu.wpi.first.util.struct
Interface Struct<T>
- Type Parameters:
T
- object type
- All Known Implementing Classes:
ArmFeedforwardStruct
,ChassisSpeedsStruct
,DCMotorStruct
,DifferentialDriveKinematicsStruct
,DifferentialDriveWheelPositionsStruct
,DifferentialDriveWheelSpeedsStruct
,DifferentialDriveWheelVoltagesStruct
,ElevatorFeedforwardStruct
,Ellipse2dStruct
,MecanumDriveKinematicsStruct
,MecanumDriveWheelPositionsStruct
,MecanumDriveWheelSpeedsStruct
,Pose2dStruct
,Pose3dStruct
,QuaternionStruct
,Rectangle2dStruct
,Rotation2dStruct
,Rotation3dStruct
,SwerveModulePositionStruct
,SwerveModuleStateStruct
,Transform2dStruct
,Transform3dStruct
,Translation2dStruct
,Translation3dStruct
,Twist2dStruct
,Twist3dStruct
public interface Struct<T>
Interface for raw struct serialization.
This is designed for serializing small fixed-size data structures in the fastest and most compact means possible. Serialization consists of making relative put() calls to a ByteBuffer and deserialization consists of making relative get() calls from a ByteBuffer.
Idiomatically, classes that support raw struct serialization should provide a static final member named "struct" that provides an instance of an implementation of this interface.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Serialized size of a "bool" value.static final int
Serialized size of an "double" or "float64" value.static final int
Serialized size of an "float" or "float32" value.static final int
Serialized size of an "int16" or "uint16" value.static final int
Serialized size of an "int32" or "uint32" value.static final int
Serialized size of an "int64" or "uint64" value.static final int
Serialized size of an "int8" or "uint8" value. -
Method Summary
Modifier and TypeMethodDescriptiondefault T
Creates a (deep) clone of the object.default Struct<?>[]
Gets the list of struct types referenced by this struct.Gets the schema.int
getSize()
Gets the serialized size (in bytes).Gets the Class object for the stored value.Gets the type string (e.g.default boolean
Returns whether or not objects are cloneable using the clone() method.default boolean
Returns whether or not objects are immutable.void
pack
(ByteBuffer bb, T value) Puts object contents to a ByteBuffer starting at the current position.unpack
(ByteBuffer bb) Deserializes an object from a raw struct serialized ByteBuffer starting at the current position.default void
unpackInto
(T out, ByteBuffer bb) Updates object contents from a raw struct serialized ByteBuffer starting at the current position.
-
Field Details
-
kSizeBool
Serialized size of a "bool" value.- See Also:
-
kSizeInt8
Serialized size of an "int8" or "uint8" value.- See Also:
-
kSizeInt16
Serialized size of an "int16" or "uint16" value.- See Also:
-
kSizeInt32
Serialized size of an "int32" or "uint32" value.- See Also:
-
kSizeInt64
Serialized size of an "int64" or "uint64" value.- See Also:
-
kSizeFloat
Serialized size of an "float" or "float32" value.- See Also:
-
kSizeDouble
Serialized size of an "double" or "float64" value.- See Also:
-
-
Method Details
-
getTypeClass
Class<T> getTypeClass()Gets the Class object for the stored value.- Returns:
- Class
-
getTypeString
Gets the type string (e.g. for NetworkTables). This should be globally unique and start with "struct:".- Returns:
- type string
-
getSize
int getSize()Gets the serialized size (in bytes). This should always be a constant.- Returns:
- serialized size
-
getSchema
Gets the schema.- Returns:
- schema
-
getNested
Gets the list of struct types referenced by this struct.- Returns:
- list of struct types
-
unpack
Deserializes an object from a raw struct serialized ByteBuffer starting at the current position. Will increment the ByteBuffer position by getStructSize() bytes. Will not otherwise modify the ByteBuffer (e.g. byte order will not be changed).- Parameters:
bb
- ByteBuffer- Returns:
- New object
-
pack
Puts object contents to a ByteBuffer starting at the current position. Will increment the ByteBuffer position by getStructSize() bytes. Will not otherwise modify the ByteBuffer (e.g. byte order will not be changed).- Parameters:
bb
- ByteBuffervalue
- object to serialize
-
unpackInto
Updates object contents from a raw struct serialized ByteBuffer starting at the current position. Will increment the ByteBuffer position by getStructSize() bytes. Will not otherwise modify the ByteBuffer (e.g. byte order will not be changed).Immutable classes cannot and should not implement this function. The default implementation throws UnsupportedOperationException.
- Parameters:
out
- object to updatebb
- ByteBuffer- Throws:
UnsupportedOperationException
- if the object is immutable
-
isImmutable
Returns whether or not objects are immutable. Immutable objects must also be comparable using the equals() method. Default implementation returns false.- Returns:
- True if object is immutable
-
isCloneable
Returns whether or not objects are cloneable using the clone() method. Clonable objects must also be comparable using the equals() method. Default implementation returns false.- Returns:
- True if object is clonable
-
clone
Creates a (deep) clone of the object. May also return the object directly if the object is immutable. Default implementation throws CloneNotSupportedException. Typically this should be implemented by implementing clone() on the object itself, and calling it from here.- Parameters:
obj
- object to clone- Returns:
- Clone of object (if immutable, may be same object)
- Throws:
CloneNotSupportedException
- if clone not supported
-