diff --git a/.gitignore b/.gitignore index 97cc1dbcf8f..513a9eef207 100644 --- a/.gitignore +++ b/.gitignore @@ -252,3 +252,6 @@ coverage_report/ # ctest /Testing/ + +# protobuf +!wpiprotoplugin.jar diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f16064cad9..dab6b3c7e83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,9 @@ if(WITH_JAVA OR WITH_JAVA_SOURCE) set(CMAKE_JAVA_COMPILE_FLAGS "-encoding" "UTF8" "-Xlint:unchecked") find_package(Java REQUIRED COMPONENTS Development) find_package(JNI REQUIRED COMPONENTS JVM) +else() + # Protoc requires the java runtime + find_package(Java REQUIRED COMPONENTS Runtime) endif() find_package(LIBSSH 0.7.1) @@ -273,6 +276,8 @@ if(WITH_NTCORE) add_subdirectory(ntcore) endif() +add_subdirectory(protoplugin) + if(WITH_WPIMATH) if(WITH_JAVA) set(WPIUNITS_DEP_REPLACE ${WPIUNITS_DEP_REPLACE_IMPL}) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 9d0f6837844..3a0ddb1510e 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -9,5 +9,5 @@ repositories { } } dependencies { - implementation "edu.wpi.first:native-utils:2025.1.0" + implementation "edu.wpi.first:native-utils:2025.2.0" } diff --git a/protoplugin/CMakeLists.txt b/protoplugin/CMakeLists.txt new file mode 100644 index 00000000000..599f8cafab8 --- /dev/null +++ b/protoplugin/CMakeLists.txt @@ -0,0 +1,20 @@ +project(protoplugin) + +set(PROTO_JAR ${CMAKE_CURRENT_SOURCE_DIR}/binary/wpiprotoplugin.jar) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/binary/wpiprotoplugin.sh.in + ${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.sh + @ONLY +) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/binary/wpiprotoplugin.bat.in + ${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.bat + @ONLY +) + +if(WIN32) + set(PROTOC_WPILIB_PLUGIN ${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.bat PARENT_SCOPE) +else() + set(PROTOC_WPILIB_PLUGIN ${CMAKE_CURRENT_BINARY_DIR}/wpiprotoplugin.sh PARENT_SCOPE) +endif() diff --git a/protoplugin/binary/wpiprotoplugin.bat.in b/protoplugin/binary/wpiprotoplugin.bat.in new file mode 100644 index 00000000000..2062ec3435d --- /dev/null +++ b/protoplugin/binary/wpiprotoplugin.bat.in @@ -0,0 +1,2 @@ +@ECHO OFF +"@Java_JAVA_EXECUTABLE@" -jar "@PROTO_JAR@" %* diff --git a/protoplugin/binary/wpiprotoplugin.jar b/protoplugin/binary/wpiprotoplugin.jar new file mode 100644 index 00000000000..8905211fee2 Binary files /dev/null and b/protoplugin/binary/wpiprotoplugin.jar differ diff --git a/protoplugin/binary/wpiprotoplugin.sh.in b/protoplugin/binary/wpiprotoplugin.sh.in new file mode 100755 index 00000000000..22d955a57f4 --- /dev/null +++ b/protoplugin/binary/wpiprotoplugin.sh.in @@ -0,0 +1,2 @@ +#!/bin/sh +exec "@Java_JAVA_EXECUTABLE@" -jar "@PROTO_JAR@" "$@" diff --git a/protoplugin/build.gradle b/protoplugin/build.gradle new file mode 100644 index 00000000000..c84734df4e6 --- /dev/null +++ b/protoplugin/build.gradle @@ -0,0 +1,33 @@ +plugins { + id 'application' + id 'java' + id 'com.gradleup.shadow' version '8.3.0' +} + +application { + mainClass = "org.wpilib.ProtoCDllGenerator" +} + +repositories { + mavenCentral() +} + +dependencies { + implementation "com.google.protobuf:protobuf-java:3.21.12" +} + +java { + sourceCompatibility = 8 + targetCompatibility = 8 +} + +def cshadow = project.tasks.register("copyShadow", Copy) { + from(tasks.shadowJar.archiveFile) { + rename { + "wpiprotoplugin.jar" + } + } + into layout.projectDirectory.dir("binary") +} + +build.dependsOn cshadow diff --git a/protoplugin/settings.gradle b/protoplugin/settings.gradle new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/protoplugin/settings.gradle @@ -0,0 +1 @@ + diff --git a/protoplugin/src/main/java/org/wpilib/ProtoCDllGenerator.java b/protoplugin/src/main/java/org/wpilib/ProtoCDllGenerator.java new file mode 100644 index 00000000000..3c7c29d51a7 --- /dev/null +++ b/protoplugin/src/main/java/org/wpilib/ProtoCDllGenerator.java @@ -0,0 +1,76 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package org.wpilib; + +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import com.google.protobuf.DescriptorProtos.FileDescriptorProto; +import com.google.protobuf.Descriptors; +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.DescriptorValidationException; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor.Type; +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; + +public final class ProtoCDllGenerator { + private ProtoCDllGenerator() { + } + + public static void main(String[] args) throws IOException, DescriptorValidationException { + CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in); + + Map descriptors = new HashMap<>(); + + Descriptors.FileDescriptor[] tmpArray = new Descriptors.FileDescriptor[0]; + + for (FileDescriptorProto proto : request.getProtoFileList()) { + // Make array of file descriptors that exists + Descriptors.FileDescriptor[] depArray = descriptors.values().toArray(tmpArray); + Descriptors.FileDescriptor desc = Descriptors.FileDescriptor.buildFrom(proto, depArray); + descriptors.put(proto.getName(), desc); + } + + // Filter to generated descriptors + CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder(); + + for (String genFile : request.getFileToGenerateList()) { + Descriptors.FileDescriptor desc = descriptors.get(genFile); + + for (Descriptor msg : desc.getMessageTypes()) { + for (FieldDescriptor field : msg.getFields()) { + if (field.getType() == Type.MESSAGE && !field.isRepeated()) { + // If we have a nested non repeated field, we need a custom accessor + String type = field.getMessageType().getFullName(); + type = "::" + type.replaceAll("\\.", "::"); + + // Add definition + response.addFileBuilder() + .setName(desc.getName().replace("proto", "pb.h")) + .setInsertionPoint("class_scope:" + msg.getFullName()) + .setContent("// Custom WPILib Accessor\n" + + "bool wpi_has_" + field.getName() + "() const;\n" + + "const " + type + "& wpi_" + field.getName() + "() const;\n"); + + // Add implementation. As were in the cc file for the proto + // we can just call straight through to the inline definitions + response.addFileBuilder() + .setName(desc.getName().replace("proto", "pb.cc")) + .setInsertionPoint("namespace_scope") + .setContent("// Custom WPILib Accessor\n" + + "bool " + msg.getName() + "::wpi_has_" + field.getName() + "() const { return has_" + + field.getName() + "(); }\n" + + "const " + type + "& " + msg.getName() + "::wpi_" + field.getName() + "() const { return " + + field.getName() + "(); }\n"); + } + } + } + } + response.build().writeTo(System.out); + } +} diff --git a/shared/java/javacommon.gradle b/shared/java/javacommon.gradle index 5d0cae57910..6151250c599 100644 --- a/shared/java/javacommon.gradle +++ b/shared/java/javacommon.gradle @@ -148,8 +148,19 @@ protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.21.12' } + plugins { + wpilib { + path = rootProject.file("protoplugin/binary/wpiprotoplugin.jar") + } + } generateProtoTasks { all().configureEach { task -> + task.inputs.file(rootProject.file("protoplugin/binary/wpiprotoplugin.jar")) + task.plugins { + wpilib { + outputSubDir = 'cpp' + } + } task.builtins { cpp {} remove java diff --git a/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch b/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch index d3ac55c09d4..123b23c4e1b 100644 --- a/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch +++ b/upstream_utils/protobuf_patches/0001-Fix-sign-compare-warnings.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 14:13:07 -0700 -Subject: [PATCH 01/12] Fix sign-compare warnings +Subject: [PATCH 01/13] Fix sign-compare warnings --- src/google/protobuf/compiler/importer.cc | 2 +- diff --git a/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch b/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch index 6916c98bd29..70288208588 100644 --- a/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch +++ b/upstream_utils/protobuf_patches/0002-Remove-redundant-move.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 14:41:39 -0700 -Subject: [PATCH 02/12] Remove redundant move +Subject: [PATCH 02/13] Remove redundant move --- src/google/protobuf/extension_set.h | 2 +- diff --git a/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch b/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch index 6888dd25eef..1f54467220d 100644 --- a/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch +++ b/upstream_utils/protobuf_patches/0003-Fix-maybe-uninitialized-warnings.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 15:00:20 -0700 -Subject: [PATCH 03/12] Fix maybe-uninitialized warnings +Subject: [PATCH 03/13] Fix maybe-uninitialized warnings --- src/google/protobuf/arena.cc | 6 +++--- diff --git a/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch b/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch index dc17497b7be..e1649137559 100644 --- a/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch +++ b/upstream_utils/protobuf_patches/0004-Fix-coded_stream-WriteRaw.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 15:03:38 -0700 -Subject: [PATCH 04/12] Fix coded_stream WriteRaw +Subject: [PATCH 04/13] Fix coded_stream WriteRaw --- src/google/protobuf/implicit_weak_message.h | 2 +- diff --git a/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch b/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch index 2919644e3ef..84712afc3b8 100644 --- a/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch +++ b/upstream_utils/protobuf_patches/0005-Suppress-enum-enum-conversion-warning.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 15:13:45 -0700 -Subject: [PATCH 05/12] Suppress enum-enum conversion warning +Subject: [PATCH 05/13] Suppress enum-enum conversion warning --- src/google/protobuf/generated_message_tctable_impl.h | 9 +++++++++ diff --git a/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch b/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch index abaa0a20b9e..70841fe6532 100644 --- a/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch +++ b/upstream_utils/protobuf_patches/0006-Fix-noreturn-function-returning.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 15:16:46 -0700 -Subject: [PATCH 06/12] Fix noreturn function returning +Subject: [PATCH 06/13] Fix noreturn function returning --- src/google/protobuf/generated_message_tctable_impl.h | 3 +++ diff --git a/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch b/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch index 543896c2bc2..0f1a050190a 100644 --- a/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch +++ b/upstream_utils/protobuf_patches/0007-Work-around-GCC-12-restrict-warning-compiler-bug.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 10 Jun 2023 15:59:45 -0700 -Subject: [PATCH 07/12] Work around GCC 12 restrict warning compiler bug +Subject: [PATCH 07/13] Work around GCC 12 restrict warning compiler bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329 --- diff --git a/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch b/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch index 92654f0ff67..716a28f8c75 100644 --- a/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch +++ b/upstream_utils/protobuf_patches/0008-Disable-MSVC-switch-warning.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 13 Jun 2023 23:56:15 -0700 -Subject: [PATCH 08/12] Disable MSVC switch warning +Subject: [PATCH 08/13] Disable MSVC switch warning --- src/google/protobuf/generated_message_reflection.cc | 4 ++++ diff --git a/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch b/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch index 9a8864951c6..7c427f11f83 100644 --- a/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch +++ b/upstream_utils/protobuf_patches/0009-Disable-unused-function-warning.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 13 Jun 2023 23:58:50 -0700 -Subject: [PATCH 09/12] Disable unused function warning +Subject: [PATCH 09/13] Disable unused function warning --- src/google/protobuf/generated_message_tctable_lite.cc | 4 ++++ diff --git a/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch b/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch index dd1860e79d4..5ae5a9c5b6d 100644 --- a/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch +++ b/upstream_utils/protobuf_patches/0010-Disable-pedantic-warning.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 14 Jun 2023 00:02:26 -0700 -Subject: [PATCH 10/12] Disable pedantic warning +Subject: [PATCH 10/13] Disable pedantic warning --- src/google/protobuf/descriptor.h | 8 ++++++++ diff --git a/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch b/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch index a0dfad86555..2d5692ccf76 100644 --- a/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch +++ b/upstream_utils/protobuf_patches/0011-Avoid-use-of-sprintf.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 9 Oct 2023 19:28:08 -0700 -Subject: [PATCH 11/12] Avoid use of sprintf +Subject: [PATCH 11/13] Avoid use of sprintf --- src/google/protobuf/stubs/strutil.cc | 14 +++++++++++--- diff --git a/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch b/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch index 929c117fce6..809bb24a75d 100644 --- a/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch +++ b/upstream_utils/protobuf_patches/0012-Suppress-stringop-overflow-warning-false-positives.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Fri, 10 Nov 2023 14:17:53 -0800 -Subject: [PATCH 12/12] Suppress stringop-overflow warning false positives +Subject: [PATCH 12/13] Suppress stringop-overflow warning false positives --- src/google/protobuf/io/coded_stream.h | 7 +++++++ diff --git a/upstream_utils/protobuf_patches/0013-Switch-descriptor-to-not-use-globals-from-header-inl.patch b/upstream_utils/protobuf_patches/0013-Switch-descriptor-to-not-use-globals-from-header-inl.patch new file mode 100644 index 00000000000..21d1b7e3ce8 --- /dev/null +++ b/upstream_utils/protobuf_patches/0013-Switch-descriptor-to-not-use-globals-from-header-inl.patch @@ -0,0 +1,167 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Thad House +Date: Sun, 18 Aug 2024 22:43:37 -0700 +Subject: [PATCH 13/13] Switch descriptor to not use globals from header inline + functions + +--- + src/google/protobuf/descriptor.cc | 66 +++++++++++++++++++------------ + src/google/protobuf/descriptor.h | 20 +++++----- + 2 files changed, 51 insertions(+), 35 deletions(-) + +diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc +index 5f3427dc72497b618c4dea3ec6985eeb39139349..5be05da4fb1c21fb1068ae7341cabef9dcf598a5 100644 +--- a/src/google/protobuf/descriptor.cc ++++ b/src/google/protobuf/descriptor.cc +@@ -791,31 +791,31 @@ class Symbol { + const internal::SymbolBase* ptr_; + }; + +-const FieldDescriptor::CppType +- FieldDescriptor::kTypeToCppTypeMap[MAX_TYPE + 1] = { +- static_cast(0), // 0 is reserved for errors +- +- CPPTYPE_DOUBLE, // TYPE_DOUBLE +- CPPTYPE_FLOAT, // TYPE_FLOAT +- CPPTYPE_INT64, // TYPE_INT64 +- CPPTYPE_UINT64, // TYPE_UINT64 +- CPPTYPE_INT32, // TYPE_INT32 +- CPPTYPE_UINT64, // TYPE_FIXED64 +- CPPTYPE_UINT32, // TYPE_FIXED32 +- CPPTYPE_BOOL, // TYPE_BOOL +- CPPTYPE_STRING, // TYPE_STRING +- CPPTYPE_MESSAGE, // TYPE_GROUP +- CPPTYPE_MESSAGE, // TYPE_MESSAGE +- CPPTYPE_STRING, // TYPE_BYTES +- CPPTYPE_UINT32, // TYPE_UINT32 +- CPPTYPE_ENUM, // TYPE_ENUM +- CPPTYPE_INT32, // TYPE_SFIXED32 +- CPPTYPE_INT64, // TYPE_SFIXED64 +- CPPTYPE_INT32, // TYPE_SINT32 +- CPPTYPE_INT64, // TYPE_SINT64 ++static const FieldDescriptor::CppType ++ kTypeToCppTypeMap[FieldDescriptor::MAX_TYPE + 1] = { ++ static_cast(0), // 0 is reserved for errors ++ ++ FieldDescriptor::CPPTYPE_DOUBLE, // TYPE_DOUBLE ++ FieldDescriptor::CPPTYPE_FLOAT, // TYPE_FLOAT ++ FieldDescriptor::CPPTYPE_INT64, // TYPE_INT64 ++ FieldDescriptor::CPPTYPE_UINT64, // TYPE_UINT64 ++ FieldDescriptor::CPPTYPE_INT32, // TYPE_INT32 ++ FieldDescriptor::CPPTYPE_UINT64, // TYPE_FIXED64 ++ FieldDescriptor::CPPTYPE_UINT32, // TYPE_FIXED32 ++ FieldDescriptor::CPPTYPE_BOOL, // TYPE_BOOL ++ FieldDescriptor::CPPTYPE_STRING, // TYPE_STRING ++ FieldDescriptor::CPPTYPE_MESSAGE, // TYPE_GROUP ++ FieldDescriptor::CPPTYPE_MESSAGE, // TYPE_MESSAGE ++ FieldDescriptor::CPPTYPE_STRING, // TYPE_BYTES ++ FieldDescriptor::CPPTYPE_UINT32, // TYPE_UINT32 ++ FieldDescriptor::CPPTYPE_ENUM, // TYPE_ENUM ++ FieldDescriptor::CPPTYPE_INT32, // TYPE_SFIXED32 ++ FieldDescriptor::CPPTYPE_INT64, // TYPE_SFIXED64 ++ FieldDescriptor::CPPTYPE_INT32, // TYPE_SINT32 ++ FieldDescriptor::CPPTYPE_INT64, // TYPE_SINT64 + }; + +-const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { ++static const char* const kTypeToName[FieldDescriptor::MAX_TYPE + 1] = { + "ERROR", // 0 is reserved for errors + + "double", // TYPE_DOUBLE +@@ -838,7 +838,7 @@ const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { + "sint64", // TYPE_SINT64 + }; + +-const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { ++static const char* const kCppTypeToName[FieldDescriptor::MAX_CPPTYPE + 1] = { + "ERROR", // 0 is reserved for errors + + "int32", // CPPTYPE_INT32 +@@ -853,7 +853,7 @@ const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { + "message", // CPPTYPE_MESSAGE + }; + +-const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { ++static const char* const kLabelToName[FieldDescriptor::MAX_LABEL + 1] = { + "ERROR", // 0 is reserved for errors + + "optional", // LABEL_OPTIONAL +@@ -861,6 +861,22 @@ const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { + "repeated", // LABEL_REPEATED + }; + ++const FieldDescriptor::CppType *FieldDescriptor::GetTypeToCppTypeMap() { ++ return kTypeToCppTypeMap; ++} ++ ++const char* const *FieldDescriptor::GetTypeToName() { ++ return kTypeToName; ++} ++ ++const char* const *FieldDescriptor::GetCppTypeToName() { ++ return kCppTypeToName; ++} ++ ++const char* const *FieldDescriptor::GetLabelToName() { ++ return kLabelToName; ++} ++ + const char* FileDescriptor::SyntaxName(FileDescriptor::Syntax syntax) { + switch (syntax) { + case SYNTAX_PROTO2: +diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h +index bee3e32b9f1d5ba47b83d1e388716a3c3b6e82c6..1cb2421b5362a757abe3735e15321e630b1cab3e 100644 +--- a/src/google/protobuf/descriptor.h ++++ b/src/google/protobuf/descriptor.h +@@ -976,13 +976,13 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { + mutable std::atomic default_generated_instance_; + }; + +- static const CppType kTypeToCppTypeMap[MAX_TYPE + 1]; ++ static const CppType *GetTypeToCppTypeMap(); + +- static const char* const kTypeToName[MAX_TYPE + 1]; ++ static const char* const *GetTypeToName(); + +- static const char* const kCppTypeToName[MAX_CPPTYPE + 1]; ++ static const char* const *GetCppTypeToName(); + +- static const char* const kLabelToName[MAX_LABEL + 1]; ++ static const char* const *GetLabelToName(); + + // Must be constructed using DescriptorPool. + FieldDescriptor() {} +@@ -2392,27 +2392,27 @@ inline int MethodDescriptor::index() const { + } + + inline const char* FieldDescriptor::type_name() const { +- return kTypeToName[type()]; ++ return GetTypeToName()[type()]; + } + + inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { +- return kTypeToCppTypeMap[type()]; ++ return GetTypeToCppTypeMap()[type()]; + } + + inline const char* FieldDescriptor::cpp_type_name() const { +- return kCppTypeToName[kTypeToCppTypeMap[type()]]; ++ return GetCppTypeToName()[GetTypeToCppTypeMap()[type()]]; + } + + inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { +- return kTypeToCppTypeMap[type]; ++ return GetTypeToCppTypeMap()[type]; + } + + inline const char* FieldDescriptor::TypeName(Type type) { +- return kTypeToName[type]; ++ return GetTypeToName()[type]; + } + + inline const char* FieldDescriptor::CppTypeName(CppType cpp_type) { +- return kCppTypeToName[cpp_type]; ++ return GetCppTypeToName()[cpp_type]; + } + + inline bool FieldDescriptor::IsTypePackable(Type field_type) { diff --git a/wpimath/CMakeLists.txt b/wpimath/CMakeLists.txt index 31afb51fc25..82cd541a818 100644 --- a/wpimath/CMakeLists.txt +++ b/wpimath/CMakeLists.txt @@ -8,14 +8,6 @@ include(DownloadAndCheck) # workaround for makefiles - for some reason parent directories aren't created. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/protobuf") file(GLOB wpimath_proto_src src/main/proto/*.proto) -protobuf_generate_cpp( - WPIMATH_PROTO_SRCS - WPIMATH_PROTO_HDRS - PROTOC_OUT_DIR - "${CMAKE_CURRENT_BINARY_DIR}/protobuf" - PROTOS - ${wpimath_proto_src} -) file( GLOB wpimath_jni_src @@ -129,20 +121,53 @@ file( list(REMOVE_ITEM wpimath_native_src ${wpimath_jni_src}) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE) -add_library(wpimath ${wpimath_native_src} ${WPIMATH_PROTO_SRCS}) + +add_library(protobuf OBJECT) +target_link_libraries(protobuf wpiutil) + +add_library(wpimath ${wpimath_native_src} $) + +protobuf_generate( + TARGET protobuf + PROTOS ${wpimath_proto_src} + PLUGIN "protoc-gen-wpilib=${PROTOC_WPILIB_PLUGIN}" + PROTOC_OPTIONS "--cpp_out=${CMAKE_CURRENT_BINARY_DIR}/protobuf" # Needed to generate C++ source + PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf" + GENERATE_EXTENSIONS ".pb.h" ".pb.cc" # Enables CMake to add the generated sources to the target + LANGUAGE wpilib # Adds a --wpilib_out arg to let our plugin modify the generated protobuf code + APPEND_PATH +) + +if(MSVC) + file( + GENERATE OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/protobuf_objects.txt + CONTENT $,\n> + ) + add_custom_command( + TARGET wpimath + PRE_LINK + COMMAND + cmake -E __create_def ${CMAKE_CURRENT_BINARY_DIR}/protobuf_exports.def + ${CMAKE_CURRENT_BINARY_DIR}/protobuf_objects.txt + ) + target_link_options( + wpimath + PRIVATE /DEF:$ + ) +endif() + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) set_target_properties(wpimath PROPERTIES DEBUG_POSTFIX "d") set_property(TARGET wpimath PROPERTY FOLDER "libraries") target_compile_definitions(wpimath PRIVATE WPILIB_EXPORTS SLEIPNIR_EXPORTS) +target_compile_features(protobuf PUBLIC cxx_std_20) target_compile_features(wpimath PUBLIC cxx_std_20) if(MSVC) target_compile_options(wpimath PUBLIC /utf-8 /bigobj) - target_link_options( - wpimath - PRIVATE /DEF:$ - ) + target_compile_options(protobuf PUBLIC /utf-8 /bigobj) endif() wpilib_target_warnings(wpimath) target_link_libraries(wpimath wpiutil) diff --git a/wpimath/src/main/native/cpp/geometry/proto/Ellipse2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Ellipse2dProto.cpp index 4597446a947..e8bd59f70b9 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Ellipse2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Ellipse2dProto.cpp @@ -17,7 +17,7 @@ frc::Ellipse2d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Ellipse2d{ - wpi::UnpackProtobuf(m->center()), + wpi::UnpackProtobuf(m->wpi_center()), units::meter_t{m->xsemiaxis()}, units::meter_t{m->ysemiaxis()}, }; diff --git a/wpimath/src/main/native/cpp/geometry/proto/Pose2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Pose2dProto.cpp index 94da8c5adaa..3e9a2342f41 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Pose2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Pose2dProto.cpp @@ -17,8 +17,8 @@ frc::Pose2d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Pose2d{ - wpi::UnpackProtobuf(m->translation()), - wpi::UnpackProtobuf(m->rotation()), + wpi::UnpackProtobuf(m->wpi_translation()), + wpi::UnpackProtobuf(m->wpi_rotation()), }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Pose3dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Pose3dProto.cpp index 4a0493596e3..763f5146c03 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Pose3dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Pose3dProto.cpp @@ -17,8 +17,8 @@ frc::Pose3d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Pose3d{ - wpi::UnpackProtobuf(m->translation()), - wpi::UnpackProtobuf(m->rotation()), + wpi::UnpackProtobuf(m->wpi_translation()), + wpi::UnpackProtobuf(m->wpi_rotation()), }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Rectangle2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Rectangle2dProto.cpp index d41fca28b4b..ac6e411ba59 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Rectangle2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Rectangle2dProto.cpp @@ -17,7 +17,7 @@ frc::Rectangle2d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Rectangle2d{ - wpi::UnpackProtobuf(m->center()), + wpi::UnpackProtobuf(m->wpi_center()), units::meter_t{m->xwidth()}, units::meter_t{m->ywidth()}, }; diff --git a/wpimath/src/main/native/cpp/geometry/proto/Rotation3dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Rotation3dProto.cpp index 7ce7488280c..10583bfd756 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Rotation3dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Rotation3dProto.cpp @@ -17,7 +17,7 @@ frc::Rotation3d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Rotation3d{ - wpi::UnpackProtobuf(m->q()), + wpi::UnpackProtobuf(m->wpi_q()), }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Transform2dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Transform2dProto.cpp index 742a1a99435..a4a56d72d36 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Transform2dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Transform2dProto.cpp @@ -17,8 +17,8 @@ frc::Transform2d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Transform2d{ - wpi::UnpackProtobuf(m->translation()), - wpi::UnpackProtobuf(m->rotation()), + wpi::UnpackProtobuf(m->wpi_translation()), + wpi::UnpackProtobuf(m->wpi_rotation()), }; } diff --git a/wpimath/src/main/native/cpp/geometry/proto/Transform3dProto.cpp b/wpimath/src/main/native/cpp/geometry/proto/Transform3dProto.cpp index ada2ea9ba8f..c7c4bb2bc64 100644 --- a/wpimath/src/main/native/cpp/geometry/proto/Transform3dProto.cpp +++ b/wpimath/src/main/native/cpp/geometry/proto/Transform3dProto.cpp @@ -17,8 +17,8 @@ frc::Transform3d wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::Transform3d{ - wpi::UnpackProtobuf(m->translation()), - wpi::UnpackProtobuf(m->rotation()), + wpi::UnpackProtobuf(m->wpi_translation()), + wpi::UnpackProtobuf(m->wpi_rotation()), }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveKinematicsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveKinematicsProto.cpp index da389fe3277..3aecee684ba 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveKinematicsProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/MecanumDriveKinematicsProto.cpp @@ -17,10 +17,10 @@ frc::MecanumDriveKinematics wpi::Protobuf::Unpack( const google::protobuf::Message& msg) { auto m = static_cast(&msg); return frc::MecanumDriveKinematics{ - wpi::UnpackProtobuf(m->front_left()), - wpi::UnpackProtobuf(m->front_right()), - wpi::UnpackProtobuf(m->rear_left()), - wpi::UnpackProtobuf(m->rear_right()), + wpi::UnpackProtobuf(m->wpi_front_left()), + wpi::UnpackProtobuf(m->wpi_front_right()), + wpi::UnpackProtobuf(m->wpi_rear_left()), + wpi::UnpackProtobuf(m->wpi_rear_right()), }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp index 45a21ac4788..7c823ad37ee 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModulePositionProto.cpp @@ -18,7 +18,7 @@ frc::SwerveModulePosition wpi::Protobuf::Unpack( auto m = static_cast(&msg); return frc::SwerveModulePosition{ units::meter_t{m->distance()}, - wpi::UnpackProtobuf(m->angle()), + wpi::UnpackProtobuf(m->wpi_angle()), }; } diff --git a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleStateProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleStateProto.cpp index d112ca7aafb..0950ec3ecd6 100644 --- a/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleStateProto.cpp +++ b/wpimath/src/main/native/cpp/kinematics/proto/SwerveModuleStateProto.cpp @@ -18,7 +18,7 @@ frc::SwerveModuleState wpi::Protobuf::Unpack( auto m = static_cast(&msg); return frc::SwerveModuleState{ units::meters_per_second_t{m->speed()}, - wpi::UnpackProtobuf(m->angle()), + wpi::UnpackProtobuf(m->wpi_angle()), }; } diff --git a/wpimath/src/main/native/cpp/trajectory/proto/TrajectoryStateProto.cpp b/wpimath/src/main/native/cpp/trajectory/proto/TrajectoryStateProto.cpp index 9a6fe92f72b..3d927de169c 100644 --- a/wpimath/src/main/native/cpp/trajectory/proto/TrajectoryStateProto.cpp +++ b/wpimath/src/main/native/cpp/trajectory/proto/TrajectoryStateProto.cpp @@ -20,7 +20,7 @@ frc::Trajectory::State wpi::Protobuf::Unpack( units::second_t{m->time()}, units::meters_per_second_t{m->velocity()}, units::meters_per_second_squared_t{m->acceleration()}, - wpi::UnpackProtobuf(m->pose()), + wpi::UnpackProtobuf(m->wpi_pose()), units::curvature_t{m->curvature()}, }; } diff --git a/wpimath/src/main/native/exports.def b/wpimath/src/main/native/exports.def deleted file mode 100644 index c6cd02dd644..00000000000 --- a/wpimath/src/main/native/exports.def +++ /dev/null @@ -1,9 +0,0 @@ -EXPORTS - ??$CreateMaybeMessage@VProtobufSimpleMotorFeedforward@proto@wpi@@$$V@Arena@protobuf@google@@CAPEAVProtobufSimpleMotorFeedforward@proto@wpi@@PEAV012@@Z - ??$CreateMaybeMessage@VProtobufTranslation2d@proto@wpi@@$$V@Arena@protobuf@google@@CAPEAVProtobufTranslation2d@proto@wpi@@PEAV012@@Z - ?Clear@ProtobufTranslation2d@proto@wpi@@UEAAXXZ - ??$CreateMaybeMessage@VProtobufSwerveDriveKinematics@proto@wpi@@$$V@Arena@protobuf@google@@CAPEAVProtobufSwerveDriveKinematics@proto@wpi@@PEAV012@@Z - ??$CreateMaybeMessage@VProtobufMatrix@proto@wpi@@$$V@Arena@protobuf@google@@CAPEAVProtobufMatrix@proto@wpi@@PEAV012@@Z - ??$CreateMaybeMessage@VProtobufVector@proto@wpi@@$$V@Arena@protobuf@google@@CAPEAVProtobufVector@proto@wpi@@PEAV012@@Z - ??$CreateMaybeMessage@VProtobufLinearSystem@proto@wpi@@$$V@Arena@protobuf@google@@CAPEAVProtobufLinearSystem@proto@wpi@@PEAV012@@Z - ?_ProtobufMatrix_default_instance_@proto@wpi@@3UProtobufMatrixDefaultTypeInternal@12@A diff --git a/wpimath/src/main/native/include/frc/system/proto/LinearSystemProto.inc b/wpimath/src/main/native/include/frc/system/proto/LinearSystemProto.inc index f8c0a814b2f..f41d8e91ec9 100644 --- a/wpimath/src/main/native/include/frc/system/proto/LinearSystemProto.inc +++ b/wpimath/src/main/native/include/frc/system/proto/LinearSystemProto.inc @@ -33,10 +33,10 @@ wpi::Protobuf>::Unpack( Outputs)); } return frc::LinearSystem{ - wpi::UnpackProtobuf>(m->a()), - wpi::UnpackProtobuf>(m->b()), - wpi::UnpackProtobuf>(m->c()), - wpi::UnpackProtobuf>(m->d())}; + wpi::UnpackProtobuf>(m->wpi_a()), + wpi::UnpackProtobuf>(m->wpi_b()), + wpi::UnpackProtobuf>(m->wpi_c()), + wpi::UnpackProtobuf>(m->wpi_d())}; } template diff --git a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h index bee3e32b9f1..1cb2421b536 100644 --- a/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h +++ b/wpiutil/src/main/native/thirdparty/protobuf/include/google/protobuf/descriptor.h @@ -976,13 +976,13 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { mutable std::atomic default_generated_instance_; }; - static const CppType kTypeToCppTypeMap[MAX_TYPE + 1]; + static const CppType *GetTypeToCppTypeMap(); - static const char* const kTypeToName[MAX_TYPE + 1]; + static const char* const *GetTypeToName(); - static const char* const kCppTypeToName[MAX_CPPTYPE + 1]; + static const char* const *GetCppTypeToName(); - static const char* const kLabelToName[MAX_LABEL + 1]; + static const char* const *GetLabelToName(); // Must be constructed using DescriptorPool. FieldDescriptor() {} @@ -2392,27 +2392,27 @@ inline int MethodDescriptor::index() const { } inline const char* FieldDescriptor::type_name() const { - return kTypeToName[type()]; + return GetTypeToName()[type()]; } inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { - return kTypeToCppTypeMap[type()]; + return GetTypeToCppTypeMap()[type()]; } inline const char* FieldDescriptor::cpp_type_name() const { - return kCppTypeToName[kTypeToCppTypeMap[type()]]; + return GetCppTypeToName()[GetTypeToCppTypeMap()[type()]]; } inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { - return kTypeToCppTypeMap[type]; + return GetTypeToCppTypeMap()[type]; } inline const char* FieldDescriptor::TypeName(Type type) { - return kTypeToName[type]; + return GetTypeToName()[type]; } inline const char* FieldDescriptor::CppTypeName(CppType cpp_type) { - return kCppTypeToName[cpp_type]; + return GetCppTypeToName()[cpp_type]; } inline bool FieldDescriptor::IsTypePackable(Type field_type) { diff --git a/wpiutil/src/main/native/thirdparty/protobuf/src/descriptor.cpp b/wpiutil/src/main/native/thirdparty/protobuf/src/descriptor.cpp index 5f3427dc724..5be05da4fb1 100644 --- a/wpiutil/src/main/native/thirdparty/protobuf/src/descriptor.cpp +++ b/wpiutil/src/main/native/thirdparty/protobuf/src/descriptor.cpp @@ -791,31 +791,31 @@ class Symbol { const internal::SymbolBase* ptr_; }; -const FieldDescriptor::CppType - FieldDescriptor::kTypeToCppTypeMap[MAX_TYPE + 1] = { - static_cast(0), // 0 is reserved for errors - - CPPTYPE_DOUBLE, // TYPE_DOUBLE - CPPTYPE_FLOAT, // TYPE_FLOAT - CPPTYPE_INT64, // TYPE_INT64 - CPPTYPE_UINT64, // TYPE_UINT64 - CPPTYPE_INT32, // TYPE_INT32 - CPPTYPE_UINT64, // TYPE_FIXED64 - CPPTYPE_UINT32, // TYPE_FIXED32 - CPPTYPE_BOOL, // TYPE_BOOL - CPPTYPE_STRING, // TYPE_STRING - CPPTYPE_MESSAGE, // TYPE_GROUP - CPPTYPE_MESSAGE, // TYPE_MESSAGE - CPPTYPE_STRING, // TYPE_BYTES - CPPTYPE_UINT32, // TYPE_UINT32 - CPPTYPE_ENUM, // TYPE_ENUM - CPPTYPE_INT32, // TYPE_SFIXED32 - CPPTYPE_INT64, // TYPE_SFIXED64 - CPPTYPE_INT32, // TYPE_SINT32 - CPPTYPE_INT64, // TYPE_SINT64 +static const FieldDescriptor::CppType + kTypeToCppTypeMap[FieldDescriptor::MAX_TYPE + 1] = { + static_cast(0), // 0 is reserved for errors + + FieldDescriptor::CPPTYPE_DOUBLE, // TYPE_DOUBLE + FieldDescriptor::CPPTYPE_FLOAT, // TYPE_FLOAT + FieldDescriptor::CPPTYPE_INT64, // TYPE_INT64 + FieldDescriptor::CPPTYPE_UINT64, // TYPE_UINT64 + FieldDescriptor::CPPTYPE_INT32, // TYPE_INT32 + FieldDescriptor::CPPTYPE_UINT64, // TYPE_FIXED64 + FieldDescriptor::CPPTYPE_UINT32, // TYPE_FIXED32 + FieldDescriptor::CPPTYPE_BOOL, // TYPE_BOOL + FieldDescriptor::CPPTYPE_STRING, // TYPE_STRING + FieldDescriptor::CPPTYPE_MESSAGE, // TYPE_GROUP + FieldDescriptor::CPPTYPE_MESSAGE, // TYPE_MESSAGE + FieldDescriptor::CPPTYPE_STRING, // TYPE_BYTES + FieldDescriptor::CPPTYPE_UINT32, // TYPE_UINT32 + FieldDescriptor::CPPTYPE_ENUM, // TYPE_ENUM + FieldDescriptor::CPPTYPE_INT32, // TYPE_SFIXED32 + FieldDescriptor::CPPTYPE_INT64, // TYPE_SFIXED64 + FieldDescriptor::CPPTYPE_INT32, // TYPE_SINT32 + FieldDescriptor::CPPTYPE_INT64, // TYPE_SINT64 }; -const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { +static const char* const kTypeToName[FieldDescriptor::MAX_TYPE + 1] = { "ERROR", // 0 is reserved for errors "double", // TYPE_DOUBLE @@ -838,7 +838,7 @@ const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { "sint64", // TYPE_SINT64 }; -const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { +static const char* const kCppTypeToName[FieldDescriptor::MAX_CPPTYPE + 1] = { "ERROR", // 0 is reserved for errors "int32", // CPPTYPE_INT32 @@ -853,7 +853,7 @@ const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { "message", // CPPTYPE_MESSAGE }; -const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { +static const char* const kLabelToName[FieldDescriptor::MAX_LABEL + 1] = { "ERROR", // 0 is reserved for errors "optional", // LABEL_OPTIONAL @@ -861,6 +861,22 @@ const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { "repeated", // LABEL_REPEATED }; +const FieldDescriptor::CppType *FieldDescriptor::GetTypeToCppTypeMap() { + return kTypeToCppTypeMap; +} + +const char* const *FieldDescriptor::GetTypeToName() { + return kTypeToName; +} + +const char* const *FieldDescriptor::GetCppTypeToName() { + return kCppTypeToName; +} + +const char* const *FieldDescriptor::GetLabelToName() { + return kLabelToName; +} + const char* FileDescriptor::SyntaxName(FileDescriptor::Syntax syntax) { switch (syntax) { case SYNTAX_PROTO2: