RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
ProtobufTopic.java
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5package org.wpilib.networktables;
6
7import org.wpilib.util.protobuf.Protobuf;
8import org.wpilib.util.protobuf.ProtobufBuffer;
9
15public final class ProtobufTopic<T> extends Topic {
16 private ProtobufTopic(Topic topic, Protobuf<T, ?> proto) {
17 super(topic.m_inst, topic.m_handle);
18 m_proto = proto;
19 }
20
21 private ProtobufTopic(NetworkTableInstance inst, int handle, Protobuf<T, ?> proto) {
22 super(inst, handle);
23 m_proto = proto;
24 }
25
34 public static <T> ProtobufTopic<T> wrap(Topic topic, Protobuf<T, ?> proto) {
35 return new ProtobufTopic<>(topic, proto);
36 }
37
48 public static <T> ProtobufTopic<T> wrap(
49 NetworkTableInstance inst, int handle, Protobuf<T, ?> proto) {
50 return new ProtobufTopic<>(inst, handle, proto);
51 }
52
65 public ProtobufSubscriber<T> subscribe(T defaultValue, PubSubOption... options) {
66 return new ProtobufEntryImpl<>(
67 this,
68 ProtobufBuffer.create(m_proto),
69 NetworkTablesJNI.subscribe(
70 m_handle, NetworkTableType.RAW.getValue(), m_proto.getTypeString(), options),
71 defaultValue,
72 false);
73 }
74
89 m_inst.addSchema(m_proto);
90 return new ProtobufEntryImpl<>(
91 this,
92 ProtobufBuffer.create(m_proto),
93 NetworkTablesJNI.publish(
94 m_handle, NetworkTableType.RAW.getValue(), m_proto.getTypeString(), options),
95 null,
96 true);
97 }
98
114 public ProtobufPublisher<T> publishEx(String properties, PubSubOption... options) {
115 m_inst.addSchema(m_proto);
116 return new ProtobufEntryImpl<>(
117 this,
118 ProtobufBuffer.create(m_proto),
119 NetworkTablesJNI.publishEx(
120 m_handle,
121 NetworkTableType.RAW.getValue(),
122 m_proto.getTypeString(),
123 properties,
124 options),
125 null,
126 true);
127 }
128
146 public ProtobufEntry<T> getEntry(T defaultValue, PubSubOption... options) {
147 return new ProtobufEntryImpl<>(
148 this,
149 ProtobufBuffer.create(m_proto),
150 NetworkTablesJNI.getEntry(
151 m_handle, NetworkTableType.RAW.getValue(), m_proto.getTypeString(), options),
152 defaultValue,
153 false);
154 }
155
162 return m_proto;
163 }
164
165 @Override
166 public boolean equals(Object other) {
167 return other == this
168 || other instanceof ProtobufTopic<?> topic
169 && super.equals(topic)
170 && m_proto == topic.m_proto;
171 }
172
173 @Override
174 public int hashCode() {
175 return super.hashCode() ^ m_proto.hashCode();
176 }
177
178 private final Protobuf<T, ?> m_proto;
179}
void addSchema(String name, String type, byte[] schema)
ProtobufPublisher< T > publish(PubSubOption... options)
static< T > ProtobufTopic< T > wrap(NetworkTableInstance inst, int handle, Protobuf< T, ?> proto)
ProtobufEntry< T > getEntry(T defaultValue, PubSubOption... options)
ProtobufPublisher< T > publishEx(String properties, PubSubOption... options)
ProtobufSubscriber< T > subscribe(T defaultValue, PubSubOption... options)
static< T > ProtobufTopic< T > wrap(Topic topic, Protobuf< T, ?> proto)
final NetworkTableInstance m_inst
Definition Topic.java:333
static< T, MessageType extends ProtoMessage<?> ProtobufBuffer< T, MessageType > create(Protobuf< T, MessageType > proto)