Interface Struct<T>

Type Parameters:
T - object type
All Known Implementing Classes:
ArmFeedforwardStruct, ChassisSpeedsStruct, DCMotorStruct, DifferentialDriveKinematicsStruct, DifferentialDriveWheelSpeedsStruct, DifferentialDriveWheelVoltagesStruct, ElevatorFeedforwardStruct, MecanumDriveKinematicsStruct, MecanumDriveWheelPositionsStruct, MecanumDriveWheelSpeedsStruct, Pose2dStruct, Pose3dStruct, QuaternionStruct, 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

    Fields 
    Modifier and Type Field Description
    static int kSizeBool
    Serialized size of a "bool" value.
    static int kSizeDouble
    Serialized size of an "double" or "float64" value.
    static int kSizeFloat
    Serialized size of an "float" or "float32" value.
    static int kSizeInt16
    Serialized size of an "int16" or "uint16" value.
    static int kSizeInt32
    Serialized size of an "int32" or "uint32" value.
    static int kSizeInt64
    Serialized size of an "int64" or "uint64" value.
    static int kSizeInt8
    Serialized size of an "int8" or "uint8" value.
  • Method Summary

    Modifier and Type Method Description
    default Struct<?>[] getNested()
    Gets the list of struct types referenced by this struct.
    String getSchema()
    Gets the schema.
    int getSize()
    Gets the serialized size (in bytes).
    Class<T> getTypeClass()
    Gets the Class object for the stored value.
    String getTypeString()
    Gets the type string (e.g.
    void pack​(ByteBuffer bb, T value)
    Puts object contents to a ByteBuffer starting at the current position.
    T 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

  • Method Details

    • 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

      default Struct<?>[] 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

      void pack​(ByteBuffer bb, T value)
      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 - ByteBuffer
      value - object to serialize
    • unpackInto

      default void unpackInto​(T out, ByteBuffer bb)
      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 update
      bb - ByteBuffer
      Throws:
      UnsupportedOperationException - if the object is immutable