Package edu.wpi.first.util.protobuf
Class ProtobufBuffer<T,MessageType extends us.hebi.quickbuf.ProtoMessage<?>>
java.lang.Object
edu.wpi.first.util.protobuf.ProtobufBuffer<T,MessageType>
- Type Parameters:
T
- object typeMessageType
- protobuf message type
public final class ProtobufBuffer<T,MessageType extends us.hebi.quickbuf.ProtoMessage<?>> extends Object
Reusable buffer for serialization/deserialization to/from a protobuf.
-
Method Summary
Modifier and Type Method Description static <T, MessageType extends us.hebi.quickbuf.ProtoMessage<?>>
ProtobufBuffer<T,MessageType>create(Protobuf<T,MessageType> proto)
Creates a ProtobufBuffer for the given Protobuf object.Protobuf<T,MessageType>
getProto()
Gets the protobuf object of the stored type.String
getTypeString()
Gets the type string.T
read(byte[] buf)
Deserializes a value from a byte array, creating a new object.T
read(byte[] buf, int start, int len)
Deserializes a value from a byte array, creating a new object.T
read(ByteBuffer buf)
Deserializes a value from a ByteBuffer, creating a new object.void
readInto(T out, byte[] buf)
Deserializes a value from a byte array into a mutable object.void
readInto(T out, byte[] buf, int start, int len)
Deserializes a value from a byte array into a mutable object.void
readInto(T out, ByteBuffer buf)
Deserializes a value from a ByteBuffer into a mutable object.ByteBuffer
write(T value)
Serializes a value to a ByteBuffer.
-
Method Details
-
create
public static <T, MessageType extends us.hebi.quickbuf.ProtoMessage<?>> ProtobufBuffer<T,MessageType> create(Protobuf<T,MessageType> proto)Creates a ProtobufBuffer for the given Protobuf object.- Type Parameters:
T
- The type to serialize.MessageType
- The Protobuf message type.- Parameters:
proto
- The Protobuf object.- Returns:
- A ProtobufBuffer for the given Protobuf object.
-
getProto
Gets the protobuf object of the stored type.- Returns:
- protobuf object
-
getTypeString
Gets the type string.- Returns:
- type string
-
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
- Throws:
IOException
- if serialization failed
-
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
- Throws:
IOException
- if deserialization failed
-
read
Deserializes a value from a byte array, creating a new object.- Parameters:
buf
- byte array- Returns:
- new object
- Throws:
IOException
- if deserialization failed
-
read
Deserializes a value from a ByteBuffer, creating a new object.- Parameters:
buf
- byte buffer- Returns:
- new object
- Throws:
IOException
- if deserialization failed
-
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:
IOException
- if deserialization failedUnsupportedOperationException
- if the object 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:
IOException
- if deserialization failedUnsupportedOperationException
- if the object 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:
IOException
- if deserialization failedUnsupportedOperationException
- if the object is immutable
-