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.RepeatedDouble; 018 019/** 020 * Protobuf type {@code ProtobufMatrix} 021 */ 022@SuppressWarnings("hiding") 023public final class ProtobufMatrix extends ProtoMessage<ProtobufMatrix> implements Cloneable { 024 private static final long serialVersionUID = 0L; 025 026 /** 027 * <code>optional uint32 num_rows = 1;</code> 028 */ 029 private int numRows; 030 031 /** 032 * <code>optional uint32 num_cols = 2;</code> 033 */ 034 private int numCols; 035 036 /** 037 * <code>repeated double data = 3;</code> 038 */ 039 private final RepeatedDouble data = RepeatedDouble.newEmptyInstance(); 040 041 private ProtobufMatrix() { 042 } 043 044 /** 045 * @return a new empty instance of {@code ProtobufMatrix} 046 */ 047 public static ProtobufMatrix newInstance() { 048 return new ProtobufMatrix(); 049 } 050 051 /** 052 * <code>optional uint32 num_rows = 1;</code> 053 * @return whether the numRows field is set 054 */ 055 public boolean hasNumRows() { 056 return (bitField0_ & 0x00000001) != 0; 057 } 058 059 /** 060 * <code>optional uint32 num_rows = 1;</code> 061 * @return this 062 */ 063 public ProtobufMatrix clearNumRows() { 064 bitField0_ &= ~0x00000001; 065 numRows = 0; 066 return this; 067 } 068 069 /** 070 * <code>optional uint32 num_rows = 1;</code> 071 * @return the numRows 072 */ 073 public int getNumRows() { 074 return numRows; 075 } 076 077 /** 078 * <code>optional uint32 num_rows = 1;</code> 079 * @param value the numRows to set 080 * @return this 081 */ 082 public ProtobufMatrix setNumRows(final int value) { 083 bitField0_ |= 0x00000001; 084 numRows = value; 085 return this; 086 } 087 088 /** 089 * <code>optional uint32 num_cols = 2;</code> 090 * @return whether the numCols field is set 091 */ 092 public boolean hasNumCols() { 093 return (bitField0_ & 0x00000002) != 0; 094 } 095 096 /** 097 * <code>optional uint32 num_cols = 2;</code> 098 * @return this 099 */ 100 public ProtobufMatrix clearNumCols() { 101 bitField0_ &= ~0x00000002; 102 numCols = 0; 103 return this; 104 } 105 106 /** 107 * <code>optional uint32 num_cols = 2;</code> 108 * @return the numCols 109 */ 110 public int getNumCols() { 111 return numCols; 112 } 113 114 /** 115 * <code>optional uint32 num_cols = 2;</code> 116 * @param value the numCols to set 117 * @return this 118 */ 119 public ProtobufMatrix setNumCols(final int value) { 120 bitField0_ |= 0x00000002; 121 numCols = value; 122 return this; 123 } 124 125 /** 126 * <code>repeated double data = 3;</code> 127 * @return whether the data field is set 128 */ 129 public boolean hasData() { 130 return (bitField0_ & 0x00000004) != 0; 131 } 132 133 /** 134 * <code>repeated double data = 3;</code> 135 * @return this 136 */ 137 public ProtobufMatrix clearData() { 138 bitField0_ &= ~0x00000004; 139 data.clear(); 140 return this; 141 } 142 143 /** 144 * <code>repeated double data = 3;</code> 145 * 146 * This method returns the internal storage object without modifying any has state. 147 * The returned object should not be modified and be treated as read-only. 148 * 149 * Use {@link #getMutableData()} if you want to modify it. 150 * 151 * @return internal storage object for reading 152 */ 153 public RepeatedDouble getData() { 154 return data; 155 } 156 157 /** 158 * <code>repeated double data = 3;</code> 159 * 160 * This method returns the internal storage object and sets the corresponding 161 * has state. The returned object will become part of this message and its 162 * contents may be modified as long as the has state is not cleared. 163 * 164 * @return internal storage object for modifications 165 */ 166 public RepeatedDouble getMutableData() { 167 bitField0_ |= 0x00000004; 168 return data; 169 } 170 171 /** 172 * <code>repeated double data = 3;</code> 173 * @param value the data to add 174 * @return this 175 */ 176 public ProtobufMatrix addData(final double value) { 177 bitField0_ |= 0x00000004; 178 data.add(value); 179 return this; 180 } 181 182 /** 183 * <code>repeated double data = 3;</code> 184 * @param values the data to add 185 * @return this 186 */ 187 public ProtobufMatrix addAllData(final double... values) { 188 bitField0_ |= 0x00000004; 189 data.addAll(values); 190 return this; 191 } 192 193 @Override 194 public ProtobufMatrix copyFrom(final ProtobufMatrix other) { 195 cachedSize = other.cachedSize; 196 if ((bitField0_ | other.bitField0_) != 0) { 197 bitField0_ = other.bitField0_; 198 numRows = other.numRows; 199 numCols = other.numCols; 200 data.copyFrom(other.data); 201 } 202 return this; 203 } 204 205 @Override 206 public ProtobufMatrix mergeFrom(final ProtobufMatrix other) { 207 if (other.isEmpty()) { 208 return this; 209 } 210 cachedSize = -1; 211 if (other.hasNumRows()) { 212 setNumRows(other.numRows); 213 } 214 if (other.hasNumCols()) { 215 setNumCols(other.numCols); 216 } 217 if (other.hasData()) { 218 getMutableData().addAll(other.data); 219 } 220 return this; 221 } 222 223 @Override 224 public ProtobufMatrix clear() { 225 if (isEmpty()) { 226 return this; 227 } 228 cachedSize = -1; 229 bitField0_ = 0; 230 numRows = 0; 231 numCols = 0; 232 data.clear(); 233 return this; 234 } 235 236 @Override 237 public ProtobufMatrix clearQuick() { 238 if (isEmpty()) { 239 return this; 240 } 241 cachedSize = -1; 242 bitField0_ = 0; 243 data.clear(); 244 return this; 245 } 246 247 @Override 248 public boolean equals(Object o) { 249 if (o == this) { 250 return true; 251 } 252 if (!(o instanceof ProtobufMatrix)) { 253 return false; 254 } 255 ProtobufMatrix other = (ProtobufMatrix) o; 256 return bitField0_ == other.bitField0_ 257 && (!hasNumRows() || numRows == other.numRows) 258 && (!hasNumCols() || numCols == other.numCols) 259 && (!hasData() || data.equals(other.data)); 260 } 261 262 @Override 263 public void writeTo(final ProtoSink output) throws IOException { 264 if ((bitField0_ & 0x00000001) != 0) { 265 output.writeRawByte((byte) 8); 266 output.writeUInt32NoTag(numRows); 267 } 268 if ((bitField0_ & 0x00000002) != 0) { 269 output.writeRawByte((byte) 16); 270 output.writeUInt32NoTag(numCols); 271 } 272 if ((bitField0_ & 0x00000004) != 0) { 273 for (int i = 0; i < data.length(); i++) { 274 output.writeRawByte((byte) 25); 275 output.writeDoubleNoTag(data.array()[i]); 276 } 277 } 278 } 279 280 @Override 281 protected int computeSerializedSize() { 282 int size = 0; 283 if ((bitField0_ & 0x00000001) != 0) { 284 size += 1 + ProtoSink.computeUInt32SizeNoTag(numRows); 285 } 286 if ((bitField0_ & 0x00000002) != 0) { 287 size += 1 + ProtoSink.computeUInt32SizeNoTag(numCols); 288 } 289 if ((bitField0_ & 0x00000004) != 0) { 290 size += (1 + 8) * data.length(); 291 } 292 return size; 293 } 294 295 @Override 296 @SuppressWarnings("fallthrough") 297 public ProtobufMatrix mergeFrom(final ProtoSource input) throws IOException { 298 // Enabled Fall-Through Optimization (QuickBuffers) 299 int tag = input.readTag(); 300 while (true) { 301 switch (tag) { 302 case 8: { 303 // numRows 304 numRows = input.readUInt32(); 305 bitField0_ |= 0x00000001; 306 tag = input.readTag(); 307 if (tag != 16) { 308 break; 309 } 310 } 311 case 16: { 312 // numCols 313 numCols = input.readUInt32(); 314 bitField0_ |= 0x00000002; 315 tag = input.readTag(); 316 if (tag != 26) { 317 break; 318 } 319 } 320 case 26: { 321 // data [packed=true] 322 input.readPackedDouble(data); 323 bitField0_ |= 0x00000004; 324 tag = input.readTag(); 325 if (tag != 0) { 326 break; 327 } 328 } 329 case 0: { 330 return this; 331 } 332 default: { 333 if (!input.skipField(tag)) { 334 return this; 335 } 336 tag = input.readTag(); 337 break; 338 } 339 case 25: { 340 // data [packed=false] 341 tag = input.readRepeatedDouble(data, tag); 342 bitField0_ |= 0x00000004; 343 break; 344 } 345 } 346 } 347 } 348 349 @Override 350 public void writeTo(final JsonSink output) throws IOException { 351 output.beginObject(); 352 if ((bitField0_ & 0x00000001) != 0) { 353 output.writeUInt32(FieldNames.numRows, numRows); 354 } 355 if ((bitField0_ & 0x00000002) != 0) { 356 output.writeUInt32(FieldNames.numCols, numCols); 357 } 358 if ((bitField0_ & 0x00000004) != 0) { 359 output.writeRepeatedDouble(FieldNames.data, data); 360 } 361 output.endObject(); 362 } 363 364 @Override 365 public ProtobufMatrix mergeFrom(final JsonSource input) throws IOException { 366 if (!input.beginObject()) { 367 return this; 368 } 369 while (!input.isAtEnd()) { 370 switch (input.readFieldHash()) { 371 case -2000982401: 372 case -1888824590: { 373 if (input.isAtField(FieldNames.numRows)) { 374 if (!input.trySkipNullValue()) { 375 numRows = input.readUInt32(); 376 bitField0_ |= 0x00000001; 377 } 378 } else { 379 input.skipUnknownField(); 380 } 381 break; 382 } 383 case -2001429607: 384 case -1889271796: { 385 if (input.isAtField(FieldNames.numCols)) { 386 if (!input.trySkipNullValue()) { 387 numCols = input.readUInt32(); 388 bitField0_ |= 0x00000002; 389 } 390 } else { 391 input.skipUnknownField(); 392 } 393 break; 394 } 395 case 3076010: { 396 if (input.isAtField(FieldNames.data)) { 397 if (!input.trySkipNullValue()) { 398 input.readRepeatedDouble(data); 399 bitField0_ |= 0x00000004; 400 } 401 } else { 402 input.skipUnknownField(); 403 } 404 break; 405 } 406 default: { 407 input.skipUnknownField(); 408 break; 409 } 410 } 411 } 412 input.endObject(); 413 return this; 414 } 415 416 @Override 417 public ProtobufMatrix clone() { 418 return new ProtobufMatrix().copyFrom(this); 419 } 420 421 @Override 422 public boolean isEmpty() { 423 return ((bitField0_) == 0); 424 } 425 426 public static ProtobufMatrix parseFrom(final byte[] data) throws InvalidProtocolBufferException { 427 return ProtoMessage.mergeFrom(new ProtobufMatrix(), data).checkInitialized(); 428 } 429 430 public static ProtobufMatrix parseFrom(final ProtoSource input) throws IOException { 431 return ProtoMessage.mergeFrom(new ProtobufMatrix(), input).checkInitialized(); 432 } 433 434 public static ProtobufMatrix parseFrom(final JsonSource input) throws IOException { 435 return ProtoMessage.mergeFrom(new ProtobufMatrix(), input).checkInitialized(); 436 } 437 438 /** 439 * @return factory for creating ProtobufMatrix messages 440 */ 441 public static MessageFactory<ProtobufMatrix> getFactory() { 442 return ProtobufMatrixFactory.INSTANCE; 443 } 444 445 /** 446 * @return this type's descriptor. 447 */ 448 public static Descriptors.Descriptor getDescriptor() { 449 return ProtobufWPIMathDescriptor.wpi_proto_ProtobufMatrix_descriptor; 450 } 451 452 private enum ProtobufMatrixFactory implements MessageFactory<ProtobufMatrix> { 453 INSTANCE; 454 455 @Override 456 public ProtobufMatrix create() { 457 return ProtobufMatrix.newInstance(); 458 } 459 } 460 461 /** 462 * Contains name constants used for serializing JSON 463 */ 464 static class FieldNames { 465 static final FieldName numRows = FieldName.forField("numRows", "num_rows"); 466 467 static final FieldName numCols = FieldName.forField("numCols", "num_cols"); 468 469 static final FieldName data = FieldName.forField("data"); 470 } 471}