Class ProtobufTopic<T>

java.lang.Object
edu.wpi.first.networktables.Topic
edu.wpi.first.networktables.ProtobufTopic<T>
Type Parameters:
T - value class

public final class ProtobufTopic<T>
extends Topic
NetworkTables protobuf-encoded value topic.
  • Method Details

    • wrap

      public static <T> ProtobufTopic<T> wrap​(Topic topic, Protobuf<T,​?> proto)
      Create a ProtobufTopic from a generic topic.
      Type Parameters:
      T - value class (inferred from proto)
      Parameters:
      topic - generic topic
      proto - protobuf serialization implementation
      Returns:
      ProtobufTopic for value class
    • wrap

      public static <T> ProtobufTopic<T> wrap​(NetworkTableInstance inst, int handle, Protobuf<T,​?> proto)
      Create a ProtobufTopic from a native handle; generally NetworkTableInstance.getProtobufTopic() should be used instead.
      Type Parameters:
      T - value class (inferred from proto)
      Parameters:
      inst - Instance
      handle - Native handle
      proto - protobuf serialization implementation
      Returns:
      ProtobufTopic for value class
    • subscribe

      public ProtobufSubscriber<T> subscribe​(T defaultValue, PubSubOption... options)
      Create a new subscriber to the topic.

      The subscriber is only active as long as the returned object is not closed.

      Subscribers that do not match the published data type do not return any values. To determine if the data type matches, use the appropriate Topic functions.

      Parameters:
      defaultValue - default value used when a default is not provided to a getter function
      options - subscribe options
      Returns:
      subscriber
    • publish

      public ProtobufPublisher<T> publish​(PubSubOption... options)
      Create a new publisher to the topic.

      The publisher is only active as long as the returned object is not closed.

      It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.

      Parameters:
      options - publish options
      Returns:
      publisher
    • publishEx

      public ProtobufPublisher<T> publishEx​(String properties, PubSubOption... options)
      Create a new publisher to the topic, with type string and initial properties.

      The publisher is only active as long as the returned object is not closed.

      It is not possible to publish two different data types to the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored). To determine if the data type matches, use the appropriate Topic functions.

      Parameters:
      properties - JSON properties
      options - publish options
      Returns:
      publisher
      Throws:
      IllegalArgumentException - if properties is not a JSON object
    • getEntry

      public ProtobufEntry<T> getEntry​(T defaultValue, PubSubOption... options)
      Create a new entry for the topic.

      Entries act as a combination of a subscriber and a weak publisher. The subscriber is active as long as the entry is not closed. The publisher is created when the entry is first written to, and remains active until either unpublish() is called or the entry is closed.

      It is not possible to use two different data types with the same topic. Conflicts between publishers are typically resolved by the server on a first-come, first-served basis. Any published values that do not match the topic's data type are dropped (ignored), and the entry will show no new values if the data type does not match. To determine if the data type matches, use the appropriate Topic functions.

      Parameters:
      defaultValue - default value used when a default is not provided to a getter function
      options - publish and/or subscribe options
      Returns:
      entry
    • getProto

      public Protobuf<T,​?> getProto()
      Returns the protobuf.
      Returns:
      The protobuf.
    • equals

      public boolean equals​(Object other)
      Overrides:
      equals in class Topic
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Topic