Package edu.wpi.first.util.protobuf
Interface Protobuf<T,MessageType extends us.hebi.quickbuf.ProtoMessage<?>>
- Type Parameters:
T
- object typeMessageType
- 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 Summary
Modifier and Type Method Description MessageType
createMessage()
Creates protobuf message.default void
forEachDescriptor(Predicate<String> exists, BiConsumer<String,byte[]> fn)
Loops over all protobuf descriptors including nested/referenced descriptors.us.hebi.quickbuf.Descriptors.Descriptor
getDescriptor()
Gets the protobuf descriptor.default Protobuf<?,?>[]
getNested()
Gets the list of protobuf types referenced by this protobuf.Class<T>
getTypeClass()
Gets the Class object for the stored value.default String
getTypeString()
Gets the type string (e.g.void
pack(MessageType msg, T value)
Copies the object contents into a protobuf message.T
unpack(MessageType msg)
Deserializes an object from a protobuf message.default void
unpackInto(T out, MessageType msg)
Updates the object contents from a protobuf message.
-
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 "proto:".- Returns:
- type string
-
getDescriptor
us.hebi.quickbuf.Descriptors.Descriptor getDescriptor()Gets the protobuf descriptor.- Returns:
- descriptor
-
getNested
Gets the list of protobuf types referenced by this protobuf.- Returns:
- list of protobuf types
-
createMessage
Creates protobuf message.- Returns:
- protobuf message
-
unpack
Deserializes an object from a protobuf message.- Parameters:
msg
- protobuf message- Returns:
- New object
-
pack
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 messagevalue
- object to serialize
-
unpackInto
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 updatemsg
- protobuf message- Throws:
UnsupportedOperationException
- if the object is immutable
-
forEachDescriptor
Loops over all protobuf descriptors including nested/referenced descriptors.- Parameters:
exists
- function that returns false if fn should be called for the given type stringfn
- function to call for each descriptor
-