001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004// Code generated by protocol buffer compiler. Do not edit!
005package org.wpilib.math.proto;
006
007import java.io.IOException;
008import us.hebi.quickbuf.Descriptors;
009import us.hebi.quickbuf.FieldName;
010import us.hebi.quickbuf.InvalidProtocolBufferException;
011import us.hebi.quickbuf.JsonSink;
012import us.hebi.quickbuf.JsonSource;
013import us.hebi.quickbuf.MessageFactory;
014import us.hebi.quickbuf.ProtoMessage;
015import us.hebi.quickbuf.ProtoSink;
016import us.hebi.quickbuf.ProtoSource;
017import us.hebi.quickbuf.RepeatedMessage;
018
019/**
020 * Protobuf type {@code ProtobufTrajectory}
021 */
022@SuppressWarnings("hiding")
023public final class ProtobufTrajectory extends ProtoMessage<ProtobufTrajectory> implements Cloneable {
024  private static final long serialVersionUID = 0L;
025
026  /**
027   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
028   */
029  private final RepeatedMessage<ProtobufTrajectoryState> states = RepeatedMessage.newEmptyInstance(ProtobufTrajectoryState.getFactory());
030
031  private ProtobufTrajectory() {
032  }
033
034  /**
035   * @return a new empty instance of {@code ProtobufTrajectory}
036   */
037  public static ProtobufTrajectory newInstance() {
038    return new ProtobufTrajectory();
039  }
040
041  /**
042   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
043   * @return whether the states field is set
044   */
045  public boolean hasStates() {
046    return (bitField0_ & 0x00000001) != 0;
047  }
048
049  /**
050   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
051   * @return this
052   */
053  public ProtobufTrajectory clearStates() {
054    bitField0_ &= ~0x00000001;
055    states.clear();
056    return this;
057  }
058
059  /**
060   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
061   *
062   * This method returns the internal storage object without modifying any has state.
063   * The returned object should not be modified and be treated as read-only.
064   *
065   * Use {@link #getMutableStates()} if you want to modify it.
066   *
067   * @return internal storage object for reading
068   */
069  public RepeatedMessage<ProtobufTrajectoryState> getStates() {
070    return states;
071  }
072
073  /**
074   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
075   *
076   * This method returns the internal storage object and sets the corresponding
077   * has state. The returned object will become part of this message and its
078   * contents may be modified as long as the has state is not cleared.
079   *
080   * @return internal storage object for modifications
081   */
082  public RepeatedMessage<ProtobufTrajectoryState> getMutableStates() {
083    bitField0_ |= 0x00000001;
084    return states;
085  }
086
087  /**
088   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
089   * @param value the states to add
090   * @return this
091   */
092  public ProtobufTrajectory addStates(final ProtobufTrajectoryState value) {
093    bitField0_ |= 0x00000001;
094    states.add(value);
095    return this;
096  }
097
098  /**
099   * <code>repeated .wpi.proto.ProtobufTrajectoryState states = 2;</code>
100   * @param values the states to add
101   * @return this
102   */
103  public ProtobufTrajectory addAllStates(final ProtobufTrajectoryState... values) {
104    bitField0_ |= 0x00000001;
105    states.addAll(values);
106    return this;
107  }
108
109  @Override
110  public ProtobufTrajectory copyFrom(final ProtobufTrajectory other) {
111    cachedSize = other.cachedSize;
112    if ((bitField0_ | other.bitField0_) != 0) {
113      bitField0_ = other.bitField0_;
114      states.copyFrom(other.states);
115    }
116    return this;
117  }
118
119  @Override
120  public ProtobufTrajectory mergeFrom(final ProtobufTrajectory other) {
121    if (other.isEmpty()) {
122      return this;
123    }
124    cachedSize = -1;
125    if (other.hasStates()) {
126      getMutableStates().addAll(other.states);
127    }
128    return this;
129  }
130
131  @Override
132  public ProtobufTrajectory clear() {
133    if (isEmpty()) {
134      return this;
135    }
136    cachedSize = -1;
137    bitField0_ = 0;
138    states.clear();
139    return this;
140  }
141
142  @Override
143  public ProtobufTrajectory clearQuick() {
144    if (isEmpty()) {
145      return this;
146    }
147    cachedSize = -1;
148    bitField0_ = 0;
149    states.clearQuick();
150    return this;
151  }
152
153  @Override
154  public boolean equals(Object o) {
155    if (o == this) {
156      return true;
157    }
158    if (!(o instanceof ProtobufTrajectory)) {
159      return false;
160    }
161    ProtobufTrajectory other = (ProtobufTrajectory) o;
162    return bitField0_ == other.bitField0_
163      && (!hasStates() || states.equals(other.states));
164  }
165
166  @Override
167  public void writeTo(final ProtoSink output) throws IOException {
168    if ((bitField0_ & 0x00000001) != 0) {
169      for (int i = 0; i < states.length(); i++) {
170        output.writeRawByte((byte) 18);
171        output.writeMessageNoTag(states.get(i));
172      }
173    }
174  }
175
176  @Override
177  protected int computeSerializedSize() {
178    int size = 0;
179    if ((bitField0_ & 0x00000001) != 0) {
180      size += (1 * states.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(states);
181    }
182    return size;
183  }
184
185  @Override
186  @SuppressWarnings("fallthrough")
187  public ProtobufTrajectory mergeFrom(final ProtoSource input) throws IOException {
188    // Enabled Fall-Through Optimization (QuickBuffers)
189    int tag = input.readTag();
190    while (true) {
191      switch (tag) {
192        case 18: {
193          // states
194          tag = input.readRepeatedMessage(states, tag);
195          bitField0_ |= 0x00000001;
196          if (tag != 0) {
197            break;
198          }
199        }
200        case 0: {
201          return this;
202        }
203        default: {
204          if (!input.skipField(tag)) {
205            return this;
206          }
207          tag = input.readTag();
208          break;
209        }
210      }
211    }
212  }
213
214  @Override
215  public void writeTo(final JsonSink output) throws IOException {
216    output.beginObject();
217    if ((bitField0_ & 0x00000001) != 0) {
218      output.writeRepeatedMessage(FieldNames.states, states);
219    }
220    output.endObject();
221  }
222
223  @Override
224  public ProtobufTrajectory mergeFrom(final JsonSource input) throws IOException {
225    if (!input.beginObject()) {
226      return this;
227    }
228    while (!input.isAtEnd()) {
229      switch (input.readFieldHash()) {
230        case -892482046: {
231          if (input.isAtField(FieldNames.states)) {
232            if (!input.trySkipNullValue()) {
233              input.readRepeatedMessage(states);
234              bitField0_ |= 0x00000001;
235            }
236          } else {
237            input.skipUnknownField();
238          }
239          break;
240        }
241        default: {
242          input.skipUnknownField();
243          break;
244        }
245      }
246    }
247    input.endObject();
248    return this;
249  }
250
251  @Override
252  public ProtobufTrajectory clone() {
253    return new ProtobufTrajectory().copyFrom(this);
254  }
255
256  @Override
257  public boolean isEmpty() {
258    return ((bitField0_) == 0);
259  }
260
261  public static ProtobufTrajectory parseFrom(final byte[] data) throws
262      InvalidProtocolBufferException {
263    return ProtoMessage.mergeFrom(new ProtobufTrajectory(), data).checkInitialized();
264  }
265
266  public static ProtobufTrajectory parseFrom(final ProtoSource input) throws IOException {
267    return ProtoMessage.mergeFrom(new ProtobufTrajectory(), input).checkInitialized();
268  }
269
270  public static ProtobufTrajectory parseFrom(final JsonSource input) throws IOException {
271    return ProtoMessage.mergeFrom(new ProtobufTrajectory(), input).checkInitialized();
272  }
273
274  /**
275   * @return factory for creating ProtobufTrajectory messages
276   */
277  public static MessageFactory<ProtobufTrajectory> getFactory() {
278    return ProtobufTrajectoryFactory.INSTANCE;
279  }
280
281  /**
282   * @return this type's descriptor.
283   */
284  public static Descriptors.Descriptor getDescriptor() {
285    return ProtobufTrajectoryDescriptor.wpi_proto_ProtobufTrajectory_descriptor;
286  }
287
288  private enum ProtobufTrajectoryFactory implements MessageFactory<ProtobufTrajectory> {
289    INSTANCE;
290
291    @Override
292    public ProtobufTrajectory create() {
293      return ProtobufTrajectory.newInstance();
294    }
295  }
296
297  /**
298   * Contains name constants used for serializing JSON
299   */
300  static class FieldNames {
301    static final FieldName states = FieldName.forField("states");
302  }
303}