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.ProtoUtil;
018
019/**
020 * Protobuf type {@code ProtobufTranslation2d}
021 */
022@SuppressWarnings("hiding")
023public final class ProtobufTranslation2d extends ProtoMessage<ProtobufTranslation2d> implements Cloneable {
024  private static final long serialVersionUID = 0L;
025
026  /**
027   * <code>optional double x = 1;</code>
028   */
029  private double x;
030
031  /**
032   * <code>optional double y = 2;</code>
033   */
034  private double y;
035
036  private ProtobufTranslation2d() {
037  }
038
039  /**
040   * @return a new empty instance of {@code ProtobufTranslation2d}
041   */
042  public static ProtobufTranslation2d newInstance() {
043    return new ProtobufTranslation2d();
044  }
045
046  /**
047   * <code>optional double x = 1;</code>
048   * @return whether the x field is set
049   */
050  public boolean hasX() {
051    return (bitField0_ & 0x00000001) != 0;
052  }
053
054  /**
055   * <code>optional double x = 1;</code>
056   * @return this
057   */
058  public ProtobufTranslation2d clearX() {
059    bitField0_ &= ~0x00000001;
060    x = 0D;
061    return this;
062  }
063
064  /**
065   * <code>optional double x = 1;</code>
066   * @return the x
067   */
068  public double getX() {
069    return x;
070  }
071
072  /**
073   * <code>optional double x = 1;</code>
074   * @param value the x to set
075   * @return this
076   */
077  public ProtobufTranslation2d setX(final double value) {
078    bitField0_ |= 0x00000001;
079    x = value;
080    return this;
081  }
082
083  /**
084   * <code>optional double y = 2;</code>
085   * @return whether the y field is set
086   */
087  public boolean hasY() {
088    return (bitField0_ & 0x00000002) != 0;
089  }
090
091  /**
092   * <code>optional double y = 2;</code>
093   * @return this
094   */
095  public ProtobufTranslation2d clearY() {
096    bitField0_ &= ~0x00000002;
097    y = 0D;
098    return this;
099  }
100
101  /**
102   * <code>optional double y = 2;</code>
103   * @return the y
104   */
105  public double getY() {
106    return y;
107  }
108
109  /**
110   * <code>optional double y = 2;</code>
111   * @param value the y to set
112   * @return this
113   */
114  public ProtobufTranslation2d setY(final double value) {
115    bitField0_ |= 0x00000002;
116    y = value;
117    return this;
118  }
119
120  @Override
121  public ProtobufTranslation2d copyFrom(final ProtobufTranslation2d other) {
122    cachedSize = other.cachedSize;
123    if ((bitField0_ | other.bitField0_) != 0) {
124      bitField0_ = other.bitField0_;
125      x = other.x;
126      y = other.y;
127    }
128    return this;
129  }
130
131  @Override
132  public ProtobufTranslation2d mergeFrom(final ProtobufTranslation2d other) {
133    if (other.isEmpty()) {
134      return this;
135    }
136    cachedSize = -1;
137    if (other.hasX()) {
138      setX(other.x);
139    }
140    if (other.hasY()) {
141      setY(other.y);
142    }
143    return this;
144  }
145
146  @Override
147  public ProtobufTranslation2d clear() {
148    if (isEmpty()) {
149      return this;
150    }
151    cachedSize = -1;
152    bitField0_ = 0;
153    x = 0D;
154    y = 0D;
155    return this;
156  }
157
158  @Override
159  public ProtobufTranslation2d clearQuick() {
160    if (isEmpty()) {
161      return this;
162    }
163    cachedSize = -1;
164    bitField0_ = 0;
165    return this;
166  }
167
168  @Override
169  public boolean equals(Object o) {
170    if (o == this) {
171      return true;
172    }
173    if (!(o instanceof ProtobufTranslation2d)) {
174      return false;
175    }
176    ProtobufTranslation2d other = (ProtobufTranslation2d) o;
177    return bitField0_ == other.bitField0_
178      && (!hasX() || ProtoUtil.isEqual(x, other.x))
179      && (!hasY() || ProtoUtil.isEqual(y, other.y));
180  }
181
182  @Override
183  public void writeTo(final ProtoSink output) throws IOException {
184    if ((bitField0_ & 0x00000001) != 0) {
185      output.writeRawByte((byte) 9);
186      output.writeDoubleNoTag(x);
187    }
188    if ((bitField0_ & 0x00000002) != 0) {
189      output.writeRawByte((byte) 17);
190      output.writeDoubleNoTag(y);
191    }
192  }
193
194  @Override
195  protected int computeSerializedSize() {
196    int size = 0;
197    if ((bitField0_ & 0x00000001) != 0) {
198      size += 9;
199    }
200    if ((bitField0_ & 0x00000002) != 0) {
201      size += 9;
202    }
203    return size;
204  }
205
206  @Override
207  @SuppressWarnings("fallthrough")
208  public ProtobufTranslation2d mergeFrom(final ProtoSource input) throws IOException {
209    // Enabled Fall-Through Optimization (QuickBuffers)
210    int tag = input.readTag();
211    while (true) {
212      switch (tag) {
213        case 9: {
214          // x
215          x = input.readDouble();
216          bitField0_ |= 0x00000001;
217          tag = input.readTag();
218          if (tag != 17) {
219            break;
220          }
221        }
222        case 17: {
223          // y
224          y = input.readDouble();
225          bitField0_ |= 0x00000002;
226          tag = input.readTag();
227          if (tag != 0) {
228            break;
229          }
230        }
231        case 0: {
232          return this;
233        }
234        default: {
235          if (!input.skipField(tag)) {
236            return this;
237          }
238          tag = input.readTag();
239          break;
240        }
241      }
242    }
243  }
244
245  @Override
246  public void writeTo(final JsonSink output) throws IOException {
247    output.beginObject();
248    if ((bitField0_ & 0x00000001) != 0) {
249      output.writeDouble(FieldNames.x, x);
250    }
251    if ((bitField0_ & 0x00000002) != 0) {
252      output.writeDouble(FieldNames.y, y);
253    }
254    output.endObject();
255  }
256
257  @Override
258  public ProtobufTranslation2d mergeFrom(final JsonSource input) throws IOException {
259    if (!input.beginObject()) {
260      return this;
261    }
262    while (!input.isAtEnd()) {
263      switch (input.readFieldHash()) {
264        case 120: {
265          if (input.isAtField(FieldNames.x)) {
266            if (!input.trySkipNullValue()) {
267              x = input.readDouble();
268              bitField0_ |= 0x00000001;
269            }
270          } else {
271            input.skipUnknownField();
272          }
273          break;
274        }
275        case 121: {
276          if (input.isAtField(FieldNames.y)) {
277            if (!input.trySkipNullValue()) {
278              y = input.readDouble();
279              bitField0_ |= 0x00000002;
280            }
281          } else {
282            input.skipUnknownField();
283          }
284          break;
285        }
286        default: {
287          input.skipUnknownField();
288          break;
289        }
290      }
291    }
292    input.endObject();
293    return this;
294  }
295
296  @Override
297  public ProtobufTranslation2d clone() {
298    return new ProtobufTranslation2d().copyFrom(this);
299  }
300
301  @Override
302  public boolean isEmpty() {
303    return ((bitField0_) == 0);
304  }
305
306  public static ProtobufTranslation2d parseFrom(final byte[] data) throws
307      InvalidProtocolBufferException {
308    return ProtoMessage.mergeFrom(new ProtobufTranslation2d(), data).checkInitialized();
309  }
310
311  public static ProtobufTranslation2d parseFrom(final ProtoSource input) throws IOException {
312    return ProtoMessage.mergeFrom(new ProtobufTranslation2d(), input).checkInitialized();
313  }
314
315  public static ProtobufTranslation2d parseFrom(final JsonSource input) throws IOException {
316    return ProtoMessage.mergeFrom(new ProtobufTranslation2d(), input).checkInitialized();
317  }
318
319  /**
320   * @return factory for creating ProtobufTranslation2d messages
321   */
322  public static MessageFactory<ProtobufTranslation2d> getFactory() {
323    return ProtobufTranslation2dFactory.INSTANCE;
324  }
325
326  /**
327   * @return this type's descriptor.
328   */
329  public static Descriptors.Descriptor getDescriptor() {
330    return ProtobufGeometry2dDescriptor.wpi_proto_ProtobufTranslation2d_descriptor;
331  }
332
333  private enum ProtobufTranslation2dFactory implements MessageFactory<ProtobufTranslation2d> {
334    INSTANCE;
335
336    @Override
337    public ProtobufTranslation2d create() {
338      return ProtobufTranslation2d.newInstance();
339    }
340  }
341
342  /**
343   * Contains name constants used for serializing JSON
344   */
345  static class FieldNames {
346    static final FieldName x = FieldName.forField("x");
347
348    static final FieldName y = FieldName.forField("y");
349  }
350}