From f0be729ec539052cbd3b3fe92b528ab8bbbcb14d Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 2 Jan 2024 07:11:23 -0500 Subject: [PATCH] Add proto for Mechanism2d classes --- .github/workflows/pregenerate.yml | 2 + wpilibj/build.gradle | 1 + wpilibj/generate_quickbuf.py | 33 + .../wpi/first/wpilibj/proto/Mechanism2D.java | 1766 +++++++++++++++++ .../smartdashboard/MechanismObject2d.java | 4 + .../proto/MechanismLigament2dProto.java | 50 + wpilibj/src/main/proto/mechanism2d.proto | 28 + 7 files changed, 1884 insertions(+) create mode 100755 wpilibj/generate_quickbuf.py create mode 100644 wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/proto/Mechanism2D.java create mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/proto/MechanismLigament2dProto.java create mode 100644 wpilibj/src/main/proto/mechanism2d.proto diff --git a/.github/workflows/pregenerate.yml b/.github/workflows/pregenerate.yml index fb851492514..d528793337b 100644 --- a/.github/workflows/pregenerate.yml +++ b/.github/workflows/pregenerate.yml @@ -30,6 +30,8 @@ jobs: run: ./hal/generate_usage_reporting.py - name: Run ntcore run: ./ntcore/generate_topics.py + - name: Run wpilibj + run: ./wpilibj/generate_quickbuf.py protoc protoc-gen-quickbuf-1.3.3-linux-x86_64.exe - name: Run wpimath run: ./wpimath/generate_numbers.py && ./wpimath/generate_quickbuf.py protoc protoc-gen-quickbuf-1.3.3-linux-x86_64.exe - name: Add untracked files to index so they count as changes diff --git a/wpilibj/build.gradle b/wpilibj/build.gradle index b31630e70ea..b7f60bd232b 100644 --- a/wpilibj/build.gradle +++ b/wpilibj/build.gradle @@ -49,6 +49,7 @@ gradle.taskGraph.addTaskExecutionGraphListener { graph -> } } +sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" sourceSets.main.java.srcDir "${buildDir}/generated/java/" compileJava { diff --git a/wpilibj/generate_quickbuf.py b/wpilibj/generate_quickbuf.py new file mode 100755 index 00000000000..0b609bb447b --- /dev/null +++ b/wpilibj/generate_quickbuf.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +# Copyright (c) FIRST and other WPILib contributors. +# Open Source Software; you can modify and/or share it under the terms of +# the WPILib BSD license file in the root directory of this project. +import os.path +import subprocess +import sys +from glob import glob + +if __name__ == "__main__": + proto_files = glob("wpilibj/src/main/proto/*.proto") + for path in proto_files: + absolute_filename = os.path.abspath(path) + absolute_dir, filename = os.path.split(absolute_filename) + subprocess.run( + [ + sys.argv[1], + f"--plugin=protoc-gen-quickbuf={sys.argv[2]}", + f"--quickbuf_out=allocation=lazymsg,gen_descriptors=true:{os.path.abspath('./wpilibj/src/generated/main/java')}", + f"-I{absolute_dir}", + absolute_filename, + ] + ) + java_files = glob("wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/proto/*.java") + for java_file in java_files: + with open(java_file) as file: + content = file.read() + with open(java_file, "tw") as file: + file.write( + "// Copyright (c) FIRST and other WPILib contributors.\n// Open Source Software; you can modify and/or share it under the terms of\n// the WPILib BSD license file in the root directory of this project.\n" + + content + ) diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/proto/Mechanism2D.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/proto/Mechanism2D.java new file mode 100644 index 00000000000..60e1c52a99a --- /dev/null +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/proto/Mechanism2D.java @@ -0,0 +1,1766 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. +// Code generated by protocol buffer compiler. Do not edit! +package edu.wpi.first.wpilibj.proto; + +import java.io.IOException; +import us.hebi.quickbuf.Descriptors; +import us.hebi.quickbuf.FieldName; +import us.hebi.quickbuf.InvalidProtocolBufferException; +import us.hebi.quickbuf.JsonSink; +import us.hebi.quickbuf.JsonSource; +import us.hebi.quickbuf.MessageFactory; +import us.hebi.quickbuf.ProtoMessage; +import us.hebi.quickbuf.ProtoSink; +import us.hebi.quickbuf.ProtoSource; +import us.hebi.quickbuf.ProtoUtil; +import us.hebi.quickbuf.RepeatedByte; +import us.hebi.quickbuf.RepeatedMessage; +import us.hebi.quickbuf.Utf8String; + +public final class Mechanism2D { + private static final RepeatedByte descriptorData = ProtoUtil.decodeBase64(1346, + "ChFtZWNoYW5pc20yZC5wcm90bxIJd3BpLnByb3RvInsKF1Byb3RvYnVmTWVjaGFuaXNtUm9vdDJkEgwK" + + "AXgYASABKAFSAXgSDAoBeRgCIAEoAVIBeRJECglsaWdhbWVudHMYAyADKAsyJi53cGkucHJvdG8uUHJv" + + "dG9idWZNZWNoYW5pc21MaWdhbWVudDJkUglsaWdhbWVudHMivwEKG1Byb3RvYnVmTWVjaGFuaXNtTGln" + + "YW1lbnQyZBIUCgVhbmdsZRgBIAEoAVIFYW5nbGUSFAoFY29sb3IYAiABKAlSBWNvbG9yEhYKBmxlbmd0" + + "aBgDIAEoAVIGbGVuZ3RoEhYKBndlaWdodBgEIAEoAVIGd2VpZ2h0EkQKCWxpZ2FtZW50cxgFIAMoCzIm" + + "LndwaS5wcm90by5Qcm90b2J1Zk1lY2hhbmlzbUxpZ2FtZW50MmRSCWxpZ2FtZW50cyKBAQoTUHJvdG9i" + + "dWZNZWNoYW5pc20yZBIMCgF4GAEgASgBUgF4EgwKAXkYAiABKAFSAXkSFAoFY29sb3IYAyABKAlSBWNv" + + "bG9yEjgKBXJvb3RzGAQgAygLMiIud3BpLnByb3RvLlByb3RvYnVmTWVjaGFuaXNtUm9vdDJkUgVyb290" + + "c0IdChtlZHUud3BpLmZpcnN0LndwaWxpYmoucHJvdG9KtwYKBhIEAAAZAQoICgEMEgMAABIKCAoBAhID" + + "AgASCggKAQgSAwQANAoJCgIIARIDBAA0CgoKAgQAEgQGAAoBCgoKAwQAARIDBggfCgsKBAQAAgASAwcE" + + "EQoMCgUEAAIABRIDBwQKCgwKBQQAAgABEgMHCwwKDAoFBAACAAMSAwcPEAoLCgQEAAIBEgMIBBEKDAoF" + + "BAACAQUSAwgECgoMCgUEAAIBARIDCAsMCgwKBQQAAgEDEgMIDxAKCwoEBAACAhIDCQQ3CgwKBQQAAgIE" + + "EgMJBAwKDAoFBAACAgYSAwkNKAoMCgUEAAICARIDCSkyCgwKBQQAAgIDEgMJNTYKCgoCBAESBAwAEgEK" + + "CgoDBAEBEgMMCCMKCwoEBAECABIDDQQVCgwKBQQBAgAFEgMNBAoKDAoFBAECAAESAw0LEAoMCgUEAQIA" + + "AxIDDRMUCgsKBAQBAgESAw4EFQoMCgUEAQIBBRIDDgQKCgwKBQQBAgEBEgMOCxAKDAoFBAECAQMSAw4T" + + "FAoLCgQEAQICEgMPBBYKDAoFBAECAgUSAw8ECgoMCgUEAQICARIDDwsRCgwKBQQBAgIDEgMPFBUKCwoE" + + "BAECAxIDEAQWCgwKBQQBAgMFEgMQBAoKDAoFBAECAwESAxALEQoMCgUEAQIDAxIDEBQVCgsKBAQBAgQS" + + "AxEENwoMCgUEAQIEBBIDEQQMCgwKBQQBAgQGEgMRDSgKDAoFBAECBAESAxEpMgoMCgUEAQIEAxIDETU2" + + "CgoKAgQCEgQUABkBCgoKAwQCARIDFAgbCgsKBAQCAgASAxUEEQoMCgUEAgIABRIDFQQKCgwKBQQCAgAB" + + "EgMVCwwKDAoFBAICAAMSAxUPEAoLCgQEAgIBEgMWBBEKDAoFBAICAQUSAxYECgoMCgUEAgIBARIDFgsM", + "CgwKBQQCAgEDEgMWDxAKCwoEBAICAhIDFwQVCgwKBQQCAgIFEgMXBAoKDAoFBAICAgESAxcLEAoMCgUE" + + "AgICAxIDFxMUCgsKBAQCAgMSAxgELwoMCgUEAgIDBBIDGAQMCgwKBQQCAgMGEgMYDSQKDAoFBAICAwES" + + "AxglKgoMCgUEAgIDAxIDGC0uYgZwcm90bzM="); + + static final Descriptors.FileDescriptor descriptor = Descriptors.FileDescriptor.internalBuildGeneratedFileFrom("mechanism2d.proto", "wpi.proto", descriptorData); + + static final Descriptors.Descriptor wpi_proto_ProtobufMechanismRoot2d_descriptor = descriptor.internalContainedType(32, 123, "ProtobufMechanismRoot2d", "wpi.proto.ProtobufMechanismRoot2d"); + + static final Descriptors.Descriptor wpi_proto_ProtobufMechanismLigament2d_descriptor = descriptor.internalContainedType(158, 191, "ProtobufMechanismLigament2d", "wpi.proto.ProtobufMechanismLigament2d"); + + static final Descriptors.Descriptor wpi_proto_ProtobufMechanism2d_descriptor = descriptor.internalContainedType(352, 129, "ProtobufMechanism2d", "wpi.proto.ProtobufMechanism2d"); + + /** + * @return this proto file's descriptor. + */ + public static Descriptors.FileDescriptor getDescriptor() { + return descriptor; + } + + /** + * Protobuf type {@code ProtobufMechanismRoot2d} + */ + public static final class ProtobufMechanismRoot2d extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional double x = 1; + */ + private double x; + + /** + * optional double y = 2; + */ + private double y; + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + */ + private RepeatedMessage ligaments = null; + + private ProtobufMechanismRoot2d() { + } + + /** + * @return a new empty instance of {@code ProtobufMechanismRoot2d} + */ + public static ProtobufMechanismRoot2d newInstance() { + return new ProtobufMechanismRoot2d(); + } + + /** + * optional double x = 1; + * @return whether the x field is set + */ + public boolean hasX() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional double x = 1; + * @return this + */ + public ProtobufMechanismRoot2d clearX() { + bitField0_ &= ~0x00000001; + x = 0D; + return this; + } + + /** + * optional double x = 1; + * @return the x + */ + public double getX() { + return x; + } + + /** + * optional double x = 1; + * @param value the x to set + * @return this + */ + public ProtobufMechanismRoot2d setX(final double value) { + bitField0_ |= 0x00000001; + x = value; + return this; + } + + /** + * optional double y = 2; + * @return whether the y field is set + */ + public boolean hasY() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional double y = 2; + * @return this + */ + public ProtobufMechanismRoot2d clearY() { + bitField0_ &= ~0x00000002; + y = 0D; + return this; + } + + /** + * optional double y = 2; + * @return the y + */ + public double getY() { + return y; + } + + /** + * optional double y = 2; + * @param value the y to set + * @return this + */ + public ProtobufMechanismRoot2d setY(final double value) { + bitField0_ |= 0x00000002; + y = value; + return this; + } + + private void initLigaments() { + if (ligaments == null) { + ligaments = RepeatedMessage.newEmptyInstance(ProtobufMechanismLigament2d.getFactory()); + } + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + * @return whether the ligaments field is set + */ + public boolean hasLigaments() { + return (bitField0_ & 0x00000004) != 0; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + * @return this + */ + public ProtobufMechanismRoot2d clearLigaments() { + bitField0_ &= ~0x00000004; + if (ligaments != null) { + ligaments.clear(); + } + return this; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableLigaments()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedMessage getLigaments() { + initLigaments(); + return ligaments; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public RepeatedMessage getMutableLigaments() { + initLigaments(); + bitField0_ |= 0x00000004; + return ligaments; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + * @param value the ligaments to add + * @return this + */ + public ProtobufMechanismRoot2d addLigaments(final ProtobufMechanismLigament2d value) { + initLigaments(); + bitField0_ |= 0x00000004; + ligaments.add(value); + return this; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 3; + * @param values the ligaments to add + * @return this + */ + public ProtobufMechanismRoot2d addAllLigaments(final ProtobufMechanismLigament2d... values) { + initLigaments(); + bitField0_ |= 0x00000004; + ligaments.addAll(values); + return this; + } + + @Override + public ProtobufMechanismRoot2d copyFrom(final ProtobufMechanismRoot2d other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + x = other.x; + y = other.y; + if (other.hasLigaments()) { + initLigaments(); + ligaments.copyFrom(other.ligaments); + } else { + clearLigaments(); + } + } + return this; + } + + @Override + public ProtobufMechanismRoot2d mergeFrom(final ProtobufMechanismRoot2d other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasX()) { + setX(other.x); + } + if (other.hasY()) { + setY(other.y); + } + if (other.hasLigaments()) { + getMutableLigaments().addAll(other.ligaments); + } + return this; + } + + @Override + public ProtobufMechanismRoot2d clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + x = 0D; + y = 0D; + if (ligaments != null) { + ligaments.clear(); + } + return this; + } + + @Override + public ProtobufMechanismRoot2d clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + if (ligaments != null) { + ligaments.clearQuick(); + } + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof ProtobufMechanismRoot2d)) { + return false; + } + ProtobufMechanismRoot2d other = (ProtobufMechanismRoot2d) o; + return bitField0_ == other.bitField0_ + && (!hasX() || ProtoUtil.isEqual(x, other.x)) + && (!hasY() || ProtoUtil.isEqual(y, other.y)) + && (!hasLigaments() || ligaments.equals(other.ligaments)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 9); + output.writeDoubleNoTag(x); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 17); + output.writeDoubleNoTag(y); + } + if ((bitField0_ & 0x00000004) != 0) { + for (int i = 0; i < ligaments.length(); i++) { + output.writeRawByte((byte) 26); + output.writeMessageNoTag(ligaments.get(i)); + } + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000002) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000004) != 0) { + size += (1 * ligaments.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(ligaments); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public ProtobufMechanismRoot2d mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 9: { + // x + x = input.readDouble(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 17) { + break; + } + } + case 17: { + // y + y = input.readDouble(); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 26) { + break; + } + } + case 26: { + // ligaments + initLigaments(); + tag = input.readRepeatedMessage(ligaments, tag); + bitField0_ |= 0x00000004; + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeDouble(FieldNames.x, x); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeDouble(FieldNames.y, y); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeRepeatedMessage(FieldNames.ligaments, ligaments); + } + output.endObject(); + } + + @Override + public ProtobufMechanismRoot2d mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 120: { + if (input.isAtField(FieldNames.x)) { + if (!input.trySkipNullValue()) { + x = input.readDouble(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case 121: { + if (input.isAtField(FieldNames.y)) { + if (!input.trySkipNullValue()) { + y = input.readDouble(); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + case 479313438: { + if (input.isAtField(FieldNames.ligaments)) { + if (!input.trySkipNullValue()) { + initLigaments(); + input.readRepeatedMessage(ligaments); + bitField0_ |= 0x00000004; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public ProtobufMechanismRoot2d clone() { + return new ProtobufMechanismRoot2d().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static ProtobufMechanismRoot2d parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new ProtobufMechanismRoot2d(), data).checkInitialized(); + } + + public static ProtobufMechanismRoot2d parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new ProtobufMechanismRoot2d(), input).checkInitialized(); + } + + public static ProtobufMechanismRoot2d parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new ProtobufMechanismRoot2d(), input).checkInitialized(); + } + + /** + * @return factory for creating ProtobufMechanismRoot2d messages + */ + public static MessageFactory getFactory() { + return ProtobufMechanismRoot2dFactory.INSTANCE; + } + + /** + * @return this type's descriptor. + */ + public static Descriptors.Descriptor getDescriptor() { + return Mechanism2D.wpi_proto_ProtobufMechanismRoot2d_descriptor; + } + + private enum ProtobufMechanismRoot2dFactory implements MessageFactory { + INSTANCE; + + @Override + public ProtobufMechanismRoot2d create() { + return ProtobufMechanismRoot2d.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName x = FieldName.forField("x"); + + static final FieldName y = FieldName.forField("y"); + + static final FieldName ligaments = FieldName.forField("ligaments"); + } + } + + /** + * Protobuf type {@code ProtobufMechanismLigament2d} + */ + public static final class ProtobufMechanismLigament2d extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional double angle = 1; + */ + private double angle; + + /** + * optional double length = 3; + */ + private double length; + + /** + * optional double weight = 4; + */ + private double weight; + + /** + * optional string color = 2; + */ + private final Utf8String color = Utf8String.newEmptyInstance(); + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + */ + private RepeatedMessage ligaments = null; + + private ProtobufMechanismLigament2d() { + } + + /** + * @return a new empty instance of {@code ProtobufMechanismLigament2d} + */ + public static ProtobufMechanismLigament2d newInstance() { + return new ProtobufMechanismLigament2d(); + } + + /** + * optional double angle = 1; + * @return whether the angle field is set + */ + public boolean hasAngle() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional double angle = 1; + * @return this + */ + public ProtobufMechanismLigament2d clearAngle() { + bitField0_ &= ~0x00000001; + angle = 0D; + return this; + } + + /** + * optional double angle = 1; + * @return the angle + */ + public double getAngle() { + return angle; + } + + /** + * optional double angle = 1; + * @param value the angle to set + * @return this + */ + public ProtobufMechanismLigament2d setAngle(final double value) { + bitField0_ |= 0x00000001; + angle = value; + return this; + } + + /** + * optional double length = 3; + * @return whether the length field is set + */ + public boolean hasLength() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional double length = 3; + * @return this + */ + public ProtobufMechanismLigament2d clearLength() { + bitField0_ &= ~0x00000002; + length = 0D; + return this; + } + + /** + * optional double length = 3; + * @return the length + */ + public double getLength() { + return length; + } + + /** + * optional double length = 3; + * @param value the length to set + * @return this + */ + public ProtobufMechanismLigament2d setLength(final double value) { + bitField0_ |= 0x00000002; + length = value; + return this; + } + + /** + * optional double weight = 4; + * @return whether the weight field is set + */ + public boolean hasWeight() { + return (bitField0_ & 0x00000004) != 0; + } + + /** + * optional double weight = 4; + * @return this + */ + public ProtobufMechanismLigament2d clearWeight() { + bitField0_ &= ~0x00000004; + weight = 0D; + return this; + } + + /** + * optional double weight = 4; + * @return the weight + */ + public double getWeight() { + return weight; + } + + /** + * optional double weight = 4; + * @param value the weight to set + * @return this + */ + public ProtobufMechanismLigament2d setWeight(final double value) { + bitField0_ |= 0x00000004; + weight = value; + return this; + } + + /** + * optional string color = 2; + * @return whether the color field is set + */ + public boolean hasColor() { + return (bitField0_ & 0x00000008) != 0; + } + + /** + * optional string color = 2; + * @return this + */ + public ProtobufMechanismLigament2d clearColor() { + bitField0_ &= ~0x00000008; + color.clear(); + return this; + } + + /** + * optional string color = 2; + * @return the color + */ + public String getColor() { + return color.getString(); + } + + /** + * optional string color = 2; + * @return internal {@code Utf8String} representation of color for reading + */ + public Utf8String getColorBytes() { + return this.color; + } + + /** + * optional string color = 2; + * @return internal {@code Utf8String} representation of color for modifications + */ + public Utf8String getMutableColorBytes() { + bitField0_ |= 0x00000008; + return this.color; + } + + /** + * optional string color = 2; + * @param value the color to set + * @return this + */ + public ProtobufMechanismLigament2d setColor(final CharSequence value) { + bitField0_ |= 0x00000008; + color.copyFrom(value); + return this; + } + + /** + * optional string color = 2; + * @param value the color to set + * @return this + */ + public ProtobufMechanismLigament2d setColor(final Utf8String value) { + bitField0_ |= 0x00000008; + color.copyFrom(value); + return this; + } + + private void initLigaments() { + if (ligaments == null) { + ligaments = RepeatedMessage.newEmptyInstance(ProtobufMechanismLigament2d.getFactory()); + } + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + * @return whether the ligaments field is set + */ + public boolean hasLigaments() { + return (bitField0_ & 0x00000010) != 0; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + * @return this + */ + public ProtobufMechanismLigament2d clearLigaments() { + bitField0_ &= ~0x00000010; + if (ligaments != null) { + ligaments.clear(); + } + return this; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableLigaments()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedMessage getLigaments() { + initLigaments(); + return ligaments; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public RepeatedMessage getMutableLigaments() { + initLigaments(); + bitField0_ |= 0x00000010; + return ligaments; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + * @param value the ligaments to add + * @return this + */ + public ProtobufMechanismLigament2d addLigaments(final ProtobufMechanismLigament2d value) { + initLigaments(); + bitField0_ |= 0x00000010; + ligaments.add(value); + return this; + } + + /** + * repeated .wpi.proto.ProtobufMechanismLigament2d ligaments = 5; + * @param values the ligaments to add + * @return this + */ + public ProtobufMechanismLigament2d addAllLigaments( + final ProtobufMechanismLigament2d... values) { + initLigaments(); + bitField0_ |= 0x00000010; + ligaments.addAll(values); + return this; + } + + @Override + public ProtobufMechanismLigament2d copyFrom(final ProtobufMechanismLigament2d other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + angle = other.angle; + length = other.length; + weight = other.weight; + color.copyFrom(other.color); + if (other.hasLigaments()) { + initLigaments(); + ligaments.copyFrom(other.ligaments); + } else { + clearLigaments(); + } + } + return this; + } + + @Override + public ProtobufMechanismLigament2d mergeFrom(final ProtobufMechanismLigament2d other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasAngle()) { + setAngle(other.angle); + } + if (other.hasLength()) { + setLength(other.length); + } + if (other.hasWeight()) { + setWeight(other.weight); + } + if (other.hasColor()) { + getMutableColorBytes().copyFrom(other.color); + } + if (other.hasLigaments()) { + getMutableLigaments().addAll(other.ligaments); + } + return this; + } + + @Override + public ProtobufMechanismLigament2d clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + angle = 0D; + length = 0D; + weight = 0D; + color.clear(); + if (ligaments != null) { + ligaments.clear(); + } + return this; + } + + @Override + public ProtobufMechanismLigament2d clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + color.clear(); + if (ligaments != null) { + ligaments.clearQuick(); + } + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof ProtobufMechanismLigament2d)) { + return false; + } + ProtobufMechanismLigament2d other = (ProtobufMechanismLigament2d) o; + return bitField0_ == other.bitField0_ + && (!hasAngle() || ProtoUtil.isEqual(angle, other.angle)) + && (!hasLength() || ProtoUtil.isEqual(length, other.length)) + && (!hasWeight() || ProtoUtil.isEqual(weight, other.weight)) + && (!hasColor() || color.equals(other.color)) + && (!hasLigaments() || ligaments.equals(other.ligaments)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 9); + output.writeDoubleNoTag(angle); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 25); + output.writeDoubleNoTag(length); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeRawByte((byte) 33); + output.writeDoubleNoTag(weight); + } + if ((bitField0_ & 0x00000008) != 0) { + output.writeRawByte((byte) 18); + output.writeStringNoTag(color); + } + if ((bitField0_ & 0x00000010) != 0) { + for (int i = 0; i < ligaments.length(); i++) { + output.writeRawByte((byte) 42); + output.writeMessageNoTag(ligaments.get(i)); + } + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000002) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000004) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000008) != 0) { + size += 1 + ProtoSink.computeStringSizeNoTag(color); + } + if ((bitField0_ & 0x00000010) != 0) { + size += (1 * ligaments.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(ligaments); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public ProtobufMechanismLigament2d mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 9: { + // angle + angle = input.readDouble(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 25) { + break; + } + } + case 25: { + // length + length = input.readDouble(); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 33) { + break; + } + } + case 33: { + // weight + weight = input.readDouble(); + bitField0_ |= 0x00000004; + tag = input.readTag(); + if (tag != 18) { + break; + } + } + case 18: { + // color + input.readString(color); + bitField0_ |= 0x00000008; + tag = input.readTag(); + if (tag != 42) { + break; + } + } + case 42: { + // ligaments + initLigaments(); + tag = input.readRepeatedMessage(ligaments, tag); + bitField0_ |= 0x00000010; + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeDouble(FieldNames.angle, angle); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeDouble(FieldNames.length, length); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeDouble(FieldNames.weight, weight); + } + if ((bitField0_ & 0x00000008) != 0) { + output.writeString(FieldNames.color, color); + } + if ((bitField0_ & 0x00000010) != 0) { + output.writeRepeatedMessage(FieldNames.ligaments, ligaments); + } + output.endObject(); + } + + @Override + public ProtobufMechanismLigament2d mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 92960979: { + if (input.isAtField(FieldNames.angle)) { + if (!input.trySkipNullValue()) { + angle = input.readDouble(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case -1106363674: { + if (input.isAtField(FieldNames.length)) { + if (!input.trySkipNullValue()) { + length = input.readDouble(); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + case -791592328: { + if (input.isAtField(FieldNames.weight)) { + if (!input.trySkipNullValue()) { + weight = input.readDouble(); + bitField0_ |= 0x00000004; + } + } else { + input.skipUnknownField(); + } + break; + } + case 94842723: { + if (input.isAtField(FieldNames.color)) { + if (!input.trySkipNullValue()) { + input.readString(color); + bitField0_ |= 0x00000008; + } + } else { + input.skipUnknownField(); + } + break; + } + case 479313438: { + if (input.isAtField(FieldNames.ligaments)) { + if (!input.trySkipNullValue()) { + initLigaments(); + input.readRepeatedMessage(ligaments); + bitField0_ |= 0x00000010; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public ProtobufMechanismLigament2d clone() { + return new ProtobufMechanismLigament2d().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static ProtobufMechanismLigament2d parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new ProtobufMechanismLigament2d(), data).checkInitialized(); + } + + public static ProtobufMechanismLigament2d parseFrom(final ProtoSource input) throws + IOException { + return ProtoMessage.mergeFrom(new ProtobufMechanismLigament2d(), input).checkInitialized(); + } + + public static ProtobufMechanismLigament2d parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new ProtobufMechanismLigament2d(), input).checkInitialized(); + } + + /** + * @return factory for creating ProtobufMechanismLigament2d messages + */ + public static MessageFactory getFactory() { + return ProtobufMechanismLigament2dFactory.INSTANCE; + } + + /** + * @return this type's descriptor. + */ + public static Descriptors.Descriptor getDescriptor() { + return Mechanism2D.wpi_proto_ProtobufMechanismLigament2d_descriptor; + } + + private enum ProtobufMechanismLigament2dFactory implements MessageFactory { + INSTANCE; + + @Override + public ProtobufMechanismLigament2d create() { + return ProtobufMechanismLigament2d.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName angle = FieldName.forField("angle"); + + static final FieldName length = FieldName.forField("length"); + + static final FieldName weight = FieldName.forField("weight"); + + static final FieldName color = FieldName.forField("color"); + + static final FieldName ligaments = FieldName.forField("ligaments"); + } + } + + /** + * Protobuf type {@code ProtobufMechanism2d} + */ + public static final class ProtobufMechanism2d extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional double x = 1; + */ + private double x; + + /** + * optional double y = 2; + */ + private double y; + + /** + * optional string color = 3; + */ + private final Utf8String color = Utf8String.newEmptyInstance(); + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + */ + private RepeatedMessage roots = null; + + private ProtobufMechanism2d() { + } + + /** + * @return a new empty instance of {@code ProtobufMechanism2d} + */ + public static ProtobufMechanism2d newInstance() { + return new ProtobufMechanism2d(); + } + + /** + * optional double x = 1; + * @return whether the x field is set + */ + public boolean hasX() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional double x = 1; + * @return this + */ + public ProtobufMechanism2d clearX() { + bitField0_ &= ~0x00000001; + x = 0D; + return this; + } + + /** + * optional double x = 1; + * @return the x + */ + public double getX() { + return x; + } + + /** + * optional double x = 1; + * @param value the x to set + * @return this + */ + public ProtobufMechanism2d setX(final double value) { + bitField0_ |= 0x00000001; + x = value; + return this; + } + + /** + * optional double y = 2; + * @return whether the y field is set + */ + public boolean hasY() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional double y = 2; + * @return this + */ + public ProtobufMechanism2d clearY() { + bitField0_ &= ~0x00000002; + y = 0D; + return this; + } + + /** + * optional double y = 2; + * @return the y + */ + public double getY() { + return y; + } + + /** + * optional double y = 2; + * @param value the y to set + * @return this + */ + public ProtobufMechanism2d setY(final double value) { + bitField0_ |= 0x00000002; + y = value; + return this; + } + + /** + * optional string color = 3; + * @return whether the color field is set + */ + public boolean hasColor() { + return (bitField0_ & 0x00000004) != 0; + } + + /** + * optional string color = 3; + * @return this + */ + public ProtobufMechanism2d clearColor() { + bitField0_ &= ~0x00000004; + color.clear(); + return this; + } + + /** + * optional string color = 3; + * @return the color + */ + public String getColor() { + return color.getString(); + } + + /** + * optional string color = 3; + * @return internal {@code Utf8String} representation of color for reading + */ + public Utf8String getColorBytes() { + return this.color; + } + + /** + * optional string color = 3; + * @return internal {@code Utf8String} representation of color for modifications + */ + public Utf8String getMutableColorBytes() { + bitField0_ |= 0x00000004; + return this.color; + } + + /** + * optional string color = 3; + * @param value the color to set + * @return this + */ + public ProtobufMechanism2d setColor(final CharSequence value) { + bitField0_ |= 0x00000004; + color.copyFrom(value); + return this; + } + + /** + * optional string color = 3; + * @param value the color to set + * @return this + */ + public ProtobufMechanism2d setColor(final Utf8String value) { + bitField0_ |= 0x00000004; + color.copyFrom(value); + return this; + } + + private void initRoots() { + if (roots == null) { + roots = RepeatedMessage.newEmptyInstance(ProtobufMechanismRoot2d.getFactory()); + } + } + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + * @return whether the roots field is set + */ + public boolean hasRoots() { + return (bitField0_ & 0x00000008) != 0; + } + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + * @return this + */ + public ProtobufMechanism2d clearRoots() { + bitField0_ &= ~0x00000008; + if (roots != null) { + roots.clear(); + } + return this; + } + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableRoots()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedMessage getRoots() { + initRoots(); + return roots; + } + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public RepeatedMessage getMutableRoots() { + initRoots(); + bitField0_ |= 0x00000008; + return roots; + } + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + * @param value the roots to add + * @return this + */ + public ProtobufMechanism2d addRoots(final ProtobufMechanismRoot2d value) { + initRoots(); + bitField0_ |= 0x00000008; + roots.add(value); + return this; + } + + /** + * repeated .wpi.proto.ProtobufMechanismRoot2d roots = 4; + * @param values the roots to add + * @return this + */ + public ProtobufMechanism2d addAllRoots(final ProtobufMechanismRoot2d... values) { + initRoots(); + bitField0_ |= 0x00000008; + roots.addAll(values); + return this; + } + + @Override + public ProtobufMechanism2d copyFrom(final ProtobufMechanism2d other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + x = other.x; + y = other.y; + color.copyFrom(other.color); + if (other.hasRoots()) { + initRoots(); + roots.copyFrom(other.roots); + } else { + clearRoots(); + } + } + return this; + } + + @Override + public ProtobufMechanism2d mergeFrom(final ProtobufMechanism2d other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasX()) { + setX(other.x); + } + if (other.hasY()) { + setY(other.y); + } + if (other.hasColor()) { + getMutableColorBytes().copyFrom(other.color); + } + if (other.hasRoots()) { + getMutableRoots().addAll(other.roots); + } + return this; + } + + @Override + public ProtobufMechanism2d clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + x = 0D; + y = 0D; + color.clear(); + if (roots != null) { + roots.clear(); + } + return this; + } + + @Override + public ProtobufMechanism2d clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + color.clear(); + if (roots != null) { + roots.clearQuick(); + } + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof ProtobufMechanism2d)) { + return false; + } + ProtobufMechanism2d other = (ProtobufMechanism2d) o; + return bitField0_ == other.bitField0_ + && (!hasX() || ProtoUtil.isEqual(x, other.x)) + && (!hasY() || ProtoUtil.isEqual(y, other.y)) + && (!hasColor() || color.equals(other.color)) + && (!hasRoots() || roots.equals(other.roots)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 9); + output.writeDoubleNoTag(x); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 17); + output.writeDoubleNoTag(y); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeRawByte((byte) 26); + output.writeStringNoTag(color); + } + if ((bitField0_ & 0x00000008) != 0) { + for (int i = 0; i < roots.length(); i++) { + output.writeRawByte((byte) 34); + output.writeMessageNoTag(roots.get(i)); + } + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000002) != 0) { + size += 9; + } + if ((bitField0_ & 0x00000004) != 0) { + size += 1 + ProtoSink.computeStringSizeNoTag(color); + } + if ((bitField0_ & 0x00000008) != 0) { + size += (1 * roots.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(roots); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public ProtobufMechanism2d mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 9: { + // x + x = input.readDouble(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 17) { + break; + } + } + case 17: { + // y + y = input.readDouble(); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 26) { + break; + } + } + case 26: { + // color + input.readString(color); + bitField0_ |= 0x00000004; + tag = input.readTag(); + if (tag != 34) { + break; + } + } + case 34: { + // roots + initRoots(); + tag = input.readRepeatedMessage(roots, tag); + bitField0_ |= 0x00000008; + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeDouble(FieldNames.x, x); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeDouble(FieldNames.y, y); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeString(FieldNames.color, color); + } + if ((bitField0_ & 0x00000008) != 0) { + output.writeRepeatedMessage(FieldNames.roots, roots); + } + output.endObject(); + } + + @Override + public ProtobufMechanism2d mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 120: { + if (input.isAtField(FieldNames.x)) { + if (!input.trySkipNullValue()) { + x = input.readDouble(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case 121: { + if (input.isAtField(FieldNames.y)) { + if (!input.trySkipNullValue()) { + y = input.readDouble(); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + case 94842723: { + if (input.isAtField(FieldNames.color)) { + if (!input.trySkipNullValue()) { + input.readString(color); + bitField0_ |= 0x00000004; + } + } else { + input.skipUnknownField(); + } + break; + } + case 108698577: { + if (input.isAtField(FieldNames.roots)) { + if (!input.trySkipNullValue()) { + initRoots(); + input.readRepeatedMessage(roots); + bitField0_ |= 0x00000008; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public ProtobufMechanism2d clone() { + return new ProtobufMechanism2d().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static ProtobufMechanism2d parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new ProtobufMechanism2d(), data).checkInitialized(); + } + + public static ProtobufMechanism2d parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new ProtobufMechanism2d(), input).checkInitialized(); + } + + public static ProtobufMechanism2d parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new ProtobufMechanism2d(), input).checkInitialized(); + } + + /** + * @return factory for creating ProtobufMechanism2d messages + */ + public static MessageFactory getFactory() { + return ProtobufMechanism2dFactory.INSTANCE; + } + + /** + * @return this type's descriptor. + */ + public static Descriptors.Descriptor getDescriptor() { + return Mechanism2D.wpi_proto_ProtobufMechanism2d_descriptor; + } + + private enum ProtobufMechanism2dFactory implements MessageFactory { + INSTANCE; + + @Override + public ProtobufMechanism2d create() { + return ProtobufMechanism2d.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName x = FieldName.forField("x"); + + static final FieldName y = FieldName.forField("y"); + + static final FieldName color = FieldName.forField("color"); + + static final FieldName roots = FieldName.forField("roots"); + } + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismObject2d.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismObject2d.java index 754bd9256cf..eefa4fb16a4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismObject2d.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/MechanismObject2d.java @@ -77,4 +77,8 @@ final synchronized void update(NetworkTable table) { public final String getName() { return m_name; } + + public final Map getObjects() { + return m_objects; + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/proto/MechanismLigament2dProto.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/proto/MechanismLigament2dProto.java new file mode 100644 index 00000000000..ff21f0aa435 --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/proto/MechanismLigament2dProto.java @@ -0,0 +1,50 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.wpilibj.smartdashboard.proto; + +import edu.wpi.first.util.protobuf.Protobuf; +import edu.wpi.first.wpilibj.proto.Mechanism2D.ProtobufMechanismLigament2d; +import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d; +import edu.wpi.first.wpilibj.smartdashboard.MechanismObject2d; +import us.hebi.quickbuf.Descriptors.Descriptor; + +public class MechanismLigament2dProto implements Protobuf { + @Override + public Class getTypeClass() { + return MechanismLigament2d.class; + } + + @Override + public Descriptor getDescriptor() { + return ProtobufMechanismLigament2d.getDescriptor(); + } + + @Override + public ProtobufMechanismLigament2d createMessage() { + return ProtobufMechanismLigament2d.newInstance(); + } + + @Override + public MechanismLigament2d unpack(ProtobufMechanismLigament2d msg) { + var root = new MechanismLigament2d("", msg.getLength(), msg.getAngle()); + for (ProtobufMechanismLigament2d l : msg.getLigaments()) { + root.append(unpack(l)); + } + return root; + } + + @Override + public void pack(ProtobufMechanismLigament2d msg, MechanismLigament2d value) { + msg.setAngle(value.getAngle()); + msg.setColor(value.getColor().toHexString()); + msg.setLength(value.getLength()); + msg.setWeight(value.getLineWeight()); + for (MechanismObject2d ligament : value.getObjects().values()) { + var nestedLigament = createMessage(); + pack(nestedLigament, (MechanismLigament2d)ligament); + msg.addLigaments(nestedLigament); + } + } +} diff --git a/wpilibj/src/main/proto/mechanism2d.proto b/wpilibj/src/main/proto/mechanism2d.proto new file mode 100644 index 00000000000..d00fd35e912 --- /dev/null +++ b/wpilibj/src/main/proto/mechanism2d.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + +package wpi.proto; + +option java_package = "edu.wpi.first.wpilibj.proto"; + +message ProtobufMechanismRoot2d { + string name = 1; + double x = 2; + double y = 3; + repeated ProtobufMechanismLigament2d ligaments = 4; +} + +message ProtobufMechanismLigament2d { + string name = 1; + double angle = 2; + string color = 3; + double length = 4; + double weight = 5; + repeated ProtobufMechanismLigament2d ligaments = 6; +} + +message ProtobufMechanism2d { + double x = 1; + double y = 2; + string color = 3; + repeated ProtobufMechanismRoot2d roots = 4; +}