Class ProtobufBuffer<T,MessageType extends us.hebi.quickbuf.ProtoMessage<?>>

java.lang.Object
edu.wpi.first.util.protobuf.ProtobufBuffer<T,MessageType>
Type Parameters:
T - object type
MessageType - 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.
    Gets the protobuf object of the stored type.
    Gets the type string.
    read(byte[] buf)
    Deserializes a value from a byte array, creating a new object.
    read(byte[] buf, int start, int len)
    Deserializes a value from a byte array, creating a new object.
    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.
    write(T value)
    Serializes a value to a ByteBuffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public ByteBuffer write(T value) throws IOException
      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

      public T read(byte[] buf, int start, int len) throws IOException
      Deserializes a value from a byte array, creating a new object.
      Parameters:
      buf - byte array
      start - starting location within byte array
      len - length of serialized data
      Returns:
      new object
      Throws:
      IOException - if deserialization failed
    • read

      public T read(byte[] buf) throws IOException
      Deserializes a value from a byte array, creating a new object.
      Parameters:
      buf - byte array
      Returns:
      new object
      Throws:
      IOException - if deserialization failed
    • read

      public T read(ByteBuffer buf) throws IOException
      Deserializes a value from a ByteBuffer, creating a new object.
      Parameters:
      buf - byte buffer
      Returns:
      new object
      Throws:
      IOException - if deserialization failed
    • readInto

      public void readInto(T out, byte[] buf, int start, int len) throws IOException
      Deserializes a value from a byte array into a mutable object.
      Parameters:
      out - object (will be updated with deserialized contents)
      buf - byte array
      start - starting location within byte array
      len - length of serialized data
      Throws:
      IOException - if deserialization failed
      UnsupportedOperationException - if the object is immutable
    • readInto

      public void readInto(T out, byte[] buf) throws IOException
      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 failed
      UnsupportedOperationException - if the object is immutable
    • readInto

      public void readInto(T out, ByteBuffer buf) throws IOException
      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 failed
      UnsupportedOperationException - if the object is immutable