mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Don't read protobuf static data across shared library lines directly (#6979)
Reading exported data from shared objects on windows is broken. It requires __declspec(dllimport). However, this is problematic, as we use the same static libraries both from a shared and static context. So we can't just blindly apply dllimport. The linker should have caught this, as data members are exported in a different way. However, due to a bug in native-utils, data member symbols were exposed directly. However, interacting with those data member was completely broken. The only way we can really solve this is to just not use static data members. We're pretty good about this in WPILib itself. However, protobuf is absolutely terrible at this. There are a ton of inline functions that access global data. For the protobuf library itself, we can solve this easily enough. However, for the generated protobuf code, this is much more problematic. The member needed to bypass the global data is private. This means using just the stock protobuf code, this problem is not solvable. But, protobuf generated code has insertion points. Those insertion points let us add our own code into the generated code via a protoc plugin. And it just so happens that an insertion point exists to add extra public methodsto the generated protobuf header. There is also an insertion point to let us add to the cpp file. The methods we need are the getters, for unpacking protobufs. For any protobuf that has a message as a member, we generate a new wpi_x() getter (the existing one is just x(), where x is the field name). We then implement this in the cpp file. A trick we can use is in the cpp file, we can safely call the x() function, as the cpp file is in the same library as the global. Thus we can call that inline method, and not actually need to directly access any internal private state of the protobuf object. TL;DR, all protobuf classes that have messages as fields now have a wpi_x() accessor that must be used instead of x() if you want the code to work on windows. After wpilibsuite/native-utils#212, the bad code will fail to link, rather then just fail at runtime.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -252,3 +252,6 @@ coverage_report/
|
||||
|
||||
# ctest
|
||||
/Testing/
|
||||
|
||||
# protobuf
|
||||
!wpiprotoplugin.jar
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -9,5 +9,5 @@ repositories {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation "edu.wpi.first:native-utils:2025.1.0"
|
||||
implementation "edu.wpi.first:native-utils:2025.2.0"
|
||||
}
|
||||
|
||||
20
protoplugin/CMakeLists.txt
Normal file
20
protoplugin/CMakeLists.txt
Normal file
@@ -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()
|
||||
2
protoplugin/binary/wpiprotoplugin.bat.in
Normal file
2
protoplugin/binary/wpiprotoplugin.bat.in
Normal file
@@ -0,0 +1,2 @@
|
||||
@ECHO OFF
|
||||
"@Java_JAVA_EXECUTABLE@" -jar "@PROTO_JAR@" %*
|
||||
BIN
protoplugin/binary/wpiprotoplugin.jar
Normal file
BIN
protoplugin/binary/wpiprotoplugin.jar
Normal file
Binary file not shown.
2
protoplugin/binary/wpiprotoplugin.sh.in
Executable file
2
protoplugin/binary/wpiprotoplugin.sh.in
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
exec "@Java_JAVA_EXECUTABLE@" -jar "@PROTO_JAR@" "$@"
|
||||
33
protoplugin/build.gradle
Normal file
33
protoplugin/build.gradle
Normal file
@@ -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
|
||||
1
protoplugin/settings.gradle
Normal file
1
protoplugin/settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
76
protoplugin/src/main/java/org/wpilib/ProtoCDllGenerator.java
Normal file
76
protoplugin/src/main/java/org/wpilib/ProtoCDllGenerator.java
Normal file
@@ -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<String, Descriptors.FileDescriptor> 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +-
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +-
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +++---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +-
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +++++++++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 ++++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 ++++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 ++++++++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
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 +++++++++++---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
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 +++++++
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Thad House <thadhouse1@gmail.com>
|
||||
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<CppType>(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<FieldDescriptor::CppType>(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<const Message*> 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) {
|
||||
@@ -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} $<TARGET_OBJECTS:protobuf>)
|
||||
|
||||
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 $<LIST:JOIN,$<TARGET_OBJECTS:protobuf>,\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:$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/protobuf_exports.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:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/exports.def>
|
||||
)
|
||||
target_compile_options(protobuf PUBLIC /utf-8 /bigobj)
|
||||
endif()
|
||||
wpilib_target_warnings(wpimath)
|
||||
target_link_libraries(wpimath wpiutil)
|
||||
|
||||
@@ -17,7 +17,7 @@ frc::Ellipse2d wpi::Protobuf<frc::Ellipse2d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufEllipse2d*>(&msg);
|
||||
return frc::Ellipse2d{
|
||||
wpi::UnpackProtobuf<frc::Pose2d>(m->center()),
|
||||
wpi::UnpackProtobuf<frc::Pose2d>(m->wpi_center()),
|
||||
units::meter_t{m->xsemiaxis()},
|
||||
units::meter_t{m->ysemiaxis()},
|
||||
};
|
||||
|
||||
@@ -17,8 +17,8 @@ frc::Pose2d wpi::Protobuf<frc::Pose2d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufPose2d*>(&msg);
|
||||
return frc::Pose2d{
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->rotation()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->wpi_translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->wpi_rotation()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ frc::Pose3d wpi::Protobuf<frc::Pose3d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufPose3d*>(&msg);
|
||||
return frc::Pose3d{
|
||||
wpi::UnpackProtobuf<frc::Translation3d>(m->translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation3d>(m->rotation()),
|
||||
wpi::UnpackProtobuf<frc::Translation3d>(m->wpi_translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation3d>(m->wpi_rotation()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ frc::Rectangle2d wpi::Protobuf<frc::Rectangle2d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufRectangle2d*>(&msg);
|
||||
return frc::Rectangle2d{
|
||||
wpi::UnpackProtobuf<frc::Pose2d>(m->center()),
|
||||
wpi::UnpackProtobuf<frc::Pose2d>(m->wpi_center()),
|
||||
units::meter_t{m->xwidth()},
|
||||
units::meter_t{m->ywidth()},
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ frc::Rotation3d wpi::Protobuf<frc::Rotation3d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufRotation3d*>(&msg);
|
||||
return frc::Rotation3d{
|
||||
wpi::UnpackProtobuf<frc::Quaternion>(m->q()),
|
||||
wpi::UnpackProtobuf<frc::Quaternion>(m->wpi_q()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ frc::Transform2d wpi::Protobuf<frc::Transform2d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufTransform2d*>(&msg);
|
||||
return frc::Transform2d{
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->rotation()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->wpi_translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->wpi_rotation()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ frc::Transform3d wpi::Protobuf<frc::Transform3d>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufTransform3d*>(&msg);
|
||||
return frc::Transform3d{
|
||||
wpi::UnpackProtobuf<frc::Translation3d>(m->translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation3d>(m->rotation()),
|
||||
wpi::UnpackProtobuf<frc::Translation3d>(m->wpi_translation()),
|
||||
wpi::UnpackProtobuf<frc::Rotation3d>(m->wpi_rotation()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ frc::MecanumDriveKinematics wpi::Protobuf<frc::MecanumDriveKinematics>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufMecanumDriveKinematics*>(&msg);
|
||||
return frc::MecanumDriveKinematics{
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->front_left()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->front_right()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->rear_left()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->rear_right()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->wpi_front_left()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->wpi_front_right()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->wpi_rear_left()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->wpi_rear_right()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ frc::SwerveModulePosition wpi::Protobuf<frc::SwerveModulePosition>::Unpack(
|
||||
auto m = static_cast<const wpi::proto::ProtobufSwerveModulePosition*>(&msg);
|
||||
return frc::SwerveModulePosition{
|
||||
units::meter_t{m->distance()},
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->angle()),
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->wpi_angle()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ frc::SwerveModuleState wpi::Protobuf<frc::SwerveModuleState>::Unpack(
|
||||
auto m = static_cast<const wpi::proto::ProtobufSwerveModuleState*>(&msg);
|
||||
return frc::SwerveModuleState{
|
||||
units::meters_per_second_t{m->speed()},
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->angle()),
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->wpi_angle()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ frc::Trajectory::State wpi::Protobuf<frc::Trajectory::State>::Unpack(
|
||||
units::second_t{m->time()},
|
||||
units::meters_per_second_t{m->velocity()},
|
||||
units::meters_per_second_squared_t{m->acceleration()},
|
||||
wpi::UnpackProtobuf<frc::Pose2d>(m->pose()),
|
||||
wpi::UnpackProtobuf<frc::Pose2d>(m->wpi_pose()),
|
||||
units::curvature_t{m->curvature()},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -33,10 +33,10 @@ wpi::Protobuf<frc::LinearSystem<States, Inputs, Outputs>>::Unpack(
|
||||
Outputs));
|
||||
}
|
||||
return frc::LinearSystem<States, Inputs, Outputs>{
|
||||
wpi::UnpackProtobuf<frc::Matrixd<States, States>>(m->a()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<States, Inputs>>(m->b()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<Outputs, States>>(m->c()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<Outputs, Inputs>>(m->d())};
|
||||
wpi::UnpackProtobuf<frc::Matrixd<States, States>>(m->wpi_a()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<States, Inputs>>(m->wpi_b()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<Outputs, States>>(m->wpi_c()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<Outputs, Inputs>>(m->wpi_d())};
|
||||
}
|
||||
|
||||
template <int States, int Inputs, int Outputs>
|
||||
|
||||
@@ -976,13 +976,13 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
|
||||
mutable std::atomic<const Message*> 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) {
|
||||
|
||||
@@ -791,31 +791,31 @@ class Symbol {
|
||||
const internal::SymbolBase* ptr_;
|
||||
};
|
||||
|
||||
const FieldDescriptor::CppType
|
||||
FieldDescriptor::kTypeToCppTypeMap[MAX_TYPE + 1] = {
|
||||
static_cast<CppType>(0), // 0 is reserved for errors
|
||||
static const FieldDescriptor::CppType
|
||||
kTypeToCppTypeMap[FieldDescriptor::MAX_TYPE + 1] = {
|
||||
static_cast<FieldDescriptor::CppType>(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
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user