Interface Protobuf<T,​MessageType extends us.hebi.quickbuf.ProtoMessage<?>>

Type Parameters:
T - object type
MessageType - protobuf message type
All Known Implementing Classes:
ArmFeedforwardProto, ChassisSpeedsProto, DCMotorProto, DifferentialDriveKinematicsProto, DifferentialDriveWheelPositionsProto, DifferentialDriveWheelSpeedsProto, DifferentialDriveWheelVoltagesProto, ElevatorFeedforwardProto, MecanumDriveKinematicsProto, MecanumDriveWheelPositionsProto, MecanumDriveWheelSpeedsProto, Pose2dProto, Pose3dProto, QuaternionProto, Rotation2dProto, Rotation3dProto, SwerveModulePositionProto, SwerveModuleStateProto, TrajectoryProto, TrajectoryStateProto, Transform2dProto, Transform3dProto, Translation2dProto, Translation3dProto, Twist2dProto, Twist3dProto

public interface Protobuf<T,​MessageType extends us.hebi.quickbuf.ProtoMessage<?>>
Interface for Protobuf serialization.

This is designed for serialization of more complex data structures including forward/backwards compatibility and repeated/nested/variable length members, etc. Serialization and deserialization code is auto-generated from .proto interface descriptions (the MessageType generic parameter).

Idiomatically, classes that support protobuf serialization should provide a static final member named "proto" that provides an instance of an implementation of this interface.

  • Method Details

    • getTypeClass

      Gets the Class object for the stored value.
      Returns:
      Class
    • getTypeString

      default String getTypeString()
      Gets the type string (e.g. for NetworkTables). This should be globally unique and start with "proto:".
      Returns:
      type string
    • getDescriptor

      us.hebi.quickbuf.Descriptors.Descriptor getDescriptor()
      Gets the protobuf descriptor.
      Returns:
      descriptor
    • getNested

      default Protobuf<?,​?>[] getNested()
      Gets the list of protobuf types referenced by this protobuf.
      Returns:
      list of protobuf types
    • createMessage

      Creates protobuf message.
      Returns:
      protobuf message
    • unpack

      T unpack​(MessageType msg)
      Deserializes an object from a protobuf message.
      Parameters:
      msg - protobuf message
      Returns:
      New object
    • pack

      void pack​(MessageType msg, T value)
      Copies the object contents into a protobuf message. Implementations should call either msg.setMember(member) or member.copyToProto(msg.getMutableMember()) for each member.
      Parameters:
      msg - protobuf message
      value - object to serialize
    • unpackInto

      default void unpackInto​(T out, MessageType msg)
      Updates the object contents from a protobuf message. Implementations should call msg.getMember(member), MemberClass.makeFromProto(msg.getMember()), or member.updateFromProto(msg.getMember()) for each member.

      Immutable classes cannot and should not implement this function. The default implementation throws UnsupportedOperationException.

      Parameters:
      out - object to update
      msg - protobuf message
      Throws:
      UnsupportedOperationException - if the object is immutable
    • forEachDescriptor

      default void forEachDescriptor​(Predicate<String> exists, BiConsumer<String,​byte[]> fn)
      Loops over all protobuf descriptors including nested/referenced descriptors.
      Parameters:
      exists - function that returns false if fn should be called for the given type string
      fn - function to call for each descriptor