diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e4cd865c71..4ff33aa29a 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -78,6 +78,43 @@ jobs: - name: Run mypy type checking run: mypy --show-column-numbers --config-file photon-lib/py/pyproject.toml photon-lib + test-photonserde-py: + needs: build-py + runs-on: ubuntu-24.04 + + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: 3.14 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest mypy + pip install -r photon-serde-tests/requirements.txt + + - name: Download artifacts + uses: actions/download-artifact@v8 + with: + name: dist + path: ./photon-lib/py/dist/ + + - name: Install PhotonLibPy package + working-directory: ./photon-lib/py + shell: bash + run: | + pip install --no-cache-dir dist/*.whl + + - name: Run PhotonSerde tests + shell: bash + run: python -m pytest --import-mode=importlib photon-serde-tests/py/AutoSerdeTest.py + build-python-examples: needs: build-py strategy: diff --git a/.wpiformat b/.wpiformat index b35d711d25..86834211c7 100644 --- a/.wpiformat +++ b/.wpiformat @@ -6,6 +6,8 @@ generatedFileExclude { photon-lib/py/photonlibpy/generated/ photon-targeting/src/generated/ photon-targeting/src/main/native/cpp/photon/constrained_solvepnp/generate/ + photon-serde-tests/src + photon-serde-tests/py } licenseUpdateExclude { diff --git a/build.gradle b/build.gradle index 1418b094b1..340a7d1a6a 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ spotless { java { target fileTree('.') { include '**/*.java' - exclude '**/build/**', '**/build-*/**', '**/src/generated/**', "**/bin/generated-sources/**" + exclude '**/build/**', '**/build-*/**', '**/src/generated/**', '**/src/generated-test/**', "**/bin/generated-sources/**", "photon-serde-tests/src/**" } toggleOffOn() googleJavaFormat() diff --git a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py index 1c668e56b1..6a40dd0058 100644 --- a/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/MultiTargetPNPResultSerde.py @@ -29,14 +29,19 @@ from typing import TYPE_CHECKING + from ..packet import Packet from ..targeting import * # noqa + + if TYPE_CHECKING: from ..targeting import MultiTargetPNPResult # noqa + from ..targeting import PnpResult # noqa + class MultiTargetPNPResultSerde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "541096947e9f3ca2d3f425ff7b04aa7b" @@ -50,7 +55,7 @@ def pack(value: "MultiTargetPNPResult") -> "Packet": ret.encodeBytes(PnpResult.photonStruct.pack(value.estimatedPose).getData()) # fiducialIDsUsed is a custom VLA! - ret.encodeShortList(value.fiducialIDsUsed) + ret.encodeListShimmed(value.fiducialIDsUsed, ret.encode16) return ret @staticmethod @@ -60,8 +65,8 @@ def unpack(packet: "Packet") -> "MultiTargetPNPResult": # estimatedPose is of non-intrinsic type PnpResult ret.estimatedPose = PnpResult.photonStruct.unpack(packet) - # fiducialIDsUsed is a custom VLA! - ret.fiducialIDsUsed = packet.decodeShortList() + # fiducialIDsUsed is an intrinsic VLA! + ret.fiducialIDsUsed = packet.decodeListShimmed(packet.decode16) return ret diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py index 9ec396384e..3ce40fd36c 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineMetadataSerde.py @@ -29,13 +29,17 @@ from typing import TYPE_CHECKING + from ..packet import Packet from ..targeting import * # noqa + + if TYPE_CHECKING: from ..targeting import PhotonPipelineMetadata # noqa + class PhotonPipelineMetadataSerde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "ac0a45f686457856fb30af77699ea356" diff --git a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py index 9bb1a715db..33d1abc5ab 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonPipelineResultSerde.py @@ -29,16 +29,23 @@ from typing import TYPE_CHECKING + from ..packet import Packet from ..targeting import * # noqa + + if TYPE_CHECKING: from ..targeting import MultiTargetPNPResult # noqa + from ..targeting import PhotonPipelineMetadata # noqa + from ..targeting import PhotonPipelineResult # noqa + from ..targeting import PhotonTrackedTarget # noqa + class PhotonPipelineResultSerde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "4b2ff16a964b5e2bf04be0c1454d91c4" @@ -49,9 +56,7 @@ def pack(value: "PhotonPipelineResult") -> "Packet": ret = Packet() # metadata is of non-intrinsic type PhotonPipelineMetadata - ret.encodeBytes( - PhotonPipelineMetadata.photonStruct.pack(value.metadata).getData() - ) + ret.encodeBytes(PhotonPipelineMetadata.photonStruct.pack(value.metadata).getData()) # targets is a custom VLA! ret.encodeList(value.targets, PhotonTrackedTarget.photonStruct) diff --git a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py index c224bbf993..617488653a 100644 --- a/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py +++ b/photon-lib/py/photonlibpy/generated/PhotonTrackedTargetSerde.py @@ -29,14 +29,19 @@ from typing import TYPE_CHECKING + from ..packet import Packet from ..targeting import * # noqa + + if TYPE_CHECKING: from ..targeting import PhotonTrackedTarget # noqa + from ..targeting import TargetCorner # noqa + class PhotonTrackedTargetSerde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "cc6dbb5c5c1e0fa808108019b20863f1" @@ -67,8 +72,10 @@ def pack(value: "PhotonTrackedTarget") -> "Packet": # objDetectConf is of intrinsic type float32 ret.encodeFloat(value.objDetectConf) + # bestCameraToTarget is of shimmed type Transform3d ret.encodeTransform(value.bestCameraToTarget) + # altCameraToTarget is of shimmed type Transform3d ret.encodeTransform(value.altCameraToTarget) # poseAmbiguity is of intrinsic type float64 diff --git a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py index 34abc0a74a..e053c4eb6f 100644 --- a/photon-lib/py/photonlibpy/generated/PnpResultSerde.py +++ b/photon-lib/py/photonlibpy/generated/PnpResultSerde.py @@ -29,13 +29,17 @@ from typing import TYPE_CHECKING + from ..packet import Packet from ..targeting import * # noqa + + if TYPE_CHECKING: from ..targeting import PnpResult # noqa + class PnpResultSerde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "ae4d655c0a3104d88df4f5db144c1e86" @@ -45,8 +49,10 @@ class PnpResultSerde: def pack(value: "PnpResult") -> "Packet": ret = Packet() + # best is of shimmed type Transform3d ret.encodeTransform(value.best) + # alt is of shimmed type Transform3d ret.encodeTransform(value.alt) # bestReprojErr is of intrinsic type float64 diff --git a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py index 3fe56a7d7e..e4c2136b7f 100644 --- a/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py +++ b/photon-lib/py/photonlibpy/generated/TargetCornerSerde.py @@ -29,13 +29,17 @@ from typing import TYPE_CHECKING + from ..packet import Packet from ..targeting import * # noqa + + if TYPE_CHECKING: from ..targeting import TargetCorner # noqa + class TargetCornerSerde: # Message definition md5sum. See photon_packet.adoc for details MESSAGE_VERSION = "16f6ac0dedc8eaccb951f4895d9e18b6" diff --git a/photon-lib/py/photonlibpy/packet.py b/photon-lib/py/photonlibpy/packet.py index 77ab756eb7..06ca8198f0 100644 --- a/photon-lib/py/photonlibpy/packet.py +++ b/photon-lib/py/photonlibpy/packet.py @@ -16,7 +16,7 @@ ############################################################################### import struct -from typing import Generic, Optional, Protocol, TypeVar +from typing import Callable, Generic, Optional, Protocol, TypeVar import wpilib from wpimath import Quaternion, Rotation3d, Transform3d, Translation3d @@ -200,12 +200,25 @@ def decodeList(self, serde: Serde[T]) -> list[T]: retList.append(serde.unpack(self)) return retList + def decodeListShimmed(self, shim: Callable[[], T]) -> list[T]: + retList = [] + arr_len = self.decode8() + for _ in range(arr_len): + retList.append(shim()) + return retList + def decodeOptional(self, serde: Serde[T]) -> Optional[T]: if self.decodeBoolean(): return serde.unpack(self) else: return None + def decodeOptionalShimmed(self, shim: Callable[[], T]) -> Optional[T]: + if self.decodeBoolean(): + return shim() + else: + return None + def _encodeGeneric(self, packFormat, value): """ Append bytes to the packet data buffer. @@ -255,22 +268,6 @@ def encodeBoolean(self, value: bool): """ self.encode8(1 if value else 0) - def encodeDoubleArray(self, values: list[float]): - """ - Encodes an array of doubles and appends it to the packet. - """ - self.encode8(len(values)) - for value in values: - self.encodeDouble(value) - - def encodeShortList(self, values: list[int]): - """ - Encodes a list of shorts, with length prefixed as a single byte. - """ - self.encode8(len(values)) - for value in values: - self.encode16(value) - def encodeTransform(self, transform: Transform3d): """ Encodes a Transform3d (translation and rotation) and appends it to the packet. @@ -297,6 +294,14 @@ def encodeList(self, values: list[T], serde: Serde[T]): self.packetData = self.packetData + packed.getData() self.size = len(self.packetData) + def encodeListShimmed(self, values: list[T], shim: Callable[[T], None]): + """ + Encodes a list of items using a specific serializer and appends it to the packet. + """ + self.encode8(len(values)) + for item in values: + shim(item) + def encodeOptional(self, value: Optional[T], serde: Serde[T]): """ Encodes an optional value using a specific serializer. @@ -309,6 +314,16 @@ def encodeOptional(self, value: Optional[T], serde: Serde[T]): self.packetData = self.packetData + packed.getData() self.size = len(self.packetData) + def encodeOptionalShimmed(self, value: Optional[T], shim: Callable[[T], None]): + """ + Encodes an optional value using a specific shimmed serializer. + """ + if value is None: + self.encodeBoolean(False) + else: + self.encodeBoolean(True) + shim(value) + def encodeBytes(self, value: bytes): self.packetData = self.packetData + value self.size = len(self.packetData) diff --git a/photon-serde-tests/README.md b/photon-serde-tests/README.md new file mode 100644 index 0000000000..89e3a04b68 --- /dev/null +++ b/photon-serde-tests/README.md @@ -0,0 +1,5 @@ +These are autogenerated tests for photon-serde. ALL CODE IN THIS DIRECTORY (except for build.gradle and requirements.txt) IS AUTOMATICALLY GENERATED + +requirements.txt is only for version-controlling WPILib. Photonlibpy itself is installed separately, and SHOULD NOT be in the requirements.txt + +These tests are separated from the main code as we don't use the autogenerated photon-serde test messages anywhere except in the tests, and we don't want to expose them to end-users in photon-lib diff --git a/photon-serde-tests/build.gradle b/photon-serde-tests/build.gradle new file mode 100644 index 0000000000..c95fb2a04d --- /dev/null +++ b/photon-serde-tests/build.gradle @@ -0,0 +1,139 @@ +ext { + nativeName = "photonserdetest" + includePhotonTargeting = true +} + +apply plugin: 'cpp' +apply plugin: 'c' +apply plugin: 'google-test-test-suite' +apply plugin: 'org.wpilib.NativeUtils' +apply plugin: 'org.photonvision.tools.WpilibTools' +apply plugin: 'org.wpilib.GradleJni' + +ext.licenseFile = file("$rootDir/LICENSE") +apply from: "${rootDir}/shared/config.gradle" +apply from: "${rootDir}/shared/javacommon.gradle" + +nativeUtils { + exportsConfigs { + "${nativeName}" {} + } +} + +model { + components { + "${nativeName}"(NativeLibrarySpec) { + sources { + cpp { + source { + srcDirs 'src/main/native/cpp' + include '**/*.cpp', '**/*.cc' + } + exportedHeaders { + srcDirs 'src/main/native/include' + include "**/*.h" + } + } + } + + binaries.all { + if(project.hasProperty('includePhotonTargeting')) { + lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared' + } + } + + nativeUtils.useRequiredLibrary(it, "wpiutil_shared") + nativeUtils.useRequiredLibrary(it, "datalog_shared") + nativeUtils.useRequiredLibrary(it, "wpimath_shared") + } + } + testSuites { + "${nativeName}Test"(GoogleTestTestSuiteSpec) { + for(NativeComponentSpec c : $.components) { + if (c.name == nativeName) { + testing c + break + } + } + sources { + cpp { + source { + srcDirs 'src/test/native/cpp' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/test/native/include' + } + } + } + + binaries.all { + lib library: nativeName, linkage: 'shared' + if(project.hasProperty('includePhotonTargeting')) { + lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared' + } + } + + nativeUtils.useRequiredLibrary(it, "wpilib_shared") + nativeUtils.useRequiredLibrary(it, "googletest_static") + nativeUtils.useRequiredLibrary(it, "datalog_shared") + } + } + + tasks { + def c = $.testSuites + project.tasks.create('runCpp', Exec) { + description = "Run the photon-lib executable" + def found = false + def systemArch = getCurrentArch() + c.each { + if (it in GoogleTestTestSuiteSpec && it.name == "${nativeName}Test") { + it.binaries.each { + if (!found) { + def arch = it.targetPlatform.name + if (arch == systemArch) { + dependsOn it.tasks.install + commandLine it.tasks.install.runScriptFile.get().asFile.toString() + def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' + test.dependsOn it.tasks.install + test.systemProperty 'java.library.path', filePath + test.environment 'LD_LIBRARY_PATH', filePath + test.environment 'DYLD_LIBRARY_PATH', filePath + test.workingDir filePath + + found = true + } + } + } + } + } + } + } +} + +apply from: "${rootDir}/shared/javacpp/publish.gradle" + +// setup wpilib bundled native libs +wpilibTools.deps.wpilibVersion = wpilibVersion + +def nativeConfigName = 'wpilibNatives' +def nativeConfig = configurations.create(nativeConfigName) + +def nativeTasks = wpilibTools.createExtractionTasks { + configurationName = nativeConfigName +} + +nativeTasks.addToSourceSetResources(sourceSets.test) + +dependencies { + wpilibNatives project(":photon-targeting") +} +nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil") +nativeConfig.dependencies.add wpilibTools.deps.wpilib("datalog") +nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath") +nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet") +nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore") +nativeConfig.dependencies.add wpilibTools.deps.wpilib("hal") +nativeConfig.dependencies.add wpilibTools.deps.wpilib("cscore") +nativeConfig.dependencies.add wpilibTools.deps.wpilibOpenCv(openCVversion) +nativeConfig.dependencies.add wpilibTools.deps.wpilib("apriltag") diff --git a/photon-serde-tests/py/AutoSerdeTest.py b/photon-serde-tests/py/AutoSerdeTest.py new file mode 100644 index 0000000000..d82de026bb --- /dev/null +++ b/photon-serde-tests/py/AutoSerdeTest.py @@ -0,0 +1,245 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * +from .messages import * + +from wpimath import Rotation3d +from wpimath import Translation3d +from wpimath import Transform3d + + +def AutoSerdeTest(data) -> bool: + packet = data.photonStruct.pack(data) + unpacked = data.photonStruct.unpack(packet) + print(f"Original: {data}") + print(f"Unpacked: {unpacked}") + return data == unpacked + + +def test_Int8Test(): + print("Running Int8Test...") + + print("Test case default_test:") + default_test = Int8TestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Int8TestMessage() + optional_test.optTest = 3 + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Int8TestMessage() + vla_test.vlaTest = [1, 2, 3] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Int8TestMessage() + general_test.test = 42 + general_test.optTest = 7 + general_test.vlaTest = [4, 5, 6] + assert AutoSerdeTest(general_test) + + +def test_Int16Test(): + print("Running Int16Test...") + + print("Test case default_test:") + default_test = Int16TestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Int16TestMessage() + optional_test.optTest = 3 + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Int16TestMessage() + vla_test.vlaTest = [1, 2, 3] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Int16TestMessage() + general_test.test = 42 + general_test.optTest = 7 + general_test.vlaTest = [4, 5, 6] + assert AutoSerdeTest(general_test) + + +def test_Int32Test(): + print("Running Int32Test...") + + print("Test case default_test:") + default_test = Int32TestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Int32TestMessage() + optional_test.optTest = 3 + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Int32TestMessage() + vla_test.vlaTest = [1, 2, 3] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Int32TestMessage() + general_test.test = 42 + general_test.optTest = 7 + general_test.vlaTest = [4, 5, 6] + assert AutoSerdeTest(general_test) + + +def test_Int64Test(): + print("Running Int64Test...") + + print("Test case default_test:") + default_test = Int64TestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Int64TestMessage() + optional_test.optTest = 3 + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Int64TestMessage() + vla_test.vlaTest = [1, 2, 3] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Int64TestMessage() + general_test.test = 42 + general_test.optTest = 7 + general_test.vlaTest = [4, 5, 6] + assert AutoSerdeTest(general_test) + + +def test_Float32Test(): + print("Running Float32Test...") + + print("Test case default_test:") + default_test = Float32TestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Float32TestMessage() + optional_test.optTest = 3.0 + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Float32TestMessage() + vla_test.vlaTest = [1.0, 2.0, 3.0] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Float32TestMessage() + general_test.test = 42.0 + general_test.optTest = 7.0 + general_test.vlaTest = [4.0, 5.0, 6.0] + assert AutoSerdeTest(general_test) + + +def test_Float64Test(): + print("Running Float64Test...") + + print("Test case default_test:") + default_test = Float64TestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Float64TestMessage() + optional_test.optTest = 3.0 + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Float64TestMessage() + vla_test.vlaTest = [1.0, 2.0, 3.0] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Float64TestMessage() + general_test.test = 42.0 + general_test.optTest = 7.0 + general_test.vlaTest = [4.0, 5.0, 6.0] + assert AutoSerdeTest(general_test) + + +def test_BoolTest(): + print("Running BoolTest...") + + print("Test case default_test:") + default_test = BoolTestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = BoolTestMessage() + optional_test.optTest = True + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = BoolTestMessage() + vla_test.vlaTest = [True, False, True] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = BoolTestMessage() + general_test.test = False + general_test.optTest = True + general_test.vlaTest = [True, False, True] + assert AutoSerdeTest(general_test) + + +def test_Transform3dTest(): + print("Running Transform3dTest...") + + print("Test case default_test:") + default_test = Transform3dTestMessage() + assert AutoSerdeTest(default_test) + + print("Test case optional_test:") + optional_test = Transform3dTestMessage() + optional_test.optTest = Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3)) + assert AutoSerdeTest(optional_test) + + print("Test case vla_test:") + vla_test = Transform3dTestMessage() + vla_test.vlaTest = [Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3)), Transform3d(Translation3d(4.0, 5.0, 6.0), Rotation3d(0.4, 0.5, 0.6))] + assert AutoSerdeTest(vla_test) + + print("Test case general_test:") + general_test = Transform3dTestMessage() + general_test.test = Transform3d(Translation3d(7.0, 8.0, 9.0), Rotation3d(0.7, 0.8, 0.9)) + general_test.optTest = Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3)) + general_test.vlaTest = [Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3)), Transform3d(Translation3d(4.0, 5.0, 6.0), Rotation3d(0.4, 0.5, 0.6))] + assert AutoSerdeTest(general_test) + diff --git a/photon-serde-tests/py/messages/BoolTestMessage.py b/photon-serde-tests/py/messages/BoolTestMessage.py new file mode 100644 index 0000000000..6b3fab6ebb --- /dev/null +++ b/photon-serde-tests/py/messages/BoolTestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .BoolTestMessageSerde import BoolTestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class BoolTestMessage: + test: bool = field( + default_factory=lambda: False + ) + vlaTest: list[bool] = field( + default_factory=list + ) + optTest: Optional[bool] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["BoolTestMessageSerde"] diff --git a/photon-serde-tests/py/messages/BoolTestMessageSerde.py b/photon-serde-tests/py/messages/BoolTestMessageSerde.py new file mode 100644 index 0000000000..adf5ed60fb --- /dev/null +++ b/photon-serde-tests/py/messages/BoolTestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .BoolTestMessage import BoolTestMessage # noqa + + +class BoolTestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "c8efe94a9c0d815658c74de6f672939c" + MESSAGE_FORMAT = "bool test;bool vlaTest[?];optional bool optTest;" + + @staticmethod + def pack(value: "BoolTestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type bool + ret.encodeBoolean(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encodeBoolean) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encodeBoolean) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "BoolTestMessage": + ret = BoolTestMessage() + + # test is of intrinsic type bool + ret.test = packet.decodeBoolean() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decodeBoolean) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decodeBoolean) + + return ret + + +# Hack ourselves into the base class +BoolTestMessage.photonStruct = BoolTestMessageSerde() diff --git a/photon-serde-tests/py/messages/Float32TestMessage.py b/photon-serde-tests/py/messages/Float32TestMessage.py new file mode 100644 index 0000000000..f5d82b400b --- /dev/null +++ b/photon-serde-tests/py/messages/Float32TestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Float32TestMessageSerde import Float32TestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class Float32TestMessage: + test: float = field( + default_factory=lambda: 0.0 + ) + vlaTest: list[float] = field( + default_factory=list + ) + optTest: Optional[float] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Float32TestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Float32TestMessageSerde.py b/photon-serde-tests/py/messages/Float32TestMessageSerde.py new file mode 100644 index 0000000000..33034bce37 --- /dev/null +++ b/photon-serde-tests/py/messages/Float32TestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Float32TestMessage import Float32TestMessage # noqa + + +class Float32TestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "9fd9ed51ec69d6738ee24af43b2b9c7e" + MESSAGE_FORMAT = "float32 test;float32 vlaTest[?];optional float32 optTest;" + + @staticmethod + def pack(value: "Float32TestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type float32 + ret.encodeFloat(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encodeFloat) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encodeFloat) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Float32TestMessage": + ret = Float32TestMessage() + + # test is of intrinsic type float32 + ret.test = packet.decodeFloat() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decodeFloat) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decodeFloat) + + return ret + + +# Hack ourselves into the base class +Float32TestMessage.photonStruct = Float32TestMessageSerde() diff --git a/photon-serde-tests/py/messages/Float64TestMessage.py b/photon-serde-tests/py/messages/Float64TestMessage.py new file mode 100644 index 0000000000..e161d9b6ac --- /dev/null +++ b/photon-serde-tests/py/messages/Float64TestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Float64TestMessageSerde import Float64TestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class Float64TestMessage: + test: float = field( + default_factory=lambda: 0.0 + ) + vlaTest: list[float] = field( + default_factory=list + ) + optTest: Optional[float] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Float64TestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Float64TestMessageSerde.py b/photon-serde-tests/py/messages/Float64TestMessageSerde.py new file mode 100644 index 0000000000..3064394769 --- /dev/null +++ b/photon-serde-tests/py/messages/Float64TestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Float64TestMessage import Float64TestMessage # noqa + + +class Float64TestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "bc96c1f7d9db9371269d0e4f4d4b4cb2" + MESSAGE_FORMAT = "float64 test;float64 vlaTest[?];optional float64 optTest;" + + @staticmethod + def pack(value: "Float64TestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type float64 + ret.encodeDouble(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encodeDouble) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encodeDouble) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Float64TestMessage": + ret = Float64TestMessage() + + # test is of intrinsic type float64 + ret.test = packet.decodeDouble() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decodeDouble) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decodeDouble) + + return ret + + +# Hack ourselves into the base class +Float64TestMessage.photonStruct = Float64TestMessageSerde() diff --git a/photon-serde-tests/py/messages/Int16TestMessage.py b/photon-serde-tests/py/messages/Int16TestMessage.py new file mode 100644 index 0000000000..60a68067e9 --- /dev/null +++ b/photon-serde-tests/py/messages/Int16TestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Int16TestMessageSerde import Int16TestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class Int16TestMessage: + test: int = field( + default_factory=lambda: 0 + ) + vlaTest: list[int] = field( + default_factory=list + ) + optTest: Optional[int] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Int16TestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Int16TestMessageSerde.py b/photon-serde-tests/py/messages/Int16TestMessageSerde.py new file mode 100644 index 0000000000..ae410ed9c1 --- /dev/null +++ b/photon-serde-tests/py/messages/Int16TestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Int16TestMessage import Int16TestMessage # noqa + + +class Int16TestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "23e6ccab160b942600aae8e94a72778a" + MESSAGE_FORMAT = "int16 test;int16 vlaTest[?];optional int16 optTest;" + + @staticmethod + def pack(value: "Int16TestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type int16 + ret.encode16(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encode16) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encode16) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Int16TestMessage": + ret = Int16TestMessage() + + # test is of intrinsic type int16 + ret.test = packet.decode16() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decode16) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decode16) + + return ret + + +# Hack ourselves into the base class +Int16TestMessage.photonStruct = Int16TestMessageSerde() diff --git a/photon-serde-tests/py/messages/Int32TestMessage.py b/photon-serde-tests/py/messages/Int32TestMessage.py new file mode 100644 index 0000000000..077b75dd64 --- /dev/null +++ b/photon-serde-tests/py/messages/Int32TestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Int32TestMessageSerde import Int32TestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class Int32TestMessage: + test: int = field( + default_factory=lambda: 0 + ) + vlaTest: list[int] = field( + default_factory=list + ) + optTest: Optional[int] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Int32TestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Int32TestMessageSerde.py b/photon-serde-tests/py/messages/Int32TestMessageSerde.py new file mode 100644 index 0000000000..e274784cd8 --- /dev/null +++ b/photon-serde-tests/py/messages/Int32TestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Int32TestMessage import Int32TestMessage # noqa + + +class Int32TestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "d8596149c4701e7b8912df238cd4ec66" + MESSAGE_FORMAT = "int32 test;int32 vlaTest[?];optional int32 optTest;" + + @staticmethod + def pack(value: "Int32TestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type int32 + ret.encodeInt(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encodeInt) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encodeInt) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Int32TestMessage": + ret = Int32TestMessage() + + # test is of intrinsic type int32 + ret.test = packet.decodeInt() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decodeInt) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decodeInt) + + return ret + + +# Hack ourselves into the base class +Int32TestMessage.photonStruct = Int32TestMessageSerde() diff --git a/photon-serde-tests/py/messages/Int64TestMessage.py b/photon-serde-tests/py/messages/Int64TestMessage.py new file mode 100644 index 0000000000..bb3352680f --- /dev/null +++ b/photon-serde-tests/py/messages/Int64TestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Int64TestMessageSerde import Int64TestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class Int64TestMessage: + test: int = field( + default_factory=lambda: 0 + ) + vlaTest: list[int] = field( + default_factory=list + ) + optTest: Optional[int] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Int64TestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Int64TestMessageSerde.py b/photon-serde-tests/py/messages/Int64TestMessageSerde.py new file mode 100644 index 0000000000..d7a317edf8 --- /dev/null +++ b/photon-serde-tests/py/messages/Int64TestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Int64TestMessage import Int64TestMessage # noqa + + +class Int64TestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "dd2e470b4d07bbcd208906c26a2ae37a" + MESSAGE_FORMAT = "int64 test;int64 vlaTest[?];optional int64 optTest;" + + @staticmethod + def pack(value: "Int64TestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type int64 + ret.encodeLong(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encodeLong) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encodeLong) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Int64TestMessage": + ret = Int64TestMessage() + + # test is of intrinsic type int64 + ret.test = packet.decodeLong() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decodeLong) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decodeLong) + + return ret + + +# Hack ourselves into the base class +Int64TestMessage.photonStruct = Int64TestMessageSerde() diff --git a/photon-serde-tests/py/messages/Int8TestMessage.py b/photon-serde-tests/py/messages/Int8TestMessage.py new file mode 100644 index 0000000000..3dd9c6a7fb --- /dev/null +++ b/photon-serde-tests/py/messages/Int8TestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Int8TestMessageSerde import Int8TestMessageSerde # noqa + + + +@dataclass(kw_only=True) +class Int8TestMessage: + test: int = field( + default_factory=lambda: 0 + ) + vlaTest: list[int] = field( + default_factory=list + ) + optTest: Optional[int] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Int8TestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Int8TestMessageSerde.py b/photon-serde-tests/py/messages/Int8TestMessageSerde.py new file mode 100644 index 0000000000..4e39b8ecad --- /dev/null +++ b/photon-serde-tests/py/messages/Int8TestMessageSerde.py @@ -0,0 +1,79 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Int8TestMessage import Int8TestMessage # noqa + + +class Int8TestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "76297a79f30e4d995b8f95c5fa6297fa" + MESSAGE_FORMAT = "int8 test;int8 vlaTest[?];optional int8 optTest;" + + @staticmethod + def pack(value: "Int8TestMessage") -> "Packet": + ret = Packet() + + # test is of intrinsic type int8 + ret.encode8(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encode8) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encode8) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Int8TestMessage": + ret = Int8TestMessage() + + # test is of intrinsic type int8 + ret.test = packet.decode8() + + # vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decode8) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decode8) + + return ret + + +# Hack ourselves into the base class +Int8TestMessage.photonStruct = Int8TestMessageSerde() diff --git a/photon-serde-tests/py/messages/Transform3dTestMessage.py b/photon-serde-tests/py/messages/Transform3dTestMessage.py new file mode 100644 index 0000000000..0cd331af2b --- /dev/null +++ b/photon-serde-tests/py/messages/Transform3dTestMessage.py @@ -0,0 +1,51 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .Transform3dTestMessageSerde import Transform3dTestMessageSerde # noqa + +from wpimath import Transform3d + +@dataclass(kw_only=True) +class Transform3dTestMessage: + test: Transform3d = field( + default_factory=lambda: Transform3d() + ) + vlaTest: list[Transform3d] = field( + default_factory=list + ) + optTest: Optional[Transform3d] = field( + default_factory=lambda: None + ) + photonStruct: ClassVar["Transform3dTestMessageSerde"] diff --git a/photon-serde-tests/py/messages/Transform3dTestMessageSerde.py b/photon-serde-tests/py/messages/Transform3dTestMessageSerde.py new file mode 100644 index 0000000000..01aedc8e35 --- /dev/null +++ b/photon-serde-tests/py/messages/Transform3dTestMessageSerde.py @@ -0,0 +1,78 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING + + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * + + + +if TYPE_CHECKING: + from .Transform3dTestMessage import Transform3dTestMessage # noqa + + +class Transform3dTestMessageSerde: + # Message definition md5sum. See photon_packet.adoc for details + MESSAGE_VERSION = "37188f532d61c3b549080489012b4d07" + MESSAGE_FORMAT = "Transform3d test;Transform3d vlaTest[?];optional Transform3d optTest;" + + @staticmethod + def pack(value: "Transform3dTestMessage") -> "Packet": + ret = Packet() + + # test is of shimmed type Transform3d + ret.encodeTransform(value.test) + + # vlaTest is a custom VLA! + ret.encodeListShimmed(value.vlaTest, ret.encodeTransform) + + # optTest is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.optTest, ret.encodeTransform) + return ret + + @staticmethod + def unpack(packet: "Packet") -> "Transform3dTestMessage": + ret = Transform3dTestMessage() + + ret.test = packet.decodeTransform() + + # vlaTest is a shimmed VLA! + ret.vlaTest = packet.decodeListShimmed(packet.decodeTransform) + + # optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalShimmed(packet.decodeTransform) + + return ret + + +# Hack ourselves into the base class +Transform3dTestMessage.photonStruct = Transform3dTestMessageSerde() diff --git a/photon-serde-tests/py/messages/__init__.py b/photon-serde-tests/py/messages/__init__.py new file mode 100644 index 0000000000..cac7dc9329 --- /dev/null +++ b/photon-serde-tests/py/messages/__init__.py @@ -0,0 +1,66 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from .Int8TestMessage import Int8TestMessage +from .Int8TestMessageSerde import Int8TestMessageSerde +from .Int16TestMessage import Int16TestMessage +from .Int16TestMessageSerde import Int16TestMessageSerde +from .Int32TestMessage import Int32TestMessage +from .Int32TestMessageSerde import Int32TestMessageSerde +from .Int64TestMessage import Int64TestMessage +from .Int64TestMessageSerde import Int64TestMessageSerde +from .Float32TestMessage import Float32TestMessage +from .Float32TestMessageSerde import Float32TestMessageSerde +from .Float64TestMessage import Float64TestMessage +from .Float64TestMessageSerde import Float64TestMessageSerde +from .BoolTestMessage import BoolTestMessage +from .BoolTestMessageSerde import BoolTestMessageSerde +from .Transform3dTestMessage import Transform3dTestMessage +from .Transform3dTestMessageSerde import Transform3dTestMessageSerde + + +__all__ = ( + "Int8TestMessage", + "Int8TestMessageSerde", + "Int16TestMessage", + "Int16TestMessageSerde", + "Int32TestMessage", + "Int32TestMessageSerde", + "Int64TestMessage", + "Int64TestMessageSerde", + "Float32TestMessage", + "Float32TestMessageSerde", + "Float64TestMessage", + "Float64TestMessageSerde", + "BoolTestMessage", + "BoolTestMessageSerde", + "Transform3dTestMessage", + "Transform3dTestMessageSerde", + +) \ No newline at end of file diff --git a/photon-serde-tests/requirements.txt b/photon-serde-tests/requirements.txt new file mode 100644 index 0000000000..c85d1cd29f --- /dev/null +++ b/photon-serde-tests/requirements.txt @@ -0,0 +1 @@ +robotpy-wpimath>=2027.0.0a6 diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/BoolTestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/BoolTestMessageSerde.java new file mode 100644 index 0000000000..d016b41c39 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/BoolTestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for BoolTestMessage + */ +public class BoolTestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "c8efe94a9c0d815658c74de6f672939c"; } + @Override + public final String getSchema() { return "bool test;bool vlaTest[?];optional bool optTest;"; } + @Override + public final String getTypeName() { return "BoolTestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, BoolTestMessage value) { + // field test is of intrinsic type bool + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packBoolean); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packBoolean); + } + + @Override + public BoolTestMessage unpack(Packet packet) { + var ret = new BoolTestMessage(); + + // test is of intrinsic type bool + ret.test = packet.decodeBoolean(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackBoolean); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackBoolean); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Float32TestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Float32TestMessageSerde.java new file mode 100644 index 0000000000..e61302dd02 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Float32TestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for Float32TestMessage + */ +public class Float32TestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "9fd9ed51ec69d6738ee24af43b2b9c7e"; } + @Override + public final String getSchema() { return "float32 test;float32 vlaTest[?];optional float32 optTest;"; } + @Override + public final String getTypeName() { return "Float32TestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Float32TestMessage value) { + // field test is of intrinsic type float32 + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packFloat); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packFloat); + } + + @Override + public Float32TestMessage unpack(Packet packet) { + var ret = new Float32TestMessage(); + + // test is of intrinsic type float32 + ret.test = packet.decodeFloat(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackFloat); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackFloat); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Float64TestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Float64TestMessageSerde.java new file mode 100644 index 0000000000..e475a5ff41 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Float64TestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for Float64TestMessage + */ +public class Float64TestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "bc96c1f7d9db9371269d0e4f4d4b4cb2"; } + @Override + public final String getSchema() { return "float64 test;float64 vlaTest[?];optional float64 optTest;"; } + @Override + public final String getTypeName() { return "Float64TestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Float64TestMessage value) { + // field test is of intrinsic type float64 + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packDouble); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packDouble); + } + + @Override + public Float64TestMessage unpack(Packet packet) { + var ret = new Float64TestMessage(); + + // test is of intrinsic type float64 + ret.test = packet.decodeDouble(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackDouble); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackDouble); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Int16TestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Int16TestMessageSerde.java new file mode 100644 index 0000000000..908134519b --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Int16TestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for Int16TestMessage + */ +public class Int16TestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "23e6ccab160b942600aae8e94a72778a"; } + @Override + public final String getSchema() { return "int16 test;int16 vlaTest[?];optional int16 optTest;"; } + @Override + public final String getTypeName() { return "Int16TestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Int16TestMessage value) { + // field test is of intrinsic type int16 + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packShort); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packShort); + } + + @Override + public Int16TestMessage unpack(Packet packet) { + var ret = new Int16TestMessage(); + + // test is of intrinsic type int16 + ret.test = packet.decodeShort(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackShort); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackShort); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Int32TestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Int32TestMessageSerde.java new file mode 100644 index 0000000000..ed8ef13400 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Int32TestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for Int32TestMessage + */ +public class Int32TestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "d8596149c4701e7b8912df238cd4ec66"; } + @Override + public final String getSchema() { return "int32 test;int32 vlaTest[?];optional int32 optTest;"; } + @Override + public final String getTypeName() { return "Int32TestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Int32TestMessage value) { + // field test is of intrinsic type int32 + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packInt); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packInt); + } + + @Override + public Int32TestMessage unpack(Packet packet) { + var ret = new Int32TestMessage(); + + // test is of intrinsic type int32 + ret.test = packet.decodeInt(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackInt); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackInt); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Int64TestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Int64TestMessageSerde.java new file mode 100644 index 0000000000..94bbef6df8 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Int64TestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for Int64TestMessage + */ +public class Int64TestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "dd2e470b4d07bbcd208906c26a2ae37a"; } + @Override + public final String getSchema() { return "int64 test;int64 vlaTest[?];optional int64 optTest;"; } + @Override + public final String getTypeName() { return "Int64TestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Int64TestMessage value) { + // field test is of intrinsic type int64 + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packLong); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packLong); + } + + @Override + public Int64TestMessage unpack(Packet packet) { + var ret = new Int64TestMessage(); + + // test is of intrinsic type int64 + ret.test = packet.decodeLong(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackLong); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackLong); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Int8TestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Int8TestMessageSerde.java new file mode 100644 index 0000000000..2d84615186 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Int8TestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated serialization/deserialization helper for Int8TestMessage + */ +public class Int8TestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "76297a79f30e4d995b8f95c5fa6297fa"; } + @Override + public final String getSchema() { return "int8 test;int8 vlaTest[?];optional int8 optTest;"; } + @Override + public final String getTypeName() { return "Int8TestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Int8TestMessage value) { + // field test is of intrinsic type int8 + packet.encode(value.test); + + // vlaTest is an intrinsic VLA! + packet.encodeListImpl(value.vlaTest,PacketUtils::packByte); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest,PacketUtils::packByte); + } + + @Override + public Int8TestMessage unpack(Packet packet) { + var ret = new Int8TestMessage(); + + // test is of intrinsic type int8 + ret.test = packet.decodeByte(); + + // vlaTest is an intrinsic VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackByte); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackByte); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/struct/Transform3dTestMessageSerde.java b/photon-serde-tests/src/main/java/org/photonvision/struct/Transform3dTestMessageSerde.java new file mode 100644 index 0000000000..24b0b6c1cc --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/struct/Transform3dTestMessageSerde.java @@ -0,0 +1,102 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.struct; + +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; + +// Assume that the base class lives here and we can import it +import org.photonvision.targeting.*; + +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; +import org.wpilib.math.geometry.Transform3d; + +/** + * Auto-generated serialization/deserialization helper for Transform3dTestMessage + */ +public class Transform3dTestMessageSerde implements PacketSerde { + + @Override + public final String getInterfaceUUID() { return "37188f532d61c3b549080489012b4d07"; } + @Override + public final String getSchema() { return "Transform3d test;Transform3d vlaTest[?];optional Transform3d optTest;"; } + @Override + public final String getTypeName() { return "Transform3dTestMessage"; } + + @Override + public int getMaxByteSize() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); + } + @Override + public void pack(Packet packet, Transform3dTestMessage value) { + // test is of shimmed type Transform3d + PacketUtils.packTransform3d(packet, value.test); + + // vlaTest is a shimmed VLA! + packet.encodeListImpl(value.vlaTest, PacketUtils::packTransform3d); + + // optTest is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.optTest, PacketUtils::packTransform3d); + } + + @Override + public Transform3dTestMessage unpack(Packet packet) { + var ret = new Transform3dTestMessage(); + + // test is of shimmed type Transform3d + ret.test = PacketUtils.unpackTransform3d(packet); + + // vlaTest is a shimmed VLA! + ret.vlaTest = packet.decodeListImpl(PacketUtils::unpackTransform3d); + + // optTest is optional! it better not be a VLA too + ret.optTest = packet.decodeOptionalImpl(PacketUtils::unpackTransform3d); + + return ret; + } + + @Override + public PacketSerde[] getNestedPhotonMessages() { + return new PacketSerde[] { + + }; + } + + @Override + public Struct[] getNestedWpilibMessages() { + return new Struct[] { + Transform3d.struct + }; + } +} diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/BoolTestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/BoolTestMessage.java new file mode 100644 index 0000000000..d11f269a96 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/BoolTestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.BoolTestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class BoolTestMessage implements PhotonStructSerializable { + + public boolean test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + BoolTestMessage other = (BoolTestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** BoolTestMessage PhotonStruct for serialization. */ + public static final BoolTestMessageSerde photonStruct = new BoolTestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "BoolTestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Float32TestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Float32TestMessage.java new file mode 100644 index 0000000000..66da4713b8 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Float32TestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Float32TestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Float32TestMessage implements PhotonStructSerializable { + + public float test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Float32TestMessage other = (Float32TestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Float32TestMessage PhotonStruct for serialization. */ + public static final Float32TestMessageSerde photonStruct = new Float32TestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Float32TestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Float64TestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Float64TestMessage.java new file mode 100644 index 0000000000..04c8422d5b --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Float64TestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Float64TestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Float64TestMessage implements PhotonStructSerializable { + + public double test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Float64TestMessage other = (Float64TestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Float64TestMessage PhotonStruct for serialization. */ + public static final Float64TestMessageSerde photonStruct = new Float64TestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Float64TestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Int16TestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int16TestMessage.java new file mode 100644 index 0000000000..38f46f8a4b --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int16TestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Int16TestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Int16TestMessage implements PhotonStructSerializable { + + public short test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Int16TestMessage other = (Int16TestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Int16TestMessage PhotonStruct for serialization. */ + public static final Int16TestMessageSerde photonStruct = new Int16TestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Int16TestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Int32TestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int32TestMessage.java new file mode 100644 index 0000000000..d3d1723099 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int32TestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Int32TestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Int32TestMessage implements PhotonStructSerializable { + + public int test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Int32TestMessage other = (Int32TestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Int32TestMessage PhotonStruct for serialization. */ + public static final Int32TestMessageSerde photonStruct = new Int32TestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Int32TestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Int64TestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int64TestMessage.java new file mode 100644 index 0000000000..6b6859bfa1 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int64TestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Int64TestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Int64TestMessage implements PhotonStructSerializable { + + public long test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Int64TestMessage other = (Int64TestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Int64TestMessage PhotonStruct for serialization. */ + public static final Int64TestMessageSerde photonStruct = new Int64TestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Int64TestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Int8TestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int8TestMessage.java new file mode 100644 index 0000000000..b8af7c5422 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Int8TestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Int8TestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; + + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Int8TestMessage implements PhotonStructSerializable { + + public byte test; + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Int8TestMessage other = (Int8TestMessage) obj; + if (this.test != other.test) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Int8TestMessage PhotonStruct for serialization. */ + public static final Int8TestMessageSerde photonStruct = new Int8TestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Int8TestMessage [" + + "test=" + + test + + ", vlaTest=" + + vlaTest + + ", optTest=" + + optTest + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/java/org/photonvision/targeting/Transform3dTestMessage.java b/photon-serde-tests/src/main/java/org/photonvision/targeting/Transform3dTestMessage.java new file mode 100644 index 0000000000..7362877940 --- /dev/null +++ b/photon-serde-tests/src/main/java/org/photonvision/targeting/Transform3dTestMessage.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.Transform3dTestMessageSerde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; +import org.wpilib.math.geometry.Transform3d; + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class Transform3dTestMessage implements PhotonStructSerializable { + + public Transform3d test = new Transform3d(); + public List vlaTest = List.of(); + public Optional optTest = Optional.empty(); + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + Transform3dTestMessage other = (Transform3dTestMessage) obj; + if (!this.test.equals(other.test)) return false; + if (!this.vlaTest.equals(other.vlaTest)) return false; + if (!this.optTest.equals(other.optTest)) return false; + return true; + } + + /** Transform3dTestMessage PhotonStruct for serialization. */ + public static final Transform3dTestMessageSerde photonStruct = new Transform3dTestMessageSerde(); + + @Override + public PacketSerde getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "Transform3dTestMessage [" + + "test=" + + test.toString() + + ", vlaTest=" + + vlaTest.toString() + + ", optTest=" + + optTest.toString() + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/BoolTestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/BoolTestMessageSerde.cpp new file mode 100644 index 0000000000..93533bdabb --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/BoolTestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/BoolTestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const BoolTestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +BoolTestMessage StructType::Unpack(Packet& packet) { + return BoolTestMessage{ BoolTestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Float32TestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Float32TestMessageSerde.cpp new file mode 100644 index 0000000000..13e20451ca --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Float32TestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Float32TestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Float32TestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Float32TestMessage StructType::Unpack(Packet& packet) { + return Float32TestMessage{ Float32TestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Float64TestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Float64TestMessageSerde.cpp new file mode 100644 index 0000000000..7215e6523e --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Float64TestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Float64TestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Float64TestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Float64TestMessage StructType::Unpack(Packet& packet) { + return Float64TestMessage{ Float64TestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Int16TestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Int16TestMessageSerde.cpp new file mode 100644 index 0000000000..99fd13699f --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Int16TestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Int16TestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Int16TestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Int16TestMessage StructType::Unpack(Packet& packet) { + return Int16TestMessage{ Int16TestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Int32TestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Int32TestMessageSerde.cpp new file mode 100644 index 0000000000..50a9ec29fd --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Int32TestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Int32TestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Int32TestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Int32TestMessage StructType::Unpack(Packet& packet) { + return Int32TestMessage{ Int32TestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Int64TestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Int64TestMessageSerde.cpp new file mode 100644 index 0000000000..a2bb7b34e6 --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Int64TestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Int64TestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Int64TestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Int64TestMessage StructType::Unpack(Packet& packet) { + return Int64TestMessage{ Int64TestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Int8TestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Int8TestMessageSerde.cpp new file mode 100644 index 0000000000..6c9f518f6f --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Int8TestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Int8TestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Int8TestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Int8TestMessage StructType::Unpack(Packet& packet) { + return Int8TestMessage{ Int8TestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/cpp/photon/serde/Transform3dTestMessageSerde.cpp b/photon-serde-tests/src/main/native/cpp/photon/serde/Transform3dTestMessageSerde.cpp new file mode 100644 index 0000000000..223bb00370 --- /dev/null +++ b/photon-serde-tests/src/main/native/cpp/photon/serde/Transform3dTestMessageSerde.cpp @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/serde/Transform3dTestMessageSerde.h" + + +namespace photon { + +using StructType = SerdeType; + +void StructType::Pack(Packet& packet, const Transform3dTestMessage& value) { + packet.Pack(value.test); + packet.Pack>(value.vlaTest); + packet.Pack>(value.optTest); +} + +Transform3dTestMessage StructType::Unpack(Packet& packet) { + return Transform3dTestMessage{ Transform3dTestMessage_PhotonStruct{ + .test = packet.Unpack(), + .vlaTest = packet.Unpack>(), + .optTest = packet.Unpack>(), + }}; +} + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/BoolTestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/BoolTestMessageSerde.h new file mode 100644 index 0000000000..a671323f45 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/BoolTestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/BoolTestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "c8efe94a9c0d815658c74de6f672939c"; + } + + static constexpr std::string_view GetSchema() { + return "bool test;bool vlaTest[?];optional bool optTest;"; + } + + static photon::BoolTestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::BoolTestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Float32TestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Float32TestMessageSerde.h new file mode 100644 index 0000000000..34d82a2ca3 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Float32TestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Float32TestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "9fd9ed51ec69d6738ee24af43b2b9c7e"; + } + + static constexpr std::string_view GetSchema() { + return "float32 test;float32 vlaTest[?];optional float32 optTest;"; + } + + static photon::Float32TestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Float32TestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Float64TestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Float64TestMessageSerde.h new file mode 100644 index 0000000000..a2d6b0f1da --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Float64TestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Float64TestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "bc96c1f7d9db9371269d0e4f4d4b4cb2"; + } + + static constexpr std::string_view GetSchema() { + return "float64 test;float64 vlaTest[?];optional float64 optTest;"; + } + + static photon::Float64TestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Float64TestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Int16TestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Int16TestMessageSerde.h new file mode 100644 index 0000000000..b71917804a --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Int16TestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Int16TestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "23e6ccab160b942600aae8e94a72778a"; + } + + static constexpr std::string_view GetSchema() { + return "int16 test;int16 vlaTest[?];optional int16 optTest;"; + } + + static photon::Int16TestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Int16TestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Int32TestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Int32TestMessageSerde.h new file mode 100644 index 0000000000..5eb44c6381 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Int32TestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Int32TestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "d8596149c4701e7b8912df238cd4ec66"; + } + + static constexpr std::string_view GetSchema() { + return "int32 test;int32 vlaTest[?];optional int32 optTest;"; + } + + static photon::Int32TestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Int32TestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Int64TestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Int64TestMessageSerde.h new file mode 100644 index 0000000000..a2beb754f4 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Int64TestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Int64TestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "dd2e470b4d07bbcd208906c26a2ae37a"; + } + + static constexpr std::string_view GetSchema() { + return "int64 test;int64 vlaTest[?];optional int64 optTest;"; + } + + static photon::Int64TestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Int64TestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Int8TestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Int8TestMessageSerde.h new file mode 100644 index 0000000000..d1c526b338 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Int8TestMessageSerde.h @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Int8TestMessage.h" + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "76297a79f30e4d995b8f95c5fa6297fa"; + } + + static constexpr std::string_view GetSchema() { + return "int8 test;int8 vlaTest[?];optional int8 optTest;"; + } + + static photon::Int8TestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Int8TestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/serde/Transform3dTestMessageSerde.h b/photon-serde-tests/src/main/native/include/photon/serde/Transform3dTestMessageSerde.h new file mode 100644 index 0000000000..69bcc31f3f --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/serde/Transform3dTestMessageSerde.h @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include + +// Include myself +#include "photon/dataflow/structures/Packet.h" +#include "photon/targeting/Transform3dTestMessage.h" + +// Includes for dependant types +#include +#include +#include +#include + + +namespace photon { + +template <> +struct WPILIB_DLLEXPORT SerdeType { + static constexpr std::string_view GetSchemaHash() { + return "37188f532d61c3b549080489012b4d07"; + } + + static constexpr std::string_view GetSchema() { + return "Transform3d test;Transform3d vlaTest[?];optional Transform3d optTest;"; + } + + static photon::Transform3dTestMessage Unpack(photon::Packet& packet); + static void Pack(photon::Packet& packet, const photon::Transform3dTestMessage& value); +}; + +static_assert(photon::PhotonStructSerializable); + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/BoolTestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/BoolTestMessageStruct.h new file mode 100644 index 0000000000..a3fca76c9d --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/BoolTestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct BoolTestMessage_PhotonStruct { + bool test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(BoolTestMessage_PhotonStruct const&, BoolTestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Float32TestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Float32TestMessageStruct.h new file mode 100644 index 0000000000..652daa87dd --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Float32TestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct Float32TestMessage_PhotonStruct { + float test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Float32TestMessage_PhotonStruct const&, Float32TestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Float64TestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Float64TestMessageStruct.h new file mode 100644 index 0000000000..5ee739d063 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Float64TestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct Float64TestMessage_PhotonStruct { + double test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Float64TestMessage_PhotonStruct const&, Float64TestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Int16TestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Int16TestMessageStruct.h new file mode 100644 index 0000000000..356b0ae1d5 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Int16TestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct Int16TestMessage_PhotonStruct { + int16_t test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Int16TestMessage_PhotonStruct const&, Int16TestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Int32TestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Int32TestMessageStruct.h new file mode 100644 index 0000000000..519a6aed06 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Int32TestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct Int32TestMessage_PhotonStruct { + int32_t test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Int32TestMessage_PhotonStruct const&, Int32TestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Int64TestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Int64TestMessageStruct.h new file mode 100644 index 0000000000..f4ce39755e --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Int64TestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct Int64TestMessage_PhotonStruct { + int64_t test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Int64TestMessage_PhotonStruct const&, Int64TestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Int8TestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Int8TestMessageStruct.h new file mode 100644 index 0000000000..5b37d13a64 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Int8TestMessageStruct.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include + + +namespace photon { + +struct Int8TestMessage_PhotonStruct { + int8_t test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Int8TestMessage_PhotonStruct const&, Int8TestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/struct/Transform3dTestMessageStruct.h b/photon-serde-tests/src/main/native/include/photon/struct/Transform3dTestMessageStruct.h new file mode 100644 index 0000000000..2cb9dd7481 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/struct/Transform3dTestMessageStruct.h @@ -0,0 +1,46 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +// Includes for dependant types +#include +#include +#include +#include + + +namespace photon { + +struct Transform3dTestMessage_PhotonStruct { + wpi::math::Transform3d test; + std::vector vlaTest; + std::optional optTest; + + friend bool operator==(Transform3dTestMessage_PhotonStruct const&, Transform3dTestMessage_PhotonStruct const&) = default; +}; + +} // namespace photon diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/BoolTestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/BoolTestMessage.h new file mode 100644 index 0000000000..ae7b782c59 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/BoolTestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/BoolTestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class BoolTestMessage : public BoolTestMessage_PhotonStruct { + using Base = BoolTestMessage_PhotonStruct; + +public: + BoolTestMessage() = default; + + explicit BoolTestMessage(Base&& data) : Base(data) {} + + template + explicit BoolTestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(BoolTestMessage const&, BoolTestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/BoolTestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Float32TestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Float32TestMessage.h new file mode 100644 index 0000000000..f020bb63ee --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Float32TestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Float32TestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Float32TestMessage : public Float32TestMessage_PhotonStruct { + using Base = Float32TestMessage_PhotonStruct; + +public: + Float32TestMessage() = default; + + explicit Float32TestMessage(Base&& data) : Base(data) {} + + template + explicit Float32TestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Float32TestMessage const&, Float32TestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Float32TestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Float64TestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Float64TestMessage.h new file mode 100644 index 0000000000..79d80fd45b --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Float64TestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Float64TestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Float64TestMessage : public Float64TestMessage_PhotonStruct { + using Base = Float64TestMessage_PhotonStruct; + +public: + Float64TestMessage() = default; + + explicit Float64TestMessage(Base&& data) : Base(data) {} + + template + explicit Float64TestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Float64TestMessage const&, Float64TestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Float64TestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Int16TestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Int16TestMessage.h new file mode 100644 index 0000000000..a05168af30 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Int16TestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Int16TestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Int16TestMessage : public Int16TestMessage_PhotonStruct { + using Base = Int16TestMessage_PhotonStruct; + +public: + Int16TestMessage() = default; + + explicit Int16TestMessage(Base&& data) : Base(data) {} + + template + explicit Int16TestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Int16TestMessage const&, Int16TestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Int16TestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Int32TestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Int32TestMessage.h new file mode 100644 index 0000000000..d5df8c6063 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Int32TestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Int32TestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Int32TestMessage : public Int32TestMessage_PhotonStruct { + using Base = Int32TestMessage_PhotonStruct; + +public: + Int32TestMessage() = default; + + explicit Int32TestMessage(Base&& data) : Base(data) {} + + template + explicit Int32TestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Int32TestMessage const&, Int32TestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Int32TestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Int64TestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Int64TestMessage.h new file mode 100644 index 0000000000..9df6fa7fee --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Int64TestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Int64TestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Int64TestMessage : public Int64TestMessage_PhotonStruct { + using Base = Int64TestMessage_PhotonStruct; + +public: + Int64TestMessage() = default; + + explicit Int64TestMessage(Base&& data) : Base(data) {} + + template + explicit Int64TestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Int64TestMessage const&, Int64TestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Int64TestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Int8TestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Int8TestMessage.h new file mode 100644 index 0000000000..d7e9e3c3ea --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Int8TestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Int8TestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Int8TestMessage : public Int8TestMessage_PhotonStruct { + using Base = Int8TestMessage_PhotonStruct; + +public: + Int8TestMessage() = default; + + explicit Int8TestMessage(Base&& data) : Base(data) {} + + template + explicit Int8TestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Int8TestMessage const&, Int8TestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Int8TestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/main/native/include/photon/targeting/Transform3dTestMessage.h b/photon-serde-tests/src/main/native/include/photon/targeting/Transform3dTestMessage.h new file mode 100644 index 0000000000..1b12f52678 --- /dev/null +++ b/photon-serde-tests/src/main/native/include/photon/targeting/Transform3dTestMessage.h @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/Transform3dTestMessageStruct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class Transform3dTestMessage : public Transform3dTestMessage_PhotonStruct { + using Base = Transform3dTestMessage_PhotonStruct; + +public: + Transform3dTestMessage() = default; + + explicit Transform3dTestMessage(Base&& data) : Base(data) {} + + template + explicit Transform3dTestMessage(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==(Transform3dTestMessage const&, Transform3dTestMessage const&) = default; +}; +} // namespace photon + +#include "photon/serde/Transform3dTestMessageSerde.h" \ No newline at end of file diff --git a/photon-serde-tests/src/test/java/org/photonvision/AutoSerdeTest.java b/photon-serde-tests/src/test/java/org/photonvision/AutoSerdeTest.java new file mode 100644 index 0000000000..f5ca569e9a --- /dev/null +++ b/photon-serde-tests/src/test/java/org/photonvision/AutoSerdeTest.java @@ -0,0 +1,261 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.targeting.*; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +import org.wpilib.math.geometry.Rotation3d; +import org.wpilib.math.geometry.Translation3d; +import org.wpilib.math.geometry.Transform3d; + + +public class AutoSerdeTest { + private > boolean testSerde(T data) { + var p = new Packet(10); + p.encode(data); + var unpackedData = p.decode(data); // kinda scuffed lowkey + System.out.println("IN: " + data.toString() + "\nOUT: " + unpackedData.toString()); + return data.equals(unpackedData); + } + + @Test + public void Int8Test() { + System.out.println("Running Int8Test"); + + System.out.println("Test case default_test:"); + var default_test = new Int8TestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Int8TestMessage(); + optional_test.optTest = Optional.of((byte) 3); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Int8TestMessage(); + vla_test.vlaTest = List.of((byte) 1, (byte) 2, (byte) 3); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Int8TestMessage(); + general_test.test = (byte) 42; + general_test.optTest = Optional.of((byte) 7); + general_test.vlaTest = List.of((byte) 4, (byte) 5, (byte) 6); + assertTrue(testSerde(general_test)); + + } + + @Test + public void Int16Test() { + System.out.println("Running Int16Test"); + + System.out.println("Test case default_test:"); + var default_test = new Int16TestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Int16TestMessage(); + optional_test.optTest = Optional.of((short) 3); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Int16TestMessage(); + vla_test.vlaTest = List.of((short) 1, (short) 2, (short) 3); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Int16TestMessage(); + general_test.test = (short) 42; + general_test.optTest = Optional.of((short) 7); + general_test.vlaTest = List.of((short) 4, (short) 5, (short) 6); + assertTrue(testSerde(general_test)); + + } + + @Test + public void Int32Test() { + System.out.println("Running Int32Test"); + + System.out.println("Test case default_test:"); + var default_test = new Int32TestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Int32TestMessage(); + optional_test.optTest = Optional.of((int) 3); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Int32TestMessage(); + vla_test.vlaTest = List.of((int) 1, (int) 2, (int) 3); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Int32TestMessage(); + general_test.test = (int) 42; + general_test.optTest = Optional.of((int) 7); + general_test.vlaTest = List.of((int) 4, (int) 5, (int) 6); + assertTrue(testSerde(general_test)); + + } + + @Test + public void Int64Test() { + System.out.println("Running Int64Test"); + + System.out.println("Test case default_test:"); + var default_test = new Int64TestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Int64TestMessage(); + optional_test.optTest = Optional.of((long) 3); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Int64TestMessage(); + vla_test.vlaTest = List.of((long) 1, (long) 2, (long) 3); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Int64TestMessage(); + general_test.test = (long) 42; + general_test.optTest = Optional.of((long) 7); + general_test.vlaTest = List.of((long) 4, (long) 5, (long) 6); + assertTrue(testSerde(general_test)); + + } + + @Test + public void Float32Test() { + System.out.println("Running Float32Test"); + + System.out.println("Test case default_test:"); + var default_test = new Float32TestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Float32TestMessage(); + optional_test.optTest = Optional.of((float) 3.0); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Float32TestMessage(); + vla_test.vlaTest = List.of((float) 1.0, (float) 2.0, (float) 3.0); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Float32TestMessage(); + general_test.test = (float) 42.0; + general_test.optTest = Optional.of((float) 7.0); + general_test.vlaTest = List.of((float) 4.0, (float) 5.0, (float) 6.0); + assertTrue(testSerde(general_test)); + + } + + @Test + public void Float64Test() { + System.out.println("Running Float64Test"); + + System.out.println("Test case default_test:"); + var default_test = new Float64TestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Float64TestMessage(); + optional_test.optTest = Optional.of((double) 3.0); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Float64TestMessage(); + vla_test.vlaTest = List.of((double) 1.0, (double) 2.0, (double) 3.0); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Float64TestMessage(); + general_test.test = (double) 42.0; + general_test.optTest = Optional.of((double) 7.0); + general_test.vlaTest = List.of((double) 4.0, (double) 5.0, (double) 6.0); + assertTrue(testSerde(general_test)); + + } + + @Test + public void BoolTest() { + System.out.println("Running BoolTest"); + + System.out.println("Test case default_test:"); + var default_test = new BoolTestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new BoolTestMessage(); + optional_test.optTest = Optional.of(true); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new BoolTestMessage(); + vla_test.vlaTest = List.of(true, false, true); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new BoolTestMessage(); + general_test.test = false; + general_test.optTest = Optional.of(true); + general_test.vlaTest = List.of(true, false, true); + assertTrue(testSerde(general_test)); + + } + + @Test + public void Transform3dTest() { + System.out.println("Running Transform3dTest"); + + System.out.println("Test case default_test:"); + var default_test = new Transform3dTestMessage(); + assertTrue(testSerde(default_test)); + + System.out.println("Test case optional_test:"); + var optional_test = new Transform3dTestMessage(); + optional_test.optTest = Optional.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3))); + assertTrue(testSerde(optional_test)); + + System.out.println("Test case vla_test:"); + var vla_test = new Transform3dTestMessage(); + vla_test.vlaTest = List.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3)), new Transform3d(new Translation3d(4.0, 5.0, 6.0), new Rotation3d(0.4, 0.5, 0.6))); + assertTrue(testSerde(vla_test)); + + System.out.println("Test case general_test:"); + var general_test = new Transform3dTestMessage(); + general_test.test = new Transform3d(new Translation3d(7.0, 8.0, 9.0), new Rotation3d(0.7, 0.8, 0.9)); + general_test.optTest = Optional.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3))); + general_test.vlaTest = List.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3)), new Transform3d(new Translation3d(4.0, 5.0, 6.0), new Rotation3d(0.4, 0.5, 0.6))); + assertTrue(testSerde(general_test)); + + } + +} \ No newline at end of file diff --git a/photon-serde-tests/src/test/native/cpp/AutoSerdeTest.cpp b/photon-serde-tests/src/test/native/cpp/AutoSerdeTest.cpp new file mode 100644 index 0000000000..bfd07cb4df --- /dev/null +++ b/photon-serde-tests/src/test/native/cpp/AutoSerdeTest.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include +#include +#include + +#include + +#include "gtest/gtest.h" + +#include +#include +#include +#include + + +#include "photon/targeting/Int8TestMessage.h" +#include "photon/targeting/Int16TestMessage.h" +#include "photon/targeting/Int32TestMessage.h" +#include "photon/targeting/Int64TestMessage.h" +#include "photon/targeting/Float32TestMessage.h" +#include "photon/targeting/Float64TestMessage.h" +#include "photon/targeting/BoolTestMessage.h" +#include "photon/targeting/Transform3dTestMessage.h" + + +// Hack +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +using namespace photon; + +template + requires(PhotonStructSerializable) +inline bool test_serde(const T& data) { + Packet p; + p.Pack(data); + T unpackedData = p.Unpack(); + return data == unpackedData; +} + + +TEST(AutoSerdeTest, Int8Test) { + std::cout << "Running Int8Test\n"; + + Int8TestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Int8TestMessage optional_test{}; + optional_test.optTest = {3}; + ASSERT_TRUE(test_serde(optional_test)); + + Int8TestMessage vla_test{}; + vla_test.vlaTest = {1, 2, 3}; + ASSERT_TRUE(test_serde(vla_test)); + + Int8TestMessage general_test{}; + general_test.test = 42; + general_test.optTest = {7}; + general_test.vlaTest = {4, 5, 6}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, Int16Test) { + std::cout << "Running Int16Test\n"; + + Int16TestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Int16TestMessage optional_test{}; + optional_test.optTest = {3}; + ASSERT_TRUE(test_serde(optional_test)); + + Int16TestMessage vla_test{}; + vla_test.vlaTest = {1, 2, 3}; + ASSERT_TRUE(test_serde(vla_test)); + + Int16TestMessage general_test{}; + general_test.test = 42; + general_test.optTest = {7}; + general_test.vlaTest = {4, 5, 6}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, Int32Test) { + std::cout << "Running Int32Test\n"; + + Int32TestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Int32TestMessage optional_test{}; + optional_test.optTest = {3}; + ASSERT_TRUE(test_serde(optional_test)); + + Int32TestMessage vla_test{}; + vla_test.vlaTest = {1, 2, 3}; + ASSERT_TRUE(test_serde(vla_test)); + + Int32TestMessage general_test{}; + general_test.test = 42; + general_test.optTest = {7}; + general_test.vlaTest = {4, 5, 6}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, Int64Test) { + std::cout << "Running Int64Test\n"; + + Int64TestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Int64TestMessage optional_test{}; + optional_test.optTest = {3}; + ASSERT_TRUE(test_serde(optional_test)); + + Int64TestMessage vla_test{}; + vla_test.vlaTest = {1, 2, 3}; + ASSERT_TRUE(test_serde(vla_test)); + + Int64TestMessage general_test{}; + general_test.test = 42; + general_test.optTest = {7}; + general_test.vlaTest = {4, 5, 6}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, Float32Test) { + std::cout << "Running Float32Test\n"; + + Float32TestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Float32TestMessage optional_test{}; + optional_test.optTest = {3.0}; + ASSERT_TRUE(test_serde(optional_test)); + + Float32TestMessage vla_test{}; + vla_test.vlaTest = {1.0, 2.0, 3.0}; + ASSERT_TRUE(test_serde(vla_test)); + + Float32TestMessage general_test{}; + general_test.test = 42.0; + general_test.optTest = {7.0}; + general_test.vlaTest = {4.0, 5.0, 6.0}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, Float64Test) { + std::cout << "Running Float64Test\n"; + + Float64TestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Float64TestMessage optional_test{}; + optional_test.optTest = {3.0}; + ASSERT_TRUE(test_serde(optional_test)); + + Float64TestMessage vla_test{}; + vla_test.vlaTest = {1.0, 2.0, 3.0}; + ASSERT_TRUE(test_serde(vla_test)); + + Float64TestMessage general_test{}; + general_test.test = 42.0; + general_test.optTest = {7.0}; + general_test.vlaTest = {4.0, 5.0, 6.0}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, BoolTest) { + std::cout << "Running BoolTest\n"; + + BoolTestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + BoolTestMessage optional_test{}; + optional_test.optTest = {true}; + ASSERT_TRUE(test_serde(optional_test)); + + BoolTestMessage vla_test{}; + vla_test.vlaTest = {true, false, true}; + ASSERT_TRUE(test_serde(vla_test)); + + BoolTestMessage general_test{}; + general_test.test = false; + general_test.optTest = {true}; + general_test.vlaTest = {true, false, true}; + ASSERT_TRUE(test_serde(general_test)); + +} + +TEST(AutoSerdeTest, Transform3dTest) { + std::cout << "Running Transform3dTest\n"; + + Transform3dTestMessage default_test{}; + ASSERT_TRUE(test_serde(default_test)); + + Transform3dTestMessage optional_test{}; + optional_test.optTest = {1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}}; + ASSERT_TRUE(test_serde(optional_test)); + + Transform3dTestMessage vla_test{}; + vla_test.vlaTest = {{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{8_m, 2_m, 1_m, wpi::math::Rotation3d{0_deg, 1_deg, 88_deg}}}; + ASSERT_TRUE(test_serde(vla_test)); + + Transform3dTestMessage general_test{}; + general_test.test = {8_m, 2_m, 1_m, wpi::math::Rotation3d{0_deg, 1_deg, 88_deg}}; + general_test.optTest = {1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}}; + general_test.vlaTest = {{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{8_m, 2_m, 1_m, wpi::math::Rotation3d{0_deg, 1_deg, 88_deg}}}; + ASSERT_TRUE(test_serde(general_test)); + +} diff --git a/photon-serde/README.md b/photon-serde/README.md index 50777ebffb..93f48a76a0 100644 --- a/photon-serde/README.md +++ b/photon-serde/README.md @@ -80,3 +80,140 @@ float64 poseAmbiguity; TargetCorner:16f6ac0dedc8eaccb951f4895d9e18b6[?] minAreaRectCorners; TargetCorner:16f6ac0dedc8eaccb951f4895d9e18b6[?] detectedCorners; ``` + +## Serialization Protocol + +photon-serde works by decomposing every message into a few intrinsic types: these are `int8` `int16` `int32` `int64` `float32` `float64` `boolean`. These intrinsic types are essentially copied directly, with no special logic for ser/de. + +Shimmed messages are a special case where we need to encode/decode a type that is not part of Photonvision (e.g. WPILib types like Transform3d, Rotation2d, etc.), so we send them to a custom shim that isn't automatically generated by photon-serde + +Custom messages essentially serialize their fields next to each other in memory. Fields can either be an intrinsic type, in which it'll be copied directly, a shimmed type, in which case it'll be encoded with the corresponding shim, or a nested custom message, in which case the corresponding ser/de will be called, which will invoke the same rules on the custom type field. Any field can also be a Variable-length array, in which case the values will be stored contiguously in binary, and prepended with a length byte telling the ser/de the length of the array (and then normal ser/de rules apply to the array elements), or an Optional, in which case the value will be prepended with a boolean flag that signal whether or not the value is present. If the flag is set, the normal ser/de rules apply. Otherwise, the flag will be followed immediately by the next field or the end of the message, without any sort of sentinal or placeholder value. However, a field cannot be BOTH a vla and optional at the same time + +Custom messages are defined in the `messages.yaml` file + +### A Worked Example + +As an example of how the serde protocol works, let's consider the following messages +```yaml +--- +- name: foo +# Every message type has a unique name + fields: + - name: foo_foo + type: int32 + - name: foo_bar + type: int16 + vla: true +- name: bar +# A single yaml file can define multiple message types + fields: + - name: bar_foo + type: int32 + - name: bar_bar + type: foo + - name: bar_baz + type: foo + vla: true + - name: bar_qux + type: foo + optional: true + - name: bar_quux + type: Transform3d + # This is an example of a shimmed type, corresponding to WPILib's Transform3d. The message definition is omitted here for brevity +``` + +`foo` would be encoded as +``` +foo_foo (int32) | foo_bar size (int8) | foo_bar data (int16[]) +``` + +and `bar` would be encoded as +``` +bar_foo (int32) | bar_bar (foo) | bar_baz size (int8) | bar_baz data (foo[]) | bar_qux present (bool) | bar_qux data (foo?) | bar_quux (Transform3d) +``` +> `bar_qux data` is skipped entirely if `bar_qux present` is `false` + +Below is C-style pseudocode for a hypothetical ser/de generated from these messages (The actual implementations of photon-serde doesn't look exactly like this, but the base logic is the same) + +```c +struct foo { + int32_t foo_foo + int16_t[size] foo_bar +} + +void serialize_foo(packet& p, foo val){ + p.packInt32(val.foo_foo) + + p.packInt8(val.foo_bar size) + for (ele in val.foo_bar) { + p.packInt16(ele) + } +} + +// fields are serialized and deserialized in the same order +foo deserialize_foo(packet& p){ + foo out + + out.foo_foo p.unpackInt32() + + int8_t size = p.unpackInt8() + out.foo_bar = int16_t[size] + for (int i; i < size; i++) { + out.foo_bar[i] = p.unpackInt16() + } + + return foo +} +``` + +```c +struct bar { + int32_t bar_foo + foo bar_bar + foo[size] bar_baz + foo? bar_quz + foo bar_quuz +} + +void serialize_bar(packet& p, foo val){ + p.packInt32(val.bar_foo) + serialize_foo(p,val.bar_bar) + + p.packInt8(val.bar_baz size) + for (ele in val.bar_baz) { + serialize_foo(p,ele) + } + + p.packBool(val.bar_quz present) + if (val.bar_quz present) { + serialize_foo(p,val.bar_quz value) + } + + Transform3d_encode_shim(p,val.bar_quuz) +} + +foo deserialize_bar(packet& p){ + bar out + + out.bar_foo = p.unpackInt32() + + out.bar_bar = deserialize_foo(p) + + int8_t bar_baz size = p.unpackInt8() + out.bar_baz = int16_t[bar_baz size] + for (int i; i < bar_baz size; i++) { + out.bar_baz[i] = deserialize_foo(p) + } + + bool bar_quz present = p.unpackBool() + if (bar_quz present) { + out.bar_quz = deserialize_foo(p) + } else { + out.bar_quz = empty + } + + out.bar_quuz = Transform3d_decode_shim(p) + + return foo +} +``` diff --git a/photon-serde/generate_messages.py b/photon-serde/generate_messages.py index 8013b0f120..c8204f02d6 100644 --- a/photon-serde/generate_messages.py +++ b/photon-serde/generate_messages.py @@ -27,6 +27,12 @@ import yaml from jinja2 import Environment, FileSystemLoader +PYTHON_INTRINSIC_DEFAULTS = { + "int": "0", + "float": "0.0", + "bool": "False", +} + class SerdeField(TypedDict): name: str @@ -39,6 +45,8 @@ class SerdeField(TypedDict): class MessageType(TypedDict): name: str fields: List[SerdeField] + # whether or not this is a test message type. If yes, test classes will be autogenerated alongside the ser/de code + test: bool # will be 'shim' if shimmed, and the shims will be set shimmed: bool java_decode_shim: str @@ -87,7 +95,16 @@ def is_shimmed(message_name: str): return is_shimmed -def get_qualified_cpp_name( +# Deal with test types +def get_test_filter(message_db): + def is_test(message_name: str): + message = get_message_by_name(message_db, message_name) + return "test" in message and message["test"] == True + + return is_test + + +def get_cpp_qualified_name( message_db: List[MessageType], data_types, field: SerdeField ): """ @@ -111,6 +128,39 @@ def get_qualified_cpp_name( return typestr +def get_python_qualified_name( + message_db: List[MessageType], data_types, field: SerdeField +): + """ + Get the full name of the type encoded. Eg: + list[Transform3d] + """ + + base_type = data_types[field["type"]]["python_type"] + + if "optional" in field and field["optional"] == True: + typestr = f"Optional[{base_type}]" + elif "vla" in field and field["vla"] == True: + typestr = f"list[{base_type}]" + else: + typestr = base_type + + return typestr + + +def get_python_default_factory( + message_db: List[MessageType], data_types, field: SerdeField +) -> str: + if "optional" in field and field["optional"] == True: + return "lambda: None" + if "vla" in field and field["vla"] == True: + return "list" + if is_intrinsic_type(field["type"]): + return f"lambda: {PYTHON_INTRINSIC_DEFAULTS[data_types[field["type"]]["python_type"]]}" + else: + return f"lambda: {field['type']}()" + + def get_message_by_name(message_db: List[MessageType], message_name: str): try: return next( @@ -177,8 +227,8 @@ def get_includes(db, message: MessageType) -> str: return sorted(set(includes)) -def parse_yaml() -> List[MessageType]: - config = yaml_to_dict("messages.yaml") +def parse_yaml(message_file: str) -> List[MessageType]: + config = yaml_to_dict(message_file) return config @@ -241,7 +291,7 @@ def get_struct_schema_str(message: MessageType, message_db: List[MessageType]): def generate_photon_messages(cpp_java_root, py_root, template_root): - messages = parse_yaml() + messages = parse_yaml("messages.yaml") for message in messages: message["message_hash"] = get_message_hash(messages, message) @@ -254,6 +304,7 @@ def generate_photon_messages(cpp_java_root, py_root, template_root): env.filters["is_intrinsic"] = is_intrinsic_type env.filters["is_shimmed"] = get_shimmed_filter(messages) + env.filters["is_test"] = lambda _x: False # no test messages in this pass # add our custom types extended_data_types = data_types.copy() @@ -263,6 +314,7 @@ def generate_photon_messages(cpp_java_root, py_root, template_root): "len": -1, "java_type": name, "cpp_type": "photon::" + name, + "python_type": name, } java_output_dir = Path(cpp_java_root) / "main/java/org/photonvision/struct" @@ -279,12 +331,19 @@ def generate_photon_messages(cpp_java_root, py_root, template_root): py_serde_source_dir = Path(py_root) py_serde_source_dir.mkdir(parents=True, exist_ok=True) - env.filters["get_qualified_name"] = lambda field: get_qualified_cpp_name( + env.filters["get_cpp_qualified_name"] = lambda field: get_cpp_qualified_name( + messages, extended_data_types, field + ) + + env.filters["get_python_qualified_name"] = lambda field: get_python_qualified_name( messages, extended_data_types, field ) + env.filters["get_python_default_factory"] = ( + lambda field: get_python_default_factory(messages, extended_data_types, field) + ) for message in messages: - # don't generate shimmed types + # don't generate shimmed types. Probably not necessa if get_shimmed_filter(messages)(message["name"]): continue @@ -349,11 +408,208 @@ def generate_photon_messages(cpp_java_root, py_root, template_root): cpp_includes=get_includes(messages, message), nested_photon_types=nested_photon_types, nested_wpilib_types=nested_wpilib_types, + test=False, ), encoding="utf-8", ) +# TODO: code duplication +def generate_tests(cpp_java_test_root, py_test_root, template_root): + + # Generate test messages + test_messages = parse_yaml("test_messages.yaml") + real_messages = parse_yaml("messages.yaml") + message_db = test_messages + real_messages + + for message in real_messages: + message["message_hash"] = get_message_hash(real_messages, message) + + for test_message in test_messages: + test_message["message_hash"] = get_message_hash(message_db, message) + + env = Environment( + loader=FileSystemLoader(str(template_root)), + # autoescape=False, + # keep_trailing_newline=False, + ) + + env.filters["is_intrinsic"] = is_intrinsic_type + env.filters["is_shimmed"] = get_shimmed_filter(message_db) + env.filters["is_test"] = get_test_filter(message_db) + + # add our custom types + extended_data_types = data_types.copy() + for message in message_db: + name = message["name"] + extended_data_types[name] = { + "len": -1, + "java_type": name, + "cpp_type": "photon::" + name, + "python_type": name, + } + + java_output_dir = Path(cpp_java_test_root) / "main/java/org/photonvision/struct" + java_output_dir.mkdir(parents=True, exist_ok=True) + + java_test_class_output_dir = ( + Path(cpp_java_test_root) / "main/java/org/photonvision/targeting" + ) + java_test_class_output_dir.mkdir(parents=True, exist_ok=True) + + cpp_serde_header_dir = Path(cpp_java_test_root) / "main/native/include/photon/serde" + cpp_serde_header_dir.mkdir(parents=True, exist_ok=True) + cpp_serde_source_dir = Path(cpp_java_test_root) / "main/native/cpp/photon/serde" + cpp_serde_source_dir.mkdir(parents=True, exist_ok=True) + + cpp_struct_header_dir = ( + Path(cpp_java_test_root) / "main/native/include/photon/struct/" + ) + cpp_struct_header_dir.mkdir(parents=True, exist_ok=True) + + cpp_test_struct_output_dir = ( + Path(cpp_java_test_root) / "main/native/include/photon/targeting/" + ) + cpp_test_struct_output_dir.mkdir(parents=True, exist_ok=True) + + py_serde_source_dir = Path(py_test_root) / "messages" + py_serde_source_dir.mkdir(parents=True, exist_ok=True) + + python_test_dataclass_output_dir = Path(py_test_root) / "messages" + + env.filters["get_cpp_qualified_name"] = lambda field: get_cpp_qualified_name( + message_db, extended_data_types, field + ) + + env.filters["get_python_qualified_name"] = lambda field: get_python_qualified_name( + message_db, extended_data_types, field + ) + env.filters["get_python_default_factory"] = ( + lambda field: get_python_default_factory(message_db, extended_data_types, field) + ) + + for test_message in test_messages: + + # don't generate shimmed types. TODO: Probably unnecessary for test messages + if get_shimmed_filter(message_db)(test_message["name"]): + continue + + test_message = cast(MessageType, test_message) + + java_name = f"{test_message['name']}Serde.java" + cpp_serde_header_name = f"{test_message['name']}Serde.h" + cpp_serde_source_name = f"{test_message['name']}Serde.cpp" + cpp_struct_header_name = f"{test_message['name']}Struct.h" + py_name = f"{test_message['name']}Serde.py" + + java_template = env.get_template("Message.java.jinja") + + cpp_serde_header_template = env.get_template("ThingSerde.h.jinja") + cpp_serde_source_template = env.get_template("ThingSerde.cpp.jinja") + cpp_struct_header_template = env.get_template("ThingStruct.h.jinja") + + py_template = env.get_template("ThingSerde.py.jinja") + + message_hash = get_message_hash(message_db, test_message) + + java_test_class_name = f"{test_message['name']}.java" + java_test_class_template = env.get_template("ThingTestClass.java.jinja") + + cpp_test_struct_name = f"{test_message['name']}.h" + cpp_test_struct_template = env.get_template("ThingTestStruct.h.jinja") + + python_test_dataclass_name = f"{test_message['name']}.py" + python_test_dataclass_template = env.get_template("ThingTestDataclass.py.jinja") + + for output_name, template, output_folder in [ + [java_name, java_template, java_output_dir], + [cpp_serde_header_name, cpp_serde_header_template, cpp_serde_header_dir], + [cpp_serde_source_name, cpp_serde_source_template, cpp_serde_source_dir], + [cpp_struct_header_name, cpp_struct_header_template, cpp_struct_header_dir], + [py_name, py_template, py_serde_source_dir], + [ + java_test_class_name, + java_test_class_template, + java_test_class_output_dir, + ], + [ + cpp_test_struct_name, + cpp_test_struct_template, + cpp_test_struct_output_dir, + ], + [ + python_test_dataclass_name, + python_test_dataclass_template, + python_test_dataclass_output_dir, + ], + ]: + # Hack in our message getter + template.globals["get_message_by_name"] = lambda name: get_message_by_name( + message_db, name + ) + + nested_photon_types = set( + [ + field["type"] + for field in test_message["fields"] + if ( + not is_intrinsic_type(field["type"]) + and not get_shimmed_filter(message_db)(field["type"]) + ) + ] + ) + nested_wpilib_types = set( + [ + field["type"] + for field in test_message["fields"] + if ( + not is_intrinsic_type(field["type"]) + and get_shimmed_filter(message_db)(field["type"]) + ) + ] + ) + + output_file = output_folder / output_name + output_file.write_text( + template.render( + test_message, + type_map=extended_data_types, + message_fmt=get_struct_schema_str(test_message, message_db), + message_hash=message_hash, + cpp_includes=get_includes(message_db, test_message), + nested_photon_types=nested_photon_types, + nested_wpilib_types=nested_wpilib_types, + test=True, + ), + encoding="utf-8", + ) + + # Generate python messages __init__.py file + pyinit_template = env.get_template("PyInit.py.jinja") + pyinit_target = py_serde_source_dir / "__init__.py" + types = [message["name"] for message in test_messages] + pyinit_target.write_text(pyinit_template.render(types=types), encoding="utf-8") + + # Generate test fixtures (WIP) + tests = parse_yaml("tests.yaml") + java_test_target = ( + Path(cpp_java_test_root) / "test/java/org/photonvision/AutoSerdeTest.java" + ) + java_test_target.parent.mkdir(parents=True, exist_ok=True) + cpp_test_target = Path(cpp_java_test_root) / "test/native/cpp/AutoSerdeTest.cpp" + cpp_test_target.parent.mkdir(parents=True, exist_ok=True) + py_test_target = Path(py_test_root) / "AutoSerdeTest.py" + py_test_target.parent.mkdir(parents=True, exist_ok=True) + + java_test_template = env.get_template("ThingTests.java.jinja") + cpp_test_template = env.get_template("ThingTests.cpp.jinja") + py_test_template = env.get_template("ThingTests.py.jinja") + + java_test_target.write_text(java_test_template.render(tests)) + cpp_test_target.write_text(cpp_test_template.render(tests)) + py_test_target.write_text(py_test_template.render(tests)) + + def main(argv): script_path = Path(__file__).resolve() dirname = script_path.parent @@ -365,23 +621,47 @@ def main(argv): default=dirname.parent / "photon-targeting/src/generated", type=Path, ) + parser.add_argument( + "--cppjava_test_output_dir", + help="Optional. If set, will spit cpp/java test files here", + default=dirname.parent / "photon-serde-tests/src", + type=Path, + ) parser.add_argument( "--py_output_dir", help="Optional. If set, will spit Python serde files here", default=dirname.parent / "photon-lib/py/photonlibpy/generated", type=Path, ) + parser.add_argument( + "--py_test_output_dir", + help="Optional. If set, will spit python test files here", + default=dirname.parent / "photon-serde-tests/py", + type=Path, + ) parser.add_argument( "--template_root", help="Optional. If set, will use this directory as the root for the jinja templates", default=dirname / "templates", type=Path, ) + parser.add_argument( + "--tests", + help="Generates tests and test messages instead of regular serde", + action="store_true", + ) args = parser.parse_args(argv) - generate_photon_messages( - args.cpp_java_output_dir, args.py_output_dir, args.template_root - ) + if args.tests: + generate_tests( + args.cppjava_test_output_dir, + args.py_test_output_dir, + args.template_root, + ) + else: + generate_photon_messages( + args.cpp_java_output_dir, args.py_output_dir, args.template_root + ) if __name__ == "__main__": diff --git a/photon-serde/message_data_types.yaml b/photon-serde/message_data_types.yaml index 834822e7f5..029ea678f0 100644 --- a/photon-serde/message_data_types.yaml +++ b/photon-serde/message_data_types.yaml @@ -2,50 +2,78 @@ bool: # length in bytes len: 1 - java_type: bool + java_type: boolean + java_boxed_type: Boolean cpp_type: bool + python_type: bool java_decode_method: decodeBoolean - java_encode_shim: encodeBoolean + java_decode_shim_ref: PacketUtils::unpackBoolean + java_encode_shim_ref: PacketUtils::packBoolean python_decode_shim: decodeBoolean python_encode_shim: encodeBoolean +int8: + len: 1 + java_type: byte + java_boxed_type: Byte + cpp_type: int8_t + python_type: int + java_decode_method: decodeByte + java_decode_shim_ref: PacketUtils::unpackByte + java_encode_shim_ref: PacketUtils::packByte + python_decode_shim: decode8 + python_encode_shim: encode8 int16: len: 2 java_type: short + java_boxed_type: Short cpp_type: int16_t java_decode_method: decodeShort - java_list_decode_method: decodeShortList - java_encode_shim: encodeShort - python_decode_shim: decodeShort - python_encode_shim: encodeShort + java_decode_shim_ref: PacketUtils::unpackShort + java_encode_shim_ref: PacketUtils::packShort + python_decode_shim: decode16 + python_encode_shim: encode16 + python_type: int int32: len: 4 java_type: int + java_boxed_type: Integer cpp_type: int32_t + python_type: int java_decode_method: decodeInt - java_encode_shim: encodeInt + java_decode_shim_ref: PacketUtils::unpackInt + java_encode_shim_ref: PacketUtils::packInt python_decode_shim: decodeInt python_encode_shim: encodeInt int64: len: 8 java_type: long + java_boxed_type: Long cpp_type: int64_t + python_type: int java_decode_method: decodeLong - java_encode_shim: encodeLong + java_decode_shim_ref: PacketUtils::unpackLong + java_encode_shim_ref: PacketUtils::packLong python_decode_shim: decodeLong python_encode_shim: encodeLong float32: len: 4 java_type: float + java_boxed_type: Float cpp_type: float + python_type: float java_decode_method: decodeFloat - java_encode_shim: encodeFloat + java_decode_shim_ref: PacketUtils::unpackFloat + java_encode_shim_ref: PacketUtils::packFloat python_decode_shim: decodeFloat python_encode_shim: encodeFloat float64: len: 8 java_type: double + java_boxed_type: Double cpp_type: double + python_type: float java_decode_method: decodeDouble - java_encode_shim: encodeDouble + java_decode_shim_ref: PacketUtils::unpackDouble + java_encode_shim_ref: PacketUtils::packDouble python_decode_shim: decodeDouble python_encode_shim: encodeDouble diff --git a/photon-serde/messages.yaml b/photon-serde/messages.yaml index 40cbc1436b..97da9e8eac 100644 --- a/photon-serde/messages.yaml +++ b/photon-serde/messages.yaml @@ -13,9 +13,12 @@ - name: Transform3d shimmed: True java_decode_shim: PacketUtils.unpackTransform3d + java_decode_shim_ref: PacketUtils::unpackTransform3d java_encode_shim: PacketUtils.packTransform3d + java_encode_shim_ref: PacketUtils::packTransform3d cpp_type: wpi::math::Transform3d - cpp_include: "" + cpp_include: "" + python_module: "wpimath" python_decode_shim: decodeTransform python_encode_shim: encodeTransform java_import: org.wpilib.math.geometry.Transform3d diff --git a/photon-serde/templates/Message.java.jinja b/photon-serde/templates/Message.java.jinja index 75983e6a51..6f5d121da2 100644 --- a/photon-serde/templates/Message.java.jinja +++ b/photon-serde/templates/Message.java.jinja @@ -33,6 +33,10 @@ import org.photonvision.utils.PacketUtils; // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; {% for type in nested_wpilib_types -%} @@ -57,27 +61,42 @@ public class {{ name }}Serde implements PacketSerde<{{name}}> { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, {{ name }} value) { {%- for field in fields -%} {%- if field.type | is_shimmed %} - {{ get_message_by_name(field.type).java_encode_shim }}(packet, value.{{ field.name }}); -{%- elif field.optional == True %} + {%- if field.optional == True %} // {{ field.name }} is optional! it better not be a VLA too - packet.encodeOptional(value.{{ field.name }}); -{%- elif field.vla == True and field.type | is_intrinsic %} - // {{ field.name }} is a intrinsic VLA! - packet.encode(value.{{ field.name }}); -{%- elif field.vla == True %} - // {{ field.name }} is a custom VLA! - packet.encodeList(value.{{ field.name }}); + packet.encodeOptionalImpl(value.{{ field.name }}, {{ get_message_by_name(field.type).java_encode_shim_ref }}); + {%- elif field.vla == True %} + // {{ field.name }} is a shimmed VLA! + packet.encodeListImpl(value.{{ field.name }}, {{ get_message_by_name(field.type).java_encode_shim_ref }}); + {%- else %} + // {{ field.name }} is of shimmed type {{ field.type }} + {{ get_message_by_name(field.type).java_encode_shim }}(packet, value.{{ field.name }}); + {%- endif %} {%- elif field.type | is_intrinsic %} + {%- if field.optional == True %} + // {{ field.name }} is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.{{ field.name }},{{ type_map[field.type].java_encode_shim_ref }}); + {%- elif field.vla == True %} + // {{ field.name }} is an intrinsic VLA! + packet.encodeListImpl(value.{{ field.name }},{{ type_map[field.type].java_encode_shim_ref }}); + {%- else %} // field {{ field.name }} is of intrinsic type {{ field.type }} - packet.encode(({{ type_map[field.type].java_type }}) value.{{ field.name }}); + packet.encode(value.{{ field.name }}); + {%- endif %} {%- else %} + {%- if field.optional == True %} + // {{ field.name }} is optional! it better not be a VLA too + packet.encodeOptionalImpl(value.{{ field.name }},{{ field.type }}.photonStruct::pack); + {%- elif field.vla == True %} + // {{ field.name }} is a custom VLA! + packet.encodeListImpl(value.{{ field.name }},{{ field.type }}.photonStruct::pack); + {%- else %} // field {{ field.name }} is of non-intrinsic type {{ field.type }} {{ field.type }}.photonStruct.pack(packet, value.{{ field.name }}); + {%- endif %} {%- endif %} {%- if not loop.last %} {% endif -%} @@ -89,22 +108,38 @@ public class {{ name }}Serde implements PacketSerde<{{name}}> { var ret = new {{ name }}(); {% for field in fields -%} {%- if field.type | is_shimmed %} - ret.{{ field.name }} = {{ get_message_by_name(field.type).java_decode_shim }}(packet); -{%- elif field.optional == True %} + {%- if field.optional == True %} // {{ field.name }} is optional! it better not be a VLA too - ret.{{ field.name }} = packet.decodeOptional({{ field.type }}.photonStruct); -{%- elif field.vla == True and not field.type | is_intrinsic %} - // {{ field.name }} is a custom VLA! - ret.{{ field.name }} = packet.decodeList({{ field.type }}.photonStruct); -{%- elif field.vla == True and field.type | is_intrinsic %} - // {{ field.name }} is a custom VLA! - ret.{{ field.name }} = packet.decode{{ type_map[field.type].java_type.title() }}List(); + ret.{{ field.name }} = packet.decodeOptionalImpl({{ get_message_by_name(field.type).java_decode_shim_ref }}); + {%- elif field.vla == True %} + // {{ field.name }} is a shimmed VLA! + ret.{{ field.name }} = packet.decodeListImpl({{ get_message_by_name(field.type).java_decode_shim_ref }}); + {%- else %} + // {{ field.name }} is of shimmed type {{ field.type }} + ret.{{ field.name }} = {{ get_message_by_name(field.type).java_decode_shim }}(packet); + {%- endif %} {%- elif field.type | is_intrinsic %} + {%- if field.optional == True %} + // {{ field.name }} is optional! it better not be a VLA too + ret.{{ field.name }} = packet.decodeOptionalImpl({{ type_map[field.type].java_decode_shim_ref }}); + {%- elif field.vla == True %} + // {{ field.name }} is an intrinsic VLA! + ret.{{ field.name }} = packet.decodeListImpl({{ type_map[field.type].java_decode_shim_ref }}); + {%- else %} // {{ field.name }} is of intrinsic type {{ field.type }} ret.{{field.name}} = packet.{{ type_map[field.type].java_decode_method }}(); + {%- endif %} {%- else %} + {%- if field.optional == True %} + // {{ field.name }} is optional! it better not be a VLA too + ret.{{ field.name }} = packet.decodeOptionalImpl({{ field.type }}.photonStruct::unpack); + {%- elif field.vla == True %} + // {{ field.name }} is a custom VLA! + ret.{{ field.name }} = packet.decodeListImpl({{ field.type }}.photonStruct::unpack); + {%- else %} // {{ field.name }} is of non-intrinsic type {{ field.type }} ret.{{field.name}} = {{ field.type }}.photonStruct.unpack(packet); + {%- endif %} {%- endif %} {%- if not loop.last %} {% endif -%} @@ -132,4 +167,4 @@ public class {{ name }}Serde implements PacketSerde<{{name}}> { {%- endfor%} }; } -}{{'\n'}} +}{{'\n'}} \ No newline at end of file diff --git a/photon-serde/templates/PyInit.py.jinja b/photon-serde/templates/PyInit.py.jinja new file mode 100644 index 0000000000..936c666c83 --- /dev/null +++ b/photon-serde/templates/PyInit.py.jinja @@ -0,0 +1,40 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +{% for type in types -%} +from .{{ type }} import {{ type }} +from .{{ type }}Serde import {{ type }}Serde +{% endfor%} + +__all__ = ( + {% for type in types -%} + "{{ type }}", + "{{ type }}Serde", + {% endfor%} +) \ No newline at end of file diff --git a/photon-serde/templates/ThingSerde.cpp.jinja b/photon-serde/templates/ThingSerde.cpp.jinja index e25214c373..c2b08f5c1d 100644 --- a/photon-serde/templates/ThingSerde.cpp.jinja +++ b/photon-serde/templates/ThingSerde.cpp.jinja @@ -26,13 +26,14 @@ #include "photon/serde/{{ name }}Serde.h" + namespace photon { using StructType = SerdeType<{{ name }}>; void StructType::Pack(Packet& packet, const {{ name }}& value) { {% for field in fields -%} - packet.Pack<{{ field | get_qualified_name }}>(value.{{ field.name }}); + packet.Pack<{{ field | get_cpp_qualified_name }}>(value.{{ field.name }}); {%- if not loop.last %} {% endif -%} {% endfor %} @@ -41,7 +42,7 @@ void StructType::Pack(Packet& packet, const {{ name }}& value) { {{ name }} StructType::Unpack(Packet& packet) { return {{ name }}{ {{ name }}_PhotonStruct{ {% for field in fields -%} - .{{ field.name}} = packet.Unpack<{{ field | get_qualified_name }}>(), + .{{ field.name}} = packet.Unpack<{{ field | get_cpp_qualified_name }}>(), {%- if not loop.last %} {% endif -%} {% endfor %} diff --git a/photon-serde/templates/ThingSerde.py.jinja b/photon-serde/templates/ThingSerde.py.jinja index 324757a520..360316218f 100644 --- a/photon-serde/templates/ThingSerde.py.jinja +++ b/photon-serde/templates/ThingSerde.py.jinja @@ -29,8 +29,15 @@ from typing import TYPE_CHECKING +{% if test %} +from photonlibpy.packet import Packet +from photonlibpy.targeting import * # noqa +from . import * +{% else %} from ..packet import Packet from ..targeting import * # noqa +{% endif %} + if TYPE_CHECKING: {%- set ns = namespace(types=[]) -%} @@ -40,7 +47,11 @@ if TYPE_CHECKING: {% set _ = ns.types.append(name) -%} {%- for type in ns.types|sort%} {%- if not type | is_shimmed and not type | is_intrinsic %} +{%- if type | is_test %} + from .{{ type }} import {{ type }} # noqa +{%- else %} from ..targeting import {{ type }} # noqa +{% endif -%} {%- endif %} {%- endfor%} @@ -55,22 +66,38 @@ class {{ name }}Serde: ret = Packet() {% for field in fields -%} {%- if field.type | is_shimmed %} - ret.{{ get_message_by_name(field.type).python_encode_shim}}(value.{{ field.name }}) -{%- elif field.optional == True %} + {%- if field.optional == True %} # {{ field.name }} is optional! it better not be a VLA too - ret.encodeOptional(value.{{ field.name }}, {{ field.type }}.photonStruct) -{%- elif field.vla == True and not field.type | is_intrinsic %} - # {{ field.name }} is a custom VLA! - ret.encodeList(value.{{ field.name }}, {{ field.type }}.photonStruct) -{%- elif field.vla == True and field.type | is_intrinsic %} + ret.encodeOptionalShimmed(value.{{ field.name }}, ret.{{ get_message_by_name(field.type).python_encode_shim }}) + {%- elif field.vla == True %} # {{ field.name }} is a custom VLA! - ret.encode{{ type_map[field.type].java_type.title() }}List(value.{{ field.name }}) + ret.encodeListShimmed(value.{{ field.name }}, ret.{{ get_message_by_name(field.type).python_encode_shim }}) + {%- else %} + # {{ field.name }} is of shimmed type {{ field.type }} + ret.{{ get_message_by_name(field.type).python_encode_shim}}(value.{{ field.name }}) + {%- endif %} {%- elif field.type | is_intrinsic %} + {%- if field.optional == True %} + # {{ field.name }} is optional! it better not be a VLA too + ret.encodeOptionalShimmed(value.{{ field.name }}, ret.{{ type_map[field.type].python_encode_shim }}) + {%- elif field.vla == True %} + # {{ field.name }} is a custom VLA! + ret.encodeListShimmed(value.{{ field.name }}, ret.{{ type_map[field.type].python_encode_shim }}) + {%- else %} # {{ field.name }} is of intrinsic type {{ field.type }} - ret.{{ type_map[field.type].python_encode_shim }}(value.{{field.name}}) + ret.{{ type_map[field.type].python_encode_shim}}(value.{{ field.name }}) + {%- endif %} {%- else %} + {%- if field.optional == True %} + # {{ field.name }} is optional! it better not be a VLA too + ret.encodeOptional(value.{{ field.name }}, {{ field.type }}.photonStruct) + {%- elif field.vla == True %} + # {{ field.name }} is a custom VLA! + ret.encodeList(value.{{ field.name }}, {{ field.type }}.photonStruct) + {%- else %} # {{ field.name }} is of non-intrinsic type {{ field.type }} ret.encodeBytes({{ field.type }}.photonStruct.pack(value.{{field.name}}).getData()) + {%- endif %} {%- endif %} {%- if not loop.last %} {% endif -%} @@ -82,22 +109,37 @@ class {{ name }}Serde: ret = {{ name }}() {% for field in fields -%} {%- if field.type | is_shimmed %} + {%- if field.optional == True %} + # {{ field.name }} is optional! it better not be a VLA too + ret.{{ field.name }} = packet.decodeOptionalShimmed(packet.{{ get_message_by_name(field.type).python_decode_shim }}) + {%- elif field.vla == True %} + # {{ field.name }} is a shimmed VLA! + ret.{{ field.name }} = packet.decodeListShimmed(packet.{{ get_message_by_name(field.type).python_decode_shim }}) + {%- else %} ret.{{ field.name }} = packet.{{ get_message_by_name(field.type).python_decode_shim }}() -{%- elif field.optional == True %} + {%- endif %} +{%- elif field.type | is_intrinsic %} + {%- if field.optional == True %} + # {{ field.name }} is optional! it better not be a VLA too + ret.{{ field.name }} = packet.decodeOptionalShimmed(packet.{{ type_map[field.type].python_decode_shim }}) + {%- elif field.vla == True %} + # {{ field.name }} is an intrinsic VLA! + ret.{{ field.name }} = packet.decodeListShimmed(packet.{{ type_map[field.type].python_decode_shim }}) + {%- else %} + # {{ field.name }} is of intrinsic type {{ field.type }} + ret.{{ field.name }} = packet.{{ type_map[field.type].python_decode_shim }}() + {%- endif %} +{%- else %} + {%- if field.optional == True %} # {{ field.name }} is optional! it better not be a VLA too ret.{{ field.name }} = packet.decodeOptional({{ field.type }}.photonStruct) -{%- elif field.vla == True and not field.type | is_intrinsic %} + {%- elif field.vla == True %} # {{ field.name }} is a custom VLA! ret.{{ field.name }} = packet.decodeList({{ field.type }}.photonStruct) -{%- elif field.vla == True and field.type | is_intrinsic %} - # {{ field.name }} is a custom VLA! - ret.{{ field.name }} = packet.decode{{ type_map[field.type].java_type.title() }}List() -{%- elif field.type | is_intrinsic %} - # {{ field.name }} is of intrinsic type {{ field.type }} - ret.{{field.name}} = packet.{{ type_map[field.type].python_decode_shim }}() -{%- else %} + {%- else %} # {{ field.name }} is of non-intrinsic type {{ field.type }} ret.{{field.name}} = {{ field.type }}.photonStruct.unpack(packet) + {%- endif %} {%- endif %} {%- if not loop.last %} {% endif -%} @@ -107,4 +149,4 @@ class {{ name }}Serde: # Hack ourselves into the base class -{{ name }}.photonStruct = {{ name }}Serde(){{'\n'}} +{{ name }}.photonStruct = {{ name }}Serde(){{'\n'}} \ No newline at end of file diff --git a/photon-serde/templates/ThingStruct.h.jinja b/photon-serde/templates/ThingStruct.h.jinja index 2ceea5e759..f79452cc0d 100644 --- a/photon-serde/templates/ThingStruct.h.jinja +++ b/photon-serde/templates/ThingStruct.h.jinja @@ -35,7 +35,7 @@ namespace photon { struct {{ name }}_PhotonStruct { {% for field in fields -%} - {{ field | get_qualified_name }} {{ field.name }}; + {{ field | get_cpp_qualified_name }} {{ field.name }}; {%- if not loop.last %} {% endif -%} {% endfor %} diff --git a/photon-serde/templates/ThingTestClass.java.jinja b/photon-serde/templates/ThingTestClass.java.jinja new file mode 100644 index 0000000000..42133cdbc7 --- /dev/null +++ b/photon-serde/templates/ThingTestClass.java.jinja @@ -0,0 +1,114 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision.targeting; + +import java.util.List; +import java.util.Optional; + +import org.photonvision.struct.{{ name }}Serde; +import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +// WPILib imports (if any) +import org.wpilib.util.struct.Struct; +{% for type in nested_wpilib_types -%} +import {{ get_message_by_name(type).java_import }}; +{%- if not loop.last %},{% endif -%} +{%- endfor%} + +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +public class {{ name }} implements PhotonStructSerializable<{{ name }}> { +{% for field in fields -%} +{%- if field.type | is_intrinsic %} + {%- if field.optional == True %} + public Optional<{{ type_map[field.type].java_boxed_type }}> {{ field.name }} = Optional.empty(); + {%- elif field.vla == True %} + public List<{{ type_map[field.type].java_boxed_type }}> {{ field.name }} = List.of(); + {%- else %} + public {{ type_map[field.type].java_type }} {{ field.name }}; + {%- endif %} +{%- else %} + {%- if field.optional == True %} + public Optional<{{ field.type }}> {{ field.name }} = Optional.empty(); + {%- elif field.vla == True %} + public List<{{ field.type }}> {{ field.name }} = List.of(); + {%- else %} + public {{ field.type }} {{ field.name }} = new {{ field.type }}(); + {%- endif %} +{%- endif %} +{%- endfor%} + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + {{ name }} other = ({{ name }}) obj; +{%- for field in fields -%} +{%- if field.type | is_intrinsic %} + {%- if field.optional == True %} + if (!this.{{ field.name }}.equals(other.{{ field.name }})) return false; + {%- elif field.vla == True %} + if (!this.{{ field.name }}.equals(other.{{ field.name }})) return false; + {%- else %} + if (this.{{ field.name }} != other.{{ field.name }}) return false; + {%- endif %} +{%- else %} + if (!this.{{ field.name }}.equals(other.{{ field.name }})) return false; +{%- endif %} +{%- endfor %} + return true; + } + + /** {{ name }} PhotonStruct for serialization. */ + public static final {{ name }}Serde photonStruct = new {{ name }}Serde(); + + @Override + public PacketSerde<{{ name }}> getSerde() { + return photonStruct; + } + + @Override + public String toString() { + return "{{ name }} [" + {%- for field in fields -%} + {%- if loop.first %} + + "{{ field.name }}=" + {%- else %} + + ", {{ field.name }}=" + {%- endif -%} + {%- if field.type | is_intrinsic %} + + {{ field.name }} + {%- else %} + + {{ field.name }}.toString() + {%- endif -%} + {%- endfor %} + + "]"; + } +} \ No newline at end of file diff --git a/photon-serde/templates/ThingTestDataclass.py.jinja b/photon-serde/templates/ThingTestDataclass.py.jinja new file mode 100644 index 0000000000..300820d672 --- /dev/null +++ b/photon-serde/templates/ThingTestDataclass.py.jinja @@ -0,0 +1,66 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from typing import TYPE_CHECKING, Optional, ClassVar +from dataclasses import dataclass, field + +from photonlibpy.targeting import * # noqa + +if TYPE_CHECKING: + from .{{ name }}Serde import {{ name }}Serde # noqa +{%- set ns = namespace(types=[]) -%} +{%- for field in fields|unique(attribute="type")-%} + {%- set _ = ns.types.append(field.type) -%} +{%- endfor -%} +{%- for type in ns.types|sort%} +{%- if not type | is_shimmed and not type | is_intrinsic %} +{%- if type | is_test %} + from .{{ type }} import {{ type }} # noqa +{%- else %} + from ..targeting import {{ type }} # noqa +{% endif -%} +{%- endif %} +{%- endfor%} + +{% for type in nested_wpilib_types -%} +from {{ get_message_by_name(type).python_module }} import {{ type }} +{%- if not loop.last %},{% endif -%} +{%- endfor%} + +@dataclass(kw_only=True) +class {{ name }}: + {% for field in fields -%} + {{ field.name }}: {{ field | get_python_qualified_name }} = field( + default_factory={{ field | get_python_default_factory }} + ) + {%- if not loop.last %} + {% endif -%} +{%- endfor %} + photonStruct: ClassVar["{{ name }}Serde"] + diff --git a/photon-serde/templates/ThingTestStruct.h.jinja b/photon-serde/templates/ThingTestStruct.h.jinja new file mode 100644 index 0000000000..8c200c9d9f --- /dev/null +++ b/photon-serde/templates/ThingTestStruct.h.jinja @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) PhotonVision + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include "photon/struct/{{ name }}Struct.h" + +namespace photon { +/** + * Auto-generated ser/de test class, not intended for use in actual dataflow + */ +class {{ name }} : public {{ name }}_PhotonStruct { + using Base = {{ name }}_PhotonStruct; + +public: + {{ name }}() = default; + + explicit {{ name }}(Base&& data) : Base(data) {} + + template + explicit {{ name }}(Args&&... args) + : Base{std::forward(args)...} {} + + friend bool operator==({{ name }} const&, {{ name }} const&) = default; +}; +} // namespace photon + +#include "photon/serde/{{ name }}Serde.h" \ No newline at end of file diff --git a/photon-serde/templates/ThingTests.cpp.jinja b/photon-serde/templates/ThingTests.cpp.jinja new file mode 100644 index 0000000000..ea9216762d --- /dev/null +++ b/photon-serde/templates/ThingTests.cpp.jinja @@ -0,0 +1,64 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +#include +#include +#include + +#include + +#include "gtest/gtest.h" + +{% for include in cpp_includes -%} +#include {{ include }} +{% endfor %} + +{% for test in tests -%} +#include "photon/targeting/{{ test.type }}.h" +{% endfor %} + +// Hack +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +using namespace photon; + +template + requires(PhotonStructSerializable) +inline bool test_serde(const T& data) { + Packet p; + p.Pack(data); + T unpackedData = p.Unpack(); + return data == unpackedData; +} + +{% for test in tests %} +TEST(AutoSerdeTest, {{ test.name }}) { + std::cout << "Running {{ test.name }}\n"; + {% for test_case in test.cases %} + {{ test.type }} {{ test_case.name }}{}; + {% for field in test_case.fields -%} + {{ test_case.name }}.{{ field.name }} = {{ field.cpp_value }}; + {% endfor -%} + ASSERT_TRUE(test_serde({{ test_case.name }})); + {% endfor %} +} +{% endfor %} \ No newline at end of file diff --git a/photon-serde/templates/ThingTests.java.jinja b/photon-serde/templates/ThingTests.java.jinja new file mode 100644 index 0000000000..dcefe44693 --- /dev/null +++ b/photon-serde/templates/ThingTests.java.jinja @@ -0,0 +1,57 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY + +package org.photonvision; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.photonvision.common.dataflow.structures.Packet; +import org.photonvision.targeting.*; +import org.photonvision.targeting.serde.PhotonStructSerializable; + +{% for dep in java_imports -%} +import {{ dep }}; +{% endfor %} + +public class AutoSerdeTest { + private > boolean testSerde(T data) { + var p = new Packet(10); + p.encode(data); + var unpackedData = p.decode(data); // kinda scuffed lowkey + System.out.println("IN: " + data.toString() + "\nOUT: " + unpackedData.toString()); + return data.equals(unpackedData); + } + {% for test in tests %} + @Test + public void {{ test.name }}() { + System.out.println("Running {{ test.name }}"); + {% for test_case in test.cases %} + System.out.println("Test case {{ test_case.name }}:"); + var {{ test_case.name }} = new {{ test.type }}(); + {% for field in test_case.fields -%} + {{ test_case.name }}.{{ field.name }} = {{ field.java_value }}; + {% endfor -%} + assertTrue(testSerde({{ test_case.name }})); + {% endfor %} + } + {% endfor %} +} diff --git a/photon-serde/templates/ThingTests.py.jinja b/photon-serde/templates/ThingTests.py.jinja new file mode 100644 index 0000000000..f81f3129de --- /dev/null +++ b/photon-serde/templates/ThingTests.py.jinja @@ -0,0 +1,56 @@ +# +# MIT License +# +# Copyright (c) PhotonVision +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +############################################################################### +## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. +## --> DO NOT MODIFY <-- +############################################################################### + +from photonlibpy.packet import Packet +from photonlibpy.targeting import * +from .messages import * + +{% for dep in python_imports -%} +{{ dep }} +{% endfor %} + +def AutoSerdeTest(data) -> bool: + packet = data.photonStruct.pack(data) + unpacked = data.photonStruct.unpack(packet) + print(f"Original: {data}") + print(f"Unpacked: {unpacked}") + return data == unpacked + +{% for test in tests %} +def test_{{ test.name }}(): + print("Running {{ test.name }}...") + {% for test_case in test.cases %} + print("Test case {{ test_case.name }}:") + {{ test_case.name }} = {{ test.type }}() + {% for field in test_case.fields -%} + {{ test_case.name }}.{{ field.name }} = {{ field.python_value }} + {% endfor -%} + assert AutoSerdeTest({{ test_case.name }}) + {% endfor %} +{% endfor %} \ No newline at end of file diff --git a/photon-serde/test_messages.yaml b/photon-serde/test_messages.yaml new file mode 100644 index 0000000000..5372482868 --- /dev/null +++ b/photon-serde/test_messages.yaml @@ -0,0 +1,98 @@ +--- +# Messages for ser/de unit tests, not actually used in dataflow +- name: Int8TestMessage + test: True + fields: + - name: test + type: int8 + - name: vlaTest + type: int8 + vla: True + - name: optTest + type: int8 + optional: True + +- name: Int16TestMessage + test: True + fields: + - name: test + type: int16 + - name: vlaTest + type: int16 + vla: True + - name: optTest + type: int16 + optional: True + +- name: Int32TestMessage + test: True + fields: + - name: test + type: int32 + - name: vlaTest + type: int32 + vla: True + - name: optTest + type: int32 + optional: True + +- name: Int64TestMessage + test: True + fields: + - name: test + type: int64 + - name: vlaTest + type: int64 + vla: True + - name: optTest + type: int64 + optional: True + +- name: Float32TestMessage + test: True + fields: + - name: test + type: float32 + - name: vlaTest + type: float32 + vla: True + - name: optTest + type: float32 + optional: True + +- name: Float64TestMessage + test: True + fields: + - name: test + type: float64 + - name: vlaTest + type: float64 + vla: True + - name: optTest + type: float64 + optional: True + +- name: BoolTestMessage + test: True + fields: + - name: test + type: bool + - name: vlaTest + type: bool + vla: True + - name: optTest + type: bool + optional: True + +# Test for shimmed ser/de +- name: Transform3dTestMessage + test: True + fields: + - name: test + type: Transform3d + - name: vlaTest + type: Transform3d + vla: True + - name: optTest + type: Transform3d + optional: True diff --git a/photon-serde/tests.yaml b/photon-serde/tests.yaml new file mode 100644 index 0000000000..351e59c6ea --- /dev/null +++ b/photon-serde/tests.yaml @@ -0,0 +1,255 @@ +--- +java_imports: +- 'org.wpilib.math.geometry.Rotation3d' +- 'org.wpilib.math.geometry.Translation3d' +- 'org.wpilib.math.geometry.Transform3d' +cpp_includes: +- '' +- '' +- '' +- '' +python_imports: +- 'from wpimath import Rotation3d' +- 'from wpimath import Translation3d' +- 'from wpimath import Transform3d' +tests: +- name: Int8Test + type: Int8TestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of((byte) 3)' + cpp_value: '{3}' + python_value: '3' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of((byte) 1, (byte) 2, (byte) 3)' + cpp_value: '{1, 2, 3}' + python_value: '[1, 2, 3]' + - name: general_test + fields: + - name: test + java_value: '(byte) 42' + cpp_value: '42' + python_value: '42' + - name: optTest + java_value: 'Optional.of((byte) 7)' + cpp_value: '{7}' + python_value: '7' + - name: vlaTest + java_value: 'List.of((byte) 4, (byte) 5, (byte) 6)' + cpp_value: '{4, 5, 6}' + python_value: '[4, 5, 6]' +- name: Int16Test + type: Int16TestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of((short) 3)' + cpp_value: '{3}' + python_value: '3' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of((short) 1, (short) 2, (short) 3)' + cpp_value: '{1, 2, 3}' + python_value: '[1, 2, 3]' + - name: general_test + fields: + - name: test + java_value: '(short) 42' + cpp_value: '42' + python_value: '42' + - name: optTest + java_value: 'Optional.of((short) 7)' + cpp_value: '{7}' + python_value: '7' + - name: vlaTest + java_value: 'List.of((short) 4, (short) 5, (short) 6)' + cpp_value: '{4, 5, 6}' + python_value: '[4, 5, 6]' +- name: Int32Test + type: Int32TestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of((int) 3)' + cpp_value: '{3}' + python_value: '3' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of((int) 1, (int) 2, (int) 3)' + cpp_value: '{1, 2, 3}' + python_value: '[1, 2, 3]' + - name: general_test + fields: + - name: test + java_value: '(int) 42' + cpp_value: '42' + python_value: '42' + - name: optTest + java_value: 'Optional.of((int) 7)' + cpp_value: '{7}' + python_value: '7' + - name: vlaTest + java_value: 'List.of((int) 4, (int) 5, (int) 6)' + cpp_value: '{4, 5, 6}' + python_value: '[4, 5, 6]' +- name: Int64Test + type: Int64TestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of((long) 3)' + cpp_value: '{3}' + python_value: '3' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of((long) 1, (long) 2, (long) 3)' + cpp_value: '{1, 2, 3}' + python_value: '[1, 2, 3]' + - name: general_test + fields: + - name: test + java_value: '(long) 42' + cpp_value: '42' + python_value: '42' + - name: optTest + java_value: 'Optional.of((long) 7)' + cpp_value: '{7}' + python_value: '7' + - name: vlaTest + java_value: 'List.of((long) 4, (long) 5, (long) 6)' + cpp_value: '{4, 5, 6}' + python_value: '[4, 5, 6]' +- name: Float32Test + type: Float32TestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of((float) 3.0)' + cpp_value: '{3.0}' + python_value: '3.0' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of((float) 1.0, (float) 2.0, (float) 3.0)' + cpp_value: '{1.0, 2.0, 3.0}' + python_value: '[1.0, 2.0, 3.0]' + - name: general_test + fields: + - name: test + java_value: '(float) 42.0' + cpp_value: '42.0' + python_value: '42.0' + - name: optTest + java_value: 'Optional.of((float) 7.0)' + cpp_value: '{7.0}' + python_value: '7.0' + - name: vlaTest + java_value: 'List.of((float) 4.0, (float) 5.0, (float) 6.0)' + cpp_value: '{4.0, 5.0, 6.0}' + python_value: '[4.0, 5.0, 6.0]' +- name: Float64Test + type: Float64TestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of((double) 3.0)' + cpp_value: '{3.0}' + python_value: '3.0' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of((double) 1.0, (double) 2.0, (double) 3.0)' + cpp_value: '{1.0, 2.0, 3.0}' + python_value: '[1.0, 2.0, 3.0]' + - name: general_test + fields: + - name: test + java_value: '(double) 42.0' + cpp_value: '42.0' + python_value: '42.0' + - name: optTest + java_value: 'Optional.of((double) 7.0)' + cpp_value: '{7.0}' + python_value: '7.0' + - name: vlaTest + java_value: 'List.of((double) 4.0, (double) 5.0, (double) 6.0)' + cpp_value: '{4.0, 5.0, 6.0}' + python_value: '[4.0, 5.0, 6.0]' +- name: BoolTest + type: BoolTestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of(true)' + cpp_value: '{true}' + python_value: 'True' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of(true, false, true)' + cpp_value: '{true, false, true}' + python_value: '[True, False, True]' + - name: general_test + fields: + - name: test + java_value: 'false' + cpp_value: 'false' + python_value: 'False' + - name: optTest + java_value: 'Optional.of(true)' + cpp_value: '{true}' + python_value: 'True' + - name: vlaTest + java_value: 'List.of(true, false, true)' + cpp_value: '{true, false, true}' + python_value: '[True, False, True]' +- name: Transform3dTest + type: Transform3dTestMessage + cases: + - name: default_test + - name: optional_test + fields: + - name: optTest + java_value: 'Optional.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3)))' + cpp_value: '{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}}' + python_value: 'Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3))' + - name: vla_test + fields: + - name: vlaTest + java_value: 'List.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3)), new Transform3d(new Translation3d(4.0, 5.0, 6.0), new Rotation3d(0.4, 0.5, 0.6)))' + cpp_value: '{{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{8_m, 2_m, 1_m, wpi::math::Rotation3d{0_deg, 1_deg, 88_deg}}}' + python_value: '[Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3)), Transform3d(Translation3d(4.0, 5.0, 6.0), Rotation3d(0.4, 0.5, 0.6))]' + - name: general_test + fields: + - name: test + java_value: 'new Transform3d(new Translation3d(7.0, 8.0, 9.0), new Rotation3d(0.7, 0.8, 0.9))' + cpp_value: '{8_m, 2_m, 1_m, wpi::math::Rotation3d{0_deg, 1_deg, 88_deg}}' + python_value: 'Transform3d(Translation3d(7.0, 8.0, 9.0), Rotation3d(0.7, 0.8, 0.9))' + - name: optTest + java_value: 'Optional.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3)))' + cpp_value: '{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}}' + python_value: 'Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3))' + - name: vlaTest + java_value: 'List.of(new Transform3d(new Translation3d(1.0, 2.0, 3.0), new Rotation3d(0.1, 0.2, 0.3)), new Transform3d(new Translation3d(4.0, 5.0, 6.0), new Rotation3d(0.4, 0.5, 0.6)))' + cpp_value: '{{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{1_m, 2_m, 3_m, wpi::math::Rotation3d{6_deg, 7_deg, 12_deg}},{8_m, 2_m, 1_m, wpi::math::Rotation3d{0_deg, 1_deg, 88_deg}}}' + python_value: '[Transform3d(Translation3d(1.0, 2.0, 3.0), Rotation3d(0.1, 0.2, 0.3)), Transform3d(Translation3d(4.0, 5.0, 6.0), Rotation3d(0.4, 0.5, 0.6))]' diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/MultiTargetPNPResultSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/MultiTargetPNPResultSerde.java index bf1c0696fe..b2fb5f6483 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/MultiTargetPNPResultSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/MultiTargetPNPResultSerde.java @@ -28,10 +28,15 @@ import org.photonvision.common.dataflow.structures.Packet; import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; @@ -53,14 +58,13 @@ public int getMaxByteSize() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, MultiTargetPNPResult value) { // field estimatedPose is of non-intrinsic type PnpResult PnpResult.photonStruct.pack(packet, value.estimatedPose); - // fiducialIDsUsed is a intrinsic VLA! - packet.encode(value.fiducialIDsUsed); + // fiducialIDsUsed is an intrinsic VLA! + packet.encodeListImpl(value.fiducialIDsUsed,PacketUtils::packShort); } @Override @@ -70,8 +74,8 @@ public MultiTargetPNPResult unpack(Packet packet) { // estimatedPose is of non-intrinsic type PnpResult ret.estimatedPose = PnpResult.photonStruct.unpack(packet); - // fiducialIDsUsed is a custom VLA! - ret.fiducialIDsUsed = packet.decodeShortList(); + // fiducialIDsUsed is an intrinsic VLA! + ret.fiducialIDsUsed = packet.decodeListImpl(PacketUtils::unpackShort); return ret; } diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineMetadataSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineMetadataSerde.java index fb8e811dd9..d60c773ced 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineMetadataSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineMetadataSerde.java @@ -28,10 +28,15 @@ import org.photonvision.common.dataflow.structures.Packet; import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; @@ -53,20 +58,19 @@ public int getMaxByteSize() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, PhotonPipelineMetadata value) { // field sequenceID is of intrinsic type int64 - packet.encode((long) value.sequenceID); + packet.encode(value.sequenceID); // field captureTimestampMicros is of intrinsic type int64 - packet.encode((long) value.captureTimestampMicros); + packet.encode(value.captureTimestampMicros); // field publishTimestampMicros is of intrinsic type int64 - packet.encode((long) value.publishTimestampMicros); + packet.encode(value.publishTimestampMicros); // field timeSinceLastPong is of intrinsic type int64 - packet.encode((long) value.timeSinceLastPong); + packet.encode(value.timeSinceLastPong); } @Override diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java index ec0371fe2f..796bf7c48a 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonPipelineResultSerde.java @@ -28,10 +28,15 @@ import org.photonvision.common.dataflow.structures.Packet; import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; @@ -53,17 +58,16 @@ public int getMaxByteSize() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, PhotonPipelineResult value) { // field metadata is of non-intrinsic type PhotonPipelineMetadata PhotonPipelineMetadata.photonStruct.pack(packet, value.metadata); // targets is a custom VLA! - packet.encodeList(value.targets); + packet.encodeListImpl(value.targets,PhotonTrackedTarget.photonStruct::pack); // multitagResult is optional! it better not be a VLA too - packet.encodeOptional(value.multitagResult); + packet.encodeOptionalImpl(value.multitagResult,MultiTargetPNPResult.photonStruct::pack); } @Override @@ -74,10 +78,10 @@ public PhotonPipelineResult unpack(Packet packet) { ret.metadata = PhotonPipelineMetadata.photonStruct.unpack(packet); // targets is a custom VLA! - ret.targets = packet.decodeList(PhotonTrackedTarget.photonStruct); + ret.targets = packet.decodeListImpl(PhotonTrackedTarget.photonStruct::unpack); // multitagResult is optional! it better not be a VLA too - ret.multitagResult = packet.decodeOptional(MultiTargetPNPResult.photonStruct); + ret.multitagResult = packet.decodeOptionalImpl(MultiTargetPNPResult.photonStruct::unpack); return ret; } @@ -85,7 +89,7 @@ public PhotonPipelineResult unpack(Packet packet) { @Override public PacketSerde[] getNestedPhotonMessages() { return new PacketSerde[] { - PhotonTrackedTarget.photonStruct,MultiTargetPNPResult.photonStruct,PhotonPipelineMetadata.photonStruct + PhotonTrackedTarget.photonStruct,PhotonPipelineMetadata.photonStruct,MultiTargetPNPResult.photonStruct }; } diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonTrackedTargetSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonTrackedTargetSerde.java index 5d1c3a84bf..aa246348c9 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonTrackedTargetSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/PhotonTrackedTargetSerde.java @@ -33,6 +33,10 @@ // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; import org.wpilib.math.geometry.Transform3d; @@ -54,42 +58,43 @@ public int getMaxByteSize() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, PhotonTrackedTarget value) { // field yaw is of intrinsic type float64 - packet.encode((double) value.yaw); + packet.encode(value.yaw); // field pitch is of intrinsic type float64 - packet.encode((double) value.pitch); + packet.encode(value.pitch); // field area is of intrinsic type float64 - packet.encode((double) value.area); + packet.encode(value.area); // field skew is of intrinsic type float64 - packet.encode((double) value.skew); + packet.encode(value.skew); // field fiducialId is of intrinsic type int32 - packet.encode((int) value.fiducialId); + packet.encode(value.fiducialId); // field objDetectId is of intrinsic type int32 - packet.encode((int) value.objDetectId); + packet.encode(value.objDetectId); // field objDetectConf is of intrinsic type float32 - packet.encode((float) value.objDetectConf); + packet.encode(value.objDetectConf); + // bestCameraToTarget is of shimmed type Transform3d PacketUtils.packTransform3d(packet, value.bestCameraToTarget); + // altCameraToTarget is of shimmed type Transform3d PacketUtils.packTransform3d(packet, value.altCameraToTarget); // field poseAmbiguity is of intrinsic type float64 - packet.encode((double) value.poseAmbiguity); + packet.encode(value.poseAmbiguity); // minAreaRectCorners is a custom VLA! - packet.encodeList(value.minAreaRectCorners); + packet.encodeListImpl(value.minAreaRectCorners,TargetCorner.photonStruct::pack); // detectedCorners is a custom VLA! - packet.encodeList(value.detectedCorners); + packet.encodeListImpl(value.detectedCorners,TargetCorner.photonStruct::pack); } @Override @@ -117,18 +122,20 @@ public PhotonTrackedTarget unpack(Packet packet) { // objDetectConf is of intrinsic type float32 ret.objDetectConf = packet.decodeFloat(); + // bestCameraToTarget is of shimmed type Transform3d ret.bestCameraToTarget = PacketUtils.unpackTransform3d(packet); + // altCameraToTarget is of shimmed type Transform3d ret.altCameraToTarget = PacketUtils.unpackTransform3d(packet); // poseAmbiguity is of intrinsic type float64 ret.poseAmbiguity = packet.decodeDouble(); // minAreaRectCorners is a custom VLA! - ret.minAreaRectCorners = packet.decodeList(TargetCorner.photonStruct); + ret.minAreaRectCorners = packet.decodeListImpl(TargetCorner.photonStruct::unpack); // detectedCorners is a custom VLA! - ret.detectedCorners = packet.decodeList(TargetCorner.photonStruct); + ret.detectedCorners = packet.decodeListImpl(TargetCorner.photonStruct::unpack); return ret; } diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/PnpResultSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/PnpResultSerde.java index 90f4b7a6f0..7917b6876e 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/PnpResultSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/PnpResultSerde.java @@ -33,6 +33,10 @@ // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; import org.wpilib.math.geometry.Transform3d; @@ -54,29 +58,32 @@ public int getMaxByteSize() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, PnpResult value) { + // best is of shimmed type Transform3d PacketUtils.packTransform3d(packet, value.best); + // alt is of shimmed type Transform3d PacketUtils.packTransform3d(packet, value.alt); // field bestReprojErr is of intrinsic type float64 - packet.encode((double) value.bestReprojErr); + packet.encode(value.bestReprojErr); // field altReprojErr is of intrinsic type float64 - packet.encode((double) value.altReprojErr); + packet.encode(value.altReprojErr); // field ambiguity is of intrinsic type float64 - packet.encode((double) value.ambiguity); + packet.encode(value.ambiguity); } @Override public PnpResult unpack(Packet packet) { var ret = new PnpResult(); + // best is of shimmed type Transform3d ret.best = PacketUtils.unpackTransform3d(packet); + // alt is of shimmed type Transform3d ret.alt = PacketUtils.unpackTransform3d(packet); // bestReprojErr is of intrinsic type float64 diff --git a/photon-targeting/src/generated/main/java/org/photonvision/struct/TargetCornerSerde.java b/photon-targeting/src/generated/main/java/org/photonvision/struct/TargetCornerSerde.java index df42d7f46f..875fdccaa4 100644 --- a/photon-targeting/src/generated/main/java/org/photonvision/struct/TargetCornerSerde.java +++ b/photon-targeting/src/generated/main/java/org/photonvision/struct/TargetCornerSerde.java @@ -28,10 +28,15 @@ import org.photonvision.common.dataflow.structures.Packet; import org.photonvision.common.dataflow.structures.PacketSerde; +import org.photonvision.utils.PacketUtils; // Assume that the base class lives here and we can import it import org.photonvision.targeting.*; +// Needed for optional shims +import java.util.function.BiConsumer; +import java.util.function.Function; + // WPILib imports (if any) import org.wpilib.util.struct.Struct; @@ -53,14 +58,13 @@ public int getMaxByteSize() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'"); } - @Override public void pack(Packet packet, TargetCorner value) { // field x is of intrinsic type float64 - packet.encode((double) value.x); + packet.encode(value.x); // field y is of intrinsic type float64 - packet.encode((double) value.y); + packet.encode(value.y); } @Override diff --git a/photon-targeting/src/generated/main/native/cpp/photon/serde/MultiTargetPNPResultSerde.cpp b/photon-targeting/src/generated/main/native/cpp/photon/serde/MultiTargetPNPResultSerde.cpp index 5676e05e44..8d377ba531 100644 --- a/photon-targeting/src/generated/main/native/cpp/photon/serde/MultiTargetPNPResultSerde.cpp +++ b/photon-targeting/src/generated/main/native/cpp/photon/serde/MultiTargetPNPResultSerde.cpp @@ -26,6 +26,7 @@ #include "photon/serde/MultiTargetPNPResultSerde.h" + namespace photon { using StructType = SerdeType; diff --git a/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineMetadataSerde.cpp b/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineMetadataSerde.cpp index 8dfddc3d0d..7c0b5574e3 100644 --- a/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineMetadataSerde.cpp +++ b/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineMetadataSerde.cpp @@ -26,6 +26,7 @@ #include "photon/serde/PhotonPipelineMetadataSerde.h" + namespace photon { using StructType = SerdeType; diff --git a/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineResultSerde.cpp b/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineResultSerde.cpp index eebb222826..d0bbbe33d2 100644 --- a/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineResultSerde.cpp +++ b/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonPipelineResultSerde.cpp @@ -26,6 +26,7 @@ #include "photon/serde/PhotonPipelineResultSerde.h" + namespace photon { using StructType = SerdeType; diff --git a/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonTrackedTargetSerde.cpp b/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonTrackedTargetSerde.cpp index d1dbbf0c1b..cb62d2bc11 100644 --- a/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonTrackedTargetSerde.cpp +++ b/photon-targeting/src/generated/main/native/cpp/photon/serde/PhotonTrackedTargetSerde.cpp @@ -26,6 +26,7 @@ #include "photon/serde/PhotonTrackedTargetSerde.h" + namespace photon { using StructType = SerdeType; diff --git a/photon-targeting/src/generated/main/native/cpp/photon/serde/PnpResultSerde.cpp b/photon-targeting/src/generated/main/native/cpp/photon/serde/PnpResultSerde.cpp index 0fc4a5882f..2d38d346c1 100644 --- a/photon-targeting/src/generated/main/native/cpp/photon/serde/PnpResultSerde.cpp +++ b/photon-targeting/src/generated/main/native/cpp/photon/serde/PnpResultSerde.cpp @@ -26,6 +26,7 @@ #include "photon/serde/PnpResultSerde.h" + namespace photon { using StructType = SerdeType; diff --git a/photon-targeting/src/generated/main/native/cpp/photon/serde/TargetCornerSerde.cpp b/photon-targeting/src/generated/main/native/cpp/photon/serde/TargetCornerSerde.cpp index 925fdd1806..d14eda59be 100644 --- a/photon-targeting/src/generated/main/native/cpp/photon/serde/TargetCornerSerde.cpp +++ b/photon-targeting/src/generated/main/native/cpp/photon/serde/TargetCornerSerde.cpp @@ -26,6 +26,7 @@ #include "photon/serde/TargetCornerSerde.h" + namespace photon { using StructType = SerdeType; diff --git a/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java b/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java index 590fd04b24..eadfa34f93 100644 --- a/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java +++ b/photon-targeting/src/main/java/org/photonvision/common/dataflow/structures/Packet.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Function; import org.photonvision.targeting.serde.PhotonStructSerializable; /** A packet that holds byte-packed data to be sent over NetworkTables. */ @@ -181,34 +183,34 @@ public void encode(int src) { } /** - * Encodes the float into the packet. + * Encodes the long into the packet. * - * @param src The float to encode. + * @param src The long to encode. */ - public void encode(float src) { - ensureCapacity(4); - int data = Float.floatToIntBits(src); - packetData[writePos++] = (byte) (data & 0xff); - packetData[writePos++] = (byte) ((data >> 8) & 0xff); - packetData[writePos++] = (byte) ((data >> 16) & 0xff); - packetData[writePos++] = (byte) ((data >> 24) & 0xff); + public void encode(long src) { + ensureCapacity(8); + packetData[writePos++] = (byte) src; + packetData[writePos++] = (byte) ((src >> 8) & 0xff); + packetData[writePos++] = (byte) ((src >> 16) & 0xff); + packetData[writePos++] = (byte) ((src >> 24) & 0xff); + packetData[writePos++] = (byte) ((src >> 32) & 0xff); + packetData[writePos++] = (byte) ((src >> 40) & 0xff); + packetData[writePos++] = (byte) ((src >> 48) & 0xff); + packetData[writePos++] = (byte) ((src >> 56) & 0xff); } /** - * Encodes the double into the packet. + * Encodes the float into the packet. * - * @param data The double to encode. + * @param src The float to encode. */ - public void encode(long data) { - ensureCapacity(8); + public void encode(float src) { + ensureCapacity(4); + int data = Float.floatToIntBits(src); packetData[writePos++] = (byte) (data & 0xff); packetData[writePos++] = (byte) ((data >> 8) & 0xff); packetData[writePos++] = (byte) ((data >> 16) & 0xff); packetData[writePos++] = (byte) ((data >> 24) & 0xff); - packetData[writePos++] = (byte) ((data >> 32) & 0xff); - packetData[writePos++] = (byte) ((data >> 40) & 0xff); - packetData[writePos++] = (byte) ((data >> 48) & 0xff); - packetData[writePos++] = (byte) ((data >> 56) & 0xff); } /** @@ -239,7 +241,11 @@ public void encode(boolean src) { packetData[writePos++] = src ? (byte) 1 : (byte) 0; } - public void encode(List data) { + public > void encode(T data) { + data.getSerde().pack(this, data); + } + + public void encodeListImpl(List data, BiConsumer encoder) { byte size = (byte) data.size(); if (data.size() > Byte.MAX_VALUE) { throw new RuntimeException("Array too long! Got " + size); @@ -249,12 +255,15 @@ public void encode(List data) { encode(size); for (var f : data) { - encode(f); + encoder.accept(this, f); } } - public > void encode(T data) { - data.getSerde().pack(this, data); + public void encodeOptionalImpl(Optional data, BiConsumer encoder) { + encode(data.isPresent()); + if (data.isPresent()) { + encoder.accept(this, data.get()); + } } /** @@ -265,24 +274,40 @@ public > void encode(T data) { * @param data */ public > void encodeList(List data) { - byte size = (byte) data.size(); - if (data.size() > Byte.MAX_VALUE) { - throw new RuntimeException("Array too long! Got " + size); + // Hack + BiConsumer encoder; + if (data.size() < 1) { + encoder = + (packet, value) -> { + ; + }; + } else { + encoder = data.get(0).getSerde()::pack; } - // length byte - encode(size); - - for (var f : data) { - f.getSerde().pack(this, f); - } + encodeListImpl(data, encoder); } + /** + * Encode an optional serializable struct. Lists are stored as [uint8 length, [length many] data + * structs] + * + * @param the class this optional will be packing + * @param data + */ public > void encodeOptional(Optional data) { - encode(data.isPresent()); + // Hack + BiConsumer encoder; if (data.isPresent()) { - data.get().getSerde().pack(this, data.get()); + encoder = + (packet, value) -> { + ; + }; + } else { + encoder = data.get().getSerde()::pack; } + + encodeOptionalImpl(data, encoder); } /** @@ -297,6 +322,18 @@ public byte decodeByte() { return packetData[readPos++]; } + /** + * Returns a decoded short from the packet + * + * @return A decoded short from the packet + */ + public short decodeShort() { + if (packetData.length < readPos + 1) { + return 0; + } + return (short) ((0xff & packetData[readPos++]) | (0xff & packetData[readPos++]) << 8); + } + /** * Returns a decoded int from the packet. * @@ -329,6 +366,24 @@ public long decodeLong() { return data; } + /** + * Returns a decoded float from the packet. + * + * @return A decoded float from the packet. + */ + public float decodeFloat() { + if (packetData.length < (readPos + 3)) { + return 0; + } + + int data = + ((0xff & packetData[readPos++] + | (0xff & packetData[readPos++]) << 8 + | (0xff & packetData[readPos++]) << 16 + | (0xff & packetData[readPos++]) << 24)); + return Float.intBitsToFloat(data); + } + /** * Returns a decoded double from the packet. * @@ -351,24 +406,6 @@ public double decodeDouble() { return Double.longBitsToDouble(data); } - /** - * Returns a decoded float from the packet. - * - * @return A decoded float from the packet. - */ - public float decodeFloat() { - if (packetData.length < (readPos + 3)) { - return 0; - } - - int data = - ((0xff & packetData[readPos++] - | (0xff & packetData[readPos++]) << 8 - | (0xff & packetData[readPos++]) << 16 - | (0xff & packetData[readPos++]) << 24)); - return Float.intBitsToFloat(data); - } - /** * Returns a decoded boolean from the packet. * @@ -381,69 +418,43 @@ public boolean decodeBoolean() { return packetData[readPos++] == 1; } - public void encode(double[] data) { - for (double d : data) { - encode(d); - } - } - - public double[] decodeDoubleArray(int len) { - double[] ret = new double[len]; - for (int i = 0; i < len; i++) { - ret[i] = decodeDouble(); - } - return ret; - } - - public short decodeShort() { - if (packetData.length < readPos + 1) { - return 0; - } - return (short) ((0xff & packetData[readPos++]) | (0xff & packetData[readPos++]) << 8); + public > T decode(PhotonStructSerializable t) { + return t.getSerde().unpack(this); } - /** - * Decode a list of serializable structs. Lists are stored as [uint8 length, [length many] data - * structs]. Because java sucks, we need to take the serde ref directly - * - * @param - * @param serde - */ - public > List decodeList(PacketSerde serde) { + public List decodeListImpl(Function decoder) { byte length = decodeByte(); var ret = new ArrayList(); ret.ensureCapacity(length); for (int i = 0; i < length; i++) { - ret.add(serde.unpack(this)); + ret.add(decoder.apply(this)); } return ret; } - public > Optional decodeOptional(PacketSerde serde) { + public Optional decodeOptionalImpl(Function decoder) { var present = decodeBoolean(); if (present) { - return Optional.of(serde.unpack(this)); + return Optional.of(decoder.apply(this)); } return Optional.empty(); } - public List decodeShortList() { - byte length = decodeByte(); - - var ret = new ArrayList(); - ret.ensureCapacity(length); - - for (int i = 0; i < length; i++) { - ret.add(decodeShort()); - } - - return ret; + /** + * Decode a list of serializable structs. Lists are stored as [uint8 length, [length many] data + * structs]. Because java sucks, we need to take the serde ref directly + * + * @param + * @param serde + */ + public > List decodeList(PacketSerde serde) { + return decodeListImpl(serde::unpack); } - public > T decode(PhotonStructSerializable t) { - return t.getSerde().unpack(this); + public > Optional decodeOptional(PacketSerde serde) { + return decodeOptionalImpl(serde::unpack); } } diff --git a/photon-targeting/src/main/java/org/photonvision/utils/PacketUtils.java b/photon-targeting/src/main/java/org/photonvision/utils/PacketUtils.java index 501d753a24..5c29371d8b 100644 --- a/photon-targeting/src/main/java/org/photonvision/utils/PacketUtils.java +++ b/photon-targeting/src/main/java/org/photonvision/utils/PacketUtils.java @@ -32,6 +32,63 @@ public class PacketUtils { public static final int POSE2D_BYTE_SIZE = TRANSLATION2D_BYTE_SIZE + ROTATION2D_BYTE_SIZE; public static final int POSE3D_BYTE_SIZE = TRANSLATION3D_BYTE_SIZE + ROTATION3D_BYTE_SIZE; + // Kinda scuffed, this is so that datatype functions have the same signature as other shims + public static void packByte(Packet packet, byte data) { + packet.encode(data); + } + + public static byte unpackByte(Packet packet) { + return packet.decodeByte(); + } + + public static void packShort(Packet packet, short data) { + packet.encode(data); + } + + public static short unpackShort(Packet packet) { + return packet.decodeShort(); + } + + public static void packInt(Packet packet, int data) { + packet.encode(data); + } + + public static int unpackInt(Packet packet) { + return packet.decodeInt(); + } + + public static void packLong(Packet packet, long data) { + packet.encode(data); + } + + public static long unpackLong(Packet packet) { + return packet.decodeLong(); + } + + public static void packFloat(Packet packet, float data) { + packet.encode(data); + } + + public static float unpackFloat(Packet packet) { + return packet.decodeFloat(); + } + + public static void packDouble(Packet packet, double data) { + packet.encode(data); + } + + public static double unpackDouble(Packet packet) { + return packet.decodeDouble(); + } + + public static void packBoolean(Packet packet, boolean data) { + packet.encode(data); + } + + public static boolean unpackBoolean(Packet packet) { + return packet.decodeBoolean(); + } + public static void packRotation2d(Packet packet, Rotation2d rotation) { packet.encode(rotation.getRadians()); } diff --git a/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h b/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h index 840ee8300c..cceff711a4 100644 --- a/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h +++ b/photon-targeting/src/main/native/include/photon/dataflow/structures/Packet.h @@ -17,19 +17,71 @@ #pragma once -#include -#include +#include +#include +#include +#include #include #include -#include +#include #include +#include +#include #include namespace photon { class Packet; +template +struct optional_inner; + +template +struct optional_inner> { + using type = T; +}; + +template +using optional_inner_t = typename optional_inner>::type; + +template +struct is_optional : std::false_type {}; + +template +struct is_optional> : std::true_type {}; + +template +concept Optional = is_optional>::value; + +template +concept OptionalWPIStructSerializable = + Optional && wpi::util::StructSerializable, I...>; + +template +struct vector_inner; + +template +struct vector_inner> { + using type = T; +}; + +template +using vector_inner_t = typename vector_inner>::type; + +template +struct is_vector : std::false_type {}; + +template +struct is_vector> : std::true_type {}; + +template +concept Vector = is_vector>::value; + +template +concept VectorWPIStructSerializable = + Vector && wpi::util::StructSerializable, I...>; + // Struct is where all our actual ser/de methods are implemented template struct SerdeType {}; @@ -104,6 +156,30 @@ class Packet { writePos = newWritePos; } + // Support encoding optional wpi structs + template + requires OptionalWPIStructSerializable + inline void Pack(const std::optional>& value) { + using T = optional_inner_t; + if (value) { + Pack(1u); + Pack(*value); + } else { + Pack(0u); + } + } + + // Support encoding wpi struct vectors + template + requires VectorWPIStructSerializable + inline void Pack(const std::vector>& value) { + using T = vector_inner_t; + Pack(value.size()); + for (const auto& thing : value) { + Pack(thing); + } + } + template requires(PhotonStructSerializable) inline void Pack(const T& value) { @@ -120,6 +196,32 @@ class Packet { return ret; } + // Support decoding optional wpi structs + template + requires OptionalWPIStructSerializable + inline std::optional> Unpack() { + using T = optional_inner_t; + if (Unpack() == 0u) { + return std::nullopt; + } else { + return std::make_optional(Unpack()); + } + } + + // Support decoding wpi struct vectors + template + requires VectorWPIStructSerializable + inline std::vector> Unpack() { + using T = vector_inner_t; + uint8_t len = Unpack(); + std::vector ret; + ret.reserve(len); + for (size_t i = 0; i < len; i++) { + ret.push_back(Unpack()); + } + return ret; + } + template requires(PhotonStructSerializable) inline T Unpack() { @@ -137,12 +239,9 @@ class Packet { size_t writePos = 0; }; -template -concept arithmetic = std::integral || std::floating_point; - // support encoding vectors template - requires(PhotonStructSerializable || arithmetic) + requires(PhotonStructSerializable) struct SerdeType> { static std::vector Unpack(Packet& packet) { uint8_t len = packet.Unpack(); @@ -173,7 +272,7 @@ struct SerdeType> { // support encoding optional types template - requires(PhotonStructSerializable || arithmetic) + requires(PhotonStructSerializable) struct SerdeType> { static std::optional Unpack(Packet& packet) { if (packet.Unpack() == 1u) { diff --git a/photon-targeting/src/test/java/org/photonvision/PacketTest.java b/photon-targeting/src/test/java/org/photonvision/PacketTest.java index b531f54816..6c49e8ed1e 100644 --- a/photon-targeting/src/test/java/org/photonvision/PacketTest.java +++ b/photon-targeting/src/test/java/org/photonvision/PacketTest.java @@ -41,7 +41,7 @@ public void testTargetCorner() { } @Test - void pipelineResultSerde() { + public void pipelineResultSerde() { var ret1 = new PhotonPipelineResult(1, 2, 3, 1024, List.of()); var p1 = new Packet(10); PhotonPipelineResult.photonStruct.pack(p1, ret1); @@ -161,4 +161,282 @@ void pipelineResultSerde() { var unpackedRet3 = PhotonPipelineResult.photonStruct.unpack(p3); assertEquals(ret3, unpackedRet3); } + + public void VLASerde() { + var ret1 = + List.of( + new PhotonPipelineResult( + 1, + 2, + 3, + 1024, + List.of( + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.0, + 4.0, + 2, + -1, + -1f, + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))), + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.1, + 6.7, + 3, + -1, + -1f, + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))))), + new PhotonPipelineResult( + 1, + 2, + 3, + 1024, + List.of( + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.0, + 4.0, + 2, + -1, + -1f, + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))), + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.1, + 6.7, + 3, + -1, + -1f, + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))))), + new PhotonPipelineResult( + 1, + 2, + 3, + 1024, + List.of( + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.0, + 4.0, + 2, + -1, + -1f, + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))), + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.1, + 6.7, + 3, + -1, + -1f, + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)))))); + var p1 = new Packet(10); + p1.encodeList(ret1); + var unpackedRet1 = p1.decodeList(PhotonPipelineResult.photonStruct); + assertEquals(ret1, unpackedRet1); + + List ret2 = List.of(); + var p2 = new Packet(10); + p2.encodeList(ret2); + var unpackedRet2 = p2.decodeList(PhotonPipelineResult.photonStruct); + assertEquals(ret2, unpackedRet2); + } + + public void optionalSerde() { + var ret1 = + Optional.of( + new PhotonPipelineResult( + 1, + 2, + 3, + 1024, + List.of( + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.0, + 4.0, + 2, + -1, + -1f, + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))), + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.1, + 6.7, + 3, + -1, + -1f, + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)))))); + var p1 = new Packet(10); + p1.encodeOptional(ret1); + var unpackedRet1 = p1.decodeOptional(PhotonPipelineResult.photonStruct); + assertEquals(p1, unpackedRet1); + + Optional ret2 = Optional.empty(); + var p2 = new Packet(10); + p2.encodeOptional(ret2); + var unpackedRet2 = p2.decodeOptional(PhotonPipelineResult.photonStruct); + assertEquals(ret2, unpackedRet2); + } + + public void encodePhotonStruct() { + var ret1 = + new PhotonPipelineResult( + 1, + 2, + 3, + 1024, + List.of( + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.0, + 4.0, + 2, + -1, + -1f, + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + new Transform3d(new Translation3d(1, 2, 3), new Rotation3d(1, 2, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))), + new PhotonTrackedTarget( + 3.0, + -4.0, + 9.1, + 6.7, + 3, + -1, + -1f, + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + new Transform3d(new Translation3d(4, 2, 3), new Rotation3d(1, 5, 3)), + 0.25, + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8)), + List.of( + new TargetCorner(1, 2), + new TargetCorner(3, 4), + new TargetCorner(5, 6), + new TargetCorner(7, 8))))); + var p1 = new Packet(10); + p1.encode(ret1); + var unpackedRet1 = p1.decode(ret1); + assertEquals(ret1, unpackedRet1); + } } diff --git a/settings.gradle b/settings.gradle index 30f98b2fb4..503440e89c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,4 +14,5 @@ include 'photon-targeting' include 'photon-core' include 'photon-server' include 'photon-lib' +include 'photon-serde-tests' include 'photon-docs'