ubuntu 重装后 发现项目有一些依赖 用的的系统路径, 遂添加到项目内
This commit is contained in:
parent
7ca282cdb3
commit
4f71b78676
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
project(IM2)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
@ -1,8 +1,8 @@
|
||||
project(imm_mongodb)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MP)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MDB/imm_mongodb)
|
||||
|
||||
link_directories(${CMAKE_SOURCE_DIR}/MDB/imm_mongodb/lib)
|
||||
|
||||
add_library(imm_mongodb
|
||||
@ -11,7 +11,6 @@ add_library(imm_mongodb
|
||||
)
|
||||
|
||||
target_link_libraries(imm_mongodb
|
||||
libmongocxx.so
|
||||
libbsoncxx.so
|
||||
libbson-1.0.so
|
||||
mongocxx
|
||||
bsoncxx
|
||||
)
|
18
MDB/imm_mongodb/bson.h
Normal file
18
MDB/imm_mongodb/bson.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2018-present MongoDB, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Including bson.h is superseded. Use bson/bson.h instead. */
|
||||
#include "bson/bson.h"
|
132
MDB/imm_mongodb/bsoncxx/bson-config.h
Normal file
132
MDB/imm_mongodb/bsoncxx/bson-config.h
Normal file
@ -0,0 +1,132 @@
|
||||
#ifndef BSON_CONFIG_H
|
||||
#define BSON_CONFIG_H
|
||||
|
||||
/*
|
||||
* Define to 1234 for Little Endian, 4321 for Big Endian.
|
||||
*/
|
||||
#define BSON_BYTE_ORDER 1234
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have stdbool.h
|
||||
*/
|
||||
#define BSON_HAVE_STDBOOL_H 1
|
||||
#if BSON_HAVE_STDBOOL_H != 1
|
||||
# undef BSON_HAVE_STDBOOL_H
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 for POSIX-like systems, 2 for Windows.
|
||||
*/
|
||||
#define BSON_OS 1
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if we have access to GCC 32-bit atomic builtins.
|
||||
* While this requires GCC 4.1+ in most cases, it is also architecture
|
||||
* dependent. For example, some PPC or ARM systems may not have it even
|
||||
* if it is a recent GCC version.
|
||||
*/
|
||||
#define BSON_HAVE_ATOMIC_32_ADD_AND_FETCH 1
|
||||
#if BSON_HAVE_ATOMIC_32_ADD_AND_FETCH != 1
|
||||
# undef BSON_HAVE_ATOMIC_32_ADD_AND_FETCH
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Similarly, define to 1 if we have access to GCC 64-bit atomic builtins.
|
||||
*/
|
||||
#define BSON_HAVE_ATOMIC_64_ADD_AND_FETCH 1
|
||||
#if BSON_HAVE_ATOMIC_64_ADD_AND_FETCH != 1
|
||||
# undef BSON_HAVE_ATOMIC_64_ADD_AND_FETCH
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if your system requires {} around PTHREAD_ONCE_INIT.
|
||||
* This is typically just Solaris 8-10.
|
||||
*/
|
||||
#define BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES 0
|
||||
#if BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES != 1
|
||||
# undef BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have clock_gettime() available.
|
||||
*/
|
||||
#define BSON_HAVE_CLOCK_GETTIME 1
|
||||
#if BSON_HAVE_CLOCK_GETTIME != 1
|
||||
# undef BSON_HAVE_CLOCK_GETTIME
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have strnlen available on your platform.
|
||||
*/
|
||||
#define BSON_HAVE_STRNLEN 1
|
||||
#if BSON_HAVE_STRNLEN != 1
|
||||
# undef BSON_HAVE_STRNLEN
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have snprintf available on your platform.
|
||||
*/
|
||||
#define BSON_HAVE_SNPRINTF 1
|
||||
#if BSON_HAVE_SNPRINTF != 1
|
||||
# undef BSON_HAVE_SNPRINTF
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have gmtime_r available on your platform.
|
||||
*/
|
||||
#define BSON_HAVE_GMTIME_R 1
|
||||
#if BSON_HAVE_GMTIME_R != 1
|
||||
# undef BSON_HAVE_GMTIME_R
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have reallocf available on your platform.
|
||||
*/
|
||||
#define BSON_HAVE_REALLOCF 0
|
||||
#if BSON_HAVE_REALLOCF != 1
|
||||
# undef BSON_HAVE_REALLOCF
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have struct timespec available on your platform.
|
||||
*/
|
||||
#define BSON_HAVE_TIMESPEC 1
|
||||
#if BSON_HAVE_TIMESPEC != 1
|
||||
# undef BSON_HAVE_TIMESPEC
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you want extra aligned types in libbson
|
||||
*/
|
||||
#define BSON_EXTRA_ALIGN 1
|
||||
#if BSON_EXTRA_ALIGN != 1
|
||||
# undef BSON_EXTRA_ALIGN
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Define to 1 if you have SYS_gettid syscall
|
||||
*/
|
||||
#define BSON_HAVE_SYSCALL_TID 1
|
||||
#if BSON_HAVE_SYSCALL_TID != 1
|
||||
# undef BSON_HAVE_SYSCALL_TID
|
||||
#endif
|
||||
|
||||
#define BSON_HAVE_RAND_R 1
|
||||
#if BSON_HAVE_RAND_R != 1
|
||||
# undef BSON_HAVE_RAND_R
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* BSON_CONFIG_H */
|
1
MDB/imm_mongodb/bsoncxx/bson-stdint.h
Normal file
1
MDB/imm_mongodb/bsoncxx/bson-stdint.h
Normal file
@ -0,0 +1 @@
|
||||
#include <stdint.h>
|
101
MDB/imm_mongodb/bsoncxx/bson-version.h
Normal file
101
MDB/imm_mongodb/bsoncxx/bson-version.h
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2013 MongoDB, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#if !defined (BSON_INSIDE) && !defined (BSON_COMPILATION)
|
||||
#error "Only <bson.h> can be included directly."
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BSON_VERSION_H
|
||||
#define BSON_VERSION_H
|
||||
|
||||
|
||||
/**
|
||||
* BSON_MAJOR_VERSION:
|
||||
*
|
||||
* BSON major version component (e.g. 1 if %BSON_VERSION is 1.2.3)
|
||||
*/
|
||||
#define BSON_MAJOR_VERSION (1)
|
||||
|
||||
|
||||
/**
|
||||
* BSON_MINOR_VERSION:
|
||||
*
|
||||
* BSON minor version component (e.g. 2 if %BSON_VERSION is 1.2.3)
|
||||
*/
|
||||
#define BSON_MINOR_VERSION (10)
|
||||
|
||||
|
||||
/**
|
||||
* BSON_MICRO_VERSION:
|
||||
*
|
||||
* BSON micro version component (e.g. 3 if %BSON_VERSION is 1.2.3)
|
||||
*/
|
||||
#define BSON_MICRO_VERSION (0)
|
||||
|
||||
|
||||
/**
|
||||
* BSON_PRERELEASE_VERSION:
|
||||
*
|
||||
* BSON prerelease version component (e.g. rc0 if %BSON_VERSION is 1.2.3-rc0)
|
||||
*/
|
||||
#define BSON_PRERELEASE_VERSION (dev)
|
||||
|
||||
/**
|
||||
* BSON_VERSION:
|
||||
*
|
||||
* BSON version.
|
||||
*/
|
||||
#define BSON_VERSION (1.10.0-dev)
|
||||
|
||||
|
||||
/**
|
||||
* BSON_VERSION_S:
|
||||
*
|
||||
* BSON version, encoded as a string, useful for printing and
|
||||
* concatenation.
|
||||
*/
|
||||
#define BSON_VERSION_S "1.10.0-dev"
|
||||
|
||||
|
||||
/**
|
||||
* BSON_VERSION_HEX:
|
||||
*
|
||||
* BSON version, encoded as an hexadecimal number, useful for
|
||||
* integer comparisons.
|
||||
*/
|
||||
#define BSON_VERSION_HEX (BSON_MAJOR_VERSION << 24 | \
|
||||
BSON_MINOR_VERSION << 16 | \
|
||||
BSON_MICRO_VERSION << 8)
|
||||
|
||||
|
||||
/**
|
||||
* BSON_CHECK_VERSION:
|
||||
* @major: required major version
|
||||
* @minor: required minor version
|
||||
* @micro: required micro version
|
||||
*
|
||||
* Compile-time version checking. Evaluates to %TRUE if the version
|
||||
* of BSON is greater than the required one.
|
||||
*/
|
||||
#define BSON_CHECK_VERSION(major,minor,micro) \
|
||||
(BSON_MAJOR_VERSION > (major) || \
|
||||
(BSON_MAJOR_VERSION == (major) && BSON_MINOR_VERSION > (minor)) || \
|
||||
(BSON_MAJOR_VERSION == (major) && BSON_MINOR_VERSION == (minor) && \
|
||||
BSON_MICRO_VERSION >= (micro)))
|
||||
|
||||
#endif /* BSON_VERSION_H */
|
23
MDB/imm_mongodb/bsoncxx/config.hpp
Normal file
23
MDB/imm_mongodb/bsoncxx/config.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2014 MongoDB Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/* #undef BSONCXX_POLY_USE_STD_EXPERIMENTAL */
|
||||
#define BSONCXX_POLY_USE_MNMLSTC
|
||||
/* #undef BSONCXX_POLY_USE_SYSTEM_MNMLSTC */
|
||||
/* #undef BSONCXX_POLY_USE_BOOST */
|
||||
/* #undef BSONCXX_POLY_USE_STD */
|
||||
|
||||
#define BSONCXX_INLINE_NAMESPACE_BEGIN inline namespace v_noabi {
|
||||
|
||||
#define BSONCXX_INLINE_NAMESPACE_END } // namespace v_noabi
|
42
MDB/imm_mongodb/bsoncxx/export.hpp
Normal file
42
MDB/imm_mongodb/bsoncxx/export.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#ifndef BSONCXX_API_H
|
||||
#define BSONCXX_API_H
|
||||
|
||||
#ifdef BSONCXX_STATIC
|
||||
# define BSONCXX_API
|
||||
# define BSONCXX_PRIVATE
|
||||
#else
|
||||
# ifndef BSONCXX_API
|
||||
# ifdef BSONCXX_EXPORT
|
||||
/* We are building this library */
|
||||
# define BSONCXX_API __attribute__((visibility("default")))
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define BSONCXX_API __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef BSONCXX_PRIVATE
|
||||
# define BSONCXX_PRIVATE __attribute__((visibility("hidden")))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef BSONCXX_DEPRECATED
|
||||
# define BSONCXX_DEPRECATED __attribute__ ((__deprecated__))
|
||||
#endif
|
||||
|
||||
#ifndef BSONCXX_DEPRECATED_EXPORT
|
||||
# define BSONCXX_DEPRECATED_EXPORT BSONCXX_API BSONCXX_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef BSONCXX_DEPRECATED_NO_EXPORT
|
||||
# define BSONCXX_DEPRECATED_NO_EXPORT BSONCXX_PRIVATE BSONCXX_DEPRECATED
|
||||
#endif
|
||||
|
||||
#if 0 /* DEFINE_NO_DEPRECATED */
|
||||
# ifndef BSONCXX_NO_DEPRECATED
|
||||
# define BSONCXX_NO_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* BSONCXX_API_H */
|
18
MDB/imm_mongodb/bsoncxx/version.hpp
Normal file
18
MDB/imm_mongodb/bsoncxx/version.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2014 MongoDB Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define BSONCXX_VERSION_MAJOR 3
|
||||
#define BSONCXX_VERSION_MINOR 7
|
||||
#define BSONCXX_VERSION_PATCH 1
|
||||
#define BSONCXX_VERSION_EXTRA
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libbsoncxx.so._noabi
Normal file
BIN
MDB/imm_mongodb/lib/libbsoncxx.so._noabi
Normal file
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libmongoc-1.0.so
Normal file
BIN
MDB/imm_mongodb/lib/libmongoc-1.0.so
Normal file
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libmongoc-1.0.so.0
Normal file
BIN
MDB/imm_mongodb/lib/libmongoc-1.0.so.0
Normal file
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libmongoc-1.0.so.0.0.0
Normal file
BIN
MDB/imm_mongodb/lib/libmongoc-1.0.so.0.0.0
Normal file
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libmongocxx.so
Executable file → Normal file
BIN
MDB/imm_mongodb/lib/libmongocxx.so
Executable file → Normal file
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libmongocxx.so.3.7.1
Executable file → Normal file
BIN
MDB/imm_mongodb/lib/libmongocxx.so.3.7.1
Executable file → Normal file
Binary file not shown.
BIN
MDB/imm_mongodb/lib/libmongocxx.so._noabi
Normal file
BIN
MDB/imm_mongodb/lib/libmongocxx.so._noabi
Normal file
Binary file not shown.
17
MDB/imm_mongodb/mongocxx/config.hpp
Normal file
17
MDB/imm_mongodb/mongocxx/config.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2014 MongoDB Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define MONGOCXX_INLINE_NAMESPACE_BEGIN inline namespace v_noabi {
|
||||
|
||||
#define MONGOCXX_INLINE_NAMESPACE_END } // namespace v_noabi
|
42
MDB/imm_mongodb/mongocxx/export.hpp
Normal file
42
MDB/imm_mongodb/mongocxx/export.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#ifndef MONGOCXX_API_H
|
||||
#define MONGOCXX_API_H
|
||||
|
||||
#ifdef MONGOCXX_STATIC
|
||||
# define MONGOCXX_API
|
||||
# define MONGOCXX_PRIVATE
|
||||
#else
|
||||
# ifndef MONGOCXX_API
|
||||
# ifdef MONGOCXX_EXPORTS
|
||||
/* We are building this library */
|
||||
# define MONGOCXX_API __attribute__((visibility("default")))
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define MONGOCXX_API __attribute__((visibility("default")))
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef MONGOCXX_PRIVATE
|
||||
# define MONGOCXX_PRIVATE __attribute__((visibility("hidden")))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef MONGOCXX_DEPRECATED
|
||||
# define MONGOCXX_DEPRECATED __attribute__ ((__deprecated__))
|
||||
#endif
|
||||
|
||||
#ifndef MONGOCXX_DEPRECATED_EXPORT
|
||||
# define MONGOCXX_DEPRECATED_EXPORT MONGOCXX_API MONGOCXX_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef MONGOCXX_DEPRECATED_NO_EXPORT
|
||||
# define MONGOCXX_DEPRECATED_NO_EXPORT MONGOCXX_PRIVATE MONGOCXX_DEPRECATED
|
||||
#endif
|
||||
|
||||
#if 0 /* DEFINE_NO_DEPRECATED */
|
||||
# ifndef MONGOCXX_NO_DEPRECATED
|
||||
# define MONGOCXX_NO_DEPRECATED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* MONGOCXX_API_H */
|
19
MDB/imm_mongodb/mongocxx/version.hpp
Normal file
19
MDB/imm_mongodb/mongocxx/version.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2014 MongoDB Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define MONGOCXX_VERSION_STRING "3.7.1"
|
||||
#define MONGOCXX_VERSION_MAJOR 3
|
||||
#define MONGOCXX_VERSION_MINOR 7
|
||||
#define MONGOCXX_VERSION_PATCH 1
|
||||
#define MONGOCXX_VERSION_EXTRA
|
@ -10,7 +10,7 @@
|
||||
#include "mongocxx/client.hpp"
|
||||
#include "bsoncxx/json.hpp"
|
||||
#include "MongoPool.h"
|
||||
#include <bsoncxx/builder/stream/document.hpp>
|
||||
#include "bsoncxx/builder/stream/document.hpp"
|
||||
|
||||
using bsoncxx::builder::basic::kvp;
|
||||
using bsoncxx::builder::basic::make_array;
|
||||
@ -21,58 +21,55 @@ int main() {
|
||||
mongocxx::uri uri("mongodb://user_session:Aa316216@124.221.152.192:27017/?authSource=im_session");
|
||||
|
||||
// 单链接
|
||||
// mongocxx::client client(uri);
|
||||
// 使用链接池
|
||||
mongocxx::pool pool{uri};
|
||||
// 自封转的一层连接池
|
||||
// MongoPool* pool = new MongoPool();
|
||||
auto client = pool.acquire();
|
||||
|
||||
// 选中库
|
||||
// auto db = client["im_session"];
|
||||
auto db = client->database("im_session");
|
||||
|
||||
auto doc_view = MsgTemplate::session_msg(mp::MP_SUB_TYPE::MP_IM_TEXT, mp::MP_SUB_TYPE::MP_FRIEND,
|
||||
0, time(nullptr), 783556037, "测试消息");
|
||||
|
||||
// 选中表
|
||||
auto collection = db.collection("chat");
|
||||
// 插入视图
|
||||
//
|
||||
// auto doc_view = MsgTemplate::session_msg(mp::MP_SUB_TYPE::MP_IM_TEXT, mp::MP_SUB_TYPE::MP_FRIEND,
|
||||
// 0, time(nullptr), 783556037, "测试消息");
|
||||
//
|
||||
// // 选中表
|
||||
// auto collection = db.collection("chat");
|
||||
// // 插入视图
|
||||
// auto wr_ret = collection.insert_one(doc_view);
|
||||
|
||||
//
|
||||
auto cursor_all = collection.find({});
|
||||
for (auto doc: cursor_all) {
|
||||
std::cout << to_string(doc["_id"].type()) << " " << doc["_id"].get_oid().value.to_string() << std::endl;
|
||||
std::cout << doc["count"].get_int32().value << std::endl;
|
||||
|
||||
auto temp_view = doc["info"].get_document().value;
|
||||
std::cout << temp_view.find("x")->get_int32() << std::endl;
|
||||
std::cout << temp_view.find("y")->get_int32() << std::endl;
|
||||
|
||||
std::cout << doc["name"].get_string().value << std::endl;
|
||||
std::cout << doc["type"].get_string().value << std::endl;
|
||||
|
||||
auto version_arr = doc["versions"].get_array().value;
|
||||
for (auto mem = version_arr.begin(); mem != version_arr.end(); ++mem) {
|
||||
std::cout << mem->get_string().value << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "collection " << collection.name()
|
||||
<< " contains these documents:" << std::endl;
|
||||
for (auto doc : cursor_all) {
|
||||
std::cout << bsoncxx::to_json(doc, bsoncxx::ExtendedJsonMode::k_relaxed) << std::endl;
|
||||
}
|
||||
|
||||
auto update_one_result =
|
||||
collection.update_one(make_document(kvp("name", "MongoDB")),
|
||||
make_document(kvp("$set", make_document(kvp("name", "update name")))));
|
||||
|
||||
|
||||
auto ret_filter = collection.find_one(make_document(kvp("count", 1)));
|
||||
if (ret_filter) {
|
||||
std::cout << ret_filter->find("_id")->get_oid().value.to_string() << std::endl;
|
||||
}
|
||||
//
|
||||
// //
|
||||
// auto cursor_all = collection.find({});
|
||||
// for (auto doc: cursor_all) {
|
||||
// std::cout << to_string(doc["_id"].type()) << " " << doc["_id"].get_oid().value.to_string() << std::endl;
|
||||
// std::cout << doc["count"].get_int32().value << std::endl;
|
||||
//
|
||||
// auto temp_view = doc["info"].get_document().value;
|
||||
// std::cout << temp_view.find("x")->get_int32() << std::endl;
|
||||
// std::cout << temp_view.find("y")->get_int32() << std::endl;
|
||||
//
|
||||
// std::cout << doc["name"].get_string().value << std::endl;
|
||||
// std::cout << doc["type"].get_string().value << std::endl;
|
||||
//
|
||||
// auto version_arr = doc["versions"].get_array().value;
|
||||
// for (auto mem = version_arr.begin(); mem != version_arr.end(); ++mem) {
|
||||
// std::cout << mem->get_string().value << std::endl;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::cout << "collection " << collection.name()
|
||||
// << " contains these documents:" << std::endl;
|
||||
// for (auto doc : cursor_all) {
|
||||
// std::cout << bsoncxx::to_json(doc, bsoncxx::ExtendedJsonMode::k_relaxed) << std::endl;
|
||||
// }
|
||||
//
|
||||
// auto update_one_result =
|
||||
// collection.update_one(make_document(kvp("name", "MongoDB")),
|
||||
// make_document(kvp("$set", make_document(kvp("name", "update name")))));
|
||||
//
|
||||
//
|
||||
// auto ret_filter = collection.find_one(make_document(kvp("count", 1)));
|
||||
// if (ret_filter) {
|
||||
// std::cout << ret_filter->find("_id")->get_oid().value.to_string() << std::endl;
|
||||
// }
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
project(imm_mysqldb)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mp)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/libevent)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mysql++)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mysql++/mysql)
|
||||
|
@ -1,7 +1,8 @@
|
||||
project(MP)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mp)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mp/proto)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
link_directories(${CMAKE_SOURCE_DIR}/lib/proto)
|
||||
|
||||
aux_source_directory(${CMAKE_SOURCE_DIR}/MP MP_DIR)
|
||||
aux_source_directory(${CMAKE_SOURCE_DIR}/MP/proto PROTO_DIR)
|
||||
@ -13,4 +14,5 @@ add_library(MP
|
||||
|
||||
target_link_libraries(MP
|
||||
protobuf
|
||||
pthread
|
||||
)
|
||||
|
@ -33,7 +33,7 @@ const char descriptor_table_protodef_mp_2emp_2eproto[] PROTOBUF_SECTION_VARIABLE
|
||||
"\022\024\n\020MP_RESPONSE_CODE\020\027\022\027\n\023MP_RESPONSE_FR"
|
||||
"IENDS\020\030\022\026\n\022MP_RESPONSE_GROUPS\020\031\022\021\n\014MP_IM"
|
||||
"_NOTICE\020\310\001\022\023\n\016MP_IM_PUSH_MSG\020\311\001\022\023\n\016MP_IM"
|
||||
"_PULL_MSG\020\312\001\022\016\n\tMP_IM_MSG\020\313\001*\353\006\n\013MP_SUB_"
|
||||
"_PULL_MSG\020\312\001\022\016\n\tMP_IM_MSG\020\313\001*\325\007\n\013MP_SUB_"
|
||||
"TYPE\022\022\n\016MP_LOGIN_EMAIL\020\000\022\022\n\016MP_LOGIN_PHO"
|
||||
"NE\020\001\022\024\n\020MP_LOGIN_ACCOUNT\020\002\022\025\n\021MP_REGISTE"
|
||||
"R_EMAIL\020\003\022\025\n\021MP_REGISTER_PHONE\020\004\022\024\n\020MP_L"
|
||||
@ -42,20 +42,23 @@ const char descriptor_table_protodef_mp_2emp_2eproto[] PROTOBUF_SECTION_VARIABLE
|
||||
"\022\021\n\rMP_CODE_EMAIL\020\017\022\021\n\rMP_CODE_PHONE\020\020\022\023"
|
||||
"\n\017MP_CODE_SUCCESS\020\021\022\020\n\014MP_CODE_FAIL\020\034\022\024\n"
|
||||
"\020MP_ADD_FRIENDS_0\0203\022\024\n\020MP_ADD_FRIENDS_1\020"
|
||||
"4\022\024\n\020MP_ADD_FRIENDS_2\0205\022\032\n\026MP_ADD_FRIEND"
|
||||
"S_ACCOUNT\0206\022\030\n\024MP_ADD_FRIENDS_EMAIL\0207\022\030\n"
|
||||
"\024MP_ADD_FRIENDS_PHONE\0208\022\025\n\021MP_ADD_BLACK_"
|
||||
"LIST\020;\022\025\n\021MP_ADD_WHITE_LIST\020<\022\024\n\020MP_REMO"
|
||||
"VE_FRIEND\020=\022\022\n\016MP_GET_FRIENDS\020>\022\022\n\016MP_AD"
|
||||
"D_GROUP_0\020\?\022\022\n\016MP_ADD_GROUP_1\020@\022\022\n\016MP_AD"
|
||||
"D_GROUP_2\020A\022\020\n\014MP_ADD_GROUP\020B\022\023\n\017MP_REMO"
|
||||
"VE_GROUP\020C\022\021\n\rMP_GET_GROUPS\020D\022\022\n\016MP_ADD_"
|
||||
"SUCCESS\020E\022\025\n\021MP_REMOVE_SUCCESS\020F\022\022\n\016MP_G"
|
||||
"ET_SUCCESS\020G\022\017\n\013MP_ADD_FAIL\020H\022\022\n\016MP_REMO"
|
||||
"VE_FAIL\020I\022\017\n\013MP_GET_FAIL\020J\022\020\n\014MP_ADD_CHE"
|
||||
"CK\020P\022\017\n\nMP_IM_TEXT\020\310\001\022\020\n\013MP_IM_PHOTO\020\311\001\022"
|
||||
"\020\n\013MP_IM_AUDIO\020\312\001\022\020\n\013MP_IM_VIDEO\020\313\001\022\016\n\tM"
|
||||
"P_FRIEND\020\254\002\022\r\n\010MP_GROUP\020\255\002b\006proto3"
|
||||
"4\022\024\n\020MP_ADD_FRIENDS_2\0205\022\035\n\031MP_SEARCH_FRI"
|
||||
"ENDS_ACCOUNT\0206\022\036\n\032MP_SEARCH_FRIENDS_USER"
|
||||
"NAME\0207\022\032\n\026MP_ADD_FRIENDS_ACCOUNT\0208\022\030\n\024MP"
|
||||
"_ADD_FRIENDS_EMAIL\0209\022\030\n\024MP_ADD_FRIENDS_P"
|
||||
"HONE\020:\022\025\n\021MP_ADD_BLACK_LIST\020;\022\025\n\021MP_ADD_"
|
||||
"WHITE_LIST\020<\022\024\n\020MP_REMOVE_FRIEND\020=\022\022\n\016MP"
|
||||
"_GET_FRIENDS\020>\022\022\n\016MP_ADD_GROUP_0\020\?\022\022\n\016MP"
|
||||
"_ADD_GROUP_1\020@\022\022\n\016MP_ADD_GROUP_2\020A\022\020\n\014MP"
|
||||
"_ADD_GROUP\020B\022\023\n\017MP_REMOVE_GROUP\020C\022\021\n\rMP_"
|
||||
"GET_GROUPS\020D\022\025\n\021MP_SEARCH_SUCCESS\020E\022\022\n\016M"
|
||||
"P_ADD_SUCCESS\020F\022\025\n\021MP_REMOVE_SUCCESS\020G\022\022"
|
||||
"\n\016MP_GET_SUCCESS\020H\022\017\n\013MP_ADD_FAIL\020I\022\022\n\016M"
|
||||
"P_REMOVE_FAIL\020J\022\017\n\013MP_GET_FAIL\020K\022\022\n\016MP_S"
|
||||
"EARCH_FAIL\020L\022\020\n\014MP_ADD_CHECK\020P\022\017\n\nMP_IM_"
|
||||
"TEXT\020\310\001\022\020\n\013MP_IM_PHOTO\020\311\001\022\020\n\013MP_IM_AUDIO"
|
||||
"\020\312\001\022\020\n\013MP_IM_VIDEO\020\313\001\022\016\n\tMP_FRIEND\020\254\002\022\r\n"
|
||||
"\010MP_GROUP\020\255\002b\006proto3"
|
||||
;
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_mp_2emp_2eproto_deps[1] = {
|
||||
};
|
||||
@ -63,7 +66,7 @@ static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_mp_
|
||||
};
|
||||
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_mp_2emp_2eproto_once;
|
||||
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_mp_2emp_2eproto = {
|
||||
false, false, descriptor_table_protodef_mp_2emp_2eproto, "mp.mp.proto", 1274,
|
||||
false, false, descriptor_table_protodef_mp_2emp_2eproto, "mp.mp.proto", 1380,
|
||||
&descriptor_table_mp_2emp_2eproto_once, descriptor_table_mp_2emp_2eproto_sccs, descriptor_table_mp_2emp_2eproto_deps, 0, 0,
|
||||
schemas, file_default_instances, TableStruct_mp_2emp_2eproto::offsets,
|
||||
file_level_metadata_mp_2emp_2eproto, 0, file_level_enum_descriptors_mp_2emp_2eproto, file_level_service_descriptors_mp_2emp_2eproto,
|
||||
@ -125,6 +128,8 @@ bool MP_SUB_TYPE_IsValid(int value) {
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 59:
|
||||
case 60:
|
||||
case 61:
|
||||
@ -141,6 +146,8 @@ bool MP_SUB_TYPE_IsValid(int value) {
|
||||
case 72:
|
||||
case 73:
|
||||
case 74:
|
||||
case 75:
|
||||
case 76:
|
||||
case 80:
|
||||
case 200:
|
||||
case 201:
|
||||
|
@ -113,9 +113,11 @@ enum MP_SUB_TYPE : int {
|
||||
MP_ADD_FRIENDS_0 = 51,
|
||||
MP_ADD_FRIENDS_1 = 52,
|
||||
MP_ADD_FRIENDS_2 = 53,
|
||||
MP_ADD_FRIENDS_ACCOUNT = 54,
|
||||
MP_ADD_FRIENDS_EMAIL = 55,
|
||||
MP_ADD_FRIENDS_PHONE = 56,
|
||||
MP_SEARCH_FRIENDS_ACCOUNT = 54,
|
||||
MP_SEARCH_FRIENDS_USERNAME = 55,
|
||||
MP_ADD_FRIENDS_ACCOUNT = 56,
|
||||
MP_ADD_FRIENDS_EMAIL = 57,
|
||||
MP_ADD_FRIENDS_PHONE = 58,
|
||||
MP_ADD_BLACK_LIST = 59,
|
||||
MP_ADD_WHITE_LIST = 60,
|
||||
MP_REMOVE_FRIEND = 61,
|
||||
@ -126,12 +128,14 @@ enum MP_SUB_TYPE : int {
|
||||
MP_ADD_GROUP = 66,
|
||||
MP_REMOVE_GROUP = 67,
|
||||
MP_GET_GROUPS = 68,
|
||||
MP_ADD_SUCCESS = 69,
|
||||
MP_REMOVE_SUCCESS = 70,
|
||||
MP_GET_SUCCESS = 71,
|
||||
MP_ADD_FAIL = 72,
|
||||
MP_REMOVE_FAIL = 73,
|
||||
MP_GET_FAIL = 74,
|
||||
MP_SEARCH_SUCCESS = 69,
|
||||
MP_ADD_SUCCESS = 70,
|
||||
MP_REMOVE_SUCCESS = 71,
|
||||
MP_GET_SUCCESS = 72,
|
||||
MP_ADD_FAIL = 73,
|
||||
MP_REMOVE_FAIL = 74,
|
||||
MP_GET_FAIL = 75,
|
||||
MP_SEARCH_FAIL = 76,
|
||||
MP_ADD_CHECK = 80,
|
||||
MP_IM_TEXT = 200,
|
||||
MP_IM_PHOTO = 201,
|
||||
|
@ -16,7 +16,7 @@ enum MP_TYPE {
|
||||
MP_RESPONSE_LOGOUT = 21; // 注销
|
||||
MP_RESPONSE_REGISTER = 22; // 注册
|
||||
MP_RESPONSE_CODE = 23; // 请求验证码
|
||||
MP_RESPONSE_FRIENDS = 24; // 添加相关操作
|
||||
MP_RESPONSE_FRIENDS = 24; // 好友相关操作
|
||||
MP_RESPONSE_GROUPS = 25; // 群相关操作
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ enum MP_TYPE {
|
||||
MP_IM_NOTICE = 200; // 消息推送通知
|
||||
MP_IM_PUSH_MSG = 201; // 推消息 ---> 推至储存库/同步库
|
||||
MP_IM_PULL_MSG = 202; // 拉消息 ---> 同步库/储存库拉取
|
||||
MP_IM_MSG = 203; // 消息包本体 包含数据
|
||||
MP_IM_MSG = 203; // 消息包本体 包含数据 阅完即焚
|
||||
}
|
||||
|
||||
enum MP_SUB_TYPE {
|
||||
@ -55,16 +55,18 @@ enum MP_SUB_TYPE {
|
||||
|
||||
|
||||
/// 添加用户/群组 ***********************************************************************************///
|
||||
MP_ADD_FRIENDS_0 = 51; // 添加权限 0 直接添加
|
||||
MP_ADD_FRIENDS_1 = 52; // 添加权限 1 回答问题
|
||||
MP_ADD_FRIENDS_2 = 53; // 添加权限 2 账户审核
|
||||
MP_ADD_FRIENDS_ACCOUNT = 54; // 按账户添加
|
||||
MP_ADD_FRIENDS_EMAIL = 55; // 按邮箱添加
|
||||
MP_ADD_FRIENDS_PHONE = 56; // 按手机添加
|
||||
MP_ADD_BLACK_LIST = 59; // 添加黑名单
|
||||
MP_ADD_WHITE_LIST = 60; // 添加白名单
|
||||
MP_REMOVE_FRIEND = 61; // 删除好友
|
||||
MP_GET_FRIENDS = 62; // 取账户好友列表
|
||||
MP_ADD_FRIENDS_0 = 51; // 添加权限 0 直接添加
|
||||
MP_ADD_FRIENDS_1 = 52; // 添加权限 1 回答问题
|
||||
MP_ADD_FRIENDS_2 = 53; // 添加权限 2 账户审核
|
||||
MP_SEARCH_FRIENDS_ACCOUNT = 54; // 按账户搜索好友
|
||||
MP_SEARCH_FRIENDS_USERNAME = 55; // 按用户名搜索好友
|
||||
MP_ADD_FRIENDS_ACCOUNT = 56; // 按账户添加
|
||||
MP_ADD_FRIENDS_EMAIL = 57; // 按邮箱添加
|
||||
MP_ADD_FRIENDS_PHONE = 58; // 按手机添加
|
||||
MP_ADD_BLACK_LIST = 59; // 添加黑名单
|
||||
MP_ADD_WHITE_LIST = 60; // 添加白名单
|
||||
MP_REMOVE_FRIEND = 61; // 删除好友
|
||||
MP_GET_FRIENDS = 62; // 取账户好友列表
|
||||
|
||||
MP_ADD_GROUP_0 = 63; // 添加权限 0 直接添加
|
||||
MP_ADD_GROUP_1 = 64; // 添加权限 1 回答问题
|
||||
@ -73,12 +75,14 @@ enum MP_SUB_TYPE {
|
||||
MP_REMOVE_GROUP = 67; // 删除群组
|
||||
MP_GET_GROUPS = 68; // 取账户群组列表
|
||||
|
||||
MP_ADD_SUCCESS = 69; // 添加成功
|
||||
MP_REMOVE_SUCCESS = 70; // 删除成功
|
||||
MP_GET_SUCCESS = 71; // 获取成功
|
||||
MP_ADD_FAIL = 72; // 添加失败
|
||||
MP_REMOVE_FAIL = 73; // 删除失败
|
||||
MP_GET_FAIL = 74; // 获取失败
|
||||
MP_SEARCH_SUCCESS = 69; // 搜索成功
|
||||
MP_ADD_SUCCESS = 70; // 添加成功
|
||||
MP_REMOVE_SUCCESS = 71; // 删除成功
|
||||
MP_GET_SUCCESS = 72; // 获取成功
|
||||
MP_ADD_FAIL = 73; // 添加失败
|
||||
MP_REMOVE_FAIL = 74; // 删除失败
|
||||
MP_GET_FAIL = 75; // 获取失败
|
||||
MP_SEARCH_FAIL = 76; // 搜索失败
|
||||
|
||||
MP_ADD_CHECK = 80; // 需要回答问题的好友/群组 验证问题
|
||||
|
||||
|
@ -8,11 +8,10 @@ aux_source_directory(smtp DIR_EMAIL)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/libevent)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/ini)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/cpp_email)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/rapidjson)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mysql++)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/mysql++/mysql)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/smtp)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/include/tbb)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MDB/imm_mysqldb)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/MP)
|
||||
@ -42,6 +41,7 @@ target_link_libraries(MS
|
||||
event
|
||||
tbb
|
||||
imm_mysqldb
|
||||
imm_mongodb
|
||||
MP
|
||||
curl
|
||||
)
|
@ -15,23 +15,32 @@ void agreement_request::set (std::shared_ptr<mp::mph> &mph, std::shared_ptr<mp::
|
||||
m_addr = addr;
|
||||
}
|
||||
|
||||
void agreement_request::set(std::shared_ptr<mp::mph> &mph, std::shared_ptr<mp::im::data> &data, bufferevent *bev,
|
||||
sockaddr_in *addr) {
|
||||
m_mph = mph;
|
||||
m_data = data;
|
||||
m_bev = bev;
|
||||
m_addr = addr;
|
||||
|
||||
}
|
||||
|
||||
agreement_response::agreement_response() : agreement() {}
|
||||
agreement_response::~agreement_response() {}
|
||||
|
||||
|
||||
void agreement_response::set(mp::sri* sri, bufferevent* bev) {
|
||||
auto resp = std::make_shared<mp::response>(mp::response());
|
||||
|
||||
m_sri = resp->sri();
|
||||
m_sri.set_subcommand(sri->subcommand());
|
||||
m_sri.set_account(sri->account());
|
||||
m_sri.set_username(sri->username());
|
||||
m_sri.set_msg(sri->msg());
|
||||
m_sri.set_token(sri->token());
|
||||
m_sri.set_data(sri->data());
|
||||
m_sri.set_email(sri->email());
|
||||
m_sri.set_phone(sri->phone());
|
||||
|
||||
// auto resp = std::make_shared<mp::response>(mp::response());
|
||||
//
|
||||
// m_sri = resp->sri();
|
||||
// m_sri.set_subcommand(sri->subcommand());
|
||||
// m_sri.set_account(sri->account());
|
||||
// m_sri.set_username(sri->username());
|
||||
// m_sri.set_msg(sri->msg());
|
||||
// m_sri.set_token(sri->token());
|
||||
// m_sri.set_data(sri->data());
|
||||
// m_sri.set_email(sri->email());
|
||||
// m_sri.set_phone(sri->phone());
|
||||
m_sri = sri;
|
||||
m_bev = bev;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "proto/mp.response.pb.h"
|
||||
#include "proto/mp.request.pb.h"
|
||||
#include "event2/bufferevent.h"
|
||||
#include "proto/mp.im.pb.h"
|
||||
|
||||
class agreement {
|
||||
public:
|
||||
@ -29,12 +30,20 @@ public:
|
||||
|
||||
public:
|
||||
void set (std::shared_ptr<mp::mph> &mph, std::shared_ptr<mp::request>& request, bufferevent* bev, sockaddr_in* addr);
|
||||
void set (std::shared_ptr<mp::mph> &mph, std::shared_ptr<mp::im::data>& data, bufferevent* bev, sockaddr_in* addr);
|
||||
|
||||
public:
|
||||
// 包头
|
||||
std::shared_ptr<mp::mph> m_mph;
|
||||
// im 包体 data
|
||||
std::shared_ptr<mp::im::data> m_data;
|
||||
// *********** 逻辑包体
|
||||
mp::body m_body;
|
||||
mp::cqi m_cqi;
|
||||
// *********** 逻辑包体 end
|
||||
// 维护此链接的描述符号 fd
|
||||
bufferevent* m_bev;
|
||||
// 请求来源地址
|
||||
sockaddr_in* m_addr;
|
||||
};
|
||||
|
||||
@ -47,8 +56,11 @@ public:
|
||||
public:
|
||||
void set (mp::sri* sri, bufferevent* bev);
|
||||
public:
|
||||
std::shared_ptr<mp::mph> m_mph;
|
||||
mp::sri m_sri;
|
||||
// im 包体 推送包
|
||||
std::shared_ptr<mp::im::notice> m_notice;
|
||||
// 返回 响应包体 内容
|
||||
mp::sri* m_sri;
|
||||
// 维护此链接的描述符号 fd
|
||||
bufferevent* m_bev;
|
||||
};
|
||||
|
||||
|
@ -14,19 +14,28 @@ class analysis {
|
||||
public:
|
||||
analysis(std::shared_ptr<mp::mph>& mph, std::shared_ptr<mp::request>& request) : m_mph(mph), m_request(request) {
|
||||
|
||||
}
|
||||
analysis(std::shared_ptr<mp::mph>& mph, std::shared_ptr<mp::im::data>& data) : m_mph(mph), m_data(data) {
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<agreement_request> operator () (bufferevent* bev, sockaddr_in* addr) {
|
||||
// agreement_request
|
||||
auto agreementRequest = std::make_shared<agreement_request>(agreement_request());
|
||||
|
||||
agreementRequest->set(m_mph, m_request, bev, addr);
|
||||
// 判断是im数据包 还是 操作逻辑包
|
||||
if (m_mph->mp_type() <= 200) {
|
||||
agreementRequest->set(m_mph, m_request, bev, addr);
|
||||
} else {
|
||||
agreementRequest->set(m_mph, m_data, bev, addr);
|
||||
}
|
||||
|
||||
return agreementRequest;
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<mp::mph> m_mph;
|
||||
std::shared_ptr<mp::request> m_request;
|
||||
std::shared_ptr<mp::im::data> m_data;
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,11 +21,11 @@ void handler::resp(const std::shared_ptr<agreement_request>& request,
|
||||
// response->m_sri.msg(), response->m_sri.token());
|
||||
|
||||
auto resp = new Response((mp::MP_TYPE) (request->m_mph->mp_type() + 20),
|
||||
response->m_sri.subcommand(),
|
||||
response->m_sri.account(), response->m_sri.username(),
|
||||
response->m_sri.email(), response->m_sri.phone(),
|
||||
response->m_sri.msg(), response->m_sri.token(),
|
||||
response->m_sri.data());
|
||||
response->m_sri->subcommand(),
|
||||
response->m_sri->account(), response->m_sri->username(),
|
||||
response->m_sri->email(), response->m_sri->phone(),
|
||||
response->m_sri->msg(), response->m_sri->token(),
|
||||
response->m_sri->data());
|
||||
|
||||
auto ret = resp->packet();
|
||||
|
||||
|
@ -29,6 +29,11 @@ mapping::mapping() {
|
||||
auto improve = new UserFriendsController();
|
||||
map.insert({mp::MP_TYPE::MP_REQUEST_FRIENDS, improve});
|
||||
map.insert({mp::MP_TYPE::MP_REQUEST_GROUPS, improve});
|
||||
|
||||
///im controller
|
||||
auto imController = new IMController();
|
||||
map.insert({mp::MP_TYPE::MP_IM_MSG, imController});
|
||||
map.insert({mp::MP_TYPE::MP_IM_PUSH_MSG, imController});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,9 @@
|
||||
//std::map<bufferevent*, std::map<std::string, std::string>> session::session_map;
|
||||
|
||||
session::session() {
|
||||
printf("timing begin");
|
||||
printf("timing begin\n");
|
||||
timing();
|
||||
printf("timing end");
|
||||
fflush(stdout);
|
||||
printf("timing end\n");
|
||||
}
|
||||
|
||||
/// curr mem user curd user session
|
||||
@ -153,7 +152,6 @@ void session::remove_session(userinfo *user) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 时间轮思路的 定时器
|
||||
void session::timing() {
|
||||
time_wheel.run([&]() {
|
||||
|
13
MS/works/controller/IMController.cpp
Normal file
13
MS/works/controller/IMController.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by dongl on 23-6-1.
|
||||
//
|
||||
|
||||
#include "IMController.h"
|
||||
|
||||
void IMController::run(std::shared_ptr<agreement_request> request, std::shared_ptr<agreement_response> response) {
|
||||
if (request->m_mph->mp_type() == mp::MP_IM_PUSH_MSG) {
|
||||
|
||||
} else if (request->m_mph->mp_type() == mp::MP_IM_MSG) {
|
||||
|
||||
}
|
||||
}
|
17
MS/works/controller/IMController.h
Normal file
17
MS/works/controller/IMController.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by dongl on 23-6-1.
|
||||
//
|
||||
|
||||
#ifndef IM2_IMCONTROLLER_H
|
||||
#define IM2_IMCONTROLLER_H
|
||||
|
||||
|
||||
#include "../../mmm/handler.h"
|
||||
|
||||
class IMController : public handler {
|
||||
public:
|
||||
void run(std::shared_ptr<agreement_request> request, std::shared_ptr<agreement_response> response) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //IM2_IMCONTROLLER_H
|
@ -8,5 +8,6 @@
|
||||
#include "UserController.h"
|
||||
#include "UserFriendsController.h"
|
||||
#include "CodeController.h"
|
||||
#include "IMController.h"
|
||||
|
||||
#endif //IM2_WORKS_H
|
||||
|
@ -9,17 +9,15 @@ UserFriendsService::~UserFriendsService() {}
|
||||
// 好友群组 添加删除 任务组 决策接口
|
||||
mp::sri *UserFriendsService::friendImProve(mp::body* body) {
|
||||
sri_clear();
|
||||
// if (body->target() == 0 || body->source() == 0) {
|
||||
// printf("请求数据有缺\n");
|
||||
// sri->set_subcommand(mp::MP_SUB_TYPE::MP_GET_FAIL);
|
||||
// sri->set_msg("请求数据有缺");
|
||||
// return sri;
|
||||
// }
|
||||
|
||||
auto subcommand = body->subcommand();
|
||||
|
||||
// 搜索
|
||||
if (subcommand == mp::MP_SUB_TYPE::MP_SEARCH_FRIENDS_ACCOUNT) {
|
||||
FetchUserFriends(strtol(body->account().c_str(), nullptr, 0), "");
|
||||
}
|
||||
// 添加
|
||||
if (subcommand == mp::MP_SUB_TYPE::MP_ADD_FRIENDS_ACCOUNT) {
|
||||
else if (subcommand == mp::MP_SUB_TYPE::MP_ADD_FRIENDS_ACCOUNT) {
|
||||
add_contact_person(body);
|
||||
}
|
||||
// 拉黑
|
||||
@ -78,8 +76,10 @@ mp::sri* UserFriendsService::add_contact_person(mp::body *body) {
|
||||
return sri;
|
||||
}
|
||||
|
||||
// 查账户好友名单
|
||||
void UserFriendsService::FetchUserFriends(uint64_t account, const std::string &data) {
|
||||
sri_clear();
|
||||
// page
|
||||
uint8_t page_begin = data.c_str()[0];
|
||||
uint8_t page_end = data.c_str()[1];
|
||||
|
||||
@ -91,6 +91,23 @@ void UserFriendsService::FetchUserFriends(uint64_t account, const std::string &d
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索指定账户信息
|
||||
void UserFriendsService::FetchUser(uint64_t account) {
|
||||
// 后续撤掉userDB 在 userfriendsDB内 添加account模糊搜索
|
||||
auto [state, user] = userDB.select_user(account, "account");
|
||||
if (state) {
|
||||
sri->set_username(user.username);
|
||||
sri->set_account(user.account);
|
||||
sri->set_phone(user.phone);
|
||||
sri->set_email(user.email);
|
||||
sri->set_msg("搜索成功");
|
||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_SEARCH_SUCCESS);
|
||||
} else {
|
||||
sri->set_msg("无此用户");
|
||||
sri->set_subcommand(mp::MP_SUB_TYPE::MP_SEARCH_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
// 唯一对开接口
|
||||
mp::sri* friendImProve(mp::body* body);
|
||||
void FetchUserFriends(uint64_t account, const std::string& data);
|
||||
void FetchUser(uint64_t account);
|
||||
|
||||
private:
|
||||
mp::sri* add_contact_person(mp::body* body);
|
||||
@ -24,6 +25,7 @@ private:
|
||||
|
||||
private:
|
||||
UserFriendsDB userFriendsDb = UserFriendsDB();
|
||||
UserDB userDB = UserDB();
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ target_link_libraries(TEST
|
||||
works
|
||||
MessageSystem
|
||||
imm_mysqldb
|
||||
imm_mongodb
|
||||
libgtest.a libgtest_main.a
|
||||
libgmock.a libgmock_main.a
|
||||
curl
|
||||
|
149
include/google/protobuf/any.h
Normal file
149
include/google/protobuf/any.h
Normal file
@ -0,0 +1,149 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_ANY_H__
|
||||
#define GOOGLE_PROTOBUF_ANY_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/message_lite.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
class FieldDescriptor;
|
||||
class Message;
|
||||
|
||||
namespace internal {
|
||||
|
||||
extern const char kAnyFullTypeName[]; // "google.protobuf.Any".
|
||||
extern const char kTypeGoogleApisComPrefix[]; // "type.googleapis.com/".
|
||||
extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/".
|
||||
|
||||
std::string GetTypeUrl(StringPiece message_name,
|
||||
StringPiece type_url_prefix);
|
||||
|
||||
// Helper class used to implement google::protobuf::Any.
|
||||
class PROTOBUF_EXPORT AnyMetadata {
|
||||
typedef ArenaStringPtr UrlType;
|
||||
typedef ArenaStringPtr ValueType;
|
||||
public:
|
||||
// AnyMetadata does not take ownership of "type_url" and "value".
|
||||
AnyMetadata(UrlType* type_url, ValueType* value);
|
||||
|
||||
// Packs a message using the default type URL prefix: "type.googleapis.com".
|
||||
// The resulted type URL will be "type.googleapis.com/<message_full_name>".
|
||||
template <typename T>
|
||||
void PackFrom(const T& message) {
|
||||
InternalPackFrom(message, kTypeGoogleApisComPrefix, T::FullMessageName());
|
||||
}
|
||||
|
||||
void PackFrom(const Message& message);
|
||||
|
||||
// Packs a message using the given type URL prefix. The type URL will be
|
||||
// constructed by concatenating the message type's full name to the prefix
|
||||
// with an optional "/" separator if the prefix doesn't already end with "/".
|
||||
// For example, both PackFrom(message, "type.googleapis.com") and
|
||||
// PackFrom(message, "type.googleapis.com/") yield the same result type
|
||||
// URL: "type.googleapis.com/<message_full_name>".
|
||||
template <typename T>
|
||||
void PackFrom(const T& message, StringPiece type_url_prefix) {
|
||||
InternalPackFrom(message, type_url_prefix, T::FullMessageName());
|
||||
}
|
||||
|
||||
void PackFrom(const Message& message, const std::string& type_url_prefix);
|
||||
|
||||
// Unpacks the payload into the given message. Returns false if the message's
|
||||
// type doesn't match the type specified in the type URL (i.e., the full
|
||||
// name after the last "/" of the type URL doesn't match the message's actual
|
||||
// full name) or parsing the payload has failed.
|
||||
template <typename T>
|
||||
bool UnpackTo(T* message) const {
|
||||
return InternalUnpackTo(T::FullMessageName(), message);
|
||||
}
|
||||
|
||||
bool UnpackTo(Message* message) const;
|
||||
|
||||
// Checks whether the type specified in the type URL matches the given type.
|
||||
// A type is considered matching if its full name matches the full name after
|
||||
// the last "/" in the type URL.
|
||||
template <typename T>
|
||||
bool Is() const {
|
||||
return InternalIs(T::FullMessageName());
|
||||
}
|
||||
|
||||
private:
|
||||
void InternalPackFrom(const MessageLite& message,
|
||||
StringPiece type_url_prefix,
|
||||
StringPiece type_name);
|
||||
bool InternalUnpackTo(StringPiece type_name,
|
||||
MessageLite* message) const;
|
||||
bool InternalIs(StringPiece type_name) const;
|
||||
|
||||
UrlType* type_url_;
|
||||
ValueType* value_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AnyMetadata);
|
||||
};
|
||||
|
||||
// Get the proto type name from Any::type_url value. For example, passing
|
||||
// "type.googleapis.com/rpc.QueryOrigin" will return "rpc.QueryOrigin" in
|
||||
// *full_type_name. Returns false if the type_url does not have a "/"
|
||||
// in the type url separating the full type name.
|
||||
//
|
||||
// NOTE: this function is available publicly as:
|
||||
// google::protobuf::Any() // static method on the generated message type.
|
||||
bool ParseAnyTypeUrl(const std::string& type_url, std::string* full_type_name);
|
||||
|
||||
// Get the proto type name and prefix from Any::type_url value. For example,
|
||||
// passing "type.googleapis.com/rpc.QueryOrigin" will return
|
||||
// "type.googleapis.com/" in *url_prefix and "rpc.QueryOrigin" in
|
||||
// *full_type_name. Returns false if the type_url does not have a "/" in the
|
||||
// type url separating the full type name.
|
||||
bool ParseAnyTypeUrl(const std::string& type_url, std::string* url_prefix,
|
||||
std::string* full_type_name);
|
||||
|
||||
// See if message is of type google.protobuf.Any, if so, return the descriptors
|
||||
// for "type_url" and "value" fields.
|
||||
bool GetAnyFieldDescriptors(const Message& message,
|
||||
const FieldDescriptor** type_url_field,
|
||||
const FieldDescriptor** value_field);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_ANY_H__
|
465
include/google/protobuf/any.pb.h
Normal file
465
include/google/protobuf/any.pb.h
Normal file
@ -0,0 +1,465 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/any.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#if PROTOBUF_VERSION < 3012000
|
||||
#error This file was generated by a newer version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please update
|
||||
#error your headers.
|
||||
#endif
|
||||
#if 3012004 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error This file was generated by an older version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please
|
||||
#error regenerate this file with a newer version of protoc.
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
#include <google/protobuf/extension_set.h> // IWYU pragma: export
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
// @@protoc_insertion_point(includes)
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fany_2eproto PROTOBUF_EXPORT
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fany_2eproto {
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[];
|
||||
};
|
||||
extern PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto;
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
class Any;
|
||||
class AnyDefaultTypeInternal;
|
||||
PROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_;
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_EXPORT PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::Any>(Arena*);
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ {
|
||||
public:
|
||||
inline Any() : Any(nullptr) {};
|
||||
virtual ~Any();
|
||||
|
||||
Any(const Any& from);
|
||||
Any(Any&& from) noexcept
|
||||
: Any() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline Any& operator=(const Any& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline Any& operator=(Any&& from) noexcept {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() {
|
||||
return GetMetadataStatic().descriptor;
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() {
|
||||
return GetMetadataStatic().reflection;
|
||||
}
|
||||
static const Any& default_instance();
|
||||
|
||||
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
|
||||
static inline const Any* internal_default_instance() {
|
||||
return reinterpret_cast<const Any*>(
|
||||
&_Any_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
// implements Any -----------------------------------------------
|
||||
|
||||
void PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message) {
|
||||
_any_metadata_.PackFrom(message);
|
||||
}
|
||||
void PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message,
|
||||
const std::string& type_url_prefix) {
|
||||
_any_metadata_.PackFrom(message, type_url_prefix);
|
||||
}
|
||||
bool UnpackTo(::PROTOBUF_NAMESPACE_ID::Message* message) const {
|
||||
return _any_metadata_.UnpackTo(message);
|
||||
}
|
||||
static bool GetAnyFieldDescriptors(
|
||||
const ::PROTOBUF_NAMESPACE_ID::Message& message,
|
||||
const ::PROTOBUF_NAMESPACE_ID::FieldDescriptor** type_url_field,
|
||||
const ::PROTOBUF_NAMESPACE_ID::FieldDescriptor** value_field);
|
||||
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
|
||||
void PackFrom(const T& message) {
|
||||
_any_metadata_.PackFrom<T>(message);
|
||||
}
|
||||
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
|
||||
void PackFrom(const T& message,
|
||||
const std::string& type_url_prefix) {
|
||||
_any_metadata_.PackFrom<T>(message, type_url_prefix);}
|
||||
template <typename T, class = typename std::enable_if<!std::is_convertible<T, const ::PROTOBUF_NAMESPACE_ID::Message&>::value>::type>
|
||||
bool UnpackTo(T* message) const {
|
||||
return _any_metadata_.UnpackTo<T>(message);
|
||||
}
|
||||
template<typename T> bool Is() const {
|
||||
return _any_metadata_.Is<T>();
|
||||
}
|
||||
static bool ParseAnyTypeUrl(const string& type_url,
|
||||
std::string* full_type_name);
|
||||
friend void swap(Any& a, Any& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(Any* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Any* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
inline Any* New() const final {
|
||||
return CreateMaybeMessage<Any>(nullptr);
|
||||
}
|
||||
|
||||
Any* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
|
||||
return CreateMaybeMessage<Any>(arena);
|
||||
}
|
||||
void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void CopyFrom(const Any& from);
|
||||
void MergeFrom(const Any& from);
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize(
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
inline void SharedCtor();
|
||||
inline void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(Any* other);
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Any";
|
||||
}
|
||||
protected:
|
||||
explicit Any(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
private:
|
||||
static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_google_2fprotobuf_2fany_2eproto);
|
||||
return ::descriptor_table_google_2fprotobuf_2fany_2eproto.file_level_metadata[kIndexInFileMessages];
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kTypeUrlFieldNumber = 1,
|
||||
kValueFieldNumber = 2,
|
||||
};
|
||||
// string type_url = 1;
|
||||
void clear_type_url();
|
||||
const std::string& type_url() const;
|
||||
void set_type_url(const std::string& value);
|
||||
void set_type_url(std::string&& value);
|
||||
void set_type_url(const char* value);
|
||||
void set_type_url(const char* value, size_t size);
|
||||
std::string* mutable_type_url();
|
||||
std::string* release_type_url();
|
||||
void set_allocated_type_url(std::string* type_url);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_type_url();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_type_url(
|
||||
std::string* type_url);
|
||||
private:
|
||||
const std::string& _internal_type_url() const;
|
||||
void _internal_set_type_url(const std::string& value);
|
||||
std::string* _internal_mutable_type_url();
|
||||
public:
|
||||
|
||||
// bytes value = 2;
|
||||
void clear_value();
|
||||
const std::string& value() const;
|
||||
void set_value(const std::string& value);
|
||||
void set_value(std::string&& value);
|
||||
void set_value(const char* value);
|
||||
void set_value(const void* value, size_t size);
|
||||
std::string* mutable_value();
|
||||
std::string* release_value();
|
||||
void set_allocated_value(std::string* value);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_value();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_value(
|
||||
std::string* value);
|
||||
private:
|
||||
const std::string& _internal_value() const;
|
||||
void _internal_set_value(const std::string& value);
|
||||
std::string* _internal_mutable_value();
|
||||
public:
|
||||
|
||||
// @@protoc_insertion_point(class_scope:google.protobuf.Any)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr type_url_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr value_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata _any_metadata_;
|
||||
friend struct ::TableStruct_google_2fprotobuf_2fany_2eproto;
|
||||
};
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// Any
|
||||
|
||||
// string type_url = 1;
|
||||
inline void Any::clear_type_url() {
|
||||
type_url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Any::type_url() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
|
||||
return _internal_type_url();
|
||||
}
|
||||
inline void Any::set_type_url(const std::string& value) {
|
||||
_internal_set_type_url(value);
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline std::string* Any::mutable_type_url() {
|
||||
// @@protoc_insertion_point(field_mutable:google.protobuf.Any.type_url)
|
||||
return _internal_mutable_type_url();
|
||||
}
|
||||
inline const std::string& Any::_internal_type_url() const {
|
||||
return type_url_.Get();
|
||||
}
|
||||
inline void Any::_internal_set_type_url(const std::string& value) {
|
||||
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Any::set_type_url(std::string&& value) {
|
||||
|
||||
type_url_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline void Any::set_type_url(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline void Any::set_type_url(const char* value,
|
||||
size_t size) {
|
||||
|
||||
type_url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline std::string* Any::_internal_mutable_type_url() {
|
||||
|
||||
return type_url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Any::release_type_url() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
|
||||
return type_url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Any::set_allocated_type_url(std::string* type_url) {
|
||||
if (type_url != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
type_url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), type_url,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
|
||||
}
|
||||
inline std::string* Any::unsafe_arena_release_type_url() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.type_url)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Any::unsafe_arena_set_allocated_type_url(
|
||||
std::string* type_url) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (type_url != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
type_url, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.type_url)
|
||||
}
|
||||
|
||||
// bytes value = 2;
|
||||
inline void Any::clear_value() {
|
||||
value_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& Any::value() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
|
||||
return _internal_value();
|
||||
}
|
||||
inline void Any::set_value(const std::string& value) {
|
||||
_internal_set_value(value);
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
|
||||
}
|
||||
inline std::string* Any::mutable_value() {
|
||||
// @@protoc_insertion_point(field_mutable:google.protobuf.Any.value)
|
||||
return _internal_mutable_value();
|
||||
}
|
||||
inline const std::string& Any::_internal_value() const {
|
||||
return value_.Get();
|
||||
}
|
||||
inline void Any::_internal_set_value(const std::string& value) {
|
||||
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void Any::set_value(std::string&& value) {
|
||||
|
||||
value_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
|
||||
}
|
||||
inline void Any::set_value(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.value)
|
||||
}
|
||||
inline void Any::set_value(const void* value,
|
||||
size_t size) {
|
||||
|
||||
value_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value)
|
||||
}
|
||||
inline std::string* Any::_internal_mutable_value() {
|
||||
|
||||
return value_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* Any::release_value() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
|
||||
return value_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void Any::set_allocated_value(std::string* value) {
|
||||
if (value != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
value_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
|
||||
}
|
||||
inline std::string* Any::unsafe_arena_release_value() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.value)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void Any::unsafe_arena_set_allocated_value(
|
||||
std::string* value) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (value != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
value, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.value)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto
|
155
include/google/protobuf/any.proto
Normal file
155
include/google/protobuf/any.proto
Normal file
@ -0,0 +1,155 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||
option go_package = "github.com/golang/protobuf/ptypes/any";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "AnyProto";
|
||||
option java_multiple_files = true;
|
||||
option objc_class_prefix = "GPB";
|
||||
|
||||
// `Any` contains an arbitrary serialized protocol buffer message along with a
|
||||
// URL that describes the type of the serialized message.
|
||||
//
|
||||
// Protobuf library provides support to pack/unpack Any values in the form
|
||||
// of utility functions or additional generated methods of the Any type.
|
||||
//
|
||||
// Example 1: Pack and unpack a message in C++.
|
||||
//
|
||||
// Foo foo = ...;
|
||||
// Any any;
|
||||
// any.PackFrom(foo);
|
||||
// ...
|
||||
// if (any.UnpackTo(&foo)) {
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// Example 2: Pack and unpack a message in Java.
|
||||
//
|
||||
// Foo foo = ...;
|
||||
// Any any = Any.pack(foo);
|
||||
// ...
|
||||
// if (any.is(Foo.class)) {
|
||||
// foo = any.unpack(Foo.class);
|
||||
// }
|
||||
//
|
||||
// Example 3: Pack and unpack a message in Python.
|
||||
//
|
||||
// foo = Foo(...)
|
||||
// any = Any()
|
||||
// any.Pack(foo)
|
||||
// ...
|
||||
// if any.Is(Foo.DESCRIPTOR):
|
||||
// any.Unpack(foo)
|
||||
// ...
|
||||
//
|
||||
// Example 4: Pack and unpack a message in Go
|
||||
//
|
||||
// foo := &pb.Foo{...}
|
||||
// any, err := ptypes.MarshalAny(foo)
|
||||
// ...
|
||||
// foo := &pb.Foo{}
|
||||
// if err := ptypes.UnmarshalAny(any, foo); err != nil {
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// The pack methods provided by protobuf library will by default use
|
||||
// 'type.googleapis.com/full.type.name' as the type URL and the unpack
|
||||
// methods only use the fully qualified type name after the last '/'
|
||||
// in the type URL, for example "foo.bar.com/x/y.z" will yield type
|
||||
// name "y.z".
|
||||
//
|
||||
//
|
||||
// JSON
|
||||
// ====
|
||||
// The JSON representation of an `Any` value uses the regular
|
||||
// representation of the deserialized, embedded message, with an
|
||||
// additional field `@type` which contains the type URL. Example:
|
||||
//
|
||||
// package google.profile;
|
||||
// message Person {
|
||||
// string first_name = 1;
|
||||
// string last_name = 2;
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// "@type": "type.googleapis.com/google.profile.Person",
|
||||
// "firstName": <string>,
|
||||
// "lastName": <string>
|
||||
// }
|
||||
//
|
||||
// If the embedded message type is well-known and has a custom JSON
|
||||
// representation, that representation will be embedded adding a field
|
||||
// `value` which holds the custom JSON in addition to the `@type`
|
||||
// field. Example (for message [google.protobuf.Duration][]):
|
||||
//
|
||||
// {
|
||||
// "@type": "type.googleapis.com/google.protobuf.Duration",
|
||||
// "value": "1.212s"
|
||||
// }
|
||||
//
|
||||
message Any {
|
||||
// A URL/resource name that uniquely identifies the type of the serialized
|
||||
// protocol buffer message. This string must contain at least
|
||||
// one "/" character. The last segment of the URL's path must represent
|
||||
// the fully qualified name of the type (as in
|
||||
// `path/google.protobuf.Duration`). The name should be in a canonical form
|
||||
// (e.g., leading "." is not accepted).
|
||||
//
|
||||
// In practice, teams usually precompile into the binary all types that they
|
||||
// expect it to use in the context of Any. However, for URLs which use the
|
||||
// scheme `http`, `https`, or no scheme, one can optionally set up a type
|
||||
// server that maps type URLs to message definitions as follows:
|
||||
//
|
||||
// * If no scheme is provided, `https` is assumed.
|
||||
// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
|
||||
// value in binary format, or produce an error.
|
||||
// * Applications are allowed to cache lookup results based on the
|
||||
// URL, or have them precompiled into a binary to avoid any
|
||||
// lookup. Therefore, binary compatibility needs to be preserved
|
||||
// on changes to types. (Use versioned type names to manage
|
||||
// breaking changes.)
|
||||
//
|
||||
// Note: this functionality is not currently available in the official
|
||||
// protobuf release, and it is not used for type URLs beginning with
|
||||
// type.googleapis.com.
|
||||
//
|
||||
// Schemes other than `http`, `https` (or the empty scheme) might be
|
||||
// used with implementation specific semantics.
|
||||
//
|
||||
string type_url = 1;
|
||||
|
||||
// Must be a valid serialized protocol buffer of the above specified type.
|
||||
bytes value = 2;
|
||||
}
|
1694
include/google/protobuf/api.pb.h
Normal file
1694
include/google/protobuf/api.pb.h
Normal file
File diff suppressed because it is too large
Load Diff
210
include/google/protobuf/api.proto
Normal file
210
include/google/protobuf/api.proto
Normal file
@ -0,0 +1,210 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
import "google/protobuf/source_context.proto";
|
||||
import "google/protobuf/type.proto";
|
||||
|
||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "ApiProto";
|
||||
option java_multiple_files = true;
|
||||
option objc_class_prefix = "GPB";
|
||||
option go_package = "google.golang.org/genproto/protobuf/api;api";
|
||||
|
||||
// Api is a light-weight descriptor for an API Interface.
|
||||
//
|
||||
// Interfaces are also described as "protocol buffer services" in some contexts,
|
||||
// such as by the "service" keyword in a .proto file, but they are different
|
||||
// from API Services, which represent a concrete implementation of an interface
|
||||
// as opposed to simply a description of methods and bindings. They are also
|
||||
// sometimes simply referred to as "APIs" in other contexts, such as the name of
|
||||
// this message itself. See https://cloud.google.com/apis/design/glossary for
|
||||
// detailed terminology.
|
||||
message Api {
|
||||
|
||||
// The fully qualified name of this interface, including package name
|
||||
// followed by the interface's simple name.
|
||||
string name = 1;
|
||||
|
||||
// The methods of this interface, in unspecified order.
|
||||
repeated Method methods = 2;
|
||||
|
||||
// Any metadata attached to the interface.
|
||||
repeated Option options = 3;
|
||||
|
||||
// A version string for this interface. If specified, must have the form
|
||||
// `major-version.minor-version`, as in `1.10`. If the minor version is
|
||||
// omitted, it defaults to zero. If the entire version field is empty, the
|
||||
// major version is derived from the package name, as outlined below. If the
|
||||
// field is not empty, the version in the package name will be verified to be
|
||||
// consistent with what is provided here.
|
||||
//
|
||||
// The versioning schema uses [semantic
|
||||
// versioning](http://semver.org) where the major version number
|
||||
// indicates a breaking change and the minor version an additive,
|
||||
// non-breaking change. Both version numbers are signals to users
|
||||
// what to expect from different versions, and should be carefully
|
||||
// chosen based on the product plan.
|
||||
//
|
||||
// The major version is also reflected in the package name of the
|
||||
// interface, which must end in `v<major-version>`, as in
|
||||
// `google.feature.v1`. For major versions 0 and 1, the suffix can
|
||||
// be omitted. Zero major versions must only be used for
|
||||
// experimental, non-GA interfaces.
|
||||
//
|
||||
//
|
||||
string version = 4;
|
||||
|
||||
// Source context for the protocol buffer service represented by this
|
||||
// message.
|
||||
SourceContext source_context = 5;
|
||||
|
||||
// Included interfaces. See [Mixin][].
|
||||
repeated Mixin mixins = 6;
|
||||
|
||||
// The source syntax of the service.
|
||||
Syntax syntax = 7;
|
||||
}
|
||||
|
||||
// Method represents a method of an API interface.
|
||||
message Method {
|
||||
|
||||
// The simple name of this method.
|
||||
string name = 1;
|
||||
|
||||
// A URL of the input message type.
|
||||
string request_type_url = 2;
|
||||
|
||||
// If true, the request is streamed.
|
||||
bool request_streaming = 3;
|
||||
|
||||
// The URL of the output message type.
|
||||
string response_type_url = 4;
|
||||
|
||||
// If true, the response is streamed.
|
||||
bool response_streaming = 5;
|
||||
|
||||
// Any metadata attached to the method.
|
||||
repeated Option options = 6;
|
||||
|
||||
// The source syntax of this method.
|
||||
Syntax syntax = 7;
|
||||
}
|
||||
|
||||
// Declares an API Interface to be included in this interface. The including
|
||||
// interface must redeclare all the methods from the included interface, but
|
||||
// documentation and options are inherited as follows:
|
||||
//
|
||||
// - If after comment and whitespace stripping, the documentation
|
||||
// string of the redeclared method is empty, it will be inherited
|
||||
// from the original method.
|
||||
//
|
||||
// - Each annotation belonging to the service config (http,
|
||||
// visibility) which is not set in the redeclared method will be
|
||||
// inherited.
|
||||
//
|
||||
// - If an http annotation is inherited, the path pattern will be
|
||||
// modified as follows. Any version prefix will be replaced by the
|
||||
// version of the including interface plus the [root][] path if
|
||||
// specified.
|
||||
//
|
||||
// Example of a simple mixin:
|
||||
//
|
||||
// package google.acl.v1;
|
||||
// service AccessControl {
|
||||
// // Get the underlying ACL object.
|
||||
// rpc GetAcl(GetAclRequest) returns (Acl) {
|
||||
// option (google.api.http).get = "/v1/{resource=**}:getAcl";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// package google.storage.v2;
|
||||
// service Storage {
|
||||
// rpc GetAcl(GetAclRequest) returns (Acl);
|
||||
//
|
||||
// // Get a data record.
|
||||
// rpc GetData(GetDataRequest) returns (Data) {
|
||||
// option (google.api.http).get = "/v2/{resource=**}";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Example of a mixin configuration:
|
||||
//
|
||||
// apis:
|
||||
// - name: google.storage.v2.Storage
|
||||
// mixins:
|
||||
// - name: google.acl.v1.AccessControl
|
||||
//
|
||||
// The mixin construct implies that all methods in `AccessControl` are
|
||||
// also declared with same name and request/response types in
|
||||
// `Storage`. A documentation generator or annotation processor will
|
||||
// see the effective `Storage.GetAcl` method after inherting
|
||||
// documentation and annotations as follows:
|
||||
//
|
||||
// service Storage {
|
||||
// // Get the underlying ACL object.
|
||||
// rpc GetAcl(GetAclRequest) returns (Acl) {
|
||||
// option (google.api.http).get = "/v2/{resource=**}:getAcl";
|
||||
// }
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// Note how the version in the path pattern changed from `v1` to `v2`.
|
||||
//
|
||||
// If the `root` field in the mixin is specified, it should be a
|
||||
// relative path under which inherited HTTP paths are placed. Example:
|
||||
//
|
||||
// apis:
|
||||
// - name: google.storage.v2.Storage
|
||||
// mixins:
|
||||
// - name: google.acl.v1.AccessControl
|
||||
// root: acls
|
||||
//
|
||||
// This implies the following inherited HTTP annotation:
|
||||
//
|
||||
// service Storage {
|
||||
// // Get the underlying ACL object.
|
||||
// rpc GetAcl(GetAclRequest) returns (Acl) {
|
||||
// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
|
||||
// }
|
||||
// ...
|
||||
// }
|
||||
message Mixin {
|
||||
// The fully qualified name of the interface which is included.
|
||||
string name = 1;
|
||||
|
||||
// If non-empty specifies a path under which inherited HTTP paths
|
||||
// are rooted.
|
||||
string root = 2;
|
||||
}
|
736
include/google/protobuf/arena.h
Normal file
736
include/google/protobuf/arena.h
Normal file
@ -0,0 +1,736 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file defines an Arena allocator for better allocation performance.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_ARENA_H__
|
||||
#define GOOGLE_PROTOBUF_ARENA_H__
|
||||
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#ifdef max
|
||||
#undef max // Visual Studio defines this macro
|
||||
#endif
|
||||
#if defined(_MSC_VER) && !defined(_LIBCPP_STD_VER) && !_HAS_EXCEPTIONS
|
||||
// Work around bugs in MSVC <typeinfo> header when _HAS_EXCEPTIONS=0.
|
||||
#include <exception>
|
||||
#include <typeinfo>
|
||||
namespace std {
|
||||
using type_info = ::type_info;
|
||||
}
|
||||
#else
|
||||
#include <typeinfo>
|
||||
#endif
|
||||
|
||||
#include <type_traits>
|
||||
#include <google/protobuf/arena_impl.h>
|
||||
#include <google/protobuf/port.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
struct ArenaOptions; // defined below
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
class Arena; // defined below
|
||||
class Message; // defined in message.h
|
||||
class MessageLite;
|
||||
template <typename Key, typename T>
|
||||
class Map;
|
||||
|
||||
namespace arena_metrics {
|
||||
|
||||
void EnableArenaMetrics(ArenaOptions* options);
|
||||
|
||||
} // namespace arena_metrics
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct ArenaStringPtr; // defined in arenastring.h
|
||||
class LazyField; // defined in lazy_field.h
|
||||
class EpsCopyInputStream; // defined in parse_context.h
|
||||
|
||||
template <typename Type>
|
||||
class GenericTypeHandler; // defined in repeated_field.h
|
||||
|
||||
// Templated cleanup methods.
|
||||
template <typename T>
|
||||
void arena_destruct_object(void* object) {
|
||||
reinterpret_cast<T*>(object)->~T();
|
||||
}
|
||||
template <typename T>
|
||||
void arena_delete_object(void* object) {
|
||||
delete reinterpret_cast<T*>(object);
|
||||
}
|
||||
inline void arena_free(void* object, size_t size) {
|
||||
#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
|
||||
::operator delete(object, size);
|
||||
#else
|
||||
(void)size;
|
||||
::operator delete(object);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// ArenaOptions provides optional additional parameters to arena construction
|
||||
// that control its block-allocation behavior.
|
||||
struct ArenaOptions {
|
||||
// This defines the size of the first block requested from the system malloc.
|
||||
// Subsequent block sizes will increase in a geometric series up to a maximum.
|
||||
size_t start_block_size;
|
||||
|
||||
// This defines the maximum block size requested from system malloc (unless an
|
||||
// individual arena allocation request occurs with a size larger than this
|
||||
// maximum). Requested block sizes increase up to this value, then remain
|
||||
// here.
|
||||
size_t max_block_size;
|
||||
|
||||
// An initial block of memory for the arena to use, or NULL for none. If
|
||||
// provided, the block must live at least as long as the arena itself. The
|
||||
// creator of the Arena retains ownership of the block after the Arena is
|
||||
// destroyed.
|
||||
char* initial_block;
|
||||
|
||||
// The size of the initial block, if provided.
|
||||
size_t initial_block_size;
|
||||
|
||||
// A function pointer to an alloc method that returns memory blocks of size
|
||||
// requested. By default, it contains a ptr to the malloc function.
|
||||
//
|
||||
// NOTE: block_alloc and dealloc functions are expected to behave like
|
||||
// malloc and free, including Asan poisoning.
|
||||
void* (*block_alloc)(size_t);
|
||||
// A function pointer to a dealloc method that takes ownership of the blocks
|
||||
// from the arena. By default, it contains a ptr to a wrapper function that
|
||||
// calls free.
|
||||
void (*block_dealloc)(void*, size_t);
|
||||
|
||||
ArenaOptions()
|
||||
: start_block_size(kDefaultStartBlockSize),
|
||||
max_block_size(kDefaultMaxBlockSize),
|
||||
initial_block(NULL),
|
||||
initial_block_size(0),
|
||||
block_alloc(&::operator new),
|
||||
block_dealloc(&internal::arena_free),
|
||||
on_arena_init(NULL),
|
||||
on_arena_reset(NULL),
|
||||
on_arena_destruction(NULL),
|
||||
on_arena_allocation(NULL) {}
|
||||
|
||||
private:
|
||||
// Hooks for adding external functionality such as user-specific metrics
|
||||
// collection, specific debugging abilities, etc.
|
||||
// Init hook (if set) will always be called at Arena init time. Init hook may
|
||||
// return a pointer to a cookie to be stored in the arena. Reset and
|
||||
// destruction hooks will then be called with the same cookie pointer. This
|
||||
// allows us to save an external object per arena instance and use it on the
|
||||
// other hooks (Note: If init hook returns NULL, the other hooks will NOT be
|
||||
// called on this arena instance).
|
||||
// on_arena_reset and on_arena_destruction also receive the space used in the
|
||||
// arena just before the reset.
|
||||
void* (*on_arena_init)(Arena* arena);
|
||||
void (*on_arena_reset)(Arena* arena, void* cookie, uint64 space_used);
|
||||
void (*on_arena_destruction)(Arena* arena, void* cookie, uint64 space_used);
|
||||
|
||||
// type_info is promised to be static - its lifetime extends to
|
||||
// match program's lifetime (It is given by typeid operator).
|
||||
// Note: typeid(void) will be passed as allocated_type every time we
|
||||
// intentionally want to avoid monitoring an allocation. (i.e. internal
|
||||
// allocations for managing the arena)
|
||||
void (*on_arena_allocation)(const std::type_info* allocated_type,
|
||||
uint64 alloc_size, void* cookie);
|
||||
|
||||
// Constants define default starting block size and max block size for
|
||||
// arena allocator behavior -- see descriptions above.
|
||||
static const size_t kDefaultStartBlockSize = 256;
|
||||
static const size_t kDefaultMaxBlockSize = 8192;
|
||||
|
||||
friend void arena_metrics::EnableArenaMetrics(ArenaOptions*);
|
||||
friend class Arena;
|
||||
friend class ArenaOptionsTestFriend;
|
||||
};
|
||||
|
||||
// Support for non-RTTI environments. (The metrics hooks API uses type
|
||||
// information.)
|
||||
#if PROTOBUF_RTTI
|
||||
#define RTTI_TYPE_ID(type) (&typeid(type))
|
||||
#else
|
||||
#define RTTI_TYPE_ID(type) (NULL)
|
||||
#endif
|
||||
|
||||
// Arena allocator. Arena allocation replaces ordinary (heap-based) allocation
|
||||
// with new/delete, and improves performance by aggregating allocations into
|
||||
// larger blocks and freeing allocations all at once. Protocol messages are
|
||||
// allocated on an arena by using Arena::CreateMessage<T>(Arena*), below, and
|
||||
// are automatically freed when the arena is destroyed.
|
||||
//
|
||||
// This is a thread-safe implementation: multiple threads may allocate from the
|
||||
// arena concurrently. Destruction is not thread-safe and the destructing
|
||||
// thread must synchronize with users of the arena first.
|
||||
//
|
||||
// An arena provides two allocation interfaces: CreateMessage<T>, which works
|
||||
// for arena-enabled proto2 message types as well as other types that satisfy
|
||||
// the appropriate protocol (described below), and Create<T>, which works for
|
||||
// any arbitrary type T. CreateMessage<T> is better when the type T supports it,
|
||||
// because this interface (i) passes the arena pointer to the created object so
|
||||
// that its sub-objects and internal allocations can use the arena too, and (ii)
|
||||
// elides the object's destructor call when possible. Create<T> does not place
|
||||
// any special requirements on the type T, and will invoke the object's
|
||||
// destructor when the arena is destroyed.
|
||||
//
|
||||
// The arena message allocation protocol, required by
|
||||
// CreateMessage<T>(Arena* arena, Args&&... args), is as follows:
|
||||
//
|
||||
// - The type T must have (at least) two constructors: a constructor callable
|
||||
// with `args` (without `arena`), called when a T is allocated on the heap;
|
||||
// and a constructor callable with `Arena* arena, Args&&... args`, called when
|
||||
// a T is allocated on an arena. If the second constructor is called with a
|
||||
// NULL arena pointer, it must be equivalent to invoking the first
|
||||
// (`args`-only) constructor.
|
||||
//
|
||||
// - The type T must have a particular type trait: a nested type
|
||||
// |InternalArenaConstructable_|. This is usually a typedef to |void|. If no
|
||||
// such type trait exists, then the instantiation CreateMessage<T> will fail
|
||||
// to compile.
|
||||
//
|
||||
// - The type T *may* have the type trait |DestructorSkippable_|. If this type
|
||||
// trait is present in the type, then its destructor will not be called if and
|
||||
// only if it was passed a non-NULL arena pointer. If this type trait is not
|
||||
// present on the type, then its destructor is always called when the
|
||||
// containing arena is destroyed.
|
||||
//
|
||||
// This protocol is implemented by all arena-enabled proto2 message classes as
|
||||
// well as protobuf container types like RepeatedPtrField and Map. The protocol
|
||||
// is internal to protobuf and is not guaranteed to be stable. Non-proto types
|
||||
// should not rely on this protocol.
|
||||
class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
|
||||
public:
|
||||
// Arena constructor taking custom options. See ArenaOptions below for
|
||||
// descriptions of the options available.
|
||||
explicit Arena(const ArenaOptions& options) : impl_(options) {
|
||||
Init(options);
|
||||
}
|
||||
|
||||
// Block overhead. Use this as a guide for how much to over-allocate the
|
||||
// initial block if you want an allocation of size N to fit inside it.
|
||||
//
|
||||
// WARNING: if you allocate multiple objects, it is difficult to guarantee
|
||||
// that a series of allocations will fit in the initial block, especially if
|
||||
// Arena changes its alignment guarantees in the future!
|
||||
static const size_t kBlockOverhead = internal::ArenaImpl::kBlockHeaderSize +
|
||||
internal::ArenaImpl::kSerialArenaSize;
|
||||
|
||||
// Default constructor with sensible default options, tuned for average
|
||||
// use-cases.
|
||||
Arena() : impl_(ArenaOptions()) { Init(ArenaOptions()); }
|
||||
|
||||
~Arena() {
|
||||
if (hooks_cookie_) {
|
||||
CallDestructorHooks();
|
||||
}
|
||||
}
|
||||
|
||||
void Init(const ArenaOptions& options) {
|
||||
on_arena_allocation_ = options.on_arena_allocation;
|
||||
on_arena_reset_ = options.on_arena_reset;
|
||||
on_arena_destruction_ = options.on_arena_destruction;
|
||||
// Call the initialization hook
|
||||
if (options.on_arena_init != NULL) {
|
||||
hooks_cookie_ = options.on_arena_init(this);
|
||||
} else {
|
||||
hooks_cookie_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// API to create proto2 message objects on the arena. If the arena passed in
|
||||
// is NULL, then a heap allocated object is returned. Type T must be a message
|
||||
// defined in a .proto file with cc_enable_arenas set to true, otherwise a
|
||||
// compilation error will occur.
|
||||
//
|
||||
// RepeatedField and RepeatedPtrField may also be instantiated directly on an
|
||||
// arena with this method.
|
||||
//
|
||||
// This function also accepts any type T that satisfies the arena message
|
||||
// allocation protocol, documented above.
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateMessage(Arena* arena, Args&&... args) {
|
||||
static_assert(
|
||||
InternalHelper<T>::is_arena_constructable::value,
|
||||
"CreateMessage can only construct types that are ArenaConstructable");
|
||||
// We must delegate to CreateMaybeMessage() and NOT CreateMessageInternal()
|
||||
// because protobuf generated classes specialize CreateMaybeMessage() and we
|
||||
// need to use that specialization for code size reasons.
|
||||
return Arena::CreateMaybeMessage<T>(arena, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// API to create any objects on the arena. Note that only the object will
|
||||
// be created on the arena; the underlying ptrs (in case of a proto2 message)
|
||||
// will be still heap allocated. Proto messages should usually be allocated
|
||||
// with CreateMessage<T>() instead.
|
||||
//
|
||||
// Note that even if T satisfies the arena message construction protocol
|
||||
// (InternalArenaConstructable_ trait and optional DestructorSkippable_
|
||||
// trait), as described above, this function does not follow the protocol;
|
||||
// instead, it treats T as a black-box type, just as if it did not have these
|
||||
// traits. Specifically, T's constructor arguments will always be only those
|
||||
// passed to Create<T>() -- no additional arena pointer is implicitly added.
|
||||
// Furthermore, the destructor will always be called at arena destruction time
|
||||
// (unless the destructor is trivial). Hence, from T's point of view, it is as
|
||||
// if the object were allocated on the heap (except that the underlying memory
|
||||
// is obtained from the arena).
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* Create(Arena* arena, Args&&... args) {
|
||||
return CreateNoMessage<T>(arena, is_arena_constructable<T>(),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// Create an array of object type T on the arena *without* invoking the
|
||||
// constructor of T. If `arena` is null, then the return value should be freed
|
||||
// with `delete[] x;` (or `::operator delete[](x);`).
|
||||
// To ensure safe uses, this function checks at compile time
|
||||
// (when compiled as C++11) that T is trivially default-constructible and
|
||||
// trivially destructible.
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateArray(Arena* arena,
|
||||
size_t num_elements) {
|
||||
static_assert(std::is_pod<T>::value,
|
||||
"CreateArray requires a trivially constructible type");
|
||||
static_assert(std::is_trivially_destructible<T>::value,
|
||||
"CreateArray requires a trivially destructible type");
|
||||
GOOGLE_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
|
||||
<< "Requested size is too large to fit into size_t.";
|
||||
if (arena == NULL) {
|
||||
return static_cast<T*>(::operator new[](num_elements * sizeof(T)));
|
||||
} else {
|
||||
return arena->CreateInternalRawArray<T>(num_elements);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the total space allocated by the arena, which is the sum of the
|
||||
// sizes of the underlying blocks. This method is relatively fast; a counter
|
||||
// is kept as blocks are allocated.
|
||||
uint64 SpaceAllocated() const { return impl_.SpaceAllocated(); }
|
||||
// Returns the total space used by the arena. Similar to SpaceAllocated but
|
||||
// does not include free space and block overhead. The total space returned
|
||||
// may not include space used by other threads executing concurrently with
|
||||
// the call to this method.
|
||||
uint64 SpaceUsed() const { return impl_.SpaceUsed(); }
|
||||
|
||||
// Frees all storage allocated by this arena after calling destructors
|
||||
// registered with OwnDestructor() and freeing objects registered with Own().
|
||||
// Any objects allocated on this arena are unusable after this call. It also
|
||||
// returns the total space used by the arena which is the sums of the sizes
|
||||
// of the allocated blocks. This method is not thread-safe.
|
||||
PROTOBUF_NOINLINE uint64 Reset() {
|
||||
// Call the reset hook
|
||||
if (on_arena_reset_ != NULL) {
|
||||
on_arena_reset_(this, hooks_cookie_, impl_.SpaceAllocated());
|
||||
}
|
||||
return impl_.Reset();
|
||||
}
|
||||
|
||||
// Adds |object| to a list of heap-allocated objects to be freed with |delete|
|
||||
// when the arena is destroyed or reset.
|
||||
template <typename T>
|
||||
PROTOBUF_NOINLINE void Own(T* object) {
|
||||
OwnInternal(object, std::is_convertible<T*, Message*>());
|
||||
}
|
||||
|
||||
// Adds |object| to a list of objects whose destructors will be manually
|
||||
// called when the arena is destroyed or reset. This differs from Own() in
|
||||
// that it does not free the underlying memory with |delete|; hence, it is
|
||||
// normally only used for objects that are placement-newed into
|
||||
// arena-allocated memory.
|
||||
template <typename T>
|
||||
PROTOBUF_NOINLINE void OwnDestructor(T* object) {
|
||||
if (object != NULL) {
|
||||
impl_.AddCleanup(object, &internal::arena_destruct_object<T>);
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a custom member function on an object to the list of destructors that
|
||||
// will be manually called when the arena is destroyed or reset. This differs
|
||||
// from OwnDestructor() in that any member function may be specified, not only
|
||||
// the class destructor.
|
||||
PROTOBUF_NOINLINE void OwnCustomDestructor(void* object,
|
||||
void (*destruct)(void*)) {
|
||||
impl_.AddCleanup(object, destruct);
|
||||
}
|
||||
|
||||
// Retrieves the arena associated with |value| if |value| is an arena-capable
|
||||
// message, or NULL otherwise. If possible, the call resolves at compile time.
|
||||
// Note that we can often devirtualize calls to `value->GetArena()` so usually
|
||||
// calling this method is unnecessary.
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE static Arena* GetArena(const T* value) {
|
||||
return GetArenaInternal(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class InternalHelper {
|
||||
template <typename U>
|
||||
static char DestructorSkippable(const typename U::DestructorSkippable_*);
|
||||
template <typename U>
|
||||
static double DestructorSkippable(...);
|
||||
|
||||
typedef std::integral_constant<
|
||||
bool, sizeof(DestructorSkippable<T>(static_cast<const T*>(0))) ==
|
||||
sizeof(char) ||
|
||||
std::is_trivially_destructible<T>::value>
|
||||
is_destructor_skippable;
|
||||
|
||||
template <typename U>
|
||||
static char ArenaConstructable(
|
||||
const typename U::InternalArenaConstructable_*);
|
||||
template <typename U>
|
||||
static double ArenaConstructable(...);
|
||||
|
||||
typedef std::integral_constant<bool, sizeof(ArenaConstructable<T>(
|
||||
static_cast<const T*>(0))) ==
|
||||
sizeof(char)>
|
||||
is_arena_constructable;
|
||||
|
||||
template <typename U,
|
||||
typename std::enable_if<
|
||||
std::is_same<Arena*, decltype(std::declval<const U>()
|
||||
.GetArena())>::value,
|
||||
int>::type = 0>
|
||||
static char HasGetArena(decltype(&U::GetArena));
|
||||
template <typename U>
|
||||
static double HasGetArena(...);
|
||||
|
||||
typedef std::integral_constant<bool, sizeof(HasGetArena<T>(nullptr)) ==
|
||||
sizeof(char)>
|
||||
has_get_arena;
|
||||
|
||||
template <typename... Args>
|
||||
static T* Construct(void* ptr, Args&&... args) {
|
||||
return new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static Arena* GetArena(const T* p) { return p->GetArena(); }
|
||||
|
||||
friend class Arena;
|
||||
};
|
||||
|
||||
// Helper typetraits that indicates support for arenas in a type T at compile
|
||||
// time. This is public only to allow construction of higher-level templated
|
||||
// utilities.
|
||||
//
|
||||
// is_arena_constructable<T>::value is true if the message type T has arena
|
||||
// support enabled, and false otherwise.
|
||||
//
|
||||
// is_destructor_skippable<T>::value is true if the message type T has told
|
||||
// the arena that it is safe to skip the destructor, and false otherwise.
|
||||
//
|
||||
// This is inside Arena because only Arena has the friend relationships
|
||||
// necessary to see the underlying generated code traits.
|
||||
template <typename T>
|
||||
struct is_arena_constructable : InternalHelper<T>::is_arena_constructable {};
|
||||
template <typename T>
|
||||
struct is_destructor_skippable : InternalHelper<T>::is_destructor_skippable {
|
||||
};
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
struct has_get_arena : InternalHelper<T>::has_get_arena {};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateMessageInternal(Arena* arena,
|
||||
Args&&... args) {
|
||||
static_assert(
|
||||
InternalHelper<T>::is_arena_constructable::value,
|
||||
"CreateMessage can only construct types that are ArenaConstructable");
|
||||
if (arena == NULL) {
|
||||
return new T(nullptr, std::forward<Args>(args)...);
|
||||
} else {
|
||||
return arena->DoCreateMessage<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
// This specialization for no arguments is necessary, because its behavior is
|
||||
// slightly different. When the arena pointer is nullptr, it calls T()
|
||||
// instead of T(nullptr).
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateMessageInternal(Arena* arena) {
|
||||
static_assert(
|
||||
InternalHelper<T>::is_arena_constructable::value,
|
||||
"CreateMessage can only construct types that are ArenaConstructable");
|
||||
if (arena == NULL) {
|
||||
return new T();
|
||||
} else {
|
||||
return arena->DoCreateMessage<T>();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateInternal(Arena* arena,
|
||||
Args&&... args) {
|
||||
if (arena == NULL) {
|
||||
return new T(std::forward<Args>(args)...);
|
||||
} else {
|
||||
return arena->DoCreate<T>(std::is_trivially_destructible<T>::value,
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
void CallDestructorHooks();
|
||||
void OnArenaAllocation(const std::type_info* allocated_type, size_t n) const;
|
||||
inline void AllocHook(const std::type_info* allocated_type, size_t n) const {
|
||||
if (PROTOBUF_PREDICT_FALSE(hooks_cookie_ != NULL)) {
|
||||
OnArenaAllocation(allocated_type, n);
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate and also optionally call on_arena_allocation callback with the
|
||||
// allocated type info when the hooks are in place in ArenaOptions and
|
||||
// the cookie is not null.
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void* AllocateInternal(bool skip_explicit_ownership) {
|
||||
static_assert(alignof(T) <= 8, "T is overaligned, see b/151247138");
|
||||
const size_t n = internal::AlignUpTo8(sizeof(T));
|
||||
AllocHook(RTTI_TYPE_ID(T), n);
|
||||
// Monitor allocation if needed.
|
||||
if (skip_explicit_ownership) {
|
||||
return AllocateAlignedNoHook(n);
|
||||
} else {
|
||||
return impl_.AllocateAlignedAndAddCleanup(
|
||||
n, &internal::arena_destruct_object<T>);
|
||||
}
|
||||
}
|
||||
|
||||
// CreateMessage<T> requires that T supports arenas, but this private method
|
||||
// works whether or not T supports arenas. These are not exposed to user code
|
||||
// as it can cause confusing API usages, and end up having double free in
|
||||
// user code. These are used only internally from LazyField and Repeated
|
||||
// fields, since they are designed to work in all mode combinations.
|
||||
template <typename Msg, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static Msg* DoCreateMaybeMessage(Arena* arena,
|
||||
std::true_type,
|
||||
Args&&... args) {
|
||||
return CreateMessageInternal<Msg>(arena, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* DoCreateMaybeMessage(Arena* arena,
|
||||
std::false_type,
|
||||
Args&&... args) {
|
||||
return CreateInternal<T>(arena, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateMaybeMessage(Arena* arena,
|
||||
Args&&... args) {
|
||||
return DoCreateMaybeMessage<T>(arena, is_arena_constructable<T>(),
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateNoMessage(Arena* arena, std::true_type,
|
||||
Args&&... args) {
|
||||
// User is constructing with Create() despite the fact that T supports arena
|
||||
// construction. In this case we have to delegate to CreateInternal(), and
|
||||
// we can't use any CreateMaybeMessage() specialization that may be defined.
|
||||
return CreateInternal<T>(arena, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE static T* CreateNoMessage(Arena* arena,
|
||||
std::false_type,
|
||||
Args&&... args) {
|
||||
// User is constructing with Create() and the type does not support arena
|
||||
// construction. In this case we can delegate to CreateMaybeMessage() and
|
||||
// use any specialization that may be available for that.
|
||||
return CreateMaybeMessage<T>(arena, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// Just allocate the required size for the given type assuming the
|
||||
// type has a trivial constructor.
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE T* CreateInternalRawArray(size_t num_elements) {
|
||||
GOOGLE_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T))
|
||||
<< "Requested size is too large to fit into size_t.";
|
||||
const size_t n = internal::AlignUpTo8(sizeof(T) * num_elements);
|
||||
// Monitor allocation if needed.
|
||||
AllocHook(RTTI_TYPE_ID(T), n);
|
||||
return static_cast<T*>(AllocateAlignedNoHook(n));
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE T* DoCreate(bool skip_explicit_ownership,
|
||||
Args&&... args) {
|
||||
return new (AllocateInternal<T>(skip_explicit_ownership))
|
||||
T(std::forward<Args>(args)...);
|
||||
}
|
||||
template <typename T, typename... Args>
|
||||
PROTOBUF_ALWAYS_INLINE T* DoCreateMessage(Args&&... args) {
|
||||
return InternalHelper<T>::Construct(
|
||||
AllocateInternal<T>(InternalHelper<T>::is_destructor_skippable::value),
|
||||
this, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// CreateInArenaStorage is used to implement map field. Without it,
|
||||
// Map need to call generated message's protected arena constructor,
|
||||
// which needs to declare Map as friend of generated message.
|
||||
template <typename T, typename... Args>
|
||||
static void CreateInArenaStorage(T* ptr, Arena* arena, Args&&... args) {
|
||||
CreateInArenaStorageInternal(ptr, arena,
|
||||
typename is_arena_constructable<T>::type(),
|
||||
std::forward<Args>(args)...);
|
||||
RegisterDestructorInternal(
|
||||
ptr, arena,
|
||||
typename InternalHelper<T>::is_destructor_skippable::type());
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static void CreateInArenaStorageInternal(T* ptr, Arena* arena,
|
||||
std::true_type, Args&&... args) {
|
||||
InternalHelper<T>::Construct(ptr, arena, std::forward<Args>(args)...);
|
||||
}
|
||||
template <typename T, typename... Args>
|
||||
static void CreateInArenaStorageInternal(T* ptr, Arena* /* arena */,
|
||||
std::false_type, Args&&... args) {
|
||||
new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void RegisterDestructorInternal(T* /* ptr */, Arena* /* arena */,
|
||||
std::true_type) {}
|
||||
template <typename T>
|
||||
static void RegisterDestructorInternal(T* ptr, Arena* arena,
|
||||
std::false_type) {
|
||||
arena->OwnDestructor(ptr);
|
||||
}
|
||||
|
||||
// These implement Own(), which registers an object for deletion (destructor
|
||||
// call and operator delete()). The second parameter has type 'true_type' if T
|
||||
// is a subtype of Message and 'false_type' otherwise. Collapsing
|
||||
// all template instantiations to one for generic Message reduces code size,
|
||||
// using the virtual destructor instead.
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void OwnInternal(T* object, std::true_type) {
|
||||
if (object != NULL) {
|
||||
impl_.AddCleanup(object, &internal::arena_delete_object<Message>);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void OwnInternal(T* object, std::false_type) {
|
||||
if (object != NULL) {
|
||||
impl_.AddCleanup(object, &internal::arena_delete_object<T>);
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation for GetArena(). Only message objects with
|
||||
// InternalArenaConstructable_ tags can be associated with an arena, and such
|
||||
// objects must implement a GetArena() method.
|
||||
template <typename T, typename std::enable_if<
|
||||
is_arena_constructable<T>::value, int>::type = 0>
|
||||
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
|
||||
return InternalHelper<T>::GetArena(value);
|
||||
}
|
||||
template <typename T,
|
||||
typename std::enable_if<!is_arena_constructable<T>::value &&
|
||||
has_get_arena<T>::value,
|
||||
int>::type = 0>
|
||||
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
|
||||
return value->GetArena();
|
||||
}
|
||||
template <typename T,
|
||||
typename std::enable_if<!is_arena_constructable<T>::value &&
|
||||
!has_get_arena<T>::value,
|
||||
int>::type = 0>
|
||||
PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) {
|
||||
(void)value;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// For friends of arena.
|
||||
void* AllocateAligned(size_t n) {
|
||||
AllocHook(NULL, n);
|
||||
return AllocateAlignedNoHook(internal::AlignUpTo8(n));
|
||||
}
|
||||
template<size_t Align>
|
||||
void* AllocateAlignedTo(size_t n) {
|
||||
static_assert(Align > 0, "Alignment must be greater than 0");
|
||||
static_assert((Align & (Align - 1)) == 0, "Alignment must be power of two");
|
||||
if (Align <= 8) return AllocateAligned(n);
|
||||
// TODO(b/151247138): if the pointer would have been aligned already,
|
||||
// this is wasting space. We should pass the alignment down.
|
||||
uintptr_t ptr = reinterpret_cast<uintptr_t>(AllocateAligned(n + Align - 8));
|
||||
ptr = (ptr + Align - 1) & -Align;
|
||||
return reinterpret_cast<void*>(ptr);
|
||||
}
|
||||
|
||||
void* AllocateAlignedNoHook(size_t n);
|
||||
|
||||
internal::ArenaImpl impl_;
|
||||
|
||||
void (*on_arena_allocation_)(const std::type_info* allocated_type,
|
||||
uint64 alloc_size, void* cookie);
|
||||
void (*on_arena_reset_)(Arena* arena, void* cookie, uint64 space_used);
|
||||
void (*on_arena_destruction_)(Arena* arena, void* cookie, uint64 space_used);
|
||||
|
||||
// The arena may save a cookie it receives from the external on_init hook
|
||||
// and then use it when calling the on_reset and on_destruction hooks.
|
||||
void* hooks_cookie_;
|
||||
|
||||
template <typename Type>
|
||||
friend class internal::GenericTypeHandler;
|
||||
friend struct internal::ArenaStringPtr; // For AllocateAligned.
|
||||
friend class internal::LazyField; // For CreateMaybeMessage.
|
||||
friend class internal::EpsCopyInputStream; // For parser performance
|
||||
friend class MessageLite;
|
||||
template <typename Key, typename T>
|
||||
friend class Map;
|
||||
};
|
||||
|
||||
// Defined above for supporting environments without RTTI.
|
||||
#undef RTTI_TYPE_ID
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_ARENA_H__
|
389
include/google/protobuf/arena_impl.h
Normal file
389
include/google/protobuf/arena_impl.h
Normal file
@ -0,0 +1,389 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file defines an Arena allocator for better allocation performance.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_ARENA_IMPL_H__
|
||||
#define GOOGLE_PROTOBUF_ARENA_IMPL_H__
|
||||
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
|
||||
#ifdef ADDRESS_SANITIZER
|
||||
#include <sanitizer/asan_interface.h>
|
||||
#endif // ADDRESS_SANITIZER
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
inline size_t AlignUpTo8(size_t n) {
|
||||
// Align n to next multiple of 8 (from Hacker's Delight, Chapter 3.)
|
||||
return (n + 7) & static_cast<size_t>(-8);
|
||||
}
|
||||
|
||||
using LifecycleId = int64_t;
|
||||
|
||||
// This class provides the core Arena memory allocation library. Different
|
||||
// implementations only need to implement the public interface below.
|
||||
// Arena is not a template type as that would only be useful if all protos
|
||||
// in turn would be templates, which will/cannot happen. However separating
|
||||
// the memory allocation part from the cruft of the API users expect we can
|
||||
// use #ifdef the select the best implementation based on hardware / OS.
|
||||
class PROTOBUF_EXPORT ArenaImpl {
|
||||
public:
|
||||
struct Options {
|
||||
size_t start_block_size;
|
||||
size_t max_block_size;
|
||||
char* initial_block;
|
||||
size_t initial_block_size;
|
||||
void* (*block_alloc)(size_t);
|
||||
void (*block_dealloc)(void*, size_t);
|
||||
|
||||
template <typename O>
|
||||
explicit Options(const O& options)
|
||||
: start_block_size(options.start_block_size),
|
||||
max_block_size(options.max_block_size),
|
||||
initial_block(options.initial_block),
|
||||
initial_block_size(options.initial_block_size),
|
||||
block_alloc(options.block_alloc),
|
||||
block_dealloc(options.block_dealloc) {}
|
||||
};
|
||||
|
||||
template <typename O>
|
||||
explicit ArenaImpl(const O& options) : options_(options) {
|
||||
if (options_.initial_block != NULL && options_.initial_block_size > 0) {
|
||||
GOOGLE_CHECK_GE(options_.initial_block_size, sizeof(Block))
|
||||
<< ": Initial block size too small for header.";
|
||||
initial_block_ = reinterpret_cast<Block*>(options_.initial_block);
|
||||
} else {
|
||||
initial_block_ = NULL;
|
||||
}
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
// Destructor deletes all owned heap allocated objects, and destructs objects
|
||||
// that have non-trivial destructors, except for proto2 message objects whose
|
||||
// destructors can be skipped. Also, frees all blocks except the initial block
|
||||
// if it was passed in.
|
||||
~ArenaImpl();
|
||||
|
||||
uint64 Reset();
|
||||
|
||||
uint64 SpaceAllocated() const;
|
||||
uint64 SpaceUsed() const;
|
||||
|
||||
void* AllocateAligned(size_t n) {
|
||||
SerialArena* arena;
|
||||
if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) {
|
||||
return arena->AllocateAligned(n);
|
||||
} else {
|
||||
return AllocateAlignedFallback(n);
|
||||
}
|
||||
}
|
||||
|
||||
// This function allocates n bytes if the common happy case is true and
|
||||
// returns true. Otherwise does nothing and returns false. This strange
|
||||
// semantics is necessary to allow callers to program functions that only
|
||||
// have fallback function calls in tail position. This substantially improves
|
||||
// code for the happy path.
|
||||
PROTOBUF_ALWAYS_INLINE bool MaybeAllocateAligned(size_t n, void** out) {
|
||||
SerialArena* a;
|
||||
if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFromThreadCache(&a))) {
|
||||
return a->MaybeAllocateAligned(n, out);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void* AllocateAlignedAndAddCleanup(size_t n, void (*cleanup)(void*));
|
||||
|
||||
// Add object pointer and cleanup function pointer to the list.
|
||||
void AddCleanup(void* elem, void (*cleanup)(void*));
|
||||
|
||||
private:
|
||||
friend class ArenaBenchmark;
|
||||
|
||||
void* AllocateAlignedFallback(size_t n);
|
||||
void* AllocateAlignedAndAddCleanupFallback(size_t n, void (*cleanup)(void*));
|
||||
void AddCleanupFallback(void* elem, void (*cleanup)(void*));
|
||||
|
||||
// Node contains the ptr of the object to be cleaned up and the associated
|
||||
// cleanup function ptr.
|
||||
struct CleanupNode {
|
||||
void* elem; // Pointer to the object to be cleaned up.
|
||||
void (*cleanup)(void*); // Function pointer to the destructor or deleter.
|
||||
};
|
||||
|
||||
// Cleanup uses a chunked linked list, to reduce pointer chasing.
|
||||
struct CleanupChunk {
|
||||
static size_t SizeOf(size_t i) {
|
||||
return sizeof(CleanupChunk) + (sizeof(CleanupNode) * (i - 1));
|
||||
}
|
||||
size_t size; // Total elements in the list.
|
||||
CleanupChunk* next; // Next node in the list.
|
||||
CleanupNode nodes[1]; // True length is |size|.
|
||||
};
|
||||
|
||||
class Block;
|
||||
|
||||
// A thread-unsafe Arena that can only be used within its owning thread.
|
||||
class PROTOBUF_EXPORT SerialArena {
|
||||
public:
|
||||
// The allocate/free methods here are a little strange, since SerialArena is
|
||||
// allocated inside a Block which it also manages. This is to avoid doing
|
||||
// an extra allocation for the SerialArena itself.
|
||||
|
||||
// Creates a new SerialArena inside Block* and returns it.
|
||||
static SerialArena* New(Block* b, void* owner, ArenaImpl* arena);
|
||||
|
||||
// Destroys this SerialArena, freeing all blocks with the given dealloc
|
||||
// function, except any block equal to |initial_block|.
|
||||
static uint64 Free(SerialArena* serial, Block* initial_block,
|
||||
void (*block_dealloc)(void*, size_t));
|
||||
|
||||
void CleanupList();
|
||||
uint64 SpaceUsed() const;
|
||||
|
||||
bool HasSpace(size_t n) { return n <= static_cast<size_t>(limit_ - ptr_); }
|
||||
|
||||
void* AllocateAligned(size_t n) {
|
||||
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned.
|
||||
GOOGLE_DCHECK_GE(limit_, ptr_);
|
||||
if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) {
|
||||
return AllocateAlignedFallback(n);
|
||||
}
|
||||
void* ret = ptr_;
|
||||
ptr_ += n;
|
||||
#ifdef ADDRESS_SANITIZER
|
||||
ASAN_UNPOISON_MEMORY_REGION(ret, n);
|
||||
#endif // ADDRESS_SANITIZER
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Allocate space if the current region provides enough space.
|
||||
bool MaybeAllocateAligned(size_t n, void** out) {
|
||||
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned.
|
||||
GOOGLE_DCHECK_GE(limit_, ptr_);
|
||||
if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) return false;
|
||||
void* ret = ptr_;
|
||||
ptr_ += n;
|
||||
#ifdef ADDRESS_SANITIZER
|
||||
ASAN_UNPOISON_MEMORY_REGION(ret, n);
|
||||
#endif // ADDRESS_SANITIZER
|
||||
*out = ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddCleanup(void* elem, void (*cleanup)(void*)) {
|
||||
if (PROTOBUF_PREDICT_FALSE(cleanup_ptr_ == cleanup_limit_)) {
|
||||
AddCleanupFallback(elem, cleanup);
|
||||
return;
|
||||
}
|
||||
cleanup_ptr_->elem = elem;
|
||||
cleanup_ptr_->cleanup = cleanup;
|
||||
cleanup_ptr_++;
|
||||
}
|
||||
|
||||
void* AllocateAlignedAndAddCleanup(size_t n, void (*cleanup)(void*)) {
|
||||
void* ret = AllocateAligned(n);
|
||||
AddCleanup(ret, cleanup);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* owner() const { return owner_; }
|
||||
SerialArena* next() const { return next_; }
|
||||
void set_next(SerialArena* next) { next_ = next; }
|
||||
|
||||
private:
|
||||
void* AllocateAlignedFallback(size_t n);
|
||||
void AddCleanupFallback(void* elem, void (*cleanup)(void*));
|
||||
void CleanupListFallback();
|
||||
|
||||
ArenaImpl* arena_; // Containing arena.
|
||||
void* owner_; // &ThreadCache of this thread;
|
||||
Block* head_; // Head of linked list of blocks.
|
||||
CleanupChunk* cleanup_; // Head of cleanup list.
|
||||
SerialArena* next_; // Next SerialArena in this linked list.
|
||||
|
||||
// Next pointer to allocate from. Always 8-byte aligned. Points inside
|
||||
// head_ (and head_->pos will always be non-canonical). We keep these
|
||||
// here to reduce indirection.
|
||||
char* ptr_;
|
||||
char* limit_;
|
||||
|
||||
// Next CleanupList members to append to. These point inside cleanup_.
|
||||
CleanupNode* cleanup_ptr_;
|
||||
CleanupNode* cleanup_limit_;
|
||||
};
|
||||
|
||||
// Blocks are variable length malloc-ed objects. The following structure
|
||||
// describes the common header for all blocks.
|
||||
class PROTOBUF_EXPORT Block {
|
||||
public:
|
||||
Block(size_t size, Block* next);
|
||||
|
||||
char* Pointer(size_t n) {
|
||||
GOOGLE_DCHECK(n <= size_);
|
||||
return reinterpret_cast<char*>(this) + n;
|
||||
}
|
||||
|
||||
Block* next() const { return next_; }
|
||||
size_t pos() const { return pos_; }
|
||||
size_t size() const { return size_; }
|
||||
void set_pos(size_t pos) { pos_ = pos; }
|
||||
|
||||
private:
|
||||
Block* next_; // Next block for this thread.
|
||||
size_t pos_;
|
||||
size_t size_;
|
||||
// data follows
|
||||
};
|
||||
|
||||
struct ThreadCache {
|
||||
#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
|
||||
// If we are using the ThreadLocalStorage class to store the ThreadCache,
|
||||
// then the ThreadCache's default constructor has to be responsible for
|
||||
// initializing it.
|
||||
ThreadCache() : last_lifecycle_id_seen(-1), last_serial_arena(NULL) {}
|
||||
#endif
|
||||
|
||||
// The ThreadCache is considered valid as long as this matches the
|
||||
// lifecycle_id of the arena being used.
|
||||
LifecycleId last_lifecycle_id_seen;
|
||||
SerialArena* last_serial_arena;
|
||||
};
|
||||
static std::atomic<LifecycleId> lifecycle_id_generator_;
|
||||
#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
|
||||
// Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom thread
|
||||
// local storage class we implemented.
|
||||
// iOS also does not support the GOOGLE_THREAD_LOCAL keyword.
|
||||
static ThreadCache& thread_cache();
|
||||
#elif defined(PROTOBUF_USE_DLLS)
|
||||
// Thread local variables cannot be exposed through DLL interface but we can
|
||||
// wrap them in static functions.
|
||||
static ThreadCache& thread_cache();
|
||||
#else
|
||||
static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_;
|
||||
static ThreadCache& thread_cache() { return thread_cache_; }
|
||||
#endif
|
||||
|
||||
void Init();
|
||||
|
||||
// Free all blocks and return the total space used which is the sums of sizes
|
||||
// of the all the allocated blocks.
|
||||
uint64 FreeBlocks();
|
||||
// Delete or Destruct all objects owned by the arena.
|
||||
void CleanupList();
|
||||
|
||||
inline void CacheSerialArena(SerialArena* serial) {
|
||||
thread_cache().last_serial_arena = serial;
|
||||
thread_cache().last_lifecycle_id_seen = lifecycle_id_;
|
||||
// TODO(haberman): evaluate whether we would gain efficiency by getting rid
|
||||
// of hint_. It's the only write we do to ArenaImpl in the allocation path,
|
||||
// which will dirty the cache line.
|
||||
|
||||
hint_.store(serial, std::memory_order_release);
|
||||
}
|
||||
|
||||
std::atomic<SerialArena*>
|
||||
threads_; // Pointer to a linked list of SerialArena.
|
||||
std::atomic<SerialArena*> hint_; // Fast thread-local block access
|
||||
std::atomic<size_t> space_allocated_; // Total size of all allocated blocks.
|
||||
|
||||
Block* initial_block_; // If non-NULL, points to the block that came from
|
||||
// user data.
|
||||
|
||||
Block* NewBlock(Block* last_block, size_t min_bytes);
|
||||
|
||||
SerialArena* GetSerialArena();
|
||||
PROTOBUF_ALWAYS_INLINE bool GetSerialArenaFast(SerialArena** arena) {
|
||||
if (GetSerialArenaFromThreadCache(arena)) return true;
|
||||
|
||||
// Check whether we own the last accessed SerialArena on this arena. This
|
||||
// fast path optimizes the case where a single thread uses multiple arenas.
|
||||
ThreadCache* tc = &thread_cache();
|
||||
SerialArena* serial = hint_.load(std::memory_order_acquire);
|
||||
if (PROTOBUF_PREDICT_TRUE(serial != NULL && serial->owner() == tc)) {
|
||||
*arena = serial;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PROTOBUF_ALWAYS_INLINE bool GetSerialArenaFromThreadCache(
|
||||
SerialArena** arena) {
|
||||
// If this thread already owns a block in this arena then try to use that.
|
||||
// This fast path optimizes the case where multiple threads allocate from
|
||||
// the same arena.
|
||||
ThreadCache* tc = &thread_cache();
|
||||
if (PROTOBUF_PREDICT_TRUE(tc->last_lifecycle_id_seen == lifecycle_id_)) {
|
||||
*arena = tc->last_serial_arena;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
SerialArena* GetSerialArenaFallback(void* me);
|
||||
LifecycleId lifecycle_id_; // Unique for each arena. Changes on Reset().
|
||||
|
||||
Options options_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArenaImpl);
|
||||
// All protos have pointers back to the arena hence Arena must have
|
||||
// pointer stability.
|
||||
ArenaImpl(ArenaImpl&&) = delete;
|
||||
ArenaImpl& operator=(ArenaImpl&&) = delete;
|
||||
|
||||
public:
|
||||
// kBlockHeaderSize is sizeof(Block), aligned up to the nearest multiple of 8
|
||||
// to protect the invariant that pos is always at a multiple of 8.
|
||||
static const size_t kBlockHeaderSize =
|
||||
(sizeof(Block) + 7) & static_cast<size_t>(-8);
|
||||
static const size_t kSerialArenaSize =
|
||||
(sizeof(SerialArena) + 7) & static_cast<size_t>(-8);
|
||||
static_assert(kBlockHeaderSize % 8 == 0,
|
||||
"kBlockHeaderSize must be a multiple of 8.");
|
||||
static_assert(kSerialArenaSize % 8 == 0,
|
||||
"kSerialArenaSize must be a multiple of 8.");
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_ARENA_IMPL_H__
|
405
include/google/protobuf/arenastring.h
Normal file
405
include/google/protobuf/arenastring.h
Normal file
@ -0,0 +1,405 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_ARENASTRING_H__
|
||||
#define GOOGLE_PROTOBUF_ARENASTRING_H__
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/fastmem.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/port.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
|
||||
// This is the implementation of arena string fields written for the open-source
|
||||
// release. The ArenaStringPtr struct below is an internal implementation class
|
||||
// and *should not be used* by user code. It is used to collect string
|
||||
// operations together into one place and abstract away the underlying
|
||||
// string-field pointer representation, so that (for example) an alternate
|
||||
// implementation that knew more about ::std::string's internals could integrate
|
||||
// more closely with the arena allocator.
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
template <typename T>
|
||||
class TaggedPtr {
|
||||
public:
|
||||
void Set(T* p) { ptr_ = reinterpret_cast<uintptr_t>(p); }
|
||||
T* Get() const { return reinterpret_cast<T*>(ptr_); }
|
||||
|
||||
bool IsNull() { return ptr_ == 0; }
|
||||
|
||||
private:
|
||||
uintptr_t ptr_;
|
||||
};
|
||||
|
||||
struct PROTOBUF_EXPORT ArenaStringPtr {
|
||||
inline void Set(const ::std::string* default_value,
|
||||
const ::std::string& value, Arena* arena) {
|
||||
if (ptr_ == default_value) {
|
||||
CreateInstance(arena, &value);
|
||||
} else {
|
||||
*ptr_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetLite(const ::std::string* default_value,
|
||||
const ::std::string& value, Arena* arena) {
|
||||
Set(default_value, value, arena);
|
||||
}
|
||||
|
||||
// Basic accessors.
|
||||
inline const ::std::string& Get() const { return *ptr_; }
|
||||
|
||||
inline ::std::string* Mutable(const ::std::string* default_value,
|
||||
Arena* arena) {
|
||||
if (ptr_ == default_value) {
|
||||
CreateInstance(arena, default_value);
|
||||
}
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
// Release returns a ::std::string* instance that is heap-allocated and is not
|
||||
// Own()'d by any arena. If the field was not set, it returns NULL. The caller
|
||||
// retains ownership. Clears this field back to NULL state. Used to implement
|
||||
// release_<field>() methods on generated classes.
|
||||
inline ::std::string* Release(const ::std::string* default_value,
|
||||
Arena* arena) {
|
||||
if (ptr_ == default_value) {
|
||||
return NULL;
|
||||
}
|
||||
return ReleaseNonDefault(default_value, arena);
|
||||
}
|
||||
|
||||
// Similar to Release, but ptr_ cannot be the default_value.
|
||||
inline ::std::string* ReleaseNonDefault(const ::std::string* default_value,
|
||||
Arena* arena) {
|
||||
GOOGLE_DCHECK(!IsDefault(default_value));
|
||||
::std::string* released = NULL;
|
||||
if (arena != NULL) {
|
||||
// ptr_ is owned by the arena.
|
||||
released = new ::std::string;
|
||||
released->swap(*ptr_);
|
||||
} else {
|
||||
released = ptr_;
|
||||
}
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
return released;
|
||||
}
|
||||
|
||||
// UnsafeArenaRelease returns a ::std::string*, but it may be arena-owned
|
||||
// (i.e. have its destructor already registered) if arena != NULL. If the
|
||||
// field was not set, this returns NULL. This method clears this field back to
|
||||
// NULL state. Used to implement unsafe_arena_release_<field>() methods on
|
||||
// generated classes.
|
||||
inline ::std::string* UnsafeArenaRelease(const ::std::string* default_value,
|
||||
Arena* /* arena */) {
|
||||
if (ptr_ == default_value) {
|
||||
return NULL;
|
||||
}
|
||||
::std::string* released = ptr_;
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
return released;
|
||||
}
|
||||
|
||||
// Takes a string that is heap-allocated, and takes ownership. The string's
|
||||
// destructor is registered with the arena. Used to implement
|
||||
// set_allocated_<field> in generated classes.
|
||||
inline void SetAllocated(const ::std::string* default_value,
|
||||
::std::string* value, Arena* arena) {
|
||||
if (arena == NULL && ptr_ != default_value) {
|
||||
Destroy(default_value, arena);
|
||||
}
|
||||
if (value != NULL) {
|
||||
ptr_ = value;
|
||||
if (arena != NULL) {
|
||||
arena->Own(value);
|
||||
}
|
||||
} else {
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
}
|
||||
}
|
||||
|
||||
// Takes a string that has lifetime equal to the arena's lifetime. The arena
|
||||
// must be non-null. It is safe only to pass this method a value returned by
|
||||
// UnsafeArenaRelease() on another field of a message in the same arena. Used
|
||||
// to implement unsafe_arena_set_allocated_<field> in generated classes.
|
||||
inline void UnsafeArenaSetAllocated(const ::std::string* default_value,
|
||||
::std::string* value,
|
||||
Arena* /* arena */) {
|
||||
if (value != NULL) {
|
||||
ptr_ = value;
|
||||
} else {
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
}
|
||||
}
|
||||
|
||||
// Swaps internal pointers. Arena-safety semantics: this is guarded by the
|
||||
// logic in Swap()/UnsafeArenaSwap() at the message level, so this method is
|
||||
// 'unsafe' if called directly.
|
||||
PROTOBUF_ALWAYS_INLINE void Swap(ArenaStringPtr* other) {
|
||||
std::swap(ptr_, other->ptr_);
|
||||
}
|
||||
PROTOBUF_ALWAYS_INLINE void Swap(ArenaStringPtr* other,
|
||||
const ::std::string* default_value,
|
||||
Arena* arena) {
|
||||
#ifndef NDEBUG
|
||||
// For debug builds, we swap the contents of the string, rather than the
|
||||
// string instances themselves. This invalidates previously taken const
|
||||
// references that are (per our documentation) invalidated by calling Swap()
|
||||
// on the message.
|
||||
//
|
||||
// If both strings are the default_value, swapping is uninteresting.
|
||||
// Otherwise, we use ArenaStringPtr::Mutable() to access the string, to
|
||||
// ensure that we do not try to mutate default_value itself.
|
||||
if (IsDefault(default_value) && other->IsDefault(default_value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
::std::string* this_ptr = Mutable(default_value, arena);
|
||||
::std::string* other_ptr = other->Mutable(default_value, arena);
|
||||
|
||||
this_ptr->swap(*other_ptr);
|
||||
#else
|
||||
std::swap(ptr_, other->ptr_);
|
||||
(void)default_value;
|
||||
(void)arena;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Frees storage (if not on an arena).
|
||||
inline void Destroy(const ::std::string* default_value, Arena* arena) {
|
||||
if (arena == NULL && ptr_ != default_value) {
|
||||
delete ptr_;
|
||||
}
|
||||
}
|
||||
|
||||
// Clears content, but keeps allocated string if arena != NULL, to avoid the
|
||||
// overhead of heap operations. After this returns, the content (as seen by
|
||||
// the user) will always be the empty string. Assumes that |default_value|
|
||||
// is an empty string.
|
||||
inline void ClearToEmpty(const ::std::string* default_value,
|
||||
Arena* /* arena */) {
|
||||
if (ptr_ == default_value) {
|
||||
// Already set to default (which is empty) -- do nothing.
|
||||
} else {
|
||||
ptr_->clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Clears content, assuming that the current value is not the empty string
|
||||
// default.
|
||||
inline void ClearNonDefaultToEmpty() { ptr_->clear(); }
|
||||
inline void ClearNonDefaultToEmptyNoArena() { ptr_->clear(); }
|
||||
|
||||
// Clears content, but keeps allocated string if arena != NULL, to avoid the
|
||||
// overhead of heap operations. After this returns, the content (as seen by
|
||||
// the user) will always be equal to |default_value|.
|
||||
inline void ClearToDefault(const ::std::string* default_value,
|
||||
Arena* /* arena */) {
|
||||
if (ptr_ == default_value) {
|
||||
// Already set to default -- do nothing.
|
||||
} else {
|
||||
// Have another allocated string -- rather than throwing this away and
|
||||
// resetting ptr_ to the canonical default string instance, we just reuse
|
||||
// this instance.
|
||||
*ptr_ = *default_value;
|
||||
}
|
||||
}
|
||||
|
||||
// Called from generated code / reflection runtime only. Resets value to point
|
||||
// to a default string pointer, with the semantics that this ArenaStringPtr
|
||||
// does not own the pointed-to memory. Disregards initial value of ptr_ (so
|
||||
// this is the *ONLY* safe method to call after construction or when
|
||||
// reinitializing after becoming the active field in a oneof union).
|
||||
inline void UnsafeSetDefault(const ::std::string* default_value) {
|
||||
// Casting away 'const' is safe here: accessors ensure that ptr_ is only
|
||||
// returned as a const if it is equal to default_value.
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
}
|
||||
|
||||
// The 'NoArena' variants of methods below assume arena == NULL and are
|
||||
// optimized to provide very little overhead relative to a raw string pointer
|
||||
// (while still being in-memory compatible with other code that assumes
|
||||
// ArenaStringPtr). Note the invariant that a class instance that has only
|
||||
// ever been mutated by NoArena methods must *only* be in the String state
|
||||
// (i.e., tag bits are not used), *NEVER* ArenaString. This allows all
|
||||
// tagged-pointer manipulations to be avoided.
|
||||
inline void SetNoArena(const ::std::string* default_value,
|
||||
const ::std::string& value) {
|
||||
if (ptr_ == default_value) {
|
||||
CreateInstanceNoArena(&value);
|
||||
} else {
|
||||
*ptr_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
void SetNoArena(const ::std::string* default_value, ::std::string&& value) {
|
||||
if (IsDefault(default_value)) {
|
||||
ptr_ = new ::std::string(std::move(value));
|
||||
} else {
|
||||
*ptr_ = std::move(value);
|
||||
}
|
||||
}
|
||||
|
||||
void AssignWithDefault(const ::std::string* default_value,
|
||||
ArenaStringPtr value);
|
||||
|
||||
inline const ::std::string& GetNoArena() const { return *ptr_; }
|
||||
|
||||
inline ::std::string* MutableNoArena(const ::std::string* default_value) {
|
||||
if (ptr_ == default_value) {
|
||||
CreateInstanceNoArena(default_value);
|
||||
}
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
inline ::std::string* ReleaseNoArena(const ::std::string* default_value) {
|
||||
if (ptr_ == default_value) {
|
||||
return NULL;
|
||||
} else {
|
||||
return ReleaseNonDefaultNoArena(default_value);
|
||||
}
|
||||
}
|
||||
|
||||
inline ::std::string* ReleaseNonDefaultNoArena(
|
||||
const ::std::string* default_value) {
|
||||
GOOGLE_DCHECK(!IsDefault(default_value));
|
||||
::std::string* released = ptr_;
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
return released;
|
||||
}
|
||||
|
||||
inline void SetAllocatedNoArena(const ::std::string* default_value,
|
||||
::std::string* value) {
|
||||
if (ptr_ != default_value) {
|
||||
delete ptr_;
|
||||
}
|
||||
if (value != NULL) {
|
||||
ptr_ = value;
|
||||
} else {
|
||||
ptr_ = const_cast< ::std::string*>(default_value);
|
||||
}
|
||||
}
|
||||
|
||||
inline void DestroyNoArena(const ::std::string* default_value) {
|
||||
if (ptr_ != default_value) {
|
||||
delete ptr_;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ClearToEmptyNoArena(const ::std::string* default_value) {
|
||||
if (ptr_ == default_value) {
|
||||
// Nothing: already equal to default (which is the empty string).
|
||||
} else {
|
||||
ptr_->clear();
|
||||
}
|
||||
}
|
||||
|
||||
inline void ClearToDefaultNoArena(const ::std::string* default_value) {
|
||||
if (ptr_ == default_value) {
|
||||
// Nothing: already set to default.
|
||||
} else {
|
||||
// Reuse existing allocated instance.
|
||||
*ptr_ = *default_value;
|
||||
}
|
||||
}
|
||||
|
||||
// Internal accessor used only at parse time to provide direct access to the
|
||||
// raw pointer from the shared parse routine (in the non-arenas case). The
|
||||
// parse routine does the string allocation in order to save code size in the
|
||||
// generated parsing code.
|
||||
inline ::std::string** UnsafeRawStringPointer() { return &ptr_; }
|
||||
|
||||
inline bool IsDefault(const ::std::string* default_value) const {
|
||||
return ptr_ == default_value;
|
||||
}
|
||||
|
||||
// Internal accessors!!!!
|
||||
void UnsafeSetTaggedPointer(TaggedPtr< ::std::string> value) {
|
||||
ptr_ = value.Get();
|
||||
}
|
||||
// Generated code only! An optimization, in certain cases the generated
|
||||
// code is certain we can obtain a string with no default checks and
|
||||
// tag tests.
|
||||
::std::string* UnsafeMutablePointer() { return ptr_; }
|
||||
|
||||
private:
|
||||
::std::string* ptr_;
|
||||
|
||||
PROTOBUF_NOINLINE
|
||||
void CreateInstance(Arena* arena, const ::std::string* initial_value) {
|
||||
GOOGLE_DCHECK(initial_value != NULL);
|
||||
// uses "new ::std::string" when arena is nullptr
|
||||
ptr_ = Arena::Create< ::std::string>(arena, *initial_value);
|
||||
}
|
||||
PROTOBUF_NOINLINE
|
||||
void CreateInstanceNoArena(const ::std::string* initial_value) {
|
||||
GOOGLE_DCHECK(initial_value != NULL);
|
||||
ptr_ = new ::std::string(*initial_value);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
inline void ArenaStringPtr::AssignWithDefault(
|
||||
const ::std::string* default_value, ArenaStringPtr value) {
|
||||
const ::std::string* me = *UnsafeRawStringPointer();
|
||||
const ::std::string* other = *value.UnsafeRawStringPointer();
|
||||
// If the pointers are the same then do nothing.
|
||||
if (me != other) {
|
||||
SetNoArena(default_value, value.GetNoArena());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_ARENASTRING_H__
|
2315
include/google/protobuf/descriptor.h
Normal file
2315
include/google/protobuf/descriptor.h
Normal file
File diff suppressed because it is too large
Load Diff
13857
include/google/protobuf/descriptor.pb.h
Normal file
13857
include/google/protobuf/descriptor.pb.h
Normal file
File diff suppressed because it is too large
Load Diff
909
include/google/protobuf/descriptor.proto
Normal file
909
include/google/protobuf/descriptor.proto
Normal file
@ -0,0 +1,909 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// The messages in this file describe the definitions found in .proto files.
|
||||
// A valid .proto file can be translated directly to a FileDescriptorProto
|
||||
// without any other information (e.g. without reading its imports).
|
||||
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "DescriptorProtos";
|
||||
option csharp_namespace = "Google.Protobuf.Reflection";
|
||||
option objc_class_prefix = "GPB";
|
||||
option cc_enable_arenas = true;
|
||||
|
||||
// descriptor.proto must be optimized for speed because reflection-based
|
||||
// algorithms don't work during bootstrapping.
|
||||
option optimize_for = SPEED;
|
||||
|
||||
// The protocol compiler can output a FileDescriptorSet containing the .proto
|
||||
// files it parses.
|
||||
message FileDescriptorSet {
|
||||
repeated FileDescriptorProto file = 1;
|
||||
}
|
||||
|
||||
// Describes a complete .proto file.
|
||||
message FileDescriptorProto {
|
||||
optional string name = 1; // file name, relative to root of source tree
|
||||
optional string package = 2; // e.g. "foo", "foo.bar", etc.
|
||||
|
||||
// Names of files imported by this file.
|
||||
repeated string dependency = 3;
|
||||
// Indexes of the public imported files in the dependency list above.
|
||||
repeated int32 public_dependency = 10;
|
||||
// Indexes of the weak imported files in the dependency list.
|
||||
// For Google-internal migration only. Do not use.
|
||||
repeated int32 weak_dependency = 11;
|
||||
|
||||
// All top-level definitions in this file.
|
||||
repeated DescriptorProto message_type = 4;
|
||||
repeated EnumDescriptorProto enum_type = 5;
|
||||
repeated ServiceDescriptorProto service = 6;
|
||||
repeated FieldDescriptorProto extension = 7;
|
||||
|
||||
optional FileOptions options = 8;
|
||||
|
||||
// This field contains optional information about the original source code.
|
||||
// You may safely remove this entire field without harming runtime
|
||||
// functionality of the descriptors -- the information is needed only by
|
||||
// development tools.
|
||||
optional SourceCodeInfo source_code_info = 9;
|
||||
|
||||
// The syntax of the proto file.
|
||||
// The supported values are "proto2" and "proto3".
|
||||
optional string syntax = 12;
|
||||
}
|
||||
|
||||
// Describes a message type.
|
||||
message DescriptorProto {
|
||||
optional string name = 1;
|
||||
|
||||
repeated FieldDescriptorProto field = 2;
|
||||
repeated FieldDescriptorProto extension = 6;
|
||||
|
||||
repeated DescriptorProto nested_type = 3;
|
||||
repeated EnumDescriptorProto enum_type = 4;
|
||||
|
||||
message ExtensionRange {
|
||||
optional int32 start = 1; // Inclusive.
|
||||
optional int32 end = 2; // Exclusive.
|
||||
|
||||
optional ExtensionRangeOptions options = 3;
|
||||
}
|
||||
repeated ExtensionRange extension_range = 5;
|
||||
|
||||
repeated OneofDescriptorProto oneof_decl = 8;
|
||||
|
||||
optional MessageOptions options = 7;
|
||||
|
||||
// Range of reserved tag numbers. Reserved tag numbers may not be used by
|
||||
// fields or extension ranges in the same message. Reserved ranges may
|
||||
// not overlap.
|
||||
message ReservedRange {
|
||||
optional int32 start = 1; // Inclusive.
|
||||
optional int32 end = 2; // Exclusive.
|
||||
}
|
||||
repeated ReservedRange reserved_range = 9;
|
||||
// Reserved field names, which may not be used by fields in the same message.
|
||||
// A given name may only be reserved once.
|
||||
repeated string reserved_name = 10;
|
||||
}
|
||||
|
||||
message ExtensionRangeOptions {
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
// Describes a field within a message.
|
||||
message FieldDescriptorProto {
|
||||
enum Type {
|
||||
// 0 is reserved for errors.
|
||||
// Order is weird for historical reasons.
|
||||
TYPE_DOUBLE = 1;
|
||||
TYPE_FLOAT = 2;
|
||||
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
||||
// negative values are likely.
|
||||
TYPE_INT64 = 3;
|
||||
TYPE_UINT64 = 4;
|
||||
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
||||
// negative values are likely.
|
||||
TYPE_INT32 = 5;
|
||||
TYPE_FIXED64 = 6;
|
||||
TYPE_FIXED32 = 7;
|
||||
TYPE_BOOL = 8;
|
||||
TYPE_STRING = 9;
|
||||
// Tag-delimited aggregate.
|
||||
// Group type is deprecated and not supported in proto3. However, Proto3
|
||||
// implementations should still be able to parse the group wire format and
|
||||
// treat group fields as unknown fields.
|
||||
TYPE_GROUP = 10;
|
||||
TYPE_MESSAGE = 11; // Length-delimited aggregate.
|
||||
|
||||
// New in version 2.
|
||||
TYPE_BYTES = 12;
|
||||
TYPE_UINT32 = 13;
|
||||
TYPE_ENUM = 14;
|
||||
TYPE_SFIXED32 = 15;
|
||||
TYPE_SFIXED64 = 16;
|
||||
TYPE_SINT32 = 17; // Uses ZigZag encoding.
|
||||
TYPE_SINT64 = 18; // Uses ZigZag encoding.
|
||||
}
|
||||
|
||||
enum Label {
|
||||
// 0 is reserved for errors
|
||||
LABEL_OPTIONAL = 1;
|
||||
LABEL_REQUIRED = 2;
|
||||
LABEL_REPEATED = 3;
|
||||
}
|
||||
|
||||
optional string name = 1;
|
||||
optional int32 number = 3;
|
||||
optional Label label = 4;
|
||||
|
||||
// If type_name is set, this need not be set. If both this and type_name
|
||||
// are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
|
||||
optional Type type = 5;
|
||||
|
||||
// For message and enum types, this is the name of the type. If the name
|
||||
// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
|
||||
// rules are used to find the type (i.e. first the nested types within this
|
||||
// message are searched, then within the parent, on up to the root
|
||||
// namespace).
|
||||
optional string type_name = 6;
|
||||
|
||||
// For extensions, this is the name of the type being extended. It is
|
||||
// resolved in the same manner as type_name.
|
||||
optional string extendee = 2;
|
||||
|
||||
// For numeric types, contains the original text representation of the value.
|
||||
// For booleans, "true" or "false".
|
||||
// For strings, contains the default text contents (not escaped in any way).
|
||||
// For bytes, contains the C escaped value. All bytes >= 128 are escaped.
|
||||
// TODO(kenton): Base-64 encode?
|
||||
optional string default_value = 7;
|
||||
|
||||
// If set, gives the index of a oneof in the containing type's oneof_decl
|
||||
// list. This field is a member of that oneof.
|
||||
optional int32 oneof_index = 9;
|
||||
|
||||
// JSON name of this field. The value is set by protocol compiler. If the
|
||||
// user has set a "json_name" option on this field, that option's value
|
||||
// will be used. Otherwise, it's deduced from the field's name by converting
|
||||
// it to camelCase.
|
||||
optional string json_name = 10;
|
||||
|
||||
optional FieldOptions options = 8;
|
||||
|
||||
// If true, this is a proto3 "optional". When a proto3 field is optional, it
|
||||
// tracks presence regardless of field type.
|
||||
//
|
||||
// When proto3_optional is true, this field must be belong to a oneof to
|
||||
// signal to old proto3 clients that presence is tracked for this field. This
|
||||
// oneof is known as a "synthetic" oneof, and this field must be its sole
|
||||
// member (each proto3 optional field gets its own synthetic oneof). Synthetic
|
||||
// oneofs exist in the descriptor only, and do not generate any API. Synthetic
|
||||
// oneofs must be ordered after all "real" oneofs.
|
||||
//
|
||||
// For message fields, proto3_optional doesn't create any semantic change,
|
||||
// since non-repeated message fields always track presence. However it still
|
||||
// indicates the semantic detail of whether the user wrote "optional" or not.
|
||||
// This can be useful for round-tripping the .proto file. For consistency we
|
||||
// give message fields a synthetic oneof also, even though it is not required
|
||||
// to track presence. This is especially important because the parser can't
|
||||
// tell if a field is a message or an enum, so it must always create a
|
||||
// synthetic oneof.
|
||||
//
|
||||
// Proto2 optional fields do not set this flag, because they already indicate
|
||||
// optional with `LABEL_OPTIONAL`.
|
||||
optional bool proto3_optional = 17;
|
||||
}
|
||||
|
||||
// Describes a oneof.
|
||||
message OneofDescriptorProto {
|
||||
optional string name = 1;
|
||||
optional OneofOptions options = 2;
|
||||
}
|
||||
|
||||
// Describes an enum type.
|
||||
message EnumDescriptorProto {
|
||||
optional string name = 1;
|
||||
|
||||
repeated EnumValueDescriptorProto value = 2;
|
||||
|
||||
optional EnumOptions options = 3;
|
||||
|
||||
// Range of reserved numeric values. Reserved values may not be used by
|
||||
// entries in the same enum. Reserved ranges may not overlap.
|
||||
//
|
||||
// Note that this is distinct from DescriptorProto.ReservedRange in that it
|
||||
// is inclusive such that it can appropriately represent the entire int32
|
||||
// domain.
|
||||
message EnumReservedRange {
|
||||
optional int32 start = 1; // Inclusive.
|
||||
optional int32 end = 2; // Inclusive.
|
||||
}
|
||||
|
||||
// Range of reserved numeric values. Reserved numeric values may not be used
|
||||
// by enum values in the same enum declaration. Reserved ranges may not
|
||||
// overlap.
|
||||
repeated EnumReservedRange reserved_range = 4;
|
||||
|
||||
// Reserved enum value names, which may not be reused. A given name may only
|
||||
// be reserved once.
|
||||
repeated string reserved_name = 5;
|
||||
}
|
||||
|
||||
// Describes a value within an enum.
|
||||
message EnumValueDescriptorProto {
|
||||
optional string name = 1;
|
||||
optional int32 number = 2;
|
||||
|
||||
optional EnumValueOptions options = 3;
|
||||
}
|
||||
|
||||
// Describes a service.
|
||||
message ServiceDescriptorProto {
|
||||
optional string name = 1;
|
||||
repeated MethodDescriptorProto method = 2;
|
||||
|
||||
optional ServiceOptions options = 3;
|
||||
}
|
||||
|
||||
// Describes a method of a service.
|
||||
message MethodDescriptorProto {
|
||||
optional string name = 1;
|
||||
|
||||
// Input and output type names. These are resolved in the same way as
|
||||
// FieldDescriptorProto.type_name, but must refer to a message type.
|
||||
optional string input_type = 2;
|
||||
optional string output_type = 3;
|
||||
|
||||
optional MethodOptions options = 4;
|
||||
|
||||
// Identifies if client streams multiple client messages
|
||||
optional bool client_streaming = 5 [default = false];
|
||||
// Identifies if server streams multiple server messages
|
||||
optional bool server_streaming = 6 [default = false];
|
||||
}
|
||||
|
||||
|
||||
// ===================================================================
|
||||
// Options
|
||||
|
||||
// Each of the definitions above may have "options" attached. These are
|
||||
// just annotations which may cause code to be generated slightly differently
|
||||
// or may contain hints for code that manipulates protocol messages.
|
||||
//
|
||||
// Clients may define custom options as extensions of the *Options messages.
|
||||
// These extensions may not yet be known at parsing time, so the parser cannot
|
||||
// store the values in them. Instead it stores them in a field in the *Options
|
||||
// message called uninterpreted_option. This field must have the same name
|
||||
// across all *Options messages. We then use this field to populate the
|
||||
// extensions when we build a descriptor, at which point all protos have been
|
||||
// parsed and so all extensions are known.
|
||||
//
|
||||
// Extension numbers for custom options may be chosen as follows:
|
||||
// * For options which will only be used within a single application or
|
||||
// organization, or for experimental options, use field numbers 50000
|
||||
// through 99999. It is up to you to ensure that you do not use the
|
||||
// same number for multiple options.
|
||||
// * For options which will be published and used publicly by multiple
|
||||
// independent entities, e-mail protobuf-global-extension-registry@google.com
|
||||
// to reserve extension numbers. Simply provide your project name (e.g.
|
||||
// Objective-C plugin) and your project website (if available) -- there's no
|
||||
// need to explain how you intend to use them. Usually you only need one
|
||||
// extension number. You can declare multiple options with only one extension
|
||||
// number by putting them in a sub-message. See the Custom Options section of
|
||||
// the docs for examples:
|
||||
// https://developers.google.com/protocol-buffers/docs/proto#options
|
||||
// If this turns out to be popular, a web service will be set up
|
||||
// to automatically assign option numbers.
|
||||
|
||||
message FileOptions {
|
||||
|
||||
// Sets the Java package where classes generated from this .proto will be
|
||||
// placed. By default, the proto package is used, but this is often
|
||||
// inappropriate because proto packages do not normally start with backwards
|
||||
// domain names.
|
||||
optional string java_package = 1;
|
||||
|
||||
|
||||
// If set, all the classes from the .proto file are wrapped in a single
|
||||
// outer class with the given name. This applies to both Proto1
|
||||
// (equivalent to the old "--one_java_file" option) and Proto2 (where
|
||||
// a .proto always translates to a single class, but you may want to
|
||||
// explicitly choose the class name).
|
||||
optional string java_outer_classname = 8;
|
||||
|
||||
// If set true, then the Java code generator will generate a separate .java
|
||||
// file for each top-level message, enum, and service defined in the .proto
|
||||
// file. Thus, these types will *not* be nested inside the outer class
|
||||
// named by java_outer_classname. However, the outer class will still be
|
||||
// generated to contain the file's getDescriptor() method as well as any
|
||||
// top-level extensions defined in the file.
|
||||
optional bool java_multiple_files = 10 [default = false];
|
||||
|
||||
// This option does nothing.
|
||||
optional bool java_generate_equals_and_hash = 20 [deprecated=true];
|
||||
|
||||
// If set true, then the Java2 code generator will generate code that
|
||||
// throws an exception whenever an attempt is made to assign a non-UTF-8
|
||||
// byte sequence to a string field.
|
||||
// Message reflection will do the same.
|
||||
// However, an extension field still accepts non-UTF-8 byte sequences.
|
||||
// This option has no effect on when used with the lite runtime.
|
||||
optional bool java_string_check_utf8 = 27 [default = false];
|
||||
|
||||
|
||||
// Generated classes can be optimized for speed or code size.
|
||||
enum OptimizeMode {
|
||||
SPEED = 1; // Generate complete code for parsing, serialization,
|
||||
// etc.
|
||||
CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
|
||||
LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
|
||||
}
|
||||
optional OptimizeMode optimize_for = 9 [default = SPEED];
|
||||
|
||||
// Sets the Go package where structs generated from this .proto will be
|
||||
// placed. If omitted, the Go package will be derived from the following:
|
||||
// - The basename of the package import path, if provided.
|
||||
// - Otherwise, the package statement in the .proto file, if present.
|
||||
// - Otherwise, the basename of the .proto file, without extension.
|
||||
optional string go_package = 11;
|
||||
|
||||
|
||||
|
||||
|
||||
// Should generic services be generated in each language? "Generic" services
|
||||
// are not specific to any particular RPC system. They are generated by the
|
||||
// main code generators in each language (without additional plugins).
|
||||
// Generic services were the only kind of service generation supported by
|
||||
// early versions of google.protobuf.
|
||||
//
|
||||
// Generic services are now considered deprecated in favor of using plugins
|
||||
// that generate code specific to your particular RPC system. Therefore,
|
||||
// these default to false. Old code which depends on generic services should
|
||||
// explicitly set them to true.
|
||||
optional bool cc_generic_services = 16 [default = false];
|
||||
optional bool java_generic_services = 17 [default = false];
|
||||
optional bool py_generic_services = 18 [default = false];
|
||||
optional bool php_generic_services = 42 [default = false];
|
||||
|
||||
// Is this file deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for everything in the file, or it will be completely ignored; in the very
|
||||
// least, this is a formalization for deprecating files.
|
||||
optional bool deprecated = 23 [default = false];
|
||||
|
||||
// Enables the use of arenas for the proto messages in this file. This applies
|
||||
// only to generated classes for C++.
|
||||
optional bool cc_enable_arenas = 31 [default = true];
|
||||
|
||||
|
||||
// Sets the objective c class prefix which is prepended to all objective c
|
||||
// generated classes from this .proto. There is no default.
|
||||
optional string objc_class_prefix = 36;
|
||||
|
||||
// Namespace for generated classes; defaults to the package.
|
||||
optional string csharp_namespace = 37;
|
||||
|
||||
// By default Swift generators will take the proto package and CamelCase it
|
||||
// replacing '.' with underscore and use that to prefix the types/symbols
|
||||
// defined. When this options is provided, they will use this value instead
|
||||
// to prefix the types/symbols defined.
|
||||
optional string swift_prefix = 39;
|
||||
|
||||
// Sets the php class prefix which is prepended to all php generated classes
|
||||
// from this .proto. Default is empty.
|
||||
optional string php_class_prefix = 40;
|
||||
|
||||
// Use this option to change the namespace of php generated classes. Default
|
||||
// is empty. When this option is empty, the package name will be used for
|
||||
// determining the namespace.
|
||||
optional string php_namespace = 41;
|
||||
|
||||
// Use this option to change the namespace of php generated metadata classes.
|
||||
// Default is empty. When this option is empty, the proto file name will be
|
||||
// used for determining the namespace.
|
||||
optional string php_metadata_namespace = 44;
|
||||
|
||||
// Use this option to change the package of ruby generated classes. Default
|
||||
// is empty. When this option is not set, the package name will be used for
|
||||
// determining the ruby package.
|
||||
optional string ruby_package = 45;
|
||||
|
||||
|
||||
// The parser stores options it doesn't recognize here.
|
||||
// See the documentation for the "Options" section above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message.
|
||||
// See the documentation for the "Options" section above.
|
||||
extensions 1000 to max;
|
||||
|
||||
reserved 38;
|
||||
}
|
||||
|
||||
message MessageOptions {
|
||||
// Set true to use the old proto1 MessageSet wire format for extensions.
|
||||
// This is provided for backwards-compatibility with the MessageSet wire
|
||||
// format. You should not use this for any other reason: It's less
|
||||
// efficient, has fewer features, and is more complicated.
|
||||
//
|
||||
// The message must be defined exactly as follows:
|
||||
// message Foo {
|
||||
// option message_set_wire_format = true;
|
||||
// extensions 4 to max;
|
||||
// }
|
||||
// Note that the message cannot have any defined fields; MessageSets only
|
||||
// have extensions.
|
||||
//
|
||||
// All extensions of your type must be singular messages; e.g. they cannot
|
||||
// be int32s, enums, or repeated messages.
|
||||
//
|
||||
// Because this is an option, the above two restrictions are not enforced by
|
||||
// the protocol compiler.
|
||||
optional bool message_set_wire_format = 1 [default = false];
|
||||
|
||||
// Disables the generation of the standard "descriptor()" accessor, which can
|
||||
// conflict with a field of the same name. This is meant to make migration
|
||||
// from proto1 easier; new code should avoid fields named "descriptor".
|
||||
optional bool no_standard_descriptor_accessor = 2 [default = false];
|
||||
|
||||
// Is this message deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for the message, or it will be completely ignored; in the very least,
|
||||
// this is a formalization for deprecating messages.
|
||||
optional bool deprecated = 3 [default = false];
|
||||
|
||||
// Whether the message is an automatically generated map entry type for the
|
||||
// maps field.
|
||||
//
|
||||
// For maps fields:
|
||||
// map<KeyType, ValueType> map_field = 1;
|
||||
// The parsed descriptor looks like:
|
||||
// message MapFieldEntry {
|
||||
// option map_entry = true;
|
||||
// optional KeyType key = 1;
|
||||
// optional ValueType value = 2;
|
||||
// }
|
||||
// repeated MapFieldEntry map_field = 1;
|
||||
//
|
||||
// Implementations may choose not to generate the map_entry=true message, but
|
||||
// use a native map in the target language to hold the keys and values.
|
||||
// The reflection APIs in such implementations still need to work as
|
||||
// if the field is a repeated message field.
|
||||
//
|
||||
// NOTE: Do not set the option in .proto files. Always use the maps syntax
|
||||
// instead. The option should only be implicitly set by the proto compiler
|
||||
// parser.
|
||||
optional bool map_entry = 7;
|
||||
|
||||
reserved 8; // javalite_serializable
|
||||
reserved 9; // javanano_as_lite
|
||||
|
||||
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
message FieldOptions {
|
||||
// The ctype option instructs the C++ code generator to use a different
|
||||
// representation of the field than it normally would. See the specific
|
||||
// options below. This option is not yet implemented in the open source
|
||||
// release -- sorry, we'll try to include it in a future version!
|
||||
optional CType ctype = 1 [default = STRING];
|
||||
enum CType {
|
||||
// Default mode.
|
||||
STRING = 0;
|
||||
|
||||
CORD = 1;
|
||||
|
||||
STRING_PIECE = 2;
|
||||
}
|
||||
// The packed option can be enabled for repeated primitive fields to enable
|
||||
// a more efficient representation on the wire. Rather than repeatedly
|
||||
// writing the tag and type for each element, the entire array is encoded as
|
||||
// a single length-delimited blob. In proto3, only explicit setting it to
|
||||
// false will avoid using packed encoding.
|
||||
optional bool packed = 2;
|
||||
|
||||
// The jstype option determines the JavaScript type used for values of the
|
||||
// field. The option is permitted only for 64 bit integral and fixed types
|
||||
// (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
|
||||
// is represented as JavaScript string, which avoids loss of precision that
|
||||
// can happen when a large value is converted to a floating point JavaScript.
|
||||
// Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
|
||||
// use the JavaScript "number" type. The behavior of the default option
|
||||
// JS_NORMAL is implementation dependent.
|
||||
//
|
||||
// This option is an enum to permit additional types to be added, e.g.
|
||||
// goog.math.Integer.
|
||||
optional JSType jstype = 6 [default = JS_NORMAL];
|
||||
enum JSType {
|
||||
// Use the default type.
|
||||
JS_NORMAL = 0;
|
||||
|
||||
// Use JavaScript strings.
|
||||
JS_STRING = 1;
|
||||
|
||||
// Use JavaScript numbers.
|
||||
JS_NUMBER = 2;
|
||||
}
|
||||
|
||||
// Should this field be parsed lazily? Lazy applies only to message-type
|
||||
// fields. It means that when the outer message is initially parsed, the
|
||||
// inner message's contents will not be parsed but instead stored in encoded
|
||||
// form. The inner message will actually be parsed when it is first accessed.
|
||||
//
|
||||
// This is only a hint. Implementations are free to choose whether to use
|
||||
// eager or lazy parsing regardless of the value of this option. However,
|
||||
// setting this option true suggests that the protocol author believes that
|
||||
// using lazy parsing on this field is worth the additional bookkeeping
|
||||
// overhead typically needed to implement it.
|
||||
//
|
||||
// This option does not affect the public interface of any generated code;
|
||||
// all method signatures remain the same. Furthermore, thread-safety of the
|
||||
// interface is not affected by this option; const methods remain safe to
|
||||
// call from multiple threads concurrently, while non-const methods continue
|
||||
// to require exclusive access.
|
||||
//
|
||||
//
|
||||
// Note that implementations may choose not to check required fields within
|
||||
// a lazy sub-message. That is, calling IsInitialized() on the outer message
|
||||
// may return true even if the inner message has missing required fields.
|
||||
// This is necessary because otherwise the inner message would have to be
|
||||
// parsed in order to perform the check, defeating the purpose of lazy
|
||||
// parsing. An implementation which chooses not to check required fields
|
||||
// must be consistent about it. That is, for any particular sub-message, the
|
||||
// implementation must either *always* check its required fields, or *never*
|
||||
// check its required fields, regardless of whether or not the message has
|
||||
// been parsed.
|
||||
optional bool lazy = 5 [default = false];
|
||||
|
||||
// Is this field deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for accessors, or it will be completely ignored; in the very least, this
|
||||
// is a formalization for deprecating fields.
|
||||
optional bool deprecated = 3 [default = false];
|
||||
|
||||
// For Google-internal migration only. Do not use.
|
||||
optional bool weak = 10 [default = false];
|
||||
|
||||
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
|
||||
reserved 4; // removed jtype
|
||||
}
|
||||
|
||||
message OneofOptions {
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
message EnumOptions {
|
||||
|
||||
// Set this option to true to allow mapping different tag names to the same
|
||||
// value.
|
||||
optional bool allow_alias = 2;
|
||||
|
||||
// Is this enum deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for the enum, or it will be completely ignored; in the very least, this
|
||||
// is a formalization for deprecating enums.
|
||||
optional bool deprecated = 3 [default = false];
|
||||
|
||||
reserved 5; // javanano_as_lite
|
||||
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
message EnumValueOptions {
|
||||
// Is this enum value deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for the enum value, or it will be completely ignored; in the very least,
|
||||
// this is a formalization for deprecating enum values.
|
||||
optional bool deprecated = 1 [default = false];
|
||||
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
message ServiceOptions {
|
||||
|
||||
// Note: Field numbers 1 through 32 are reserved for Google's internal RPC
|
||||
// framework. We apologize for hoarding these numbers to ourselves, but
|
||||
// we were already using them long before we decided to release Protocol
|
||||
// Buffers.
|
||||
|
||||
// Is this service deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for the service, or it will be completely ignored; in the very least,
|
||||
// this is a formalization for deprecating services.
|
||||
optional bool deprecated = 33 [default = false];
|
||||
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
message MethodOptions {
|
||||
|
||||
// Note: Field numbers 1 through 32 are reserved for Google's internal RPC
|
||||
// framework. We apologize for hoarding these numbers to ourselves, but
|
||||
// we were already using them long before we decided to release Protocol
|
||||
// Buffers.
|
||||
|
||||
// Is this method deprecated?
|
||||
// Depending on the target platform, this can emit Deprecated annotations
|
||||
// for the method, or it will be completely ignored; in the very least,
|
||||
// this is a formalization for deprecating methods.
|
||||
optional bool deprecated = 33 [default = false];
|
||||
|
||||
// Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
|
||||
// or neither? HTTP based RPC implementation may choose GET verb for safe
|
||||
// methods, and PUT verb for idempotent methods instead of the default POST.
|
||||
enum IdempotencyLevel {
|
||||
IDEMPOTENCY_UNKNOWN = 0;
|
||||
NO_SIDE_EFFECTS = 1; // implies idempotent
|
||||
IDEMPOTENT = 2; // idempotent, but may have side effects
|
||||
}
|
||||
optional IdempotencyLevel idempotency_level = 34
|
||||
[default = IDEMPOTENCY_UNKNOWN];
|
||||
|
||||
// The parser stores options it doesn't recognize here. See above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message. See above.
|
||||
extensions 1000 to max;
|
||||
}
|
||||
|
||||
|
||||
// A message representing a option the parser does not recognize. This only
|
||||
// appears in options protos created by the compiler::Parser class.
|
||||
// DescriptorPool resolves these when building Descriptor objects. Therefore,
|
||||
// options protos in descriptor objects (e.g. returned by Descriptor::options(),
|
||||
// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
|
||||
// in them.
|
||||
message UninterpretedOption {
|
||||
// The name of the uninterpreted option. Each string represents a segment in
|
||||
// a dot-separated name. is_extension is true iff a segment represents an
|
||||
// extension (denoted with parentheses in options specs in .proto files).
|
||||
// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
|
||||
// "foo.(bar.baz).qux".
|
||||
message NamePart {
|
||||
required string name_part = 1;
|
||||
required bool is_extension = 2;
|
||||
}
|
||||
repeated NamePart name = 2;
|
||||
|
||||
// The value of the uninterpreted option, in whatever type the tokenizer
|
||||
// identified it as during parsing. Exactly one of these should be set.
|
||||
optional string identifier_value = 3;
|
||||
optional uint64 positive_int_value = 4;
|
||||
optional int64 negative_int_value = 5;
|
||||
optional double double_value = 6;
|
||||
optional bytes string_value = 7;
|
||||
optional string aggregate_value = 8;
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Optional source code info
|
||||
|
||||
// Encapsulates information about the original source file from which a
|
||||
// FileDescriptorProto was generated.
|
||||
message SourceCodeInfo {
|
||||
// A Location identifies a piece of source code in a .proto file which
|
||||
// corresponds to a particular definition. This information is intended
|
||||
// to be useful to IDEs, code indexers, documentation generators, and similar
|
||||
// tools.
|
||||
//
|
||||
// For example, say we have a file like:
|
||||
// message Foo {
|
||||
// optional string foo = 1;
|
||||
// }
|
||||
// Let's look at just the field definition:
|
||||
// optional string foo = 1;
|
||||
// ^ ^^ ^^ ^ ^^^
|
||||
// a bc de f ghi
|
||||
// We have the following locations:
|
||||
// span path represents
|
||||
// [a,i) [ 4, 0, 2, 0 ] The whole field definition.
|
||||
// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
|
||||
// [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
|
||||
// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
|
||||
// [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
|
||||
//
|
||||
// Notes:
|
||||
// - A location may refer to a repeated field itself (i.e. not to any
|
||||
// particular index within it). This is used whenever a set of elements are
|
||||
// logically enclosed in a single code segment. For example, an entire
|
||||
// extend block (possibly containing multiple extension definitions) will
|
||||
// have an outer location whose path refers to the "extensions" repeated
|
||||
// field without an index.
|
||||
// - Multiple locations may have the same path. This happens when a single
|
||||
// logical declaration is spread out across multiple places. The most
|
||||
// obvious example is the "extend" block again -- there may be multiple
|
||||
// extend blocks in the same scope, each of which will have the same path.
|
||||
// - A location's span is not always a subset of its parent's span. For
|
||||
// example, the "extendee" of an extension declaration appears at the
|
||||
// beginning of the "extend" block and is shared by all extensions within
|
||||
// the block.
|
||||
// - Just because a location's span is a subset of some other location's span
|
||||
// does not mean that it is a descendant. For example, a "group" defines
|
||||
// both a type and a field in a single declaration. Thus, the locations
|
||||
// corresponding to the type and field and their components will overlap.
|
||||
// - Code which tries to interpret locations should probably be designed to
|
||||
// ignore those that it doesn't understand, as more types of locations could
|
||||
// be recorded in the future.
|
||||
repeated Location location = 1;
|
||||
message Location {
|
||||
// Identifies which part of the FileDescriptorProto was defined at this
|
||||
// location.
|
||||
//
|
||||
// Each element is a field number or an index. They form a path from
|
||||
// the root FileDescriptorProto to the place where the definition. For
|
||||
// example, this path:
|
||||
// [ 4, 3, 2, 7, 1 ]
|
||||
// refers to:
|
||||
// file.message_type(3) // 4, 3
|
||||
// .field(7) // 2, 7
|
||||
// .name() // 1
|
||||
// This is because FileDescriptorProto.message_type has field number 4:
|
||||
// repeated DescriptorProto message_type = 4;
|
||||
// and DescriptorProto.field has field number 2:
|
||||
// repeated FieldDescriptorProto field = 2;
|
||||
// and FieldDescriptorProto.name has field number 1:
|
||||
// optional string name = 1;
|
||||
//
|
||||
// Thus, the above path gives the location of a field name. If we removed
|
||||
// the last element:
|
||||
// [ 4, 3, 2, 7 ]
|
||||
// this path refers to the whole field declaration (from the beginning
|
||||
// of the label to the terminating semicolon).
|
||||
repeated int32 path = 1 [packed = true];
|
||||
|
||||
// Always has exactly three or four elements: start line, start column,
|
||||
// end line (optional, otherwise assumed same as start line), end column.
|
||||
// These are packed into a single field for efficiency. Note that line
|
||||
// and column numbers are zero-based -- typically you will want to add
|
||||
// 1 to each before displaying to a user.
|
||||
repeated int32 span = 2 [packed = true];
|
||||
|
||||
// If this SourceCodeInfo represents a complete declaration, these are any
|
||||
// comments appearing before and after the declaration which appear to be
|
||||
// attached to the declaration.
|
||||
//
|
||||
// A series of line comments appearing on consecutive lines, with no other
|
||||
// tokens appearing on those lines, will be treated as a single comment.
|
||||
//
|
||||
// leading_detached_comments will keep paragraphs of comments that appear
|
||||
// before (but not connected to) the current element. Each paragraph,
|
||||
// separated by empty lines, will be one comment element in the repeated
|
||||
// field.
|
||||
//
|
||||
// Only the comment content is provided; comment markers (e.g. //) are
|
||||
// stripped out. For block comments, leading whitespace and an asterisk
|
||||
// will be stripped from the beginning of each line other than the first.
|
||||
// Newlines are included in the output.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// optional int32 foo = 1; // Comment attached to foo.
|
||||
// // Comment attached to bar.
|
||||
// optional int32 bar = 2;
|
||||
//
|
||||
// optional string baz = 3;
|
||||
// // Comment attached to baz.
|
||||
// // Another line attached to baz.
|
||||
//
|
||||
// // Comment attached to qux.
|
||||
// //
|
||||
// // Another line attached to qux.
|
||||
// optional double qux = 4;
|
||||
//
|
||||
// // Detached comment for corge. This is not leading or trailing comments
|
||||
// // to qux or corge because there are blank lines separating it from
|
||||
// // both.
|
||||
//
|
||||
// // Detached comment for corge paragraph 2.
|
||||
//
|
||||
// optional string corge = 5;
|
||||
// /* Block comment attached
|
||||
// * to corge. Leading asterisks
|
||||
// * will be removed. */
|
||||
// /* Block comment attached to
|
||||
// * grault. */
|
||||
// optional int32 grault = 6;
|
||||
//
|
||||
// // ignored detached comments.
|
||||
optional string leading_comments = 3;
|
||||
optional string trailing_comments = 4;
|
||||
repeated string leading_detached_comments = 6;
|
||||
}
|
||||
}
|
||||
|
||||
// Describes the relationship between generated code and its original source
|
||||
// file. A GeneratedCodeInfo message is associated with only one generated
|
||||
// source file, but may contain references to different source .proto files.
|
||||
message GeneratedCodeInfo {
|
||||
// An Annotation connects some span of text in generated code to an element
|
||||
// of its generating .proto file.
|
||||
repeated Annotation annotation = 1;
|
||||
message Annotation {
|
||||
// Identifies the element in the original source .proto file. This field
|
||||
// is formatted the same as SourceCodeInfo.Location.path.
|
||||
repeated int32 path = 1 [packed = true];
|
||||
|
||||
// Identifies the filesystem path to the original source .proto.
|
||||
optional string source_file = 2;
|
||||
|
||||
// Identifies the starting offset in bytes in the generated code
|
||||
// that relates to the identified object.
|
||||
optional int32 begin = 3;
|
||||
|
||||
// Identifies the ending offset in bytes in the generated code that
|
||||
// relates to the identified offset. The end offset should be one past
|
||||
// the last relevant byte (so the length of the text = end - begin).
|
||||
optional int32 end = 4;
|
||||
}
|
||||
}
|
407
include/google/protobuf/descriptor_database.h
Normal file
407
include/google/protobuf/descriptor_database.h
Normal file
@ -0,0 +1,407 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// Interface for manipulating databases of descriptors.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__
|
||||
#define GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
// Defined in this file.
|
||||
class DescriptorDatabase;
|
||||
class SimpleDescriptorDatabase;
|
||||
class EncodedDescriptorDatabase;
|
||||
class DescriptorPoolDatabase;
|
||||
class MergedDescriptorDatabase;
|
||||
|
||||
// Abstract interface for a database of descriptors.
|
||||
//
|
||||
// This is useful if you want to create a DescriptorPool which loads
|
||||
// descriptors on-demand from some sort of large database. If the database
|
||||
// is large, it may be inefficient to enumerate every .proto file inside it
|
||||
// calling DescriptorPool::BuildFile() for each one. Instead, a DescriptorPool
|
||||
// can be created which wraps a DescriptorDatabase and only builds particular
|
||||
// descriptors when they are needed.
|
||||
class PROTOBUF_EXPORT DescriptorDatabase {
|
||||
public:
|
||||
inline DescriptorDatabase() {}
|
||||
virtual ~DescriptorDatabase();
|
||||
|
||||
// Find a file by file name. Fills in in *output and returns true if found.
|
||||
// Otherwise, returns false, leaving the contents of *output undefined.
|
||||
virtual bool FindFileByName(const std::string& filename,
|
||||
FileDescriptorProto* output) = 0;
|
||||
|
||||
// Find the file that declares the given fully-qualified symbol name.
|
||||
// If found, fills in *output and returns true, otherwise returns false
|
||||
// and leaves *output undefined.
|
||||
virtual bool FindFileContainingSymbol(const std::string& symbol_name,
|
||||
FileDescriptorProto* output) = 0;
|
||||
|
||||
// Find the file which defines an extension extending the given message type
|
||||
// with the given field number. If found, fills in *output and returns true,
|
||||
// otherwise returns false and leaves *output undefined. containing_type
|
||||
// must be a fully-qualified type name.
|
||||
virtual bool FindFileContainingExtension(const std::string& containing_type,
|
||||
int field_number,
|
||||
FileDescriptorProto* output) = 0;
|
||||
|
||||
// Finds the tag numbers used by all known extensions of
|
||||
// extendee_type, and appends them to output in an undefined
|
||||
// order. This method is best-effort: it's not guaranteed that the
|
||||
// database will find all extensions, and it's not guaranteed that
|
||||
// FindFileContainingExtension will return true on all of the found
|
||||
// numbers. Returns true if the search was successful, otherwise
|
||||
// returns false and leaves output unchanged.
|
||||
//
|
||||
// This method has a default implementation that always returns
|
||||
// false.
|
||||
virtual bool FindAllExtensionNumbers(const std::string& /* extendee_type */,
|
||||
std::vector<int>* /* output */) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Finds the file names and appends them to the output in an
|
||||
// undefined order. This method is best-effort: it's not guaranteed that the
|
||||
// database will find all files. Returns true if the database supports
|
||||
// searching all file names, otherwise returns false and leaves output
|
||||
// unchanged.
|
||||
//
|
||||
// This method has a default implementation that always returns
|
||||
// false.
|
||||
virtual bool FindAllFileNames(std::vector<std::string>* /*output*/) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finds the package names and appends them to the output in an
|
||||
// undefined order. This method is best-effort: it's not guaranteed that the
|
||||
// database will find all packages. Returns true if the database supports
|
||||
// searching all package names, otherwise returns false and leaves output
|
||||
// unchanged.
|
||||
bool FindAllPackageNames(std::vector<std::string>* output);
|
||||
|
||||
// Finds the message names and appends them to the output in an
|
||||
// undefined order. This method is best-effort: it's not guaranteed that the
|
||||
// database will find all messages. Returns true if the database supports
|
||||
// searching all message names, otherwise returns false and leaves output
|
||||
// unchanged.
|
||||
bool FindAllMessageNames(std::vector<std::string>* output);
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase);
|
||||
};
|
||||
|
||||
// A DescriptorDatabase into which you can insert files manually.
|
||||
//
|
||||
// FindFileContainingSymbol() is fully-implemented. When you add a file, its
|
||||
// symbols will be indexed for this purpose. Note that the implementation
|
||||
// may return false positives, but only if it isn't possible for the symbol
|
||||
// to be defined in any other file. In particular, if a file defines a symbol
|
||||
// "Foo", then searching for "Foo.[anything]" will match that file. This way,
|
||||
// the database does not need to aggressively index all children of a symbol.
|
||||
//
|
||||
// FindFileContainingExtension() is mostly-implemented. It works if and only
|
||||
// if the original FieldDescriptorProto defining the extension has a
|
||||
// fully-qualified type name in its "extendee" field (i.e. starts with a '.').
|
||||
// If the extendee is a relative name, SimpleDescriptorDatabase will not
|
||||
// attempt to resolve the type, so it will not know what type the extension is
|
||||
// extending. Therefore, calling FindFileContainingExtension() with the
|
||||
// extension's containing type will never actually find that extension. Note
|
||||
// that this is an unlikely problem, as all FileDescriptorProtos created by the
|
||||
// protocol compiler (as well as ones created by calling
|
||||
// FileDescriptor::CopyTo()) will always use fully-qualified names for all
|
||||
// types. You only need to worry if you are constructing FileDescriptorProtos
|
||||
// yourself, or are calling compiler::Parser directly.
|
||||
class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
|
||||
public:
|
||||
SimpleDescriptorDatabase();
|
||||
~SimpleDescriptorDatabase() override;
|
||||
|
||||
// Adds the FileDescriptorProto to the database, making a copy. The object
|
||||
// can be deleted after Add() returns. Returns false if the file conflicted
|
||||
// with a file already in the database, in which case an error will have
|
||||
// been written to GOOGLE_LOG(ERROR).
|
||||
bool Add(const FileDescriptorProto& file);
|
||||
|
||||
// Adds the FileDescriptorProto to the database and takes ownership of it.
|
||||
bool AddAndOwn(const FileDescriptorProto* file);
|
||||
|
||||
// implements DescriptorDatabase -----------------------------------
|
||||
bool FindFileByName(const std::string& filename,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingSymbol(const std::string& symbol_name,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingExtension(const std::string& containing_type,
|
||||
int field_number,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindAllExtensionNumbers(const std::string& extendee_type,
|
||||
std::vector<int>* output) override;
|
||||
|
||||
bool FindAllFileNames(std::vector<std::string>* output) override;
|
||||
|
||||
private:
|
||||
// So that it can use DescriptorIndex.
|
||||
friend class EncodedDescriptorDatabase;
|
||||
|
||||
// An index mapping file names, symbol names, and extension numbers to
|
||||
// some sort of values.
|
||||
template <typename Value>
|
||||
class DescriptorIndex {
|
||||
public:
|
||||
// Helpers to recursively add particular descriptors and all their contents
|
||||
// to the index.
|
||||
bool AddFile(const FileDescriptorProto& file, Value value);
|
||||
bool AddSymbol(const std::string& name, Value value);
|
||||
bool AddNestedExtensions(const std::string& filename,
|
||||
const DescriptorProto& message_type, Value value);
|
||||
bool AddExtension(const std::string& filename,
|
||||
const FieldDescriptorProto& field, Value value);
|
||||
|
||||
Value FindFile(const std::string& filename);
|
||||
Value FindSymbol(const std::string& name);
|
||||
Value FindExtension(const std::string& containing_type, int field_number);
|
||||
bool FindAllExtensionNumbers(const std::string& containing_type,
|
||||
std::vector<int>* output);
|
||||
void FindAllFileNames(std::vector<std::string>* output);
|
||||
|
||||
private:
|
||||
std::map<std::string, Value> by_name_;
|
||||
std::map<std::string, Value> by_symbol_;
|
||||
std::map<std::pair<std::string, int>, Value> by_extension_;
|
||||
|
||||
// Invariant: The by_symbol_ map does not contain any symbols which are
|
||||
// prefixes of other symbols in the map. For example, "foo.bar" is a
|
||||
// prefix of "foo.bar.baz" (but is not a prefix of "foo.barbaz").
|
||||
//
|
||||
// This invariant is important because it means that given a symbol name,
|
||||
// we can find a key in the map which is a prefix of the symbol in O(lg n)
|
||||
// time, and we know that there is at most one such key.
|
||||
//
|
||||
// The prefix lookup algorithm works like so:
|
||||
// 1) Find the last key in the map which is less than or equal to the
|
||||
// search key.
|
||||
// 2) If the found key is a prefix of the search key, then return it.
|
||||
// Otherwise, there is no match.
|
||||
//
|
||||
// I am sure this algorithm has been described elsewhere, but since I
|
||||
// wasn't able to find it quickly I will instead prove that it works
|
||||
// myself. The key to the algorithm is that if a match exists, step (1)
|
||||
// will find it. Proof:
|
||||
// 1) Define the "search key" to be the key we are looking for, the "found
|
||||
// key" to be the key found in step (1), and the "match key" to be the
|
||||
// key which actually matches the search key (i.e. the key we're trying
|
||||
// to find).
|
||||
// 2) The found key must be less than or equal to the search key by
|
||||
// definition.
|
||||
// 3) The match key must also be less than or equal to the search key
|
||||
// (because it is a prefix).
|
||||
// 4) The match key cannot be greater than the found key, because if it
|
||||
// were, then step (1) of the algorithm would have returned the match
|
||||
// key instead (since it finds the *greatest* key which is less than or
|
||||
// equal to the search key).
|
||||
// 5) Therefore, the found key must be between the match key and the search
|
||||
// key, inclusive.
|
||||
// 6) Since the search key must be a sub-symbol of the match key, if it is
|
||||
// not equal to the match key, then search_key[match_key.size()] must
|
||||
// be '.'.
|
||||
// 7) Since '.' sorts before any other character that is valid in a symbol
|
||||
// name, then if the found key is not equal to the match key, then
|
||||
// found_key[match_key.size()] must also be '.', because any other value
|
||||
// would make it sort after the search key.
|
||||
// 8) Therefore, if the found key is not equal to the match key, then the
|
||||
// found key must be a sub-symbol of the match key. However, this would
|
||||
// contradict our map invariant which says that no symbol in the map is
|
||||
// a sub-symbol of any other.
|
||||
// 9) Therefore, the found key must match the match key.
|
||||
//
|
||||
// The above proof assumes the match key exists. In the case that the
|
||||
// match key does not exist, then step (1) will return some other symbol.
|
||||
// That symbol cannot be a super-symbol of the search key since if it were,
|
||||
// then it would be a match, and we're assuming the match key doesn't exist.
|
||||
// Therefore, step 2 will correctly return no match.
|
||||
|
||||
// Find the last entry in the by_symbol_ map whose key is less than or
|
||||
// equal to the given name.
|
||||
typename std::map<std::string, Value>::iterator FindLastLessOrEqual(
|
||||
const std::string& name);
|
||||
|
||||
// True if either the arguments are equal or super_symbol identifies a
|
||||
// parent symbol of sub_symbol (e.g. "foo.bar" is a parent of
|
||||
// "foo.bar.baz", but not a parent of "foo.barbaz").
|
||||
bool IsSubSymbol(const std::string& sub_symbol,
|
||||
const std::string& super_symbol);
|
||||
|
||||
// Returns true if and only if all characters in the name are alphanumerics,
|
||||
// underscores, or periods.
|
||||
bool ValidateSymbolName(const std::string& name);
|
||||
};
|
||||
|
||||
DescriptorIndex<const FileDescriptorProto*> index_;
|
||||
std::vector<std::unique_ptr<const FileDescriptorProto>> files_to_delete_;
|
||||
|
||||
// If file is non-NULL, copy it into *output and return true, otherwise
|
||||
// return false.
|
||||
bool MaybeCopy(const FileDescriptorProto* file, FileDescriptorProto* output);
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase);
|
||||
};
|
||||
|
||||
// Very similar to SimpleDescriptorDatabase, but stores all the descriptors
|
||||
// as raw bytes and generally tries to use as little memory as possible.
|
||||
//
|
||||
// The same caveats regarding FindFileContainingExtension() apply as with
|
||||
// SimpleDescriptorDatabase.
|
||||
class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase {
|
||||
public:
|
||||
EncodedDescriptorDatabase();
|
||||
~EncodedDescriptorDatabase() override;
|
||||
|
||||
// Adds the FileDescriptorProto to the database. The descriptor is provided
|
||||
// in encoded form. The database does not make a copy of the bytes, nor
|
||||
// does it take ownership; it's up to the caller to make sure the bytes
|
||||
// remain valid for the life of the database. Returns false and logs an error
|
||||
// if the bytes are not a valid FileDescriptorProto or if the file conflicted
|
||||
// with a file already in the database.
|
||||
bool Add(const void* encoded_file_descriptor, int size);
|
||||
|
||||
// Like Add(), but makes a copy of the data, so that the caller does not
|
||||
// need to keep it around.
|
||||
bool AddCopy(const void* encoded_file_descriptor, int size);
|
||||
|
||||
// Like FindFileContainingSymbol but returns only the name of the file.
|
||||
bool FindNameOfFileContainingSymbol(const std::string& symbol_name,
|
||||
std::string* output);
|
||||
|
||||
// implements DescriptorDatabase -----------------------------------
|
||||
bool FindFileByName(const std::string& filename,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingSymbol(const std::string& symbol_name,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingExtension(const std::string& containing_type,
|
||||
int field_number,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindAllExtensionNumbers(const std::string& extendee_type,
|
||||
std::vector<int>* output) override;
|
||||
bool FindAllFileNames(std::vector<std::string>* output) override;
|
||||
|
||||
private:
|
||||
SimpleDescriptorDatabase::DescriptorIndex<std::pair<const void*, int> >
|
||||
index_;
|
||||
std::vector<void*> files_to_delete_;
|
||||
|
||||
// If encoded_file.first is non-NULL, parse the data into *output and return
|
||||
// true, otherwise return false.
|
||||
bool MaybeParse(std::pair<const void*, int> encoded_file,
|
||||
FileDescriptorProto* output);
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase);
|
||||
};
|
||||
|
||||
// A DescriptorDatabase that fetches files from a given pool.
|
||||
class PROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase {
|
||||
public:
|
||||
explicit DescriptorPoolDatabase(const DescriptorPool& pool);
|
||||
~DescriptorPoolDatabase() override;
|
||||
|
||||
// implements DescriptorDatabase -----------------------------------
|
||||
bool FindFileByName(const std::string& filename,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingSymbol(const std::string& symbol_name,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingExtension(const std::string& containing_type,
|
||||
int field_number,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindAllExtensionNumbers(const std::string& extendee_type,
|
||||
std::vector<int>* output) override;
|
||||
|
||||
private:
|
||||
const DescriptorPool& pool_;
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase);
|
||||
};
|
||||
|
||||
// A DescriptorDatabase that wraps two or more others. It first searches the
|
||||
// first database and, if that fails, tries the second, and so on.
|
||||
class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
|
||||
public:
|
||||
// Merge just two databases. The sources remain property of the caller.
|
||||
MergedDescriptorDatabase(DescriptorDatabase* source1,
|
||||
DescriptorDatabase* source2);
|
||||
// Merge more than two databases. The sources remain property of the caller.
|
||||
// The vector may be deleted after the constructor returns but the
|
||||
// DescriptorDatabases need to stick around.
|
||||
explicit MergedDescriptorDatabase(
|
||||
const std::vector<DescriptorDatabase*>& sources);
|
||||
~MergedDescriptorDatabase() override;
|
||||
|
||||
// implements DescriptorDatabase -----------------------------------
|
||||
bool FindFileByName(const std::string& filename,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingSymbol(const std::string& symbol_name,
|
||||
FileDescriptorProto* output) override;
|
||||
bool FindFileContainingExtension(const std::string& containing_type,
|
||||
int field_number,
|
||||
FileDescriptorProto* output) override;
|
||||
// Merges the results of calling all databases. Returns true iff any
|
||||
// of the databases returned true.
|
||||
bool FindAllExtensionNumbers(const std::string& extendee_type,
|
||||
std::vector<int>* output) override;
|
||||
|
||||
|
||||
private:
|
||||
std::vector<DescriptorDatabase*> sources_;
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase);
|
||||
};
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__
|
277
include/google/protobuf/duration.pb.h
Normal file
277
include/google/protobuf/duration.pb.h
Normal file
@ -0,0 +1,277 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/duration.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#if PROTOBUF_VERSION < 3012000
|
||||
#error This file was generated by a newer version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please update
|
||||
#error your headers.
|
||||
#endif
|
||||
#if 3012004 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error This file was generated by an older version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please
|
||||
#error regenerate this file with a newer version of protoc.
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
#include <google/protobuf/extension_set.h> // IWYU pragma: export
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
// @@protoc_insertion_point(includes)
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fduration_2eproto PROTOBUF_EXPORT
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fduration_2eproto {
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[];
|
||||
};
|
||||
extern PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fduration_2eproto;
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
class Duration;
|
||||
class DurationDefaultTypeInternal;
|
||||
PROTOBUF_EXPORT extern DurationDefaultTypeInternal _Duration_default_instance_;
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_EXPORT PROTOBUF_NAMESPACE_ID::Duration* Arena::CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::Duration>(Arena*);
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT Duration PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Duration) */ {
|
||||
public:
|
||||
inline Duration() : Duration(nullptr) {};
|
||||
virtual ~Duration();
|
||||
|
||||
Duration(const Duration& from);
|
||||
Duration(Duration&& from) noexcept
|
||||
: Duration() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline Duration& operator=(const Duration& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline Duration& operator=(Duration&& from) noexcept {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() {
|
||||
return GetMetadataStatic().descriptor;
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() {
|
||||
return GetMetadataStatic().reflection;
|
||||
}
|
||||
static const Duration& default_instance();
|
||||
|
||||
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
|
||||
static inline const Duration* internal_default_instance() {
|
||||
return reinterpret_cast<const Duration*>(
|
||||
&_Duration_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(Duration& a, Duration& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(Duration* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Duration* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
inline Duration* New() const final {
|
||||
return CreateMaybeMessage<Duration>(nullptr);
|
||||
}
|
||||
|
||||
Duration* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
|
||||
return CreateMaybeMessage<Duration>(arena);
|
||||
}
|
||||
void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void CopyFrom(const Duration& from);
|
||||
void MergeFrom(const Duration& from);
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize(
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
inline void SharedCtor();
|
||||
inline void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(Duration* other);
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Duration";
|
||||
}
|
||||
protected:
|
||||
explicit Duration(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
private:
|
||||
static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_google_2fprotobuf_2fduration_2eproto);
|
||||
return ::descriptor_table_google_2fprotobuf_2fduration_2eproto.file_level_metadata[kIndexInFileMessages];
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kSecondsFieldNumber = 1,
|
||||
kNanosFieldNumber = 2,
|
||||
};
|
||||
// int64 seconds = 1;
|
||||
void clear_seconds();
|
||||
::PROTOBUF_NAMESPACE_ID::int64 seconds() const;
|
||||
void set_seconds(::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
private:
|
||||
::PROTOBUF_NAMESPACE_ID::int64 _internal_seconds() const;
|
||||
void _internal_set_seconds(::PROTOBUF_NAMESPACE_ID::int64 value);
|
||||
public:
|
||||
|
||||
// int32 nanos = 2;
|
||||
void clear_nanos();
|
||||
::PROTOBUF_NAMESPACE_ID::int32 nanos() const;
|
||||
void set_nanos(::PROTOBUF_NAMESPACE_ID::int32 value);
|
||||
private:
|
||||
::PROTOBUF_NAMESPACE_ID::int32 _internal_nanos() const;
|
||||
void _internal_set_nanos(::PROTOBUF_NAMESPACE_ID::int32 value);
|
||||
public:
|
||||
|
||||
// @@protoc_insertion_point(class_scope:google.protobuf.Duration)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::int64 seconds_;
|
||||
::PROTOBUF_NAMESPACE_ID::int32 nanos_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
friend struct ::TableStruct_google_2fprotobuf_2fduration_2eproto;
|
||||
};
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// Duration
|
||||
|
||||
// int64 seconds = 1;
|
||||
inline void Duration::clear_seconds() {
|
||||
seconds_ = PROTOBUF_LONGLONG(0);
|
||||
}
|
||||
inline ::PROTOBUF_NAMESPACE_ID::int64 Duration::_internal_seconds() const {
|
||||
return seconds_;
|
||||
}
|
||||
inline ::PROTOBUF_NAMESPACE_ID::int64 Duration::seconds() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Duration.seconds)
|
||||
return _internal_seconds();
|
||||
}
|
||||
inline void Duration::_internal_set_seconds(::PROTOBUF_NAMESPACE_ID::int64 value) {
|
||||
|
||||
seconds_ = value;
|
||||
}
|
||||
inline void Duration::set_seconds(::PROTOBUF_NAMESPACE_ID::int64 value) {
|
||||
_internal_set_seconds(value);
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds)
|
||||
}
|
||||
|
||||
// int32 nanos = 2;
|
||||
inline void Duration::clear_nanos() {
|
||||
nanos_ = 0;
|
||||
}
|
||||
inline ::PROTOBUF_NAMESPACE_ID::int32 Duration::_internal_nanos() const {
|
||||
return nanos_;
|
||||
}
|
||||
inline ::PROTOBUF_NAMESPACE_ID::int32 Duration::nanos() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.Duration.nanos)
|
||||
return _internal_nanos();
|
||||
}
|
||||
inline void Duration::_internal_set_nanos(::PROTOBUF_NAMESPACE_ID::int32 value) {
|
||||
|
||||
nanos_ = value;
|
||||
}
|
||||
inline void Duration::set_nanos(::PROTOBUF_NAMESPACE_ID::int32 value) {
|
||||
_internal_set_nanos(value);
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto
|
116
include/google/protobuf/duration.proto
Normal file
116
include/google/protobuf/duration.proto
Normal file
@ -0,0 +1,116 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||
option cc_enable_arenas = true;
|
||||
option go_package = "github.com/golang/protobuf/ptypes/duration";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "DurationProto";
|
||||
option java_multiple_files = true;
|
||||
option objc_class_prefix = "GPB";
|
||||
|
||||
// A Duration represents a signed, fixed-length span of time represented
|
||||
// as a count of seconds and fractions of seconds at nanosecond
|
||||
// resolution. It is independent of any calendar and concepts like "day"
|
||||
// or "month". It is related to Timestamp in that the difference between
|
||||
// two Timestamp values is a Duration and it can be added or subtracted
|
||||
// from a Timestamp. Range is approximately +-10,000 years.
|
||||
//
|
||||
// # Examples
|
||||
//
|
||||
// Example 1: Compute Duration from two Timestamps in pseudo code.
|
||||
//
|
||||
// Timestamp start = ...;
|
||||
// Timestamp end = ...;
|
||||
// Duration duration = ...;
|
||||
//
|
||||
// duration.seconds = end.seconds - start.seconds;
|
||||
// duration.nanos = end.nanos - start.nanos;
|
||||
//
|
||||
// if (duration.seconds < 0 && duration.nanos > 0) {
|
||||
// duration.seconds += 1;
|
||||
// duration.nanos -= 1000000000;
|
||||
// } else if (duration.seconds > 0 && duration.nanos < 0) {
|
||||
// duration.seconds -= 1;
|
||||
// duration.nanos += 1000000000;
|
||||
// }
|
||||
//
|
||||
// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
|
||||
//
|
||||
// Timestamp start = ...;
|
||||
// Duration duration = ...;
|
||||
// Timestamp end = ...;
|
||||
//
|
||||
// end.seconds = start.seconds + duration.seconds;
|
||||
// end.nanos = start.nanos + duration.nanos;
|
||||
//
|
||||
// if (end.nanos < 0) {
|
||||
// end.seconds -= 1;
|
||||
// end.nanos += 1000000000;
|
||||
// } else if (end.nanos >= 1000000000) {
|
||||
// end.seconds += 1;
|
||||
// end.nanos -= 1000000000;
|
||||
// }
|
||||
//
|
||||
// Example 3: Compute Duration from datetime.timedelta in Python.
|
||||
//
|
||||
// td = datetime.timedelta(days=3, minutes=10)
|
||||
// duration = Duration()
|
||||
// duration.FromTimedelta(td)
|
||||
//
|
||||
// # JSON Mapping
|
||||
//
|
||||
// In JSON format, the Duration type is encoded as a string rather than an
|
||||
// object, where the string ends in the suffix "s" (indicating seconds) and
|
||||
// is preceded by the number of seconds, with nanoseconds expressed as
|
||||
// fractional seconds. For example, 3 seconds with 0 nanoseconds should be
|
||||
// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
|
||||
// be expressed in JSON format as "3.000000001s", and 3 seconds and 1
|
||||
// microsecond should be expressed in JSON format as "3.000001s".
|
||||
//
|
||||
//
|
||||
message Duration {
|
||||
// Signed seconds of the span of time. Must be from -315,576,000,000
|
||||
// to +315,576,000,000 inclusive. Note: these bounds are computed from:
|
||||
// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
|
||||
int64 seconds = 1;
|
||||
|
||||
// Signed fractions of a second at nanosecond resolution of the span
|
||||
// of time. Durations less than one second are represented with a 0
|
||||
// `seconds` field and a positive or negative `nanos` field. For durations
|
||||
// of one second or more, a non-zero value for the `nanos` field must be
|
||||
// of the same sign as the `seconds` field. Must be from -999,999,999
|
||||
// to +999,999,999 inclusive.
|
||||
int32 nanos = 2;
|
||||
}
|
239
include/google/protobuf/dynamic_message.h
Normal file
239
include/google/protobuf/dynamic_message.h
Normal file
@ -0,0 +1,239 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// Defines an implementation of Message which can emulate types which are not
|
||||
// known at compile-time.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
|
||||
#define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/stubs/mutex.h>
|
||||
#include <google/protobuf/reflection.h>
|
||||
#include <google/protobuf/repeated_field.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
// Defined in other files.
|
||||
class Descriptor; // descriptor.h
|
||||
class DescriptorPool; // descriptor.h
|
||||
|
||||
// Constructs implementations of Message which can emulate types which are not
|
||||
// known at compile-time.
|
||||
//
|
||||
// Sometimes you want to be able to manipulate protocol types that you don't
|
||||
// know about at compile time. It would be nice to be able to construct
|
||||
// a Message object which implements the message type given by any arbitrary
|
||||
// Descriptor. DynamicMessage provides this.
|
||||
//
|
||||
// As it turns out, a DynamicMessage needs to construct extra
|
||||
// information about its type in order to operate. Most of this information
|
||||
// can be shared between all DynamicMessages of the same type. But, caching
|
||||
// this information in some sort of global map would be a bad idea, since
|
||||
// the cached information for a particular descriptor could outlive the
|
||||
// descriptor itself. To avoid this problem, DynamicMessageFactory
|
||||
// encapsulates this "cache". All DynamicMessages of the same type created
|
||||
// from the same factory will share the same support data. Any Descriptors
|
||||
// used with a particular factory must outlive the factory.
|
||||
class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
|
||||
public:
|
||||
// Construct a DynamicMessageFactory that will search for extensions in
|
||||
// the DescriptorPool in which the extendee is defined.
|
||||
DynamicMessageFactory();
|
||||
|
||||
// Construct a DynamicMessageFactory that will search for extensions in
|
||||
// the given DescriptorPool.
|
||||
//
|
||||
// DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the
|
||||
// parser to look for extensions in an alternate pool. However, note that
|
||||
// this is almost never what you want to do. Almost all users should use
|
||||
// the zero-arg constructor.
|
||||
DynamicMessageFactory(const DescriptorPool* pool);
|
||||
|
||||
~DynamicMessageFactory();
|
||||
|
||||
// Call this to tell the DynamicMessageFactory that if it is given a
|
||||
// Descriptor d for which:
|
||||
// d->file()->pool() == DescriptorPool::generated_pool(),
|
||||
// then it should delegate to MessageFactory::generated_factory() instead
|
||||
// of constructing a dynamic implementation of the message. In theory there
|
||||
// is no down side to doing this, so it may become the default in the future.
|
||||
void SetDelegateToGeneratedFactory(bool enable) {
|
||||
delegate_to_generated_factory_ = enable;
|
||||
}
|
||||
|
||||
// implements MessageFactory ---------------------------------------
|
||||
|
||||
// Given a Descriptor, constructs the default (prototype) Message of that
|
||||
// type. You can then call that message's New() method to construct a
|
||||
// mutable message of that type.
|
||||
//
|
||||
// Calling this method twice with the same Descriptor returns the same
|
||||
// object. The returned object remains property of the factory and will
|
||||
// be destroyed when the factory is destroyed. Also, any objects created
|
||||
// by calling the prototype's New() method share some data with the
|
||||
// prototype, so these must be destroyed before the DynamicMessageFactory
|
||||
// is destroyed.
|
||||
//
|
||||
// The given descriptor must outlive the returned message, and hence must
|
||||
// outlive the DynamicMessageFactory.
|
||||
//
|
||||
// The method is thread-safe.
|
||||
const Message* GetPrototype(const Descriptor* type) override;
|
||||
|
||||
private:
|
||||
const DescriptorPool* pool_;
|
||||
bool delegate_to_generated_factory_;
|
||||
|
||||
// This struct just contains a hash_map. We can't #include <hash_map> from
|
||||
// this header due to hacks needed for hash_map portability in the open source
|
||||
// release. Namely, stubs/hash.h, which defines hash_map portably, is not a
|
||||
// public header (for good reason), but dynamic_message.h is, and public
|
||||
// headers may only #include other public headers.
|
||||
struct PrototypeMap;
|
||||
std::unique_ptr<PrototypeMap> prototypes_;
|
||||
mutable internal::WrappedMutex prototypes_mutex_;
|
||||
|
||||
friend class DynamicMessage;
|
||||
const Message* GetPrototypeNoLock(const Descriptor* type);
|
||||
|
||||
// Construct default oneof instance for reflection usage if oneof
|
||||
// is defined.
|
||||
static void ConstructDefaultOneofInstance(const Descriptor* type,
|
||||
const uint32 offsets[],
|
||||
void* default_oneof_instance);
|
||||
// Delete default oneof instance. Called by ~DynamicMessageFactory.
|
||||
static void DeleteDefaultOneofInstance(const Descriptor* type,
|
||||
const uint32 offsets[],
|
||||
const void* default_oneof_instance);
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory);
|
||||
};
|
||||
|
||||
// Helper for computing a sorted list of map entries via reflection.
|
||||
class PROTOBUF_EXPORT DynamicMapSorter {
|
||||
public:
|
||||
static std::vector<const Message*> Sort(const Message& message, int map_size,
|
||||
const Reflection* reflection,
|
||||
const FieldDescriptor* field) {
|
||||
std::vector<const Message*> result;
|
||||
result.reserve(map_size);
|
||||
RepeatedFieldRef<Message> map_field =
|
||||
reflection->GetRepeatedFieldRef<Message>(message, field);
|
||||
for (auto it = map_field.begin(); it != map_field.end(); ++it) {
|
||||
result.push_back(&*it);
|
||||
}
|
||||
MapEntryMessageComparator comparator(field->message_type());
|
||||
std::stable_sort(result.begin(), result.end(), comparator);
|
||||
// Complain if the keys aren't in ascending order.
|
||||
#ifndef NDEBUG
|
||||
for (size_t j = 1; j < static_cast<size_t>(map_size); j++) {
|
||||
if (!comparator(result[j - 1], result[j])) {
|
||||
GOOGLE_LOG(ERROR) << (comparator(result[j], result[j - 1])
|
||||
? "internal error in map key sorting"
|
||||
: "map keys are not unique");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
class PROTOBUF_EXPORT MapEntryMessageComparator {
|
||||
public:
|
||||
explicit MapEntryMessageComparator(const Descriptor* descriptor)
|
||||
: field_(descriptor->field(0)) {}
|
||||
|
||||
bool operator()(const Message* a, const Message* b) {
|
||||
const Reflection* reflection = a->GetReflection();
|
||||
switch (field_->cpp_type()) {
|
||||
case FieldDescriptor::CPPTYPE_BOOL: {
|
||||
bool first = reflection->GetBool(*a, field_);
|
||||
bool second = reflection->GetBool(*b, field_);
|
||||
return first < second;
|
||||
}
|
||||
case FieldDescriptor::CPPTYPE_INT32: {
|
||||
int32 first = reflection->GetInt32(*a, field_);
|
||||
int32 second = reflection->GetInt32(*b, field_);
|
||||
return first < second;
|
||||
}
|
||||
case FieldDescriptor::CPPTYPE_INT64: {
|
||||
int64 first = reflection->GetInt64(*a, field_);
|
||||
int64 second = reflection->GetInt64(*b, field_);
|
||||
return first < second;
|
||||
}
|
||||
case FieldDescriptor::CPPTYPE_UINT32: {
|
||||
uint32 first = reflection->GetUInt32(*a, field_);
|
||||
uint32 second = reflection->GetUInt32(*b, field_);
|
||||
return first < second;
|
||||
}
|
||||
case FieldDescriptor::CPPTYPE_UINT64: {
|
||||
uint64 first = reflection->GetUInt64(*a, field_);
|
||||
uint64 second = reflection->GetUInt64(*b, field_);
|
||||
return first < second;
|
||||
}
|
||||
case FieldDescriptor::CPPTYPE_STRING: {
|
||||
std::string first = reflection->GetString(*a, field_);
|
||||
std::string second = reflection->GetString(*b, field_);
|
||||
return first < second;
|
||||
}
|
||||
default:
|
||||
GOOGLE_LOG(DFATAL) << "Invalid key for map field.";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const FieldDescriptor* field_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
|
213
include/google/protobuf/empty.pb.h
Normal file
213
include/google/protobuf/empty.pb.h
Normal file
@ -0,0 +1,213 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/empty.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#if PROTOBUF_VERSION < 3012000
|
||||
#error This file was generated by a newer version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please update
|
||||
#error your headers.
|
||||
#endif
|
||||
#if 3012004 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error This file was generated by an older version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please
|
||||
#error regenerate this file with a newer version of protoc.
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
#include <google/protobuf/extension_set.h> // IWYU pragma: export
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
// @@protoc_insertion_point(includes)
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fempty_2eproto PROTOBUF_EXPORT
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fempty_2eproto {
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[];
|
||||
};
|
||||
extern PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fempty_2eproto;
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
class Empty;
|
||||
class EmptyDefaultTypeInternal;
|
||||
PROTOBUF_EXPORT extern EmptyDefaultTypeInternal _Empty_default_instance_;
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_EXPORT PROTOBUF_NAMESPACE_ID::Empty* Arena::CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::Empty>(Arena*);
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT Empty PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Empty) */ {
|
||||
public:
|
||||
inline Empty() : Empty(nullptr) {};
|
||||
virtual ~Empty();
|
||||
|
||||
Empty(const Empty& from);
|
||||
Empty(Empty&& from) noexcept
|
||||
: Empty() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline Empty& operator=(const Empty& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline Empty& operator=(Empty&& from) noexcept {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() {
|
||||
return GetMetadataStatic().descriptor;
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() {
|
||||
return GetMetadataStatic().reflection;
|
||||
}
|
||||
static const Empty& default_instance();
|
||||
|
||||
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
|
||||
static inline const Empty* internal_default_instance() {
|
||||
return reinterpret_cast<const Empty*>(
|
||||
&_Empty_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(Empty& a, Empty& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(Empty* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Empty* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
inline Empty* New() const final {
|
||||
return CreateMaybeMessage<Empty>(nullptr);
|
||||
}
|
||||
|
||||
Empty* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
|
||||
return CreateMaybeMessage<Empty>(arena);
|
||||
}
|
||||
void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void CopyFrom(const Empty& from);
|
||||
void MergeFrom(const Empty& from);
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize(
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
inline void SharedCtor();
|
||||
inline void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(Empty* other);
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.Empty";
|
||||
}
|
||||
protected:
|
||||
explicit Empty(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
private:
|
||||
static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_google_2fprotobuf_2fempty_2eproto);
|
||||
return ::descriptor_table_google_2fprotobuf_2fempty_2eproto.file_level_metadata[kIndexInFileMessages];
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
// @@protoc_insertion_point(class_scope:google.protobuf.Empty)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
friend struct ::TableStruct_google_2fprotobuf_2fempty_2eproto;
|
||||
};
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// Empty
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto
|
52
include/google/protobuf/empty.proto
Normal file
52
include/google/protobuf/empty.proto
Normal file
@ -0,0 +1,52 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||
option go_package = "github.com/golang/protobuf/ptypes/empty";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "EmptyProto";
|
||||
option java_multiple_files = true;
|
||||
option objc_class_prefix = "GPB";
|
||||
option cc_enable_arenas = true;
|
||||
|
||||
// A generic empty message that you can re-use to avoid defining duplicated
|
||||
// empty messages in your APIs. A typical example is to use it as the request
|
||||
// or the response type of an API method. For instance:
|
||||
//
|
||||
// service Foo {
|
||||
// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
|
||||
// }
|
||||
//
|
||||
// The JSON representation for `Empty` is empty JSON object `{}`.
|
||||
message Empty {}
|
1588
include/google/protobuf/extension_set.h
Normal file
1588
include/google/protobuf/extension_set.h
Normal file
File diff suppressed because it is too large
Load Diff
284
include/google/protobuf/extension_set_inl.h
Normal file
284
include/google/protobuf/extension_set_inl.h
Normal file
@ -0,0 +1,284 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__
|
||||
#define GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__
|
||||
|
||||
#include <google/protobuf/parse_context.h>
|
||||
#include <google/protobuf/extension_set.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
template <typename T>
|
||||
const char* ExtensionSet::ParseFieldWithExtensionInfo(
|
||||
int number, bool was_packed_on_wire, const ExtensionInfo& extension,
|
||||
InternalMetadata* metadata, const char* ptr, internal::ParseContext* ctx) {
|
||||
if (was_packed_on_wire) {
|
||||
switch (extension.type) {
|
||||
#define HANDLE_TYPE(UPPERCASE, CPP_CAMELCASE) \
|
||||
case WireFormatLite::TYPE_##UPPERCASE: \
|
||||
return internal::Packed##CPP_CAMELCASE##Parser( \
|
||||
MutableRawRepeatedField(number, extension.type, extension.is_packed, \
|
||||
extension.descriptor), \
|
||||
ptr, ctx);
|
||||
HANDLE_TYPE(INT32, Int32);
|
||||
HANDLE_TYPE(INT64, Int64);
|
||||
HANDLE_TYPE(UINT32, UInt32);
|
||||
HANDLE_TYPE(UINT64, UInt64);
|
||||
HANDLE_TYPE(SINT32, SInt32);
|
||||
HANDLE_TYPE(SINT64, SInt64);
|
||||
HANDLE_TYPE(FIXED32, Fixed32);
|
||||
HANDLE_TYPE(FIXED64, Fixed64);
|
||||
HANDLE_TYPE(SFIXED32, SFixed32);
|
||||
HANDLE_TYPE(SFIXED64, SFixed64);
|
||||
HANDLE_TYPE(FLOAT, Float);
|
||||
HANDLE_TYPE(DOUBLE, Double);
|
||||
HANDLE_TYPE(BOOL, Bool);
|
||||
#undef HANDLE_TYPE
|
||||
|
||||
case WireFormatLite::TYPE_ENUM:
|
||||
return internal::PackedEnumParserArg<T>(
|
||||
MutableRawRepeatedField(number, extension.type, extension.is_packed,
|
||||
extension.descriptor),
|
||||
ptr, ctx, extension.enum_validity_check.func,
|
||||
extension.enum_validity_check.arg, metadata, number);
|
||||
case WireFormatLite::TYPE_STRING:
|
||||
case WireFormatLite::TYPE_BYTES:
|
||||
case WireFormatLite::TYPE_GROUP:
|
||||
case WireFormatLite::TYPE_MESSAGE:
|
||||
GOOGLE_LOG(FATAL) << "Non-primitive types can't be packed.";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (extension.type) {
|
||||
#define HANDLE_VARINT_TYPE(UPPERCASE, CPP_CAMELCASE) \
|
||||
case WireFormatLite::TYPE_##UPPERCASE: { \
|
||||
uint64 value; \
|
||||
ptr = VarintParse(ptr, &value); \
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); \
|
||||
if (extension.is_repeated) { \
|
||||
Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \
|
||||
extension.is_packed, value, extension.descriptor); \
|
||||
} else { \
|
||||
Set##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, value, \
|
||||
extension.descriptor); \
|
||||
} \
|
||||
} break
|
||||
|
||||
HANDLE_VARINT_TYPE(INT32, Int32);
|
||||
HANDLE_VARINT_TYPE(INT64, Int64);
|
||||
HANDLE_VARINT_TYPE(UINT32, UInt32);
|
||||
HANDLE_VARINT_TYPE(UINT64, UInt64);
|
||||
HANDLE_VARINT_TYPE(BOOL, Bool);
|
||||
#undef HANDLE_VARINT_TYPE
|
||||
#define HANDLE_SVARINT_TYPE(UPPERCASE, CPP_CAMELCASE, SIZE) \
|
||||
case WireFormatLite::TYPE_##UPPERCASE: { \
|
||||
uint64 val; \
|
||||
ptr = VarintParse(ptr, &val); \
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); \
|
||||
auto value = WireFormatLite::ZigZagDecode##SIZE(val); \
|
||||
if (extension.is_repeated) { \
|
||||
Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \
|
||||
extension.is_packed, value, extension.descriptor); \
|
||||
} else { \
|
||||
Set##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, value, \
|
||||
extension.descriptor); \
|
||||
} \
|
||||
} break
|
||||
|
||||
HANDLE_SVARINT_TYPE(SINT32, Int32, 32);
|
||||
HANDLE_SVARINT_TYPE(SINT64, Int64, 64);
|
||||
#undef HANDLE_SVARINT_TYPE
|
||||
#define HANDLE_FIXED_TYPE(UPPERCASE, CPP_CAMELCASE, CPPTYPE) \
|
||||
case WireFormatLite::TYPE_##UPPERCASE: { \
|
||||
auto value = UnalignedLoad<CPPTYPE>(ptr); \
|
||||
ptr += sizeof(CPPTYPE); \
|
||||
if (extension.is_repeated) { \
|
||||
Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \
|
||||
extension.is_packed, value, extension.descriptor); \
|
||||
} else { \
|
||||
Set##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, value, \
|
||||
extension.descriptor); \
|
||||
} \
|
||||
} break
|
||||
|
||||
HANDLE_FIXED_TYPE(FIXED32, UInt32, uint32);
|
||||
HANDLE_FIXED_TYPE(FIXED64, UInt64, uint64);
|
||||
HANDLE_FIXED_TYPE(SFIXED32, Int32, int32);
|
||||
HANDLE_FIXED_TYPE(SFIXED64, Int64, int64);
|
||||
HANDLE_FIXED_TYPE(FLOAT, Float, float);
|
||||
HANDLE_FIXED_TYPE(DOUBLE, Double, double);
|
||||
#undef HANDLE_FIXED_TYPE
|
||||
|
||||
case WireFormatLite::TYPE_ENUM: {
|
||||
uint64 val;
|
||||
ptr = VarintParse(ptr, &val);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
int value = val;
|
||||
|
||||
if (!extension.enum_validity_check.func(
|
||||
extension.enum_validity_check.arg, value)) {
|
||||
WriteVarint(number, val, metadata->mutable_unknown_fields<T>());
|
||||
} else if (extension.is_repeated) {
|
||||
AddEnum(number, WireFormatLite::TYPE_ENUM, extension.is_packed, value,
|
||||
extension.descriptor);
|
||||
} else {
|
||||
SetEnum(number, WireFormatLite::TYPE_ENUM, value,
|
||||
extension.descriptor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WireFormatLite::TYPE_BYTES:
|
||||
case WireFormatLite::TYPE_STRING: {
|
||||
std::string* value =
|
||||
extension.is_repeated
|
||||
? AddString(number, WireFormatLite::TYPE_STRING,
|
||||
extension.descriptor)
|
||||
: MutableString(number, WireFormatLite::TYPE_STRING,
|
||||
extension.descriptor);
|
||||
int size = ReadSize(&ptr);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
return ctx->ReadString(ptr, size, value);
|
||||
}
|
||||
|
||||
case WireFormatLite::TYPE_GROUP: {
|
||||
MessageLite* value =
|
||||
extension.is_repeated
|
||||
? AddMessage(number, WireFormatLite::TYPE_GROUP,
|
||||
*extension.message_info.prototype,
|
||||
extension.descriptor)
|
||||
: MutableMessage(number, WireFormatLite::TYPE_GROUP,
|
||||
*extension.message_info.prototype,
|
||||
extension.descriptor);
|
||||
uint32 tag = (number << 3) + WireFormatLite::WIRETYPE_START_GROUP;
|
||||
return ctx->ParseGroup(value, ptr, tag);
|
||||
}
|
||||
|
||||
case WireFormatLite::TYPE_MESSAGE: {
|
||||
MessageLite* value =
|
||||
extension.is_repeated
|
||||
? AddMessage(number, WireFormatLite::TYPE_MESSAGE,
|
||||
*extension.message_info.prototype,
|
||||
extension.descriptor)
|
||||
: MutableMessage(number, WireFormatLite::TYPE_MESSAGE,
|
||||
*extension.message_info.prototype,
|
||||
extension.descriptor);
|
||||
return ctx->ParseMessage(value, ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename Msg, typename T>
|
||||
const char* ExtensionSet::ParseMessageSetItemTmpl(
|
||||
const char* ptr, const Msg* containing_type,
|
||||
internal::InternalMetadata* metadata, internal::ParseContext* ctx) {
|
||||
std::string payload;
|
||||
uint32 type_id;
|
||||
enum class State { kNoTag, kHasType, kHasPayload, kDone };
|
||||
State state = State::kNoTag;
|
||||
while (!ctx->Done(&ptr)) {
|
||||
uint32 tag = static_cast<uint8>(*ptr++);
|
||||
if (tag == WireFormatLite::kMessageSetTypeIdTag) {
|
||||
uint64 tmp;
|
||||
ptr = ParseBigVarint(ptr, &tmp);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
if (state == State::kNoTag) {
|
||||
type_id = tmp;
|
||||
state = State::kHasType;
|
||||
} else if (state == State::kHasPayload) {
|
||||
type_id = tmp;
|
||||
ExtensionInfo extension;
|
||||
bool was_packed_on_wire;
|
||||
if (!FindExtension(2, type_id, containing_type, ctx, &extension,
|
||||
&was_packed_on_wire)) {
|
||||
WriteLengthDelimited(type_id, payload,
|
||||
metadata->mutable_unknown_fields<T>());
|
||||
} else {
|
||||
MessageLite* value =
|
||||
extension.is_repeated
|
||||
? AddMessage(type_id, WireFormatLite::TYPE_MESSAGE,
|
||||
*extension.message_info.prototype,
|
||||
extension.descriptor)
|
||||
: MutableMessage(type_id, WireFormatLite::TYPE_MESSAGE,
|
||||
*extension.message_info.prototype,
|
||||
extension.descriptor);
|
||||
|
||||
const char* p;
|
||||
// We can't use regular parse from string as we have to track
|
||||
// proper recursion depth and descriptor pools.
|
||||
ParseContext tmp_ctx(ctx->depth(), false, &p, payload);
|
||||
tmp_ctx.data().pool = ctx->data().pool;
|
||||
tmp_ctx.data().factory = ctx->data().factory;
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(value->_InternalParse(p, &tmp_ctx) &&
|
||||
tmp_ctx.EndedAtLimit());
|
||||
}
|
||||
state = State::kDone;
|
||||
}
|
||||
} else if (tag == WireFormatLite::kMessageSetMessageTag) {
|
||||
if (state == State::kHasType) {
|
||||
ptr = ParseFieldMaybeLazily(static_cast<uint64>(type_id) * 8 + 2, ptr,
|
||||
containing_type, metadata, ctx);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr != nullptr);
|
||||
state = State::kDone;
|
||||
} else {
|
||||
std::string tmp;
|
||||
int32 size = ReadSize(&ptr);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
ptr = ctx->ReadString(ptr, size, &tmp);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
if (state == State::kNoTag) {
|
||||
payload = std::move(tmp);
|
||||
state = State::kHasPayload;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ptr = ReadTag(ptr - 1, &tag);
|
||||
if (tag == 0 || (tag & 7) == 4) {
|
||||
ctx->SetLastTag(tag);
|
||||
return ptr;
|
||||
}
|
||||
ptr = ParseField(tag, ptr, containing_type, metadata, ctx);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__
|
315
include/google/protobuf/field_mask.pb.h
Normal file
315
include/google/protobuf/field_mask.pb.h
Normal file
@ -0,0 +1,315 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/field_mask.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#if PROTOBUF_VERSION < 3012000
|
||||
#error This file was generated by a newer version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please update
|
||||
#error your headers.
|
||||
#endif
|
||||
#if 3012004 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error This file was generated by an older version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please
|
||||
#error regenerate this file with a newer version of protoc.
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
#include <google/protobuf/extension_set.h> // IWYU pragma: export
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
// @@protoc_insertion_point(includes)
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ffield_5fmask_2eproto PROTOBUF_EXPORT
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto {
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[];
|
||||
};
|
||||
extern PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto;
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
class FieldMask;
|
||||
class FieldMaskDefaultTypeInternal;
|
||||
PROTOBUF_EXPORT extern FieldMaskDefaultTypeInternal _FieldMask_default_instance_;
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_EXPORT PROTOBUF_NAMESPACE_ID::FieldMask* Arena::CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::FieldMask>(Arena*);
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT FieldMask PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldMask) */ {
|
||||
public:
|
||||
inline FieldMask() : FieldMask(nullptr) {};
|
||||
virtual ~FieldMask();
|
||||
|
||||
FieldMask(const FieldMask& from);
|
||||
FieldMask(FieldMask&& from) noexcept
|
||||
: FieldMask() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline FieldMask& operator=(const FieldMask& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline FieldMask& operator=(FieldMask&& from) noexcept {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() {
|
||||
return GetMetadataStatic().descriptor;
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() {
|
||||
return GetMetadataStatic().reflection;
|
||||
}
|
||||
static const FieldMask& default_instance();
|
||||
|
||||
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
|
||||
static inline const FieldMask* internal_default_instance() {
|
||||
return reinterpret_cast<const FieldMask*>(
|
||||
&_FieldMask_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(FieldMask& a, FieldMask& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(FieldMask* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(FieldMask* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
inline FieldMask* New() const final {
|
||||
return CreateMaybeMessage<FieldMask>(nullptr);
|
||||
}
|
||||
|
||||
FieldMask* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
|
||||
return CreateMaybeMessage<FieldMask>(arena);
|
||||
}
|
||||
void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void CopyFrom(const FieldMask& from);
|
||||
void MergeFrom(const FieldMask& from);
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize(
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
inline void SharedCtor();
|
||||
inline void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(FieldMask* other);
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.FieldMask";
|
||||
}
|
||||
protected:
|
||||
explicit FieldMask(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
private:
|
||||
static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto);
|
||||
return ::descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto.file_level_metadata[kIndexInFileMessages];
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kPathsFieldNumber = 1,
|
||||
};
|
||||
// repeated string paths = 1;
|
||||
int paths_size() const;
|
||||
private:
|
||||
int _internal_paths_size() const;
|
||||
public:
|
||||
void clear_paths();
|
||||
const std::string& paths(int index) const;
|
||||
std::string* mutable_paths(int index);
|
||||
void set_paths(int index, const std::string& value);
|
||||
void set_paths(int index, std::string&& value);
|
||||
void set_paths(int index, const char* value);
|
||||
void set_paths(int index, const char* value, size_t size);
|
||||
std::string* add_paths();
|
||||
void add_paths(const std::string& value);
|
||||
void add_paths(std::string&& value);
|
||||
void add_paths(const char* value);
|
||||
void add_paths(const char* value, size_t size);
|
||||
const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>& paths() const;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>* mutable_paths();
|
||||
private:
|
||||
const std::string& _internal_paths(int index) const;
|
||||
std::string* _internal_add_paths();
|
||||
public:
|
||||
|
||||
// @@protoc_insertion_point(class_scope:google.protobuf.FieldMask)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string> paths_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
friend struct ::TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto;
|
||||
};
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// FieldMask
|
||||
|
||||
// repeated string paths = 1;
|
||||
inline int FieldMask::_internal_paths_size() const {
|
||||
return paths_.size();
|
||||
}
|
||||
inline int FieldMask::paths_size() const {
|
||||
return _internal_paths_size();
|
||||
}
|
||||
inline void FieldMask::clear_paths() {
|
||||
paths_.Clear();
|
||||
}
|
||||
inline std::string* FieldMask::add_paths() {
|
||||
// @@protoc_insertion_point(field_add_mutable:google.protobuf.FieldMask.paths)
|
||||
return _internal_add_paths();
|
||||
}
|
||||
inline const std::string& FieldMask::_internal_paths(int index) const {
|
||||
return paths_.Get(index);
|
||||
}
|
||||
inline const std::string& FieldMask::paths(int index) const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.FieldMask.paths)
|
||||
return _internal_paths(index);
|
||||
}
|
||||
inline std::string* FieldMask::mutable_paths(int index) {
|
||||
// @@protoc_insertion_point(field_mutable:google.protobuf.FieldMask.paths)
|
||||
return paths_.Mutable(index);
|
||||
}
|
||||
inline void FieldMask::set_paths(int index, const std::string& value) {
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
|
||||
paths_.Mutable(index)->assign(value);
|
||||
}
|
||||
inline void FieldMask::set_paths(int index, std::string&& value) {
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
|
||||
paths_.Mutable(index)->assign(std::move(value));
|
||||
}
|
||||
inline void FieldMask::set_paths(int index, const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
paths_.Mutable(index)->assign(value);
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths)
|
||||
}
|
||||
inline void FieldMask::set_paths(int index, const char* value, size_t size) {
|
||||
paths_.Mutable(index)->assign(
|
||||
reinterpret_cast<const char*>(value), size);
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldMask.paths)
|
||||
}
|
||||
inline std::string* FieldMask::_internal_add_paths() {
|
||||
return paths_.Add();
|
||||
}
|
||||
inline void FieldMask::add_paths(const std::string& value) {
|
||||
paths_.Add()->assign(value);
|
||||
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
|
||||
}
|
||||
inline void FieldMask::add_paths(std::string&& value) {
|
||||
paths_.Add(std::move(value));
|
||||
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
|
||||
}
|
||||
inline void FieldMask::add_paths(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
paths_.Add()->assign(value);
|
||||
// @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths)
|
||||
}
|
||||
inline void FieldMask::add_paths(const char* value, size_t size) {
|
||||
paths_.Add()->assign(reinterpret_cast<const char*>(value), size);
|
||||
// @@protoc_insertion_point(field_add_pointer:google.protobuf.FieldMask.paths)
|
||||
}
|
||||
inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>&
|
||||
FieldMask::paths() const {
|
||||
// @@protoc_insertion_point(field_list:google.protobuf.FieldMask.paths)
|
||||
return paths_;
|
||||
}
|
||||
inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>*
|
||||
FieldMask::mutable_paths() {
|
||||
// @@protoc_insertion_point(field_mutable_list:google.protobuf.FieldMask.paths)
|
||||
return &paths_;
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto
|
245
include/google/protobuf/field_mask.proto
Normal file
245
include/google/protobuf/field_mask.proto
Normal file
@ -0,0 +1,245 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "FieldMaskProto";
|
||||
option java_multiple_files = true;
|
||||
option objc_class_prefix = "GPB";
|
||||
option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask";
|
||||
option cc_enable_arenas = true;
|
||||
|
||||
// `FieldMask` represents a set of symbolic field paths, for example:
|
||||
//
|
||||
// paths: "f.a"
|
||||
// paths: "f.b.d"
|
||||
//
|
||||
// Here `f` represents a field in some root message, `a` and `b`
|
||||
// fields in the message found in `f`, and `d` a field found in the
|
||||
// message in `f.b`.
|
||||
//
|
||||
// Field masks are used to specify a subset of fields that should be
|
||||
// returned by a get operation or modified by an update operation.
|
||||
// Field masks also have a custom JSON encoding (see below).
|
||||
//
|
||||
// # Field Masks in Projections
|
||||
//
|
||||
// When used in the context of a projection, a response message or
|
||||
// sub-message is filtered by the API to only contain those fields as
|
||||
// specified in the mask. For example, if the mask in the previous
|
||||
// example is applied to a response message as follows:
|
||||
//
|
||||
// f {
|
||||
// a : 22
|
||||
// b {
|
||||
// d : 1
|
||||
// x : 2
|
||||
// }
|
||||
// y : 13
|
||||
// }
|
||||
// z: 8
|
||||
//
|
||||
// The result will not contain specific values for fields x,y and z
|
||||
// (their value will be set to the default, and omitted in proto text
|
||||
// output):
|
||||
//
|
||||
//
|
||||
// f {
|
||||
// a : 22
|
||||
// b {
|
||||
// d : 1
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// A repeated field is not allowed except at the last position of a
|
||||
// paths string.
|
||||
//
|
||||
// If a FieldMask object is not present in a get operation, the
|
||||
// operation applies to all fields (as if a FieldMask of all fields
|
||||
// had been specified).
|
||||
//
|
||||
// Note that a field mask does not necessarily apply to the
|
||||
// top-level response message. In case of a REST get operation, the
|
||||
// field mask applies directly to the response, but in case of a REST
|
||||
// list operation, the mask instead applies to each individual message
|
||||
// in the returned resource list. In case of a REST custom method,
|
||||
// other definitions may be used. Where the mask applies will be
|
||||
// clearly documented together with its declaration in the API. In
|
||||
// any case, the effect on the returned resource/resources is required
|
||||
// behavior for APIs.
|
||||
//
|
||||
// # Field Masks in Update Operations
|
||||
//
|
||||
// A field mask in update operations specifies which fields of the
|
||||
// targeted resource are going to be updated. The API is required
|
||||
// to only change the values of the fields as specified in the mask
|
||||
// and leave the others untouched. If a resource is passed in to
|
||||
// describe the updated values, the API ignores the values of all
|
||||
// fields not covered by the mask.
|
||||
//
|
||||
// If a repeated field is specified for an update operation, new values will
|
||||
// be appended to the existing repeated field in the target resource. Note that
|
||||
// a repeated field is only allowed in the last position of a `paths` string.
|
||||
//
|
||||
// If a sub-message is specified in the last position of the field mask for an
|
||||
// update operation, then new value will be merged into the existing sub-message
|
||||
// in the target resource.
|
||||
//
|
||||
// For example, given the target message:
|
||||
//
|
||||
// f {
|
||||
// b {
|
||||
// d: 1
|
||||
// x: 2
|
||||
// }
|
||||
// c: [1]
|
||||
// }
|
||||
//
|
||||
// And an update message:
|
||||
//
|
||||
// f {
|
||||
// b {
|
||||
// d: 10
|
||||
// }
|
||||
// c: [2]
|
||||
// }
|
||||
//
|
||||
// then if the field mask is:
|
||||
//
|
||||
// paths: ["f.b", "f.c"]
|
||||
//
|
||||
// then the result will be:
|
||||
//
|
||||
// f {
|
||||
// b {
|
||||
// d: 10
|
||||
// x: 2
|
||||
// }
|
||||
// c: [1, 2]
|
||||
// }
|
||||
//
|
||||
// An implementation may provide options to override this default behavior for
|
||||
// repeated and message fields.
|
||||
//
|
||||
// In order to reset a field's value to the default, the field must
|
||||
// be in the mask and set to the default value in the provided resource.
|
||||
// Hence, in order to reset all fields of a resource, provide a default
|
||||
// instance of the resource and set all fields in the mask, or do
|
||||
// not provide a mask as described below.
|
||||
//
|
||||
// If a field mask is not present on update, the operation applies to
|
||||
// all fields (as if a field mask of all fields has been specified).
|
||||
// Note that in the presence of schema evolution, this may mean that
|
||||
// fields the client does not know and has therefore not filled into
|
||||
// the request will be reset to their default. If this is unwanted
|
||||
// behavior, a specific service may require a client to always specify
|
||||
// a field mask, producing an error if not.
|
||||
//
|
||||
// As with get operations, the location of the resource which
|
||||
// describes the updated values in the request message depends on the
|
||||
// operation kind. In any case, the effect of the field mask is
|
||||
// required to be honored by the API.
|
||||
//
|
||||
// ## Considerations for HTTP REST
|
||||
//
|
||||
// The HTTP kind of an update operation which uses a field mask must
|
||||
// be set to PATCH instead of PUT in order to satisfy HTTP semantics
|
||||
// (PUT must only be used for full updates).
|
||||
//
|
||||
// # JSON Encoding of Field Masks
|
||||
//
|
||||
// In JSON, a field mask is encoded as a single string where paths are
|
||||
// separated by a comma. Fields name in each path are converted
|
||||
// to/from lower-camel naming conventions.
|
||||
//
|
||||
// As an example, consider the following message declarations:
|
||||
//
|
||||
// message Profile {
|
||||
// User user = 1;
|
||||
// Photo photo = 2;
|
||||
// }
|
||||
// message User {
|
||||
// string display_name = 1;
|
||||
// string address = 2;
|
||||
// }
|
||||
//
|
||||
// In proto a field mask for `Profile` may look as such:
|
||||
//
|
||||
// mask {
|
||||
// paths: "user.display_name"
|
||||
// paths: "photo"
|
||||
// }
|
||||
//
|
||||
// In JSON, the same mask is represented as below:
|
||||
//
|
||||
// {
|
||||
// mask: "user.displayName,photo"
|
||||
// }
|
||||
//
|
||||
// # Field Masks and Oneof Fields
|
||||
//
|
||||
// Field masks treat fields in oneofs just as regular fields. Consider the
|
||||
// following message:
|
||||
//
|
||||
// message SampleMessage {
|
||||
// oneof test_oneof {
|
||||
// string name = 4;
|
||||
// SubMessage sub_message = 9;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// The field mask can be:
|
||||
//
|
||||
// mask {
|
||||
// paths: "name"
|
||||
// }
|
||||
//
|
||||
// Or:
|
||||
//
|
||||
// mask {
|
||||
// paths: "sub_message"
|
||||
// }
|
||||
//
|
||||
// Note that oneof type names ("test_oneof" in this case) cannot be used in
|
||||
// paths.
|
||||
//
|
||||
// ## Field Mask Verification
|
||||
//
|
||||
// The implementation of any API method which has a FieldMask type field in the
|
||||
// request should verify the included field paths, and return an
|
||||
// `INVALID_ARGUMENT` error if any path is unmappable.
|
||||
message FieldMask {
|
||||
// The set of field mask paths.
|
||||
repeated string paths = 1;
|
||||
}
|
97
include/google/protobuf/generated_enum_reflection.h
Normal file
97
include/google/protobuf/generated_enum_reflection.h
Normal file
@ -0,0 +1,97 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: jasonh@google.com (Jason Hsueh)
|
||||
//
|
||||
// This header is logically internal, but is made public because it is used
|
||||
// from protocol-compiler-generated code, which may reside in other components.
|
||||
// It provides reflection support for generated enums, and is included in
|
||||
// generated .pb.h files and should have minimal dependencies. The methods are
|
||||
// implemented in generated_message_reflection.cc.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__
|
||||
#define GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/generated_enum_util.h>
|
||||
#include <google/protobuf/port.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class EnumDescriptor;
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
// Returns the EnumDescriptor for enum type E, which must be a
|
||||
// proto-declared enum type. Code generated by the protocol compiler
|
||||
// will include specializations of this template for each enum type declared.
|
||||
template <typename E>
|
||||
const EnumDescriptor* GetEnumDescriptor();
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Helper for EnumType_Parse functions: try to parse the string 'name' as
|
||||
// an enum name of the given type, returning true and filling in value on
|
||||
// success, or returning false and leaving value unchanged on failure.
|
||||
PROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor,
|
||||
const std::string& name, int* value);
|
||||
|
||||
template <typename EnumType>
|
||||
bool ParseNamedEnum(const EnumDescriptor* descriptor, const std::string& name,
|
||||
EnumType* value) {
|
||||
int tmp;
|
||||
if (!ParseNamedEnum(descriptor, name, &tmp)) return false;
|
||||
*value = static_cast<EnumType>(tmp);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Just a wrapper around printing the name of a value. The main point of this
|
||||
// function is not to be inlined, so that you can do this without including
|
||||
// descriptor.h.
|
||||
PROTOBUF_EXPORT const std::string& NameOfEnum(const EnumDescriptor* descriptor,
|
||||
int value);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__
|
83
include/google/protobuf/generated_enum_util.h
Normal file
83
include/google/protobuf/generated_enum_util.h
Normal file
@ -0,0 +1,83 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__
|
||||
#define GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <google/protobuf/message_lite.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
// This type trait can be used to cause templates to only match proto2 enum
|
||||
// types.
|
||||
template <typename T>
|
||||
struct is_proto_enum : ::std::false_type {};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// The table entry format for storing enum name-to-value mapping used with lite
|
||||
// protos. This struct and the following related functions should only be used
|
||||
// by protobuf generated code.
|
||||
struct EnumEntry {
|
||||
StringPiece name;
|
||||
int value;
|
||||
};
|
||||
|
||||
// Looks up a numeric enum value given the string name.
|
||||
PROTOBUF_EXPORT bool LookUpEnumValue(const EnumEntry* enums, size_t size,
|
||||
StringPiece name, int* value);
|
||||
|
||||
// Looks up an enum name given the numeric value.
|
||||
PROTOBUF_EXPORT int LookUpEnumName(const EnumEntry* enums,
|
||||
const int* sorted_indices, size_t size,
|
||||
int value);
|
||||
|
||||
// Initializes the list of enum names in std::string form.
|
||||
PROTOBUF_EXPORT bool InitializeEnumStrings(
|
||||
const EnumEntry* enums, const int* sorted_indices, size_t size,
|
||||
internal::ExplicitlyConstructed<std::string>* enum_strings);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__
|
317
include/google/protobuf/generated_message_reflection.h
Normal file
317
include/google/protobuf/generated_message_reflection.h
Normal file
@ -0,0 +1,317 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// This header is logically internal, but is made public because it is used
|
||||
// from protocol-compiler-generated code, which may reside in other components.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
|
||||
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <google/protobuf/stubs/casts.h>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
// TODO(jasonh): Remove this once the compiler change to directly include this
|
||||
// is released to components.
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/generated_enum_reflection.h>
|
||||
#include <google/protobuf/stubs/once.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class DescriptorPool;
|
||||
class MapKey;
|
||||
class MapValueRef;
|
||||
class MessageLayoutInspector;
|
||||
class Message;
|
||||
struct Metadata;
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
class DefaultEmptyOneof;
|
||||
// Defined in other files.
|
||||
class ExtensionSet; // extension_set.h
|
||||
class WeakFieldMap; // weak_field_map.h
|
||||
|
||||
// This struct describes the internal layout of the message, hence this is
|
||||
// used to act on the message reflectively.
|
||||
// default_instance: The default instance of the message. This is only
|
||||
// used to obtain pointers to default instances of embedded
|
||||
// messages, which GetMessage() will return if the particular
|
||||
// sub-message has not been initialized yet. (Thus, all
|
||||
// embedded message fields *must* have non-null pointers
|
||||
// in the default instance.)
|
||||
// offsets: An array of ints giving the byte offsets.
|
||||
// For each oneof or weak field, the offset is relative to the
|
||||
// default_instance. These can be computed at compile time
|
||||
// using the
|
||||
// PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET()
|
||||
// macro. For each none oneof field, the offset is related to
|
||||
// the start of the message object. These can be computed at
|
||||
// compile time using the
|
||||
// PROTO2_GENERATED_MESSAGE_FIELD_OFFSET() macro.
|
||||
// Besides offsets for all fields, this array also contains
|
||||
// offsets for oneof unions. The offset of the i-th oneof union
|
||||
// is offsets[descriptor->field_count() + i].
|
||||
// has_bit_indices: Mapping from field indexes to their index in the has
|
||||
// bit array.
|
||||
// has_bits_offset: Offset in the message of an array of uint32s of size
|
||||
// descriptor->field_count()/32, rounded up. This is a
|
||||
// bitfield where each bit indicates whether or not the
|
||||
// corresponding field of the message has been initialized.
|
||||
// The bit for field index i is obtained by the expression:
|
||||
// has_bits[i / 32] & (1 << (i % 32))
|
||||
// unknown_fields_offset: Offset in the message of the UnknownFieldSet for
|
||||
// the message.
|
||||
// extensions_offset: Offset in the message of the ExtensionSet for the
|
||||
// message, or -1 if the message type has no extension
|
||||
// ranges.
|
||||
// oneof_case_offset: Offset in the message of an array of uint32s of
|
||||
// size descriptor->oneof_decl_count(). Each uint32
|
||||
// indicates what field is set for each oneof.
|
||||
// object_size: The size of a message object of this type, as measured
|
||||
// by sizeof().
|
||||
// arena_offset: If a message doesn't have a unknown_field_set that stores
|
||||
// the arena, it must have a direct pointer to the arena.
|
||||
// weak_field_map_offset: If the message proto has weak fields, this is the
|
||||
// offset of _weak_field_map_ in the generated proto. Otherwise
|
||||
// -1.
|
||||
struct ReflectionSchema {
|
||||
public:
|
||||
// Size of a google::protobuf::Message object of this type.
|
||||
uint32 GetObjectSize() const { return static_cast<uint32>(object_size_); }
|
||||
|
||||
bool InRealOneof(const FieldDescriptor* field) const {
|
||||
return field->containing_oneof() &&
|
||||
!field->containing_oneof()->is_synthetic();
|
||||
}
|
||||
|
||||
// Offset of a non-oneof field. Getting a field offset is slightly more
|
||||
// efficient when we know statically that it is not a oneof field.
|
||||
uint32 GetFieldOffsetNonOneof(const FieldDescriptor* field) const {
|
||||
GOOGLE_DCHECK(!InRealOneof(field));
|
||||
return OffsetValue(offsets_[field->index()], field->type());
|
||||
}
|
||||
|
||||
// Offset of any field.
|
||||
uint32 GetFieldOffset(const FieldDescriptor* field) const {
|
||||
if (InRealOneof(field)) {
|
||||
size_t offset =
|
||||
static_cast<size_t>(field->containing_type()->field_count() +
|
||||
field->containing_oneof()->index());
|
||||
return OffsetValue(offsets_[offset], field->type());
|
||||
} else {
|
||||
return GetFieldOffsetNonOneof(field);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsFieldInlined(const FieldDescriptor* field) const {
|
||||
if (InRealOneof(field)) {
|
||||
size_t offset =
|
||||
static_cast<size_t>(field->containing_type()->field_count() +
|
||||
field->containing_oneof()->index());
|
||||
return Inlined(offsets_[offset], field->type());
|
||||
} else {
|
||||
return Inlined(offsets_[field->index()], field->type());
|
||||
}
|
||||
}
|
||||
|
||||
uint32 GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {
|
||||
return static_cast<uint32>(oneof_case_offset_) +
|
||||
static_cast<uint32>(static_cast<size_t>(oneof_descriptor->index()) *
|
||||
sizeof(uint32));
|
||||
}
|
||||
|
||||
bool HasHasbits() const { return has_bits_offset_ != -1; }
|
||||
|
||||
// Bit index within the bit array of hasbits. Bit order is low-to-high.
|
||||
uint32 HasBitIndex(const FieldDescriptor* field) const {
|
||||
if (has_bits_offset_ == -1) return static_cast<uint32>(-1);
|
||||
GOOGLE_DCHECK(HasHasbits());
|
||||
return has_bit_indices_[field->index()];
|
||||
}
|
||||
|
||||
// Byte offset of the hasbits array.
|
||||
uint32 HasBitsOffset() const {
|
||||
GOOGLE_DCHECK(HasHasbits());
|
||||
return static_cast<uint32>(has_bits_offset_);
|
||||
}
|
||||
|
||||
// The offset of the InternalMetadataWithArena member.
|
||||
// For Lite this will actually be an InternalMetadataWithArenaLite.
|
||||
// The schema doesn't contain enough information to distinguish between
|
||||
// these two cases.
|
||||
uint32 GetMetadataOffset() const {
|
||||
return static_cast<uint32>(metadata_offset_);
|
||||
}
|
||||
|
||||
// Whether this message has an ExtensionSet.
|
||||
bool HasExtensionSet() const { return extensions_offset_ != -1; }
|
||||
|
||||
// The offset of the ExtensionSet in this message.
|
||||
uint32 GetExtensionSetOffset() const {
|
||||
GOOGLE_DCHECK(HasExtensionSet());
|
||||
return static_cast<uint32>(extensions_offset_);
|
||||
}
|
||||
|
||||
// The off set of WeakFieldMap when the message contains weak fields.
|
||||
// The default is 0 for now.
|
||||
int GetWeakFieldMapOffset() const { return weak_field_map_offset_; }
|
||||
|
||||
bool IsDefaultInstance(const Message& message) const {
|
||||
return &message == default_instance_;
|
||||
}
|
||||
|
||||
// Returns a pointer to the default value for this field. The size and type
|
||||
// of the underlying data depends on the field's type.
|
||||
const void* GetFieldDefault(const FieldDescriptor* field) const {
|
||||
return reinterpret_cast<const uint8*>(default_instance_) +
|
||||
OffsetValue(offsets_[field->index()], field->type());
|
||||
}
|
||||
|
||||
|
||||
bool HasWeakFields() const { return weak_field_map_offset_ > 0; }
|
||||
|
||||
// These members are intended to be private, but we cannot actually make them
|
||||
// private because this prevents us from using aggregate initialization of
|
||||
// them, ie.
|
||||
//
|
||||
// ReflectionSchema schema = {a, b, c, d, e, ...};
|
||||
// private:
|
||||
const Message* default_instance_;
|
||||
const uint32* offsets_;
|
||||
const uint32* has_bit_indices_;
|
||||
int has_bits_offset_;
|
||||
int metadata_offset_;
|
||||
int extensions_offset_;
|
||||
int oneof_case_offset_;
|
||||
int object_size_;
|
||||
int weak_field_map_offset_;
|
||||
|
||||
// We tag offset values to provide additional data about fields (such as
|
||||
// inlined).
|
||||
static uint32 OffsetValue(uint32 v, FieldDescriptor::Type type) {
|
||||
if (type == FieldDescriptor::TYPE_STRING ||
|
||||
type == FieldDescriptor::TYPE_BYTES) {
|
||||
return v & ~1u;
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
static bool Inlined(uint32 v, FieldDescriptor::Type type) {
|
||||
if (type == FieldDescriptor::TYPE_STRING ||
|
||||
type == FieldDescriptor::TYPE_BYTES) {
|
||||
return v & 1u;
|
||||
} else {
|
||||
// Non string/byte fields are not inlined.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Structs that the code generator emits directly to describe a message.
|
||||
// These should never used directly except to build a ReflectionSchema
|
||||
// object.
|
||||
//
|
||||
// EXPERIMENTAL: these are changing rapidly, and may completely disappear
|
||||
// or merge with ReflectionSchema.
|
||||
struct MigrationSchema {
|
||||
int32 offsets_index;
|
||||
int32 has_bit_indices_index;
|
||||
int object_size;
|
||||
};
|
||||
|
||||
struct SCCInfoBase;
|
||||
|
||||
struct PROTOBUF_EXPORT DescriptorTable {
|
||||
mutable bool is_initialized;
|
||||
bool is_eager;
|
||||
const char* descriptor;
|
||||
const char* filename;
|
||||
int size; // of serialized descriptor
|
||||
once_flag* once;
|
||||
SCCInfoBase* const* init_default_instances;
|
||||
const DescriptorTable* const* deps;
|
||||
int num_sccs;
|
||||
int num_deps;
|
||||
const MigrationSchema* schemas;
|
||||
const Message* const* default_instances;
|
||||
const uint32* offsets;
|
||||
// update the following descriptor arrays.
|
||||
Metadata* file_level_metadata;
|
||||
int num_messages;
|
||||
const EnumDescriptor** file_level_enum_descriptors;
|
||||
const ServiceDescriptor** file_level_service_descriptors;
|
||||
};
|
||||
|
||||
// AssignDescriptors() pulls the compiled FileDescriptor from the DescriptorPool
|
||||
// and uses it to populate all of the global variables which store pointers to
|
||||
// the descriptor objects. It also constructs the reflection objects. It is
|
||||
// called the first time anyone calls descriptor() or GetReflection() on one of
|
||||
// the types defined in the file. AssignDescriptors() is thread-safe.
|
||||
void PROTOBUF_EXPORT AssignDescriptors(const DescriptorTable* table,
|
||||
bool eager = false);
|
||||
|
||||
// AddDescriptors() is a file-level procedure which adds the encoded
|
||||
// FileDescriptorProto for this .proto file to the global DescriptorPool for
|
||||
// generated files (DescriptorPool::generated_pool()). It ordinarily runs at
|
||||
// static initialization time, but is not used at all in LITE_RUNTIME mode.
|
||||
// AddDescriptors() is *not* thread-safe.
|
||||
void PROTOBUF_EXPORT AddDescriptors(const DescriptorTable* table);
|
||||
|
||||
// These cannot be in lite so we put them in the reflection.
|
||||
PROTOBUF_EXPORT void UnknownFieldSetSerializer(const uint8* base, uint32 offset,
|
||||
uint32 tag, uint32 has_offset,
|
||||
io::CodedOutputStream* output);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
|
339
include/google/protobuf/generated_message_table_driven.h
Normal file
339
include/google/protobuf/generated_message_table_driven.h
Normal file
@ -0,0 +1,339 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__
|
||||
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__
|
||||
|
||||
#include <google/protobuf/map.h>
|
||||
#include <google/protobuf/map_entry_lite.h>
|
||||
#include <google/protobuf/map_field_lite.h>
|
||||
#include <google/protobuf/message_lite.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
|
||||
// We require C++11 and Clang to use constexpr for variables, as GCC 4.8
|
||||
// requires constexpr to be consistent between declarations of variables
|
||||
// unnecessarily (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58541).
|
||||
// VS 2017 Update 3 also supports this usage of constexpr.
|
||||
#if defined(__clang__) || (defined(_MSC_VER) && _MSC_VER >= 1911)
|
||||
#define PROTOBUF_CONSTEXPR_VAR constexpr
|
||||
#else // !__clang__
|
||||
#define PROTOBUF_CONSTEXPR_VAR
|
||||
#endif // !_clang
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// Processing-type masks.
|
||||
static constexpr const unsigned char kOneofMask = 0x40;
|
||||
static constexpr const unsigned char kRepeatedMask = 0x20;
|
||||
// Mask for the raw type: either a WireFormatLite::FieldType or one of the
|
||||
// ProcessingTypes below, without the oneof or repeated flag.
|
||||
static constexpr const unsigned char kTypeMask = 0x1f;
|
||||
|
||||
// Wire type masks.
|
||||
static constexpr const unsigned char kNotPackedMask = 0x10;
|
||||
static constexpr const unsigned char kInvalidMask = 0x20;
|
||||
|
||||
enum ProcessingTypes {
|
||||
TYPE_STRING_CORD = 19,
|
||||
TYPE_STRING_STRING_PIECE = 20,
|
||||
TYPE_BYTES_CORD = 21,
|
||||
TYPE_BYTES_STRING_PIECE = 22,
|
||||
TYPE_STRING_INLINED = 23,
|
||||
TYPE_BYTES_INLINED = 24,
|
||||
TYPE_MAP = 25,
|
||||
};
|
||||
|
||||
static_assert(TYPE_MAP < kRepeatedMask, "Invalid enum");
|
||||
|
||||
struct PROTOBUF_EXPORT FieldMetadata {
|
||||
uint32 offset; // offset of this field in the struct
|
||||
uint32 tag; // field * 8 + wire_type
|
||||
// byte offset * 8 + bit_offset;
|
||||
// if the high bit is set then this is the byte offset of the oneof_case
|
||||
// for this field.
|
||||
uint32 has_offset;
|
||||
uint32 type; // the type of this field.
|
||||
const void* ptr; // auxiliary data
|
||||
|
||||
// From the serializer point of view each fundamental type can occur in
|
||||
// 4 different ways. For simplicity we treat all combinations as a cartesion
|
||||
// product although not all combinations are allowed.
|
||||
enum FieldTypeClass {
|
||||
kPresence,
|
||||
kNoPresence,
|
||||
kRepeated,
|
||||
kPacked,
|
||||
kOneOf,
|
||||
kNumTypeClasses // must be last enum
|
||||
};
|
||||
// C++ protobuf has 20 fundamental types, were we added Cord and StringPiece
|
||||
// and also distinquish the same types if they have different wire format.
|
||||
enum {
|
||||
kCordType = 19,
|
||||
kStringPieceType = 20,
|
||||
kInlinedType = 21,
|
||||
kNumTypes = 21,
|
||||
kSpecial = kNumTypes * kNumTypeClasses,
|
||||
};
|
||||
|
||||
static int CalculateType(int fundamental_type, FieldTypeClass type_class);
|
||||
};
|
||||
|
||||
// TODO(ckennelly): Add a static assertion to ensure that these masks do not
|
||||
// conflict with wiretypes.
|
||||
|
||||
// ParseTableField is kept small to help simplify instructions for computing
|
||||
// offsets, as we will always need this information to parse a field.
|
||||
// Additional data, needed for some types, is stored in
|
||||
// AuxillaryParseTableField.
|
||||
struct ParseTableField {
|
||||
uint32 offset;
|
||||
// The presence_index ordinarily represents a has_bit index, but for fields
|
||||
// inside a oneof it represents the index in _oneof_case_.
|
||||
uint32 presence_index;
|
||||
unsigned char normal_wiretype;
|
||||
unsigned char packed_wiretype;
|
||||
|
||||
// processing_type is given by:
|
||||
// (FieldDescriptor->type() << 1) | FieldDescriptor->is_packed()
|
||||
unsigned char processing_type;
|
||||
|
||||
unsigned char tag_size;
|
||||
};
|
||||
|
||||
struct ParseTable;
|
||||
|
||||
union AuxillaryParseTableField {
|
||||
typedef bool (*EnumValidator)(int);
|
||||
|
||||
// Enums
|
||||
struct enum_aux {
|
||||
EnumValidator validator;
|
||||
};
|
||||
enum_aux enums;
|
||||
// Group, messages
|
||||
struct message_aux {
|
||||
// ExplicitlyInitialized<T> -> T requires a reinterpret_cast, which prevents
|
||||
// the tables from being constructed as a constexpr. We use void to avoid
|
||||
// the cast.
|
||||
const void* default_message_void;
|
||||
const MessageLite* default_message() const {
|
||||
return static_cast<const MessageLite*>(default_message_void);
|
||||
}
|
||||
};
|
||||
message_aux messages;
|
||||
// Strings
|
||||
struct string_aux {
|
||||
const void* default_ptr;
|
||||
const char* field_name;
|
||||
};
|
||||
string_aux strings;
|
||||
|
||||
struct map_aux {
|
||||
bool (*parse_map)(io::CodedInputStream*, void*);
|
||||
};
|
||||
map_aux maps;
|
||||
|
||||
AuxillaryParseTableField() = default;
|
||||
constexpr AuxillaryParseTableField(AuxillaryParseTableField::enum_aux e)
|
||||
: enums(e) {}
|
||||
constexpr AuxillaryParseTableField(AuxillaryParseTableField::message_aux m)
|
||||
: messages(m) {}
|
||||
constexpr AuxillaryParseTableField(AuxillaryParseTableField::string_aux s)
|
||||
: strings(s) {}
|
||||
constexpr AuxillaryParseTableField(AuxillaryParseTableField::map_aux m)
|
||||
: maps(m) {}
|
||||
};
|
||||
|
||||
struct ParseTable {
|
||||
const ParseTableField* fields;
|
||||
const AuxillaryParseTableField* aux;
|
||||
int max_field_number;
|
||||
// TODO(ckennelly): Do something with this padding.
|
||||
|
||||
// TODO(ckennelly): Vet these for sign extension.
|
||||
int64 has_bits_offset;
|
||||
int64 oneof_case_offset;
|
||||
int64 extension_offset;
|
||||
int64 arena_offset;
|
||||
|
||||
// ExplicitlyInitialized<T> -> T requires a reinterpret_cast, which prevents
|
||||
// the tables from being constructed as a constexpr. We use void to avoid
|
||||
// the cast.
|
||||
const void* default_instance_void;
|
||||
const MessageLite* default_instance() const {
|
||||
return static_cast<const MessageLite*>(default_instance_void);
|
||||
}
|
||||
|
||||
bool unknown_field_set;
|
||||
};
|
||||
|
||||
static_assert(sizeof(ParseTableField) <= 16, "ParseTableField is too large");
|
||||
// The tables must be composed of POD components to ensure link-time
|
||||
// initialization.
|
||||
static_assert(std::is_pod<ParseTableField>::value, "");
|
||||
static_assert(std::is_pod<AuxillaryParseTableField>::value, "");
|
||||
static_assert(std::is_pod<AuxillaryParseTableField::enum_aux>::value, "");
|
||||
static_assert(std::is_pod<AuxillaryParseTableField::message_aux>::value, "");
|
||||
static_assert(std::is_pod<AuxillaryParseTableField::string_aux>::value, "");
|
||||
static_assert(std::is_pod<ParseTable>::value, "");
|
||||
|
||||
// TODO(ckennelly): Consolidate these implementations into a single one, using
|
||||
// dynamic dispatch to the appropriate unknown field handler.
|
||||
bool MergePartialFromCodedStream(MessageLite* msg, const ParseTable& table,
|
||||
io::CodedInputStream* input);
|
||||
bool MergePartialFromCodedStreamLite(MessageLite* msg, const ParseTable& table,
|
||||
io::CodedInputStream* input);
|
||||
|
||||
template <typename Entry>
|
||||
bool ParseMap(io::CodedInputStream* input, void* map_field) {
|
||||
typedef typename MapEntryToMapField<Entry>::MapFieldType MapFieldType;
|
||||
typedef Map<typename Entry::EntryKeyType, typename Entry::EntryValueType>
|
||||
MapType;
|
||||
typedef typename Entry::template Parser<MapFieldType, MapType> ParserType;
|
||||
|
||||
ParserType parser(static_cast<MapFieldType*>(map_field));
|
||||
return WireFormatLite::ReadMessageNoVirtual(input, &parser);
|
||||
}
|
||||
|
||||
struct SerializationTable {
|
||||
int num_fields;
|
||||
const FieldMetadata* field_table;
|
||||
};
|
||||
|
||||
PROTOBUF_EXPORT void SerializeInternal(const uint8* base,
|
||||
const FieldMetadata* table,
|
||||
int32 num_fields,
|
||||
io::CodedOutputStream* output);
|
||||
|
||||
inline void TableSerialize(const MessageLite& msg,
|
||||
const SerializationTable* table,
|
||||
io::CodedOutputStream* output) {
|
||||
const FieldMetadata* field_table = table->field_table;
|
||||
int num_fields = table->num_fields - 1;
|
||||
const uint8* base = reinterpret_cast<const uint8*>(&msg);
|
||||
// TODO(gerbens) This skips the first test if we could use the fast
|
||||
// array serialization path, we should make this
|
||||
// int cached_size =
|
||||
// *reinterpret_cast<const int32*>(base + field_table->offset);
|
||||
// SerializeWithCachedSize(msg, field_table + 1, num_fields, cached_size, ...)
|
||||
// But we keep conformance with the old way for now.
|
||||
SerializeInternal(base, field_table + 1, num_fields, output);
|
||||
}
|
||||
|
||||
uint8* SerializeInternalToArray(const uint8* base, const FieldMetadata* table,
|
||||
int32 num_fields, bool is_deterministic,
|
||||
uint8* buffer);
|
||||
|
||||
inline uint8* TableSerializeToArray(const MessageLite& msg,
|
||||
const SerializationTable* table,
|
||||
bool is_deterministic, uint8* buffer) {
|
||||
const uint8* base = reinterpret_cast<const uint8*>(&msg);
|
||||
const FieldMetadata* field_table = table->field_table + 1;
|
||||
int num_fields = table->num_fields - 1;
|
||||
return SerializeInternalToArray(base, field_table, num_fields,
|
||||
is_deterministic, buffer);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct CompareHelper {
|
||||
bool operator()(const T& a, const T& b) const { return a < b; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct CompareHelper<ArenaStringPtr> {
|
||||
bool operator()(const ArenaStringPtr& a, const ArenaStringPtr& b) const {
|
||||
return a.Get() < b.Get();
|
||||
}
|
||||
};
|
||||
|
||||
struct CompareMapKey {
|
||||
template <typename T>
|
||||
bool operator()(const MapEntryHelper<T>& a,
|
||||
const MapEntryHelper<T>& b) const {
|
||||
return Compare(a.key_, b.key_);
|
||||
}
|
||||
template <typename T>
|
||||
bool Compare(const T& a, const T& b) const {
|
||||
return CompareHelper<T>()(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename MapFieldType, const SerializationTable* table>
|
||||
void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag,
|
||||
uint32 has_offset, io::CodedOutputStream* output) {
|
||||
typedef MapEntryHelper<typename MapFieldType::EntryTypeTrait> Entry;
|
||||
typedef typename MapFieldType::MapType::const_iterator Iter;
|
||||
|
||||
const MapFieldType& map_field =
|
||||
*reinterpret_cast<const MapFieldType*>(base + offset);
|
||||
const SerializationTable* t =
|
||||
table +
|
||||
has_offset; // has_offset is overloaded for maps to mean table offset
|
||||
if (!output->IsSerializationDeterministic()) {
|
||||
for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end();
|
||||
++it) {
|
||||
Entry map_entry(*it);
|
||||
output->WriteVarint32(tag);
|
||||
output->WriteVarint32(map_entry._cached_size_);
|
||||
SerializeInternal(reinterpret_cast<const uint8*>(&map_entry),
|
||||
t->field_table, t->num_fields, output);
|
||||
}
|
||||
} else {
|
||||
std::vector<Entry> v;
|
||||
for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end();
|
||||
++it) {
|
||||
v.push_back(Entry(*it));
|
||||
}
|
||||
std::sort(v.begin(), v.end(), CompareMapKey());
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
output->WriteVarint32(tag);
|
||||
output->WriteVarint32(v[i]._cached_size_);
|
||||
SerializeInternal(reinterpret_cast<const uint8*>(&v[i]), t->field_table,
|
||||
t->num_fields, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__
|
260
include/google/protobuf/generated_message_util.h
Normal file
260
include/google/protobuf/generated_message_util.h
Normal file
@ -0,0 +1,260 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// This file contains miscellaneous helper code used by generated code --
|
||||
// including lite types -- but which should not be used directly by users.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
|
||||
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/any.h>
|
||||
#include <google/protobuf/has_bits.h>
|
||||
#include <google/protobuf/implicit_weak_message.h>
|
||||
#include <google/protobuf/message_lite.h>
|
||||
#include <google/protobuf/stubs/once.h> // Add direct dep on port for pb.cc
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/repeated_field.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
#include <google/protobuf/stubs/casts.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
class Arena;
|
||||
class Message;
|
||||
|
||||
namespace io {
|
||||
class CodedInputStream;
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename To, typename From>
|
||||
inline To DownCast(From* f) {
|
||||
return PROTOBUF_NAMESPACE_ID::internal::down_cast<To>(f);
|
||||
}
|
||||
template <typename To, typename From>
|
||||
inline To DownCast(From& f) {
|
||||
return PROTOBUF_NAMESPACE_ID::internal::down_cast<To>(f);
|
||||
}
|
||||
|
||||
|
||||
PROTOBUF_EXPORT void InitProtobufDefaults();
|
||||
|
||||
// This used by proto1
|
||||
PROTOBUF_EXPORT inline const std::string& GetEmptyString() {
|
||||
InitProtobufDefaults();
|
||||
return GetEmptyStringAlreadyInited();
|
||||
}
|
||||
|
||||
|
||||
// True if IsInitialized() is true for all elements of t. Type is expected
|
||||
// to be a RepeatedPtrField<some message type>. It's useful to have this
|
||||
// helper here to keep the protobuf compiler from ever having to emit loops in
|
||||
// IsInitialized() methods. We want the C++ compiler to inline this or not
|
||||
// as it sees fit.
|
||||
template <typename Msg>
|
||||
bool AllAreInitialized(const RepeatedPtrField<Msg>& t) {
|
||||
for (int i = t.size(); --i >= 0;) {
|
||||
if (!t.Get(i).IsInitialized()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// "Weak" variant of AllAreInitialized, used to implement implicit weak fields.
|
||||
// This version operates on MessageLite to avoid introducing a dependency on the
|
||||
// concrete message type.
|
||||
template <class T>
|
||||
bool AllAreInitializedWeak(const RepeatedPtrField<T>& t) {
|
||||
for (int i = t.size(); --i >= 0;) {
|
||||
if (!reinterpret_cast<const RepeatedPtrFieldBase&>(t)
|
||||
.Get<ImplicitWeakTypeHandler<T> >(i)
|
||||
.IsInitialized()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool IsPresent(const void* base, uint32 hasbit) {
|
||||
const uint32* has_bits_array = static_cast<const uint32*>(base);
|
||||
return (has_bits_array[hasbit / 32] & (1u << (hasbit & 31))) != 0;
|
||||
}
|
||||
|
||||
inline bool IsOneofPresent(const void* base, uint32 offset, uint32 tag) {
|
||||
const uint32* oneof =
|
||||
reinterpret_cast<const uint32*>(static_cast<const uint8*>(base) + offset);
|
||||
return *oneof == tag >> 3;
|
||||
}
|
||||
|
||||
typedef void (*SpecialSerializer)(const uint8* base, uint32 offset, uint32 tag,
|
||||
uint32 has_offset,
|
||||
io::CodedOutputStream* output);
|
||||
|
||||
PROTOBUF_EXPORT void ExtensionSerializer(const uint8* base, uint32 offset,
|
||||
uint32 tag, uint32 has_offset,
|
||||
io::CodedOutputStream* output);
|
||||
PROTOBUF_EXPORT void UnknownFieldSerializerLite(const uint8* base,
|
||||
uint32 offset, uint32 tag,
|
||||
uint32 has_offset,
|
||||
io::CodedOutputStream* output);
|
||||
|
||||
PROTOBUF_EXPORT MessageLite* DuplicateIfNonNullInternal(MessageLite* message);
|
||||
PROTOBUF_EXPORT MessageLite* GetOwnedMessageInternal(Arena* message_arena,
|
||||
MessageLite* submessage,
|
||||
Arena* submessage_arena);
|
||||
PROTOBUF_EXPORT void GenericSwap(MessageLite* m1, MessageLite* m2);
|
||||
// We specialize GenericSwap for non-lite messages to benefit from reflection.
|
||||
PROTOBUF_EXPORT void GenericSwap(Message* m1, Message* m2);
|
||||
|
||||
template <typename T>
|
||||
T* DuplicateIfNonNull(T* message) {
|
||||
// The casts must be reinterpret_cast<> because T might be a forward-declared
|
||||
// type that the compiler doesn't know is related to MessageLite.
|
||||
return reinterpret_cast<T*>(
|
||||
DuplicateIfNonNullInternal(reinterpret_cast<MessageLite*>(message)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* GetOwnedMessage(Arena* message_arena, T* submessage,
|
||||
Arena* submessage_arena) {
|
||||
// The casts must be reinterpret_cast<> because T might be a forward-declared
|
||||
// type that the compiler doesn't know is related to MessageLite.
|
||||
return reinterpret_cast<T*>(GetOwnedMessageInternal(
|
||||
message_arena, reinterpret_cast<MessageLite*>(submessage),
|
||||
submessage_arena));
|
||||
}
|
||||
|
||||
// Hide atomic from the public header and allow easy change to regular int
|
||||
// on platforms where the atomic might have a perf impact.
|
||||
class PROTOBUF_EXPORT CachedSize {
|
||||
public:
|
||||
int Get() const { return size_.load(std::memory_order_relaxed); }
|
||||
void Set(int size) { size_.store(size, std::memory_order_relaxed); }
|
||||
|
||||
private:
|
||||
std::atomic<int> size_{0};
|
||||
};
|
||||
|
||||
// SCCInfo represents information of a strongly connected component of
|
||||
// mutual dependent messages.
|
||||
struct PROTOBUF_EXPORT SCCInfoBase {
|
||||
// We use 0 for the Initialized state, because test eax,eax, jnz is smaller
|
||||
// and is subject to macro fusion.
|
||||
enum {
|
||||
kInitialized = 0, // final state
|
||||
kRunning = 1,
|
||||
kUninitialized = -1, // initial state
|
||||
};
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
// MSVC doesn't make std::atomic constant initialized. This union trick
|
||||
// makes it so.
|
||||
union {
|
||||
int visit_status_to_make_linker_init;
|
||||
std::atomic<int> visit_status;
|
||||
};
|
||||
#else
|
||||
std::atomic<int> visit_status;
|
||||
#endif
|
||||
int num_deps;
|
||||
int num_implicit_weak_deps;
|
||||
void (*init_func)();
|
||||
// This is followed by an array of num_deps
|
||||
// const SCCInfoBase* deps[];
|
||||
};
|
||||
|
||||
// Zero-length arrays are a language extension available in GCC and Clang but
|
||||
// not MSVC.
|
||||
#ifdef __GNUC__
|
||||
#define PROTOBUF_ARRAY_SIZE(n) (n)
|
||||
#else
|
||||
#define PROTOBUF_ARRAY_SIZE(n) ((n) ? (n) : 1)
|
||||
#endif
|
||||
|
||||
template <int N>
|
||||
struct SCCInfo {
|
||||
SCCInfoBase base;
|
||||
// Semantically this is const SCCInfo<T>* which is is a templated type.
|
||||
// The obvious inheriting from SCCInfoBase mucks with struct initialization.
|
||||
// Attempts showed the compiler was generating dynamic initialization code.
|
||||
// This deps array consists of base.num_deps pointers to SCCInfoBase followed
|
||||
// by base.num_implicit_weak_deps pointers to SCCInfoBase*. We need the extra
|
||||
// pointer indirection for implicit weak fields. We cannot use a union type
|
||||
// here, since that would prevent the array from being linker-initialized.
|
||||
void* deps[PROTOBUF_ARRAY_SIZE(N)];
|
||||
};
|
||||
|
||||
#undef PROTOBUF_ARRAY_SIZE
|
||||
|
||||
PROTOBUF_EXPORT void InitSCCImpl(SCCInfoBase* scc);
|
||||
|
||||
inline void InitSCC(SCCInfoBase* scc) {
|
||||
auto status = scc->visit_status.load(std::memory_order_acquire);
|
||||
if (PROTOBUF_PREDICT_FALSE(status != SCCInfoBase::kInitialized))
|
||||
InitSCCImpl(scc);
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT void DestroyMessage(const void* message);
|
||||
PROTOBUF_EXPORT void DestroyString(const void* s);
|
||||
// Destroy (not delete) the message
|
||||
inline void OnShutdownDestroyMessage(const void* ptr) {
|
||||
OnShutdownRun(DestroyMessage, ptr);
|
||||
}
|
||||
// Destroy the string (call std::string destructor)
|
||||
inline void OnShutdownDestroyString(const std::string* ptr) {
|
||||
OnShutdownRun(DestroyString, ptr);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
|
116
include/google/protobuf/has_bits.h
Normal file
116
include/google/protobuf/has_bits.h
Normal file
@ -0,0 +1,116 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_HAS_BITS_H__
|
||||
#define GOOGLE_PROTOBUF_HAS_BITS_H__
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/port.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
template <size_t doublewords>
|
||||
class HasBits {
|
||||
public:
|
||||
HasBits() PROTOBUF_ALWAYS_INLINE { Clear(); }
|
||||
|
||||
void Clear() PROTOBUF_ALWAYS_INLINE {
|
||||
memset(has_bits_, 0, sizeof(has_bits_));
|
||||
}
|
||||
|
||||
uint32& operator[](int index) PROTOBUF_ALWAYS_INLINE {
|
||||
return has_bits_[index];
|
||||
}
|
||||
|
||||
const uint32& operator[](int index) const PROTOBUF_ALWAYS_INLINE {
|
||||
return has_bits_[index];
|
||||
}
|
||||
|
||||
bool operator==(const HasBits<doublewords>& rhs) const {
|
||||
return memcmp(has_bits_, rhs.has_bits_, sizeof(has_bits_)) == 0;
|
||||
}
|
||||
|
||||
bool operator!=(const HasBits<doublewords>& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
void Or(const HasBits<doublewords>& rhs) {
|
||||
for (size_t i = 0; i < doublewords; i++) has_bits_[i] |= rhs[i];
|
||||
}
|
||||
|
||||
bool empty() const;
|
||||
|
||||
private:
|
||||
uint32 has_bits_[doublewords];
|
||||
};
|
||||
|
||||
template <>
|
||||
inline bool HasBits<1>::empty() const {
|
||||
return !has_bits_[0];
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool HasBits<2>::empty() const {
|
||||
return !(has_bits_[0] | has_bits_[1]);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool HasBits<3>::empty() const {
|
||||
return !(has_bits_[0] | has_bits_[1] | has_bits_[2]);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool HasBits<4>::empty() const {
|
||||
return !(has_bits_[0] | has_bits_[1] | has_bits_[2] | has_bits_[3]);
|
||||
}
|
||||
|
||||
template <size_t doublewords>
|
||||
inline bool HasBits<doublewords>::empty() const {
|
||||
for (size_t i = 0; i < doublewords; ++i) {
|
||||
if (has_bits_[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_HAS_BITS_H__
|
190
include/google/protobuf/implicit_weak_message.h
Normal file
190
include/google/protobuf/implicit_weak_message.h
Normal file
@ -0,0 +1,190 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
|
||||
#define GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/message_lite.h>
|
||||
#include <google/protobuf/repeated_field.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
// This file is logically internal-only and should only be used by protobuf
|
||||
// generated code.
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// An implementation of MessageLite that treats all data as unknown. This type
|
||||
// acts as a placeholder for an implicit weak field in the case where the true
|
||||
// message type does not get linked into the binary.
|
||||
class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
|
||||
public:
|
||||
ImplicitWeakMessage() {}
|
||||
explicit ImplicitWeakMessage(Arena* arena) : MessageLite(arena) {}
|
||||
|
||||
static const ImplicitWeakMessage* default_instance();
|
||||
|
||||
std::string GetTypeName() const override { return ""; }
|
||||
|
||||
MessageLite* New() const override { return new ImplicitWeakMessage; }
|
||||
MessageLite* New(Arena* arena) const override {
|
||||
return Arena::CreateMessage<ImplicitWeakMessage>(arena);
|
||||
}
|
||||
|
||||
void Clear() override { data_.clear(); }
|
||||
|
||||
bool IsInitialized() const override { return true; }
|
||||
|
||||
void CheckTypeAndMergeFrom(const MessageLite& other) override {
|
||||
data_.append(static_cast<const ImplicitWeakMessage&>(other).data_);
|
||||
}
|
||||
|
||||
const char* _InternalParse(const char* ptr, ParseContext* ctx) final;
|
||||
|
||||
size_t ByteSizeLong() const override { return data_.size(); }
|
||||
|
||||
uint8* _InternalSerialize(uint8* target,
|
||||
io::EpsCopyOutputStream* stream) const final {
|
||||
return stream->WriteRaw(data_.data(), static_cast<int>(data_.size()),
|
||||
target);
|
||||
}
|
||||
|
||||
int GetCachedSize() const override { return static_cast<int>(data_.size()); }
|
||||
|
||||
typedef void InternalArenaConstructable_;
|
||||
|
||||
private:
|
||||
std::string data_;
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImplicitWeakMessage);
|
||||
};
|
||||
|
||||
// A type handler for use with implicit weak repeated message fields.
|
||||
template <typename ImplicitWeakType>
|
||||
class ImplicitWeakTypeHandler {
|
||||
public:
|
||||
typedef MessageLite Type;
|
||||
static constexpr bool Moveable = false;
|
||||
|
||||
static inline MessageLite* NewFromPrototype(const MessageLite* prototype,
|
||||
Arena* arena = NULL) {
|
||||
return prototype->New(arena);
|
||||
}
|
||||
|
||||
static inline void Delete(MessageLite* value, Arena* arena) {
|
||||
if (arena == NULL) {
|
||||
delete value;
|
||||
}
|
||||
}
|
||||
static inline Arena* GetArena(MessageLite* value) {
|
||||
return value->GetArena();
|
||||
}
|
||||
static inline void* GetMaybeArenaPointer(MessageLite* value) {
|
||||
return value->GetArena();
|
||||
}
|
||||
static inline void Clear(MessageLite* value) { value->Clear(); }
|
||||
static void Merge(const MessageLite& from, MessageLite* to) {
|
||||
to->CheckTypeAndMergeFrom(from);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <typename T>
|
||||
struct WeakRepeatedPtrField {
|
||||
using TypeHandler = internal::ImplicitWeakTypeHandler<T>;
|
||||
WeakRepeatedPtrField() : weak() {}
|
||||
explicit WeakRepeatedPtrField(Arena* arena) : weak(arena) {}
|
||||
~WeakRepeatedPtrField() { weak.template Destroy<TypeHandler>(); }
|
||||
|
||||
typedef internal::RepeatedPtrIterator<MessageLite> iterator;
|
||||
typedef internal::RepeatedPtrIterator<const MessageLite> const_iterator;
|
||||
typedef internal::RepeatedPtrOverPtrsIterator<MessageLite*, void*>
|
||||
pointer_iterator;
|
||||
typedef internal::RepeatedPtrOverPtrsIterator<const MessageLite* const,
|
||||
const void* const>
|
||||
const_pointer_iterator;
|
||||
|
||||
iterator begin() { return iterator(base().raw_data()); }
|
||||
const_iterator begin() const { return iterator(base().raw_data()); }
|
||||
const_iterator cbegin() const { return begin(); }
|
||||
iterator end() { return begin() + base().size(); }
|
||||
const_iterator end() const { return begin() + base().size(); }
|
||||
const_iterator cend() const { return end(); }
|
||||
pointer_iterator pointer_begin() {
|
||||
return pointer_iterator(base().raw_mutable_data());
|
||||
}
|
||||
const_pointer_iterator pointer_begin() const {
|
||||
return const_pointer_iterator(base().raw_mutable_data());
|
||||
}
|
||||
pointer_iterator pointer_end() {
|
||||
return pointer_iterator(base().raw_mutable_data() + base().size());
|
||||
}
|
||||
const_pointer_iterator pointer_end() const {
|
||||
return const_pointer_iterator(base().raw_mutable_data() + base().size());
|
||||
}
|
||||
|
||||
MessageLite* AddWeak(const MessageLite* prototype) {
|
||||
return base().AddWeak(prototype);
|
||||
}
|
||||
T* Add() { return weak.Add(); }
|
||||
void Clear() { base().template Clear<TypeHandler>(); }
|
||||
void MergeFrom(const WeakRepeatedPtrField& other) {
|
||||
base().template MergeFrom<TypeHandler>(other.base());
|
||||
}
|
||||
void InternalSwap(WeakRepeatedPtrField* other) {
|
||||
base().InternalSwap(&other->base());
|
||||
}
|
||||
|
||||
const internal::RepeatedPtrFieldBase& base() const { return weak; }
|
||||
internal::RepeatedPtrFieldBase& base() { return weak; }
|
||||
// Union disables running the destructor. Which would create a strong link.
|
||||
// Instead we explicitly destroy the underlying base through the virtual
|
||||
// destructor.
|
||||
union {
|
||||
RepeatedPtrField<T> weak;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
|
260
include/google/protobuf/inlined_string_field.h
Normal file
260
include/google/protobuf/inlined_string_field.h
Normal file
@ -0,0 +1,260 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
|
||||
#define GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
|
||||
// Must be included last.
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
class Arena;
|
||||
|
||||
namespace internal {
|
||||
|
||||
// InlinedStringField wraps a std::string instance and exposes an API similar to
|
||||
// ArenaStringPtr's wrapping of a std::string* instance. As std::string is
|
||||
// never allocated on the Arena, we expose only the *NoArena methods of
|
||||
// ArenaStringPtr.
|
||||
//
|
||||
// default_value parameters are taken for consistency with ArenaStringPtr, but
|
||||
// are not used for most methods. With inlining, these should be removed from
|
||||
// the generated binary.
|
||||
class PROTOBUF_EXPORT InlinedStringField {
|
||||
public:
|
||||
InlinedStringField() PROTOBUF_ALWAYS_INLINE;
|
||||
explicit InlinedStringField(const std::string& default_value);
|
||||
|
||||
void AssignWithDefault(const std::string* default_value,
|
||||
const InlinedStringField& from) PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
void ClearToEmpty(const std::string* default_value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
ClearToEmptyNoArena(default_value);
|
||||
}
|
||||
void ClearNonDefaultToEmpty() PROTOBUF_ALWAYS_INLINE {
|
||||
ClearNonDefaultToEmptyNoArena();
|
||||
}
|
||||
void ClearToEmptyNoArena(const std::string* /*default_value*/)
|
||||
PROTOBUF_ALWAYS_INLINE {
|
||||
ClearNonDefaultToEmptyNoArena();
|
||||
}
|
||||
void ClearNonDefaultToEmptyNoArena() PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
void ClearToDefault(const std::string* default_value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
ClearToDefaultNoArena(default_value);
|
||||
}
|
||||
void ClearToDefaultNoArena(const std::string* default_value)
|
||||
PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
void Destroy(const std::string* default_value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
DestroyNoArena(default_value);
|
||||
}
|
||||
void DestroyNoArena(const std::string* default_value) PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
const std::string& Get() const PROTOBUF_ALWAYS_INLINE { return GetNoArena(); }
|
||||
const std::string& GetNoArena() const PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
std::string* Mutable(const std::string* default_value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
return MutableNoArena(default_value);
|
||||
}
|
||||
std::string* MutableNoArena(const std::string* default_value)
|
||||
PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
std::string* Release(const std::string* default_value, Arena* /*arena*/) {
|
||||
return ReleaseNoArena(default_value);
|
||||
}
|
||||
std::string* ReleaseNonDefault(const std::string* default_value,
|
||||
Arena* /*arena*/) {
|
||||
return ReleaseNonDefaultNoArena(default_value);
|
||||
}
|
||||
std::string* ReleaseNoArena(const std::string* default_value) {
|
||||
return ReleaseNonDefaultNoArena(default_value);
|
||||
}
|
||||
std::string* ReleaseNonDefaultNoArena(const std::string* default_value);
|
||||
|
||||
void Set(const std::string* default_value, StringPiece value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
SetNoArena(default_value, value);
|
||||
}
|
||||
void SetLite(const std::string* default_value, StringPiece value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
SetNoArena(default_value, value);
|
||||
}
|
||||
void SetNoArena(const std::string* default_value,
|
||||
StringPiece value) PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
void Set(const std::string* default_value, const std::string& value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
SetNoArena(default_value, value);
|
||||
}
|
||||
void SetLite(const std::string* default_value, const std::string& value,
|
||||
Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
|
||||
SetNoArena(default_value, value);
|
||||
}
|
||||
void SetNoArena(const std::string* default_value,
|
||||
const std::string& value) PROTOBUF_ALWAYS_INLINE;
|
||||
|
||||
void SetNoArena(const std::string* default_value,
|
||||
std::string&& value) PROTOBUF_ALWAYS_INLINE;
|
||||
void SetAllocated(const std::string* default_value, std::string* value,
|
||||
Arena* /*arena*/) {
|
||||
SetAllocatedNoArena(default_value, value);
|
||||
}
|
||||
void SetAllocatedNoArena(const std::string* default_value,
|
||||
std::string* value);
|
||||
void Swap(InlinedStringField* from) PROTOBUF_ALWAYS_INLINE;
|
||||
std::string* UnsafeMutablePointer();
|
||||
void UnsafeSetDefault(const std::string* default_value);
|
||||
std::string* UnsafeArenaRelease(const std::string* default_value,
|
||||
Arena* arena);
|
||||
void UnsafeArenaSetAllocated(const std::string* default_value,
|
||||
std::string* value, Arena* arena);
|
||||
|
||||
bool IsDefault(const std::string* /*default_value*/) { return false; }
|
||||
|
||||
private:
|
||||
std::string value_;
|
||||
};
|
||||
|
||||
inline InlinedStringField::InlinedStringField() {}
|
||||
|
||||
inline InlinedStringField::InlinedStringField(const std::string& default_value)
|
||||
: value_(default_value) {}
|
||||
|
||||
inline void InlinedStringField::AssignWithDefault(
|
||||
const std::string* /*default_value*/, const InlinedStringField& from) {
|
||||
value_ = from.value_;
|
||||
}
|
||||
|
||||
inline const std::string& InlinedStringField::GetNoArena() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
inline std::string* InlinedStringField::MutableNoArena(const std::string*) {
|
||||
return &value_;
|
||||
}
|
||||
|
||||
inline void InlinedStringField::SetAllocatedNoArena(
|
||||
const std::string* default_value, std::string* value) {
|
||||
if (value == NULL) {
|
||||
value_.assign(*default_value);
|
||||
} else {
|
||||
value_.assign(std::move(*value));
|
||||
delete value;
|
||||
}
|
||||
}
|
||||
|
||||
inline void InlinedStringField::DestroyNoArena(const std::string*) {
|
||||
// This is invoked from the generated message's ArenaDtor, which is used to
|
||||
// clean up objects not allocated on the Arena.
|
||||
this->~InlinedStringField();
|
||||
}
|
||||
|
||||
inline void InlinedStringField::ClearNonDefaultToEmptyNoArena() {
|
||||
value_.clear();
|
||||
}
|
||||
|
||||
inline void InlinedStringField::ClearToDefaultNoArena(
|
||||
const std::string* default_value) {
|
||||
value_.assign(*default_value);
|
||||
}
|
||||
|
||||
inline std::string* InlinedStringField::ReleaseNonDefaultNoArena(
|
||||
const std::string* default_value) {
|
||||
std::string* released = new std::string(*default_value);
|
||||
value_.swap(*released);
|
||||
return released;
|
||||
}
|
||||
|
||||
inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
|
||||
StringPiece value) {
|
||||
value_.assign(value.data(), value.length());
|
||||
}
|
||||
|
||||
inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
|
||||
const std::string& value) {
|
||||
value_.assign(value);
|
||||
}
|
||||
|
||||
inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
|
||||
std::string&& value) {
|
||||
value_.assign(std::move(value));
|
||||
}
|
||||
|
||||
inline void InlinedStringField::Swap(InlinedStringField* from) {
|
||||
value_.swap(from->value_);
|
||||
}
|
||||
|
||||
inline std::string* InlinedStringField::UnsafeMutablePointer() {
|
||||
return &value_;
|
||||
}
|
||||
|
||||
inline void InlinedStringField::UnsafeSetDefault(
|
||||
const std::string* default_value) {
|
||||
value_.assign(*default_value);
|
||||
}
|
||||
|
||||
inline std::string* InlinedStringField::UnsafeArenaRelease(
|
||||
const std::string* default_value, Arena* /*arena*/) {
|
||||
return ReleaseNoArena(default_value);
|
||||
}
|
||||
|
||||
inline void InlinedStringField::UnsafeArenaSetAllocated(
|
||||
const std::string* default_value, std::string* value, Arena* /*arena*/) {
|
||||
if (value == NULL) {
|
||||
value_.assign(*default_value);
|
||||
} else {
|
||||
value_.assign(*value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
|
1714
include/google/protobuf/io/coded_stream.h
Normal file
1714
include/google/protobuf/io/coded_stream.h
Normal file
File diff suppressed because it is too large
Load Diff
202
include/google/protobuf/io/gzip_stream.h
Normal file
202
include/google/protobuf/io/gzip_stream.h
Normal file
@ -0,0 +1,202 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: brianolson@google.com (Brian Olson)
|
||||
//
|
||||
// This file contains the definition for classes GzipInputStream and
|
||||
// GzipOutputStream.
|
||||
//
|
||||
// GzipInputStream decompresses data from an underlying
|
||||
// ZeroCopyInputStream and provides the decompressed data as a
|
||||
// ZeroCopyInputStream.
|
||||
//
|
||||
// GzipOutputStream is an ZeroCopyOutputStream that compresses data to
|
||||
// an underlying ZeroCopyOutputStream.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__
|
||||
#define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__
|
||||
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
// A ZeroCopyInputStream that reads compressed data through zlib
|
||||
class PROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream {
|
||||
public:
|
||||
// Format key for constructor
|
||||
enum Format {
|
||||
// zlib will autodetect gzip header or deflate stream
|
||||
AUTO = 0,
|
||||
|
||||
// GZIP streams have some extra header data for file attributes.
|
||||
GZIP = 1,
|
||||
|
||||
// Simpler zlib stream format.
|
||||
ZLIB = 2,
|
||||
};
|
||||
|
||||
// buffer_size and format may be -1 for default of 64kB and GZIP format
|
||||
explicit GzipInputStream(ZeroCopyInputStream* sub_stream,
|
||||
Format format = AUTO, int buffer_size = -1);
|
||||
virtual ~GzipInputStream();
|
||||
|
||||
// Return last error message or NULL if no error.
|
||||
inline const char* ZlibErrorMessage() const { return zcontext_.msg; }
|
||||
inline int ZlibErrorCode() const { return zerror_; }
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size);
|
||||
void BackUp(int count);
|
||||
bool Skip(int count);
|
||||
int64_t ByteCount() const;
|
||||
|
||||
private:
|
||||
Format format_;
|
||||
|
||||
ZeroCopyInputStream* sub_stream_;
|
||||
|
||||
z_stream zcontext_;
|
||||
int zerror_;
|
||||
|
||||
void* output_buffer_;
|
||||
void* output_position_;
|
||||
size_t output_buffer_length_;
|
||||
int64 byte_count_;
|
||||
|
||||
int Inflate(int flush);
|
||||
void DoNextOutput(const void** data, int* size);
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipInputStream);
|
||||
};
|
||||
|
||||
class PROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream {
|
||||
public:
|
||||
// Format key for constructor
|
||||
enum Format {
|
||||
// GZIP streams have some extra header data for file attributes.
|
||||
GZIP = 1,
|
||||
|
||||
// Simpler zlib stream format.
|
||||
ZLIB = 2,
|
||||
};
|
||||
|
||||
struct PROTOBUF_EXPORT Options {
|
||||
// Defaults to GZIP.
|
||||
Format format;
|
||||
|
||||
// What size buffer to use internally. Defaults to 64kB.
|
||||
int buffer_size;
|
||||
|
||||
// A number between 0 and 9, where 0 is no compression and 9 is best
|
||||
// compression. Defaults to Z_DEFAULT_COMPRESSION (see zlib.h).
|
||||
int compression_level;
|
||||
|
||||
// Defaults to Z_DEFAULT_STRATEGY. Can also be set to Z_FILTERED,
|
||||
// Z_HUFFMAN_ONLY, or Z_RLE. See the documentation for deflateInit2 in
|
||||
// zlib.h for definitions of these constants.
|
||||
int compression_strategy;
|
||||
|
||||
Options(); // Initializes with default values.
|
||||
};
|
||||
|
||||
// Create a GzipOutputStream with default options.
|
||||
explicit GzipOutputStream(ZeroCopyOutputStream* sub_stream);
|
||||
|
||||
// Create a GzipOutputStream with the given options.
|
||||
GzipOutputStream(ZeroCopyOutputStream* sub_stream, const Options& options);
|
||||
|
||||
virtual ~GzipOutputStream();
|
||||
|
||||
// Return last error message or NULL if no error.
|
||||
inline const char* ZlibErrorMessage() const { return zcontext_.msg; }
|
||||
inline int ZlibErrorCode() const { return zerror_; }
|
||||
|
||||
// Flushes data written so far to zipped data in the underlying stream.
|
||||
// It is the caller's responsibility to flush the underlying stream if
|
||||
// necessary.
|
||||
// Compression may be less efficient stopping and starting around flushes.
|
||||
// Returns true if no error.
|
||||
//
|
||||
// Please ensure that block size is > 6. Here is an excerpt from the zlib
|
||||
// doc that explains why:
|
||||
//
|
||||
// In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out
|
||||
// is greater than six to avoid repeated flush markers due to
|
||||
// avail_out == 0 on return.
|
||||
bool Flush();
|
||||
|
||||
// Writes out all data and closes the gzip stream.
|
||||
// It is the caller's responsibility to close the underlying stream if
|
||||
// necessary.
|
||||
// Returns true if no error.
|
||||
bool Close();
|
||||
|
||||
// implements ZeroCopyOutputStream ---------------------------------
|
||||
bool Next(void** data, int* size);
|
||||
void BackUp(int count);
|
||||
int64_t ByteCount() const;
|
||||
|
||||
private:
|
||||
ZeroCopyOutputStream* sub_stream_;
|
||||
// Result from calling Next() on sub_stream_
|
||||
void* sub_data_;
|
||||
int sub_data_size_;
|
||||
|
||||
z_stream zcontext_;
|
||||
int zerror_;
|
||||
void* input_buffer_;
|
||||
size_t input_buffer_length_;
|
||||
|
||||
// Shared constructor code.
|
||||
void Init(ZeroCopyOutputStream* sub_stream, const Options& options);
|
||||
|
||||
// Do some compression.
|
||||
// Takes zlib flush mode.
|
||||
// Returns zlib error code.
|
||||
int Deflate(int flush);
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipOutputStream);
|
||||
};
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__
|
139
include/google/protobuf/io/io_win32.h
Normal file
139
include/google/protobuf/io/io_win32.h
Normal file
@ -0,0 +1,139 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: laszlocsomor@google.com (Laszlo Csomor)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
|
||||
// This file contains the declarations for Windows implementations of
|
||||
// commonly used POSIX functions such as open(2) and access(2), as well
|
||||
// as macro definitions for flags of these functions.
|
||||
//
|
||||
// By including this file you'll redefine open/access/etc. to
|
||||
// ::google::protobuf::io::win32::{open/access/etc.}.
|
||||
// Make sure you don't include a header that attempts to redeclare or
|
||||
// redefine these functions, that'll lead to confusing compilation
|
||||
// errors. It's best to #include this file as the last one to ensure that.
|
||||
//
|
||||
// This file is only used on Windows, it's empty on other platforms.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_IO_WIN32_H__
|
||||
#define GOOGLE_PROTOBUF_IO_IO_WIN32_H__
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
// Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the
|
||||
// following functions already, except for mkdir.
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
namespace win32 {
|
||||
|
||||
PROTOBUF_EXPORT FILE* fopen(const char* path, const char* mode);
|
||||
PROTOBUF_EXPORT int access(const char* path, int mode);
|
||||
PROTOBUF_EXPORT int chdir(const char* path);
|
||||
PROTOBUF_EXPORT int close(int fd);
|
||||
PROTOBUF_EXPORT int dup(int fd);
|
||||
PROTOBUF_EXPORT int dup2(int fd1, int fd2);
|
||||
PROTOBUF_EXPORT int mkdir(const char* path, int _mode);
|
||||
PROTOBUF_EXPORT int open(const char* path, int flags, int mode = 0);
|
||||
PROTOBUF_EXPORT int read(int fd, void* buffer, size_t size);
|
||||
PROTOBUF_EXPORT int setmode(int fd, int mode);
|
||||
PROTOBUF_EXPORT int stat(const char* path, struct _stat* buffer);
|
||||
PROTOBUF_EXPORT int write(int fd, const void* buffer, size_t size);
|
||||
PROTOBUF_EXPORT std::wstring testonly_utf8_to_winpath(const char* path);
|
||||
|
||||
enum class ExpandWildcardsResult {
|
||||
kSuccess = 0,
|
||||
kErrorNoMatchingFile = 1,
|
||||
kErrorInputPathConversion = 2,
|
||||
kErrorOutputPathConversion = 3,
|
||||
};
|
||||
|
||||
// Expand wildcards in a path pattern, feed the result to a consumer function.
|
||||
//
|
||||
// `path` must be a valid, Windows-style path. It may be absolute, or relative
|
||||
// to the current working directory, and it may contain wildcards ("*" and "?")
|
||||
// in the last path segment. This function passes all matching file names to
|
||||
// `consume`. The resulting paths may not be absolute nor normalized.
|
||||
//
|
||||
// The function returns a value from `ExpandWildcardsResult`.
|
||||
PROTOBUF_EXPORT ExpandWildcardsResult ExpandWildcards(
|
||||
const std::string& path, std::function<void(const std::string&)> consume);
|
||||
|
||||
namespace strings {
|
||||
|
||||
// Convert from UTF-16 to Active-Code-Page-encoded or to UTF-8-encoded text.
|
||||
PROTOBUF_EXPORT bool wcs_to_mbs(const wchar_t* s, std::string* out,
|
||||
bool outUtf8);
|
||||
|
||||
// Convert from Active-Code-Page-encoded or UTF-8-encoded text to UTF-16.
|
||||
PROTOBUF_EXPORT bool mbs_to_wcs(const char* s, std::wstring* out, bool inUtf8);
|
||||
|
||||
// Convert from UTF-8-encoded text to UTF-16.
|
||||
PROTOBUF_EXPORT bool utf8_to_wcs(const char* input, std::wstring* out);
|
||||
|
||||
// Convert from UTF-16-encoded text to UTF-8.
|
||||
PROTOBUF_EXPORT bool wcs_to_utf8(const wchar_t* input, std::string* out);
|
||||
|
||||
} // namespace strings
|
||||
|
||||
} // namespace win32
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#ifndef W_OK
|
||||
#define W_OK 02 // not defined by MSVC for whatever reason
|
||||
#endif
|
||||
|
||||
#ifndef F_OK
|
||||
#define F_OK 00 // not defined by MSVC for whatever reason
|
||||
#endif
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_IO_WIN32_H__
|
385
include/google/protobuf/io/printer.h
Normal file
385
include/google/protobuf/io/printer.h
Normal file
@ -0,0 +1,385 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// Utility class for writing text to a ZeroCopyOutputStream.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__
|
||||
#define GOOGLE_PROTOBUF_IO_PRINTER_H__
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
class ZeroCopyOutputStream; // zero_copy_stream.h
|
||||
|
||||
// Records annotations about a Printer's output.
|
||||
class PROTOBUF_EXPORT AnnotationCollector {
|
||||
public:
|
||||
// Annotation is a offset range and a payload pair.
|
||||
typedef std::pair<std::pair<size_t, size_t>, std::string> Annotation;
|
||||
|
||||
// Records that the bytes in file_path beginning with begin_offset and ending
|
||||
// before end_offset are associated with the SourceCodeInfo-style path.
|
||||
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
|
||||
const std::string& file_path,
|
||||
const std::vector<int>& path) = 0;
|
||||
|
||||
// TODO(gerbens) I don't see why we need virtuals here. Just a vector of
|
||||
// range, payload pairs stored in a context should suffice.
|
||||
virtual void AddAnnotationNew(Annotation& a) {}
|
||||
|
||||
virtual ~AnnotationCollector() {}
|
||||
};
|
||||
|
||||
// Records annotations about a Printer's output to the given protocol buffer,
|
||||
// assuming that the buffer has an ::Annotation message exposing path,
|
||||
// source_file, begin and end fields.
|
||||
template <typename AnnotationProto>
|
||||
class AnnotationProtoCollector : public AnnotationCollector {
|
||||
public:
|
||||
// annotation_proto is the protocol buffer to which new Annotations should be
|
||||
// added. It is not owned by the AnnotationProtoCollector.
|
||||
explicit AnnotationProtoCollector(AnnotationProto* annotation_proto)
|
||||
: annotation_proto_(annotation_proto) {}
|
||||
|
||||
// Override for AnnotationCollector::AddAnnotation.
|
||||
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
|
||||
const std::string& file_path,
|
||||
const std::vector<int>& path) {
|
||||
typename AnnotationProto::Annotation* annotation =
|
||||
annotation_proto_->add_annotation();
|
||||
for (int i = 0; i < path.size(); ++i) {
|
||||
annotation->add_path(path[i]);
|
||||
}
|
||||
annotation->set_source_file(file_path);
|
||||
annotation->set_begin(begin_offset);
|
||||
annotation->set_end(end_offset);
|
||||
}
|
||||
// Override for AnnotationCollector::AddAnnotation.
|
||||
virtual void AddAnnotationNew(Annotation& a) {
|
||||
auto* annotation = annotation_proto_->add_annotation();
|
||||
annotation->ParseFromString(a.second);
|
||||
annotation->set_begin(a.first.first);
|
||||
annotation->set_end(a.first.second);
|
||||
}
|
||||
|
||||
private:
|
||||
// The protocol buffer to which new annotations should be added.
|
||||
AnnotationProto* const annotation_proto_;
|
||||
};
|
||||
|
||||
// This simple utility class assists in code generation. It basically
|
||||
// allows the caller to define a set of variables and then output some
|
||||
// text with variable substitutions. Example usage:
|
||||
//
|
||||
// Printer printer(output, '$');
|
||||
// map<string, string> vars;
|
||||
// vars["name"] = "Bob";
|
||||
// printer.Print(vars, "My name is $name$.");
|
||||
//
|
||||
// The above writes "My name is Bob." to the output stream.
|
||||
//
|
||||
// Printer aggressively enforces correct usage, crashing (with assert failures)
|
||||
// in the case of undefined variables in debug builds. This helps greatly in
|
||||
// debugging code which uses it.
|
||||
//
|
||||
// If a Printer is constructed with an AnnotationCollector, it will provide it
|
||||
// with annotations that connect the Printer's output to paths that can identify
|
||||
// various descriptors. In the above example, if person_ is a descriptor that
|
||||
// identifies Bob, we can associate the output string "My name is Bob." with
|
||||
// a source path pointing to that descriptor with:
|
||||
//
|
||||
// printer.Annotate("name", person_);
|
||||
//
|
||||
// The AnnotationCollector will be sent an annotation linking the output range
|
||||
// covering "Bob" to the logical path provided by person_. Tools may use
|
||||
// this association to (for example) link "Bob" in the output back to the
|
||||
// source file that defined the person_ descriptor identifying Bob.
|
||||
//
|
||||
// Annotate can only examine variables substituted during the last call to
|
||||
// Print. It is invalid to refer to a variable that was used multiple times
|
||||
// in a single Print call.
|
||||
//
|
||||
// In full generality, one may specify a range of output text using a beginning
|
||||
// substitution variable and an ending variable. The resulting annotation will
|
||||
// span from the first character of the substituted value for the beginning
|
||||
// variable to the last character of the substituted value for the ending
|
||||
// variable. For example, the Annotate call above is equivalent to this one:
|
||||
//
|
||||
// printer.Annotate("name", "name", person_);
|
||||
//
|
||||
// This is useful if multiple variables combine to form a single span of output
|
||||
// that should be annotated with the same source path. For example:
|
||||
//
|
||||
// Printer printer(output, '$');
|
||||
// map<string, string> vars;
|
||||
// vars["first"] = "Alice";
|
||||
// vars["last"] = "Smith";
|
||||
// printer.Print(vars, "My name is $first$ $last$.");
|
||||
// printer.Annotate("first", "last", person_);
|
||||
//
|
||||
// This code would associate the span covering "Alice Smith" in the output with
|
||||
// the person_ descriptor.
|
||||
//
|
||||
// Note that the beginning variable must come before (or overlap with, in the
|
||||
// case of zero-sized substitution values) the ending variable.
|
||||
//
|
||||
// It is also sometimes useful to use variables with zero-sized values as
|
||||
// markers. This avoids issues with multiple references to the same variable
|
||||
// and also allows annotation ranges to span literal text from the Print
|
||||
// templates:
|
||||
//
|
||||
// Printer printer(output, '$');
|
||||
// map<string, string> vars;
|
||||
// vars["foo"] = "bar";
|
||||
// vars["function"] = "call";
|
||||
// vars["mark"] = "";
|
||||
// printer.Print(vars, "$function$($foo$,$foo$)$mark$");
|
||||
// printer.Annotate("function", "mark", call_);
|
||||
//
|
||||
// This code associates the span covering "call(bar,bar)" in the output with the
|
||||
// call_ descriptor.
|
||||
|
||||
class PROTOBUF_EXPORT Printer {
|
||||
public:
|
||||
// Create a printer that writes text to the given output stream. Use the
|
||||
// given character as the delimiter for variables.
|
||||
Printer(ZeroCopyOutputStream* output, char variable_delimiter);
|
||||
|
||||
// Create a printer that writes text to the given output stream. Use the
|
||||
// given character as the delimiter for variables. If annotation_collector
|
||||
// is not null, Printer will provide it with annotations about code written
|
||||
// to the stream. annotation_collector is not owned by Printer.
|
||||
Printer(ZeroCopyOutputStream* output, char variable_delimiter,
|
||||
AnnotationCollector* annotation_collector);
|
||||
|
||||
~Printer();
|
||||
|
||||
// Link a substitution variable emitted by the last call to Print to the
|
||||
// object described by descriptor.
|
||||
template <typename SomeDescriptor>
|
||||
void Annotate(const char* varname, const SomeDescriptor* descriptor) {
|
||||
Annotate(varname, varname, descriptor);
|
||||
}
|
||||
|
||||
// Link the output range defined by the substitution variables as emitted by
|
||||
// the last call to Print to the object described by descriptor. The range
|
||||
// begins at begin_varname's value and ends after the last character of the
|
||||
// value substituted for end_varname.
|
||||
template <typename SomeDescriptor>
|
||||
void Annotate(const char* begin_varname, const char* end_varname,
|
||||
const SomeDescriptor* descriptor) {
|
||||
if (annotation_collector_ == NULL) {
|
||||
// Annotations aren't turned on for this Printer, so don't pay the cost
|
||||
// of building the location path.
|
||||
return;
|
||||
}
|
||||
std::vector<int> path;
|
||||
descriptor->GetLocationPath(&path);
|
||||
Annotate(begin_varname, end_varname, descriptor->file()->name(), path);
|
||||
}
|
||||
|
||||
// Link a substitution variable emitted by the last call to Print to the file
|
||||
// with path file_name.
|
||||
void Annotate(const char* varname, const std::string& file_name) {
|
||||
Annotate(varname, varname, file_name);
|
||||
}
|
||||
|
||||
// Link the output range defined by the substitution variables as emitted by
|
||||
// the last call to Print to the file with path file_name. The range begins
|
||||
// at begin_varname's value and ends after the last character of the value
|
||||
// substituted for end_varname.
|
||||
void Annotate(const char* begin_varname, const char* end_varname,
|
||||
const std::string& file_name) {
|
||||
if (annotation_collector_ == NULL) {
|
||||
// Annotations aren't turned on for this Printer.
|
||||
return;
|
||||
}
|
||||
std::vector<int> empty_path;
|
||||
Annotate(begin_varname, end_varname, file_name, empty_path);
|
||||
}
|
||||
|
||||
// Print some text after applying variable substitutions. If a particular
|
||||
// variable in the text is not defined, this will crash. Variables to be
|
||||
// substituted are identified by their names surrounded by delimiter
|
||||
// characters (as given to the constructor). The variable bindings are
|
||||
// defined by the given map.
|
||||
void Print(const std::map<std::string, std::string>& variables,
|
||||
const char* text);
|
||||
|
||||
// Like the first Print(), except the substitutions are given as parameters.
|
||||
template <typename... Args>
|
||||
void Print(const char* text, const Args&... args) {
|
||||
std::map<std::string, std::string> vars;
|
||||
PrintInternal(&vars, text, args...);
|
||||
}
|
||||
|
||||
// Indent text by two spaces. After calling Indent(), two spaces will be
|
||||
// inserted at the beginning of each line of text. Indent() may be called
|
||||
// multiple times to produce deeper indents.
|
||||
void Indent();
|
||||
|
||||
// Reduces the current indent level by two spaces, or crashes if the indent
|
||||
// level is zero.
|
||||
void Outdent();
|
||||
|
||||
// Write a string to the output buffer.
|
||||
// This method does not look for newlines to add indentation.
|
||||
void PrintRaw(const std::string& data);
|
||||
|
||||
// Write a zero-delimited string to output buffer.
|
||||
// This method does not look for newlines to add indentation.
|
||||
void PrintRaw(const char* data);
|
||||
|
||||
// Write some bytes to the output buffer.
|
||||
// This method does not look for newlines to add indentation.
|
||||
void WriteRaw(const char* data, int size);
|
||||
|
||||
// FormatInternal is a helper function not meant to use directly, use
|
||||
// compiler::cpp::Formatter instead. This function is meant to support
|
||||
// formatting text using named variables (eq. "$foo$) from a lookup map (vars)
|
||||
// and variables directly supplied by arguments (eq "$1$" meaning first
|
||||
// argument which is the zero index element of args).
|
||||
void FormatInternal(const std::vector<std::string>& args,
|
||||
const std::map<std::string, std::string>& vars,
|
||||
const char* format);
|
||||
|
||||
// True if any write to the underlying stream failed. (We don't just
|
||||
// crash in this case because this is an I/O failure, not a programming
|
||||
// error.)
|
||||
bool failed() const { return failed_; }
|
||||
|
||||
private:
|
||||
// Link the output range defined by the substitution variables as emitted by
|
||||
// the last call to Print to the object found at the SourceCodeInfo-style path
|
||||
// in a file with path file_path. The range begins at the start of
|
||||
// begin_varname's value and ends after the last character of the value
|
||||
// substituted for end_varname. Note that begin_varname and end_varname
|
||||
// may refer to the same variable.
|
||||
void Annotate(const char* begin_varname, const char* end_varname,
|
||||
const std::string& file_path, const std::vector<int>& path);
|
||||
|
||||
// Base case
|
||||
void PrintInternal(std::map<std::string, std::string>* vars,
|
||||
const char* text) {
|
||||
Print(*vars, text);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void PrintInternal(std::map<std::string, std::string>* vars, const char* text,
|
||||
const char* key, const std::string& value,
|
||||
const Args&... args) {
|
||||
(*vars)[key] = value;
|
||||
PrintInternal(vars, text, args...);
|
||||
}
|
||||
|
||||
// Copy size worth of bytes from data to buffer_.
|
||||
void CopyToBuffer(const char* data, int size);
|
||||
|
||||
void push_back(char c) {
|
||||
if (failed_) return;
|
||||
if (buffer_size_ == 0) {
|
||||
if (!Next()) return;
|
||||
}
|
||||
*buffer_++ = c;
|
||||
buffer_size_--;
|
||||
offset_++;
|
||||
}
|
||||
|
||||
bool Next();
|
||||
|
||||
inline void IndentIfAtStart();
|
||||
const char* WriteVariable(
|
||||
const std::vector<std::string>& args,
|
||||
const std::map<std::string, std::string>& vars, const char* format,
|
||||
int* arg_index,
|
||||
std::vector<AnnotationCollector::Annotation>* annotations);
|
||||
|
||||
const char variable_delimiter_;
|
||||
|
||||
ZeroCopyOutputStream* const output_;
|
||||
char* buffer_;
|
||||
int buffer_size_;
|
||||
// The current position, in bytes, in the output stream. This is equivalent
|
||||
// to the total number of bytes that have been written so far. This value is
|
||||
// used to calculate annotation ranges in the substitutions_ map below.
|
||||
size_t offset_;
|
||||
|
||||
std::string indent_;
|
||||
bool at_start_of_line_;
|
||||
bool failed_;
|
||||
|
||||
// A map from variable name to [start, end) offsets in the output buffer.
|
||||
// These refer to the offsets used for a variable after the last call to
|
||||
// Print. If a variable was used more than once, the entry used in
|
||||
// this map is set to a negative-length span. For singly-used variables, the
|
||||
// start offset is the beginning of the substitution; the end offset is the
|
||||
// last byte of the substitution plus one (such that (end - start) is the
|
||||
// length of the substituted string).
|
||||
std::map<std::string, std::pair<size_t, size_t> > substitutions_;
|
||||
|
||||
// Keeps track of the keys in substitutions_ that need to be updated when
|
||||
// indents are inserted. These are keys that refer to the beginning of the
|
||||
// current line.
|
||||
std::vector<std::string> line_start_variables_;
|
||||
|
||||
// Returns true and sets range to the substitution range in the output for
|
||||
// varname if varname was used once in the last call to Print. If varname
|
||||
// was not used, or if it was used multiple times, returns false (and
|
||||
// fails a debug assertion).
|
||||
bool GetSubstitutionRange(const char* varname,
|
||||
std::pair<size_t, size_t>* range);
|
||||
|
||||
// If non-null, annotation_collector_ is used to store annotations about
|
||||
// generated code.
|
||||
AnnotationCollector* const annotation_collector_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Printer);
|
||||
};
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_PRINTER_H__
|
55
include/google/protobuf/io/strtod.h
Normal file
55
include/google/protobuf/io/strtod.h
Normal file
@ -0,0 +1,55 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// A locale-independent version of strtod(), used to parse floating
|
||||
// point default values in .proto files, where the decimal separator
|
||||
// is always a dot.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_STRTOD_H__
|
||||
#define GOOGLE_PROTOBUF_IO_STRTOD_H__
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
// A locale-independent version of the standard strtod(), which always
|
||||
// uses a dot as the decimal separator.
|
||||
double NoLocaleStrtod(const char* str, char** endptr);
|
||||
|
||||
// Casts a double value to a float value. If the value is outside of the
|
||||
// representable range of float, it will be converted to positive or negative
|
||||
// infinity.
|
||||
float SafeDoubleToFloat(double value);
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_STRTOD_H__
|
413
include/google/protobuf/io/tokenizer.h
Normal file
413
include/google/protobuf/io/tokenizer.h
Normal file
@ -0,0 +1,413 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// Class for parsing tokenized text from a ZeroCopyInputStream.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_TOKENIZER_H__
|
||||
#define GOOGLE_PROTOBUF_IO_TOKENIZER_H__
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
class ZeroCopyInputStream; // zero_copy_stream.h
|
||||
|
||||
// Defined in this file.
|
||||
class ErrorCollector;
|
||||
class Tokenizer;
|
||||
|
||||
// By "column number", the proto compiler refers to a count of the number
|
||||
// of bytes before a given byte, except that a tab character advances to
|
||||
// the next multiple of 8 bytes. Note in particular that column numbers
|
||||
// are zero-based, while many user interfaces use one-based column numbers.
|
||||
typedef int ColumnNumber;
|
||||
|
||||
// Abstract interface for an object which collects the errors that occur
|
||||
// during parsing. A typical implementation might simply print the errors
|
||||
// to stdout.
|
||||
class PROTOBUF_EXPORT ErrorCollector {
|
||||
public:
|
||||
inline ErrorCollector() {}
|
||||
virtual ~ErrorCollector();
|
||||
|
||||
// Indicates that there was an error in the input at the given line and
|
||||
// column numbers. The numbers are zero-based, so you may want to add
|
||||
// 1 to each before printing them.
|
||||
virtual void AddError(int line, ColumnNumber column,
|
||||
const std::string& message) = 0;
|
||||
|
||||
// Indicates that there was a warning in the input at the given line and
|
||||
// column numbers. The numbers are zero-based, so you may want to add
|
||||
// 1 to each before printing them.
|
||||
virtual void AddWarning(int line, ColumnNumber column,
|
||||
const std::string& message) {}
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector);
|
||||
};
|
||||
|
||||
// This class converts a stream of raw text into a stream of tokens for
|
||||
// the protocol definition parser to parse. The tokens recognized are
|
||||
// similar to those that make up the C language; see the TokenType enum for
|
||||
// precise descriptions. Whitespace and comments are skipped. By default,
|
||||
// C- and C++-style comments are recognized, but other styles can be used by
|
||||
// calling set_comment_style().
|
||||
class PROTOBUF_EXPORT Tokenizer {
|
||||
public:
|
||||
// Construct a Tokenizer that reads and tokenizes text from the given
|
||||
// input stream and writes errors to the given error_collector.
|
||||
// The caller keeps ownership of input and error_collector.
|
||||
Tokenizer(ZeroCopyInputStream* input, ErrorCollector* error_collector);
|
||||
~Tokenizer();
|
||||
|
||||
enum TokenType {
|
||||
TYPE_START, // Next() has not yet been called.
|
||||
TYPE_END, // End of input reached. "text" is empty.
|
||||
|
||||
TYPE_IDENTIFIER, // A sequence of letters, digits, and underscores, not
|
||||
// starting with a digit. It is an error for a number
|
||||
// to be followed by an identifier with no space in
|
||||
// between.
|
||||
TYPE_INTEGER, // A sequence of digits representing an integer. Normally
|
||||
// the digits are decimal, but a prefix of "0x" indicates
|
||||
// a hex number and a leading zero indicates octal, just
|
||||
// like with C numeric literals. A leading negative sign
|
||||
// is NOT included in the token; it's up to the parser to
|
||||
// interpret the unary minus operator on its own.
|
||||
TYPE_FLOAT, // A floating point literal, with a fractional part and/or
|
||||
// an exponent. Always in decimal. Again, never
|
||||
// negative.
|
||||
TYPE_STRING, // A quoted sequence of escaped characters. Either single
|
||||
// or double quotes can be used, but they must match.
|
||||
// A string literal cannot cross a line break.
|
||||
TYPE_SYMBOL, // Any other printable character, like '!' or '+'.
|
||||
// Symbols are always a single character, so "!+$%" is
|
||||
// four tokens.
|
||||
};
|
||||
|
||||
// Structure representing a token read from the token stream.
|
||||
struct Token {
|
||||
TokenType type;
|
||||
std::string text; // The exact text of the token as it appeared in
|
||||
// the input. e.g. tokens of TYPE_STRING will still
|
||||
// be escaped and in quotes.
|
||||
|
||||
// "line" and "column" specify the position of the first character of
|
||||
// the token within the input stream. They are zero-based.
|
||||
int line;
|
||||
ColumnNumber column;
|
||||
ColumnNumber end_column;
|
||||
};
|
||||
|
||||
// Get the current token. This is updated when Next() is called. Before
|
||||
// the first call to Next(), current() has type TYPE_START and no contents.
|
||||
const Token& current();
|
||||
|
||||
// Return the previous token -- i.e. what current() returned before the
|
||||
// previous call to Next().
|
||||
const Token& previous();
|
||||
|
||||
// Advance to the next token. Returns false if the end of the input is
|
||||
// reached.
|
||||
bool Next();
|
||||
|
||||
// Like Next(), but also collects comments which appear between the previous
|
||||
// and next tokens.
|
||||
//
|
||||
// Comments which appear to be attached to the previous token are stored
|
||||
// in *prev_tailing_comments. Comments which appear to be attached to the
|
||||
// next token are stored in *next_leading_comments. Comments appearing in
|
||||
// between which do not appear to be attached to either will be added to
|
||||
// detached_comments. Any of these parameters can be NULL to simply discard
|
||||
// the comments.
|
||||
//
|
||||
// A series of line comments appearing on consecutive lines, with no other
|
||||
// tokens appearing on those lines, will be treated as a single comment.
|
||||
//
|
||||
// Only the comment content is returned; comment markers (e.g. //) are
|
||||
// stripped out. For block comments, leading whitespace and an asterisk will
|
||||
// be stripped from the beginning of each line other than the first. Newlines
|
||||
// are included in the output.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// optional int32 foo = 1; // Comment attached to foo.
|
||||
// // Comment attached to bar.
|
||||
// optional int32 bar = 2;
|
||||
//
|
||||
// optional string baz = 3;
|
||||
// // Comment attached to baz.
|
||||
// // Another line attached to baz.
|
||||
//
|
||||
// // Comment attached to qux.
|
||||
// //
|
||||
// // Another line attached to qux.
|
||||
// optional double qux = 4;
|
||||
//
|
||||
// // Detached comment. This is not attached to qux or corge
|
||||
// // because there are blank lines separating it from both.
|
||||
//
|
||||
// optional string corge = 5;
|
||||
// /* Block comment attached
|
||||
// * to corge. Leading asterisks
|
||||
// * will be removed. */
|
||||
// /* Block comment attached to
|
||||
// * grault. */
|
||||
// optional int32 grault = 6;
|
||||
bool NextWithComments(std::string* prev_trailing_comments,
|
||||
std::vector<std::string>* detached_comments,
|
||||
std::string* next_leading_comments);
|
||||
|
||||
// Parse helpers ---------------------------------------------------
|
||||
|
||||
// Parses a TYPE_FLOAT token. This never fails, so long as the text actually
|
||||
// comes from a TYPE_FLOAT token parsed by Tokenizer. If it doesn't, the
|
||||
// result is undefined (possibly an assert failure).
|
||||
static double ParseFloat(const std::string& text);
|
||||
|
||||
// Parses a TYPE_STRING token. This never fails, so long as the text actually
|
||||
// comes from a TYPE_STRING token parsed by Tokenizer. If it doesn't, the
|
||||
// result is undefined (possibly an assert failure).
|
||||
static void ParseString(const std::string& text, std::string* output);
|
||||
|
||||
// Identical to ParseString, but appends to output.
|
||||
static void ParseStringAppend(const std::string& text, std::string* output);
|
||||
|
||||
// Parses a TYPE_INTEGER token. Returns false if the result would be
|
||||
// greater than max_value. Otherwise, returns true and sets *output to the
|
||||
// result. If the text is not from a Token of type TYPE_INTEGER originally
|
||||
// parsed by a Tokenizer, the result is undefined (possibly an assert
|
||||
// failure).
|
||||
static bool ParseInteger(const std::string& text, uint64 max_value,
|
||||
uint64* output);
|
||||
|
||||
// Options ---------------------------------------------------------
|
||||
|
||||
// Set true to allow floats to be suffixed with the letter 'f'. Tokens
|
||||
// which would otherwise be integers but which have the 'f' suffix will be
|
||||
// forced to be interpreted as floats. For all other purposes, the 'f' is
|
||||
// ignored.
|
||||
void set_allow_f_after_float(bool value) { allow_f_after_float_ = value; }
|
||||
|
||||
// Valid values for set_comment_style().
|
||||
enum CommentStyle {
|
||||
// Line comments begin with "//", block comments are delimited by "/*" and
|
||||
// "*/".
|
||||
CPP_COMMENT_STYLE,
|
||||
// Line comments begin with "#". No way to write block comments.
|
||||
SH_COMMENT_STYLE
|
||||
};
|
||||
|
||||
// Sets the comment style.
|
||||
void set_comment_style(CommentStyle style) { comment_style_ = style; }
|
||||
|
||||
// Whether to require whitespace between a number and a field name.
|
||||
// Default is true. Do not use this; for Google-internal cleanup only.
|
||||
void set_require_space_after_number(bool require) {
|
||||
require_space_after_number_ = require;
|
||||
}
|
||||
|
||||
// Whether to allow string literals to span multiple lines. Default is false.
|
||||
// Do not use this; for Google-internal cleanup only.
|
||||
void set_allow_multiline_strings(bool allow) {
|
||||
allow_multiline_strings_ = allow;
|
||||
}
|
||||
|
||||
// External helper: validate an identifier.
|
||||
static bool IsIdentifier(const std::string& text);
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Tokenizer);
|
||||
|
||||
Token current_; // Returned by current().
|
||||
Token previous_; // Returned by previous().
|
||||
|
||||
ZeroCopyInputStream* input_;
|
||||
ErrorCollector* error_collector_;
|
||||
|
||||
char current_char_; // == buffer_[buffer_pos_], updated by NextChar().
|
||||
const char* buffer_; // Current buffer returned from input_.
|
||||
int buffer_size_; // Size of buffer_.
|
||||
int buffer_pos_; // Current position within the buffer.
|
||||
bool read_error_; // Did we previously encounter a read error?
|
||||
|
||||
// Line and column number of current_char_ within the whole input stream.
|
||||
int line_;
|
||||
ColumnNumber column_;
|
||||
|
||||
// String to which text should be appended as we advance through it.
|
||||
// Call RecordTo(&str) to start recording and StopRecording() to stop.
|
||||
// E.g. StartToken() calls RecordTo(¤t_.text). record_start_ is the
|
||||
// position within the current buffer where recording started.
|
||||
std::string* record_target_;
|
||||
int record_start_;
|
||||
|
||||
// Options.
|
||||
bool allow_f_after_float_;
|
||||
CommentStyle comment_style_;
|
||||
bool require_space_after_number_;
|
||||
bool allow_multiline_strings_;
|
||||
|
||||
// Since we count columns we need to interpret tabs somehow. We'll take
|
||||
// the standard 8-character definition for lack of any way to do better.
|
||||
// This must match the documentation of ColumnNumber.
|
||||
static const int kTabWidth = 8;
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// Helper methods.
|
||||
|
||||
// Consume this character and advance to the next one.
|
||||
void NextChar();
|
||||
|
||||
// Read a new buffer from the input.
|
||||
void Refresh();
|
||||
|
||||
inline void RecordTo(std::string* target);
|
||||
inline void StopRecording();
|
||||
|
||||
// Called when the current character is the first character of a new
|
||||
// token (not including whitespace or comments).
|
||||
inline void StartToken();
|
||||
// Called when the current character is the first character after the
|
||||
// end of the last token. After this returns, current_.text will
|
||||
// contain all text consumed since StartToken() was called.
|
||||
inline void EndToken();
|
||||
|
||||
// Convenience method to add an error at the current line and column.
|
||||
void AddError(const std::string& message) {
|
||||
error_collector_->AddError(line_, column_, message);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// The following four methods are used to consume tokens of specific
|
||||
// types. They are actually used to consume all characters *after*
|
||||
// the first, since the calling function consumes the first character
|
||||
// in order to decide what kind of token is being read.
|
||||
|
||||
// Read and consume a string, ending when the given delimiter is
|
||||
// consumed.
|
||||
void ConsumeString(char delimiter);
|
||||
|
||||
// Read and consume a number, returning TYPE_FLOAT or TYPE_INTEGER
|
||||
// depending on what was read. This needs to know if the first
|
||||
// character was a zero in order to correctly recognize hex and octal
|
||||
// numbers.
|
||||
// It also needs to know if the first character was a . to parse floating
|
||||
// point correctly.
|
||||
TokenType ConsumeNumber(bool started_with_zero, bool started_with_dot);
|
||||
|
||||
// Consume the rest of a line.
|
||||
void ConsumeLineComment(std::string* content);
|
||||
// Consume until "*/".
|
||||
void ConsumeBlockComment(std::string* content);
|
||||
|
||||
enum NextCommentStatus {
|
||||
// Started a line comment.
|
||||
LINE_COMMENT,
|
||||
|
||||
// Started a block comment.
|
||||
BLOCK_COMMENT,
|
||||
|
||||
// Consumed a slash, then realized it wasn't a comment. current_ has
|
||||
// been filled in with a slash token. The caller should return it.
|
||||
SLASH_NOT_COMMENT,
|
||||
|
||||
// We do not appear to be starting a comment here.
|
||||
NO_COMMENT
|
||||
};
|
||||
|
||||
// If we're at the start of a new comment, consume it and return what kind
|
||||
// of comment it is.
|
||||
NextCommentStatus TryConsumeCommentStart();
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// These helper methods make the parsing code more readable. The
|
||||
// "character classes" referred to are defined at the top of the .cc file.
|
||||
// Basically it is a C++ class with one method:
|
||||
// static bool InClass(char c);
|
||||
// The method returns true if c is a member of this "class", like "Letter"
|
||||
// or "Digit".
|
||||
|
||||
// Returns true if the current character is of the given character
|
||||
// class, but does not consume anything.
|
||||
template <typename CharacterClass>
|
||||
inline bool LookingAt();
|
||||
|
||||
// If the current character is in the given class, consume it and return
|
||||
// true. Otherwise return false.
|
||||
// e.g. TryConsumeOne<Letter>()
|
||||
template <typename CharacterClass>
|
||||
inline bool TryConsumeOne();
|
||||
|
||||
// Like above, but try to consume the specific character indicated.
|
||||
inline bool TryConsume(char c);
|
||||
|
||||
// Consume zero or more of the given character class.
|
||||
template <typename CharacterClass>
|
||||
inline void ConsumeZeroOrMore();
|
||||
|
||||
// Consume one or more of the given character class or log the given
|
||||
// error message.
|
||||
// e.g. ConsumeOneOrMore<Digit>("Expected digits.");
|
||||
template <typename CharacterClass>
|
||||
inline void ConsumeOneOrMore(const char* error);
|
||||
};
|
||||
|
||||
// inline methods ====================================================
|
||||
inline const Tokenizer::Token& Tokenizer::current() { return current_; }
|
||||
|
||||
inline const Tokenizer::Token& Tokenizer::previous() { return previous_; }
|
||||
|
||||
inline void Tokenizer::ParseString(const std::string& text,
|
||||
std::string* output) {
|
||||
output->clear();
|
||||
ParseStringAppend(text, output);
|
||||
}
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_TOKENIZER_H__
|
253
include/google/protobuf/io/zero_copy_stream.h
Normal file
253
include/google/protobuf/io/zero_copy_stream.h
Normal file
@ -0,0 +1,253 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// This file contains the ZeroCopyInputStream and ZeroCopyOutputStream
|
||||
// interfaces, which represent abstract I/O streams to and from which
|
||||
// protocol buffers can be read and written. For a few simple
|
||||
// implementations of these interfaces, see zero_copy_stream_impl.h.
|
||||
//
|
||||
// These interfaces are different from classic I/O streams in that they
|
||||
// try to minimize the amount of data copying that needs to be done.
|
||||
// To accomplish this, responsibility for allocating buffers is moved to
|
||||
// the stream object, rather than being the responsibility of the caller.
|
||||
// So, the stream can return a buffer which actually points directly into
|
||||
// the final data structure where the bytes are to be stored, and the caller
|
||||
// can interact directly with that buffer, eliminating an intermediate copy
|
||||
// operation.
|
||||
//
|
||||
// As an example, consider the common case in which you are reading bytes
|
||||
// from an array that is already in memory (or perhaps an mmap()ed file).
|
||||
// With classic I/O streams, you would do something like:
|
||||
// char buffer[BUFFER_SIZE];
|
||||
// input->Read(buffer, BUFFER_SIZE);
|
||||
// DoSomething(buffer, BUFFER_SIZE);
|
||||
// Then, the stream basically just calls memcpy() to copy the data from
|
||||
// the array into your buffer. With a ZeroCopyInputStream, you would do
|
||||
// this instead:
|
||||
// const void* buffer;
|
||||
// int size;
|
||||
// input->Next(&buffer, &size);
|
||||
// DoSomething(buffer, size);
|
||||
// Here, no copy is performed. The input stream returns a pointer directly
|
||||
// into the backing array, and the caller ends up reading directly from it.
|
||||
//
|
||||
// If you want to be able to read the old-fashion way, you can create
|
||||
// a CodedInputStream or CodedOutputStream wrapping these objects and use
|
||||
// their ReadRaw()/WriteRaw() methods. These will, of course, add a copy
|
||||
// step, but Coded*Stream will handle buffering so at least it will be
|
||||
// reasonably efficient.
|
||||
//
|
||||
// ZeroCopyInputStream example:
|
||||
// // Read in a file and print its contents to stdout.
|
||||
// int fd = open("myfile", O_RDONLY);
|
||||
// ZeroCopyInputStream* input = new FileInputStream(fd);
|
||||
//
|
||||
// const void* buffer;
|
||||
// int size;
|
||||
// while (input->Next(&buffer, &size)) {
|
||||
// cout.write(buffer, size);
|
||||
// }
|
||||
//
|
||||
// delete input;
|
||||
// close(fd);
|
||||
//
|
||||
// ZeroCopyOutputStream example:
|
||||
// // Copy the contents of "infile" to "outfile", using plain read() for
|
||||
// // "infile" but a ZeroCopyOutputStream for "outfile".
|
||||
// int infd = open("infile", O_RDONLY);
|
||||
// int outfd = open("outfile", O_WRONLY);
|
||||
// ZeroCopyOutputStream* output = new FileOutputStream(outfd);
|
||||
//
|
||||
// void* buffer;
|
||||
// int size;
|
||||
// while (output->Next(&buffer, &size)) {
|
||||
// int bytes = read(infd, buffer, size);
|
||||
// if (bytes < size) {
|
||||
// // Reached EOF.
|
||||
// output->BackUp(size - bytes);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// delete output;
|
||||
// close(infd);
|
||||
// close(outfd);
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__
|
||||
#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
// Defined in this file.
|
||||
class ZeroCopyInputStream;
|
||||
class ZeroCopyOutputStream;
|
||||
|
||||
// Abstract interface similar to an input stream but designed to minimize
|
||||
// copying.
|
||||
class PROTOBUF_EXPORT ZeroCopyInputStream {
|
||||
public:
|
||||
ZeroCopyInputStream() {}
|
||||
virtual ~ZeroCopyInputStream() {}
|
||||
|
||||
// Obtains a chunk of data from the stream.
|
||||
//
|
||||
// Preconditions:
|
||||
// * "size" and "data" are not NULL.
|
||||
//
|
||||
// Postconditions:
|
||||
// * If the returned value is false, there is no more data to return or
|
||||
// an error occurred. All errors are permanent.
|
||||
// * Otherwise, "size" points to the actual number of bytes read and "data"
|
||||
// points to a pointer to a buffer containing these bytes.
|
||||
// * Ownership of this buffer remains with the stream, and the buffer
|
||||
// remains valid only until some other method of the stream is called
|
||||
// or the stream is destroyed.
|
||||
// * It is legal for the returned buffer to have zero size, as long
|
||||
// as repeatedly calling Next() eventually yields a buffer with non-zero
|
||||
// size.
|
||||
virtual bool Next(const void** data, int* size) = 0;
|
||||
|
||||
// Backs up a number of bytes, so that the next call to Next() returns
|
||||
// data again that was already returned by the last call to Next(). This
|
||||
// is useful when writing procedures that are only supposed to read up
|
||||
// to a certain point in the input, then return. If Next() returns a
|
||||
// buffer that goes beyond what you wanted to read, you can use BackUp()
|
||||
// to return to the point where you intended to finish.
|
||||
//
|
||||
// Preconditions:
|
||||
// * The last method called must have been Next().
|
||||
// * count must be less than or equal to the size of the last buffer
|
||||
// returned by Next().
|
||||
//
|
||||
// Postconditions:
|
||||
// * The last "count" bytes of the last buffer returned by Next() will be
|
||||
// pushed back into the stream. Subsequent calls to Next() will return
|
||||
// the same data again before producing new data.
|
||||
virtual void BackUp(int count) = 0;
|
||||
|
||||
// Skips a number of bytes. Returns false if the end of the stream is
|
||||
// reached or some input error occurred. In the end-of-stream case, the
|
||||
// stream is advanced to the end of the stream (so ByteCount() will return
|
||||
// the total size of the stream).
|
||||
virtual bool Skip(int count) = 0;
|
||||
|
||||
// Returns the total number of bytes read since this object was created.
|
||||
virtual int64_t ByteCount() const = 0;
|
||||
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyInputStream);
|
||||
};
|
||||
|
||||
// Abstract interface similar to an output stream but designed to minimize
|
||||
// copying.
|
||||
class PROTOBUF_EXPORT ZeroCopyOutputStream {
|
||||
public:
|
||||
ZeroCopyOutputStream() {}
|
||||
virtual ~ZeroCopyOutputStream() {}
|
||||
|
||||
// Obtains a buffer into which data can be written. Any data written
|
||||
// into this buffer will eventually (maybe instantly, maybe later on)
|
||||
// be written to the output.
|
||||
//
|
||||
// Preconditions:
|
||||
// * "size" and "data" are not NULL.
|
||||
//
|
||||
// Postconditions:
|
||||
// * If the returned value is false, an error occurred. All errors are
|
||||
// permanent.
|
||||
// * Otherwise, "size" points to the actual number of bytes in the buffer
|
||||
// and "data" points to the buffer.
|
||||
// * Ownership of this buffer remains with the stream, and the buffer
|
||||
// remains valid only until some other method of the stream is called
|
||||
// or the stream is destroyed.
|
||||
// * Any data which the caller stores in this buffer will eventually be
|
||||
// written to the output (unless BackUp() is called).
|
||||
// * It is legal for the returned buffer to have zero size, as long
|
||||
// as repeatedly calling Next() eventually yields a buffer with non-zero
|
||||
// size.
|
||||
virtual bool Next(void** data, int* size) = 0;
|
||||
|
||||
// Backs up a number of bytes, so that the end of the last buffer returned
|
||||
// by Next() is not actually written. This is needed when you finish
|
||||
// writing all the data you want to write, but the last buffer was bigger
|
||||
// than you needed. You don't want to write a bunch of garbage after the
|
||||
// end of your data, so you use BackUp() to back up.
|
||||
//
|
||||
// Preconditions:
|
||||
// * The last method called must have been Next().
|
||||
// * count must be less than or equal to the size of the last buffer
|
||||
// returned by Next().
|
||||
// * The caller must not have written anything to the last "count" bytes
|
||||
// of that buffer.
|
||||
//
|
||||
// Postconditions:
|
||||
// * The last "count" bytes of the last buffer returned by Next() will be
|
||||
// ignored.
|
||||
virtual void BackUp(int count) = 0;
|
||||
|
||||
// Returns the total number of bytes written since this object was created.
|
||||
virtual int64_t ByteCount() const = 0;
|
||||
|
||||
// Write a given chunk of data to the output. Some output streams may
|
||||
// implement this in a way that avoids copying. Check AllowsAliasing() before
|
||||
// calling WriteAliasedRaw(). It will GOOGLE_CHECK fail if WriteAliasedRaw() is
|
||||
// called on a stream that does not allow aliasing.
|
||||
//
|
||||
// NOTE: It is caller's responsibility to ensure that the chunk of memory
|
||||
// remains live until all of the data has been consumed from the stream.
|
||||
virtual bool WriteAliasedRaw(const void* data, int size);
|
||||
virtual bool AllowsAliasing() const { return false; }
|
||||
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyOutputStream);
|
||||
};
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__
|
338
include/google/protobuf/io/zero_copy_stream_impl.h
Normal file
338
include/google/protobuf/io/zero_copy_stream_impl.h
Normal file
@ -0,0 +1,338 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// This file contains common implementations of the interfaces defined in
|
||||
// zero_copy_stream.h which are only included in the full (non-lite)
|
||||
// protobuf library. These implementations include Unix file descriptors
|
||||
// and C++ iostreams. See also: zero_copy_stream_impl_lite.h
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__
|
||||
#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__
|
||||
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyInputStream which reads from a file descriptor.
|
||||
//
|
||||
// FileInputStream is preferred over using an ifstream with IstreamInputStream.
|
||||
// The latter will introduce an extra layer of buffering, harming performance.
|
||||
// Also, it's conceivable that FileInputStream could someday be enhanced
|
||||
// to use zero-copy file descriptors on OSs which support them.
|
||||
class PROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream {
|
||||
public:
|
||||
// Creates a stream that reads from the given Unix file descriptor.
|
||||
// If a block_size is given, it specifies the number of bytes that
|
||||
// should be read and returned with each call to Next(). Otherwise,
|
||||
// a reasonable default is used.
|
||||
explicit FileInputStream(int file_descriptor, int block_size = -1);
|
||||
|
||||
// Flushes any buffers and closes the underlying file. Returns false if
|
||||
// an error occurs during the process; use GetErrno() to examine the error.
|
||||
// Even if an error occurs, the file descriptor is closed when this returns.
|
||||
bool Close();
|
||||
|
||||
// By default, the file descriptor is not closed when the stream is
|
||||
// destroyed. Call SetCloseOnDelete(true) to change that. WARNING:
|
||||
// This leaves no way for the caller to detect if close() fails. If
|
||||
// detecting close() errors is important to you, you should arrange
|
||||
// to close the descriptor yourself.
|
||||
void SetCloseOnDelete(bool value) { copying_input_.SetCloseOnDelete(value); }
|
||||
|
||||
// If an I/O error has occurred on this file descriptor, this is the
|
||||
// errno from that error. Otherwise, this is zero. Once an error
|
||||
// occurs, the stream is broken and all subsequent operations will
|
||||
// fail.
|
||||
int GetErrno() const { return copying_input_.GetErrno(); }
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
bool Skip(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
class PROTOBUF_EXPORT CopyingFileInputStream : public CopyingInputStream {
|
||||
public:
|
||||
CopyingFileInputStream(int file_descriptor);
|
||||
~CopyingFileInputStream() override;
|
||||
|
||||
bool Close();
|
||||
void SetCloseOnDelete(bool value) { close_on_delete_ = value; }
|
||||
int GetErrno() const { return errno_; }
|
||||
|
||||
// implements CopyingInputStream ---------------------------------
|
||||
int Read(void* buffer, int size) override;
|
||||
int Skip(int count) override;
|
||||
|
||||
private:
|
||||
// The file descriptor.
|
||||
const int file_;
|
||||
bool close_on_delete_;
|
||||
bool is_closed_;
|
||||
|
||||
// The errno of the I/O error, if one has occurred. Otherwise, zero.
|
||||
int errno_;
|
||||
|
||||
// Did we try to seek once and fail? If so, we assume this file descriptor
|
||||
// doesn't support seeking and won't try again.
|
||||
bool previous_seek_failed_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileInputStream);
|
||||
};
|
||||
|
||||
CopyingFileInputStream copying_input_;
|
||||
CopyingInputStreamAdaptor impl_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileInputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyOutputStream which writes to a file descriptor.
|
||||
//
|
||||
// FileOutputStream is preferred over using an ofstream with
|
||||
// OstreamOutputStream. The latter will introduce an extra layer of buffering,
|
||||
// harming performance. Also, it's conceivable that FileOutputStream could
|
||||
// someday be enhanced to use zero-copy file descriptors on OSs which
|
||||
// support them.
|
||||
class PROTOBUF_EXPORT FileOutputStream : public ZeroCopyOutputStream {
|
||||
public:
|
||||
// Creates a stream that writes to the given Unix file descriptor.
|
||||
// If a block_size is given, it specifies the size of the buffers
|
||||
// that should be returned by Next(). Otherwise, a reasonable default
|
||||
// is used.
|
||||
explicit FileOutputStream(int file_descriptor, int block_size = -1);
|
||||
~FileOutputStream() override;
|
||||
|
||||
// Flushes any buffers and closes the underlying file. Returns false if
|
||||
// an error occurs during the process; use GetErrno() to examine the error.
|
||||
// Even if an error occurs, the file descriptor is closed when this returns.
|
||||
bool Close();
|
||||
|
||||
// Flushes FileOutputStream's buffers but does not close the
|
||||
// underlying file. No special measures are taken to ensure that
|
||||
// underlying operating system file object is synchronized to disk.
|
||||
bool Flush();
|
||||
|
||||
// By default, the file descriptor is not closed when the stream is
|
||||
// destroyed. Call SetCloseOnDelete(true) to change that. WARNING:
|
||||
// This leaves no way for the caller to detect if close() fails. If
|
||||
// detecting close() errors is important to you, you should arrange
|
||||
// to close the descriptor yourself.
|
||||
void SetCloseOnDelete(bool value) { copying_output_.SetCloseOnDelete(value); }
|
||||
|
||||
// If an I/O error has occurred on this file descriptor, this is the
|
||||
// errno from that error. Otherwise, this is zero. Once an error
|
||||
// occurs, the stream is broken and all subsequent operations will
|
||||
// fail.
|
||||
int GetErrno() const { return copying_output_.GetErrno(); }
|
||||
|
||||
// implements ZeroCopyOutputStream ---------------------------------
|
||||
bool Next(void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
class PROTOBUF_EXPORT CopyingFileOutputStream : public CopyingOutputStream {
|
||||
public:
|
||||
CopyingFileOutputStream(int file_descriptor);
|
||||
~CopyingFileOutputStream() override;
|
||||
|
||||
bool Close();
|
||||
void SetCloseOnDelete(bool value) { close_on_delete_ = value; }
|
||||
int GetErrno() const { return errno_; }
|
||||
|
||||
// implements CopyingOutputStream --------------------------------
|
||||
bool Write(const void* buffer, int size) override;
|
||||
|
||||
private:
|
||||
// The file descriptor.
|
||||
const int file_;
|
||||
bool close_on_delete_;
|
||||
bool is_closed_;
|
||||
|
||||
// The errno of the I/O error, if one has occurred. Otherwise, zero.
|
||||
int errno_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileOutputStream);
|
||||
};
|
||||
|
||||
CopyingFileOutputStream copying_output_;
|
||||
CopyingOutputStreamAdaptor impl_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileOutputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyInputStream which reads from a C++ istream.
|
||||
//
|
||||
// Note that for reading files (or anything represented by a file descriptor),
|
||||
// FileInputStream is more efficient.
|
||||
class PROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream {
|
||||
public:
|
||||
// Creates a stream that reads from the given C++ istream.
|
||||
// If a block_size is given, it specifies the number of bytes that
|
||||
// should be read and returned with each call to Next(). Otherwise,
|
||||
// a reasonable default is used.
|
||||
explicit IstreamInputStream(std::istream* stream, int block_size = -1);
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
bool Skip(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
class PROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream {
|
||||
public:
|
||||
CopyingIstreamInputStream(std::istream* input);
|
||||
~CopyingIstreamInputStream() override;
|
||||
|
||||
// implements CopyingInputStream ---------------------------------
|
||||
int Read(void* buffer, int size) override;
|
||||
// (We use the default implementation of Skip().)
|
||||
|
||||
private:
|
||||
// The stream.
|
||||
std::istream* input_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream);
|
||||
};
|
||||
|
||||
CopyingIstreamInputStream copying_input_;
|
||||
CopyingInputStreamAdaptor impl_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyOutputStream which writes to a C++ ostream.
|
||||
//
|
||||
// Note that for writing files (or anything represented by a file descriptor),
|
||||
// FileOutputStream is more efficient.
|
||||
class PROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream {
|
||||
public:
|
||||
// Creates a stream that writes to the given C++ ostream.
|
||||
// If a block_size is given, it specifies the size of the buffers
|
||||
// that should be returned by Next(). Otherwise, a reasonable default
|
||||
// is used.
|
||||
explicit OstreamOutputStream(std::ostream* stream, int block_size = -1);
|
||||
~OstreamOutputStream() override;
|
||||
|
||||
// implements ZeroCopyOutputStream ---------------------------------
|
||||
bool Next(void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
class PROTOBUF_EXPORT CopyingOstreamOutputStream
|
||||
: public CopyingOutputStream {
|
||||
public:
|
||||
CopyingOstreamOutputStream(std::ostream* output);
|
||||
~CopyingOstreamOutputStream() override;
|
||||
|
||||
// implements CopyingOutputStream --------------------------------
|
||||
bool Write(const void* buffer, int size) override;
|
||||
|
||||
private:
|
||||
// The stream.
|
||||
std::ostream* output_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream);
|
||||
};
|
||||
|
||||
CopyingOstreamOutputStream copying_output_;
|
||||
CopyingOutputStreamAdaptor impl_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyInputStream which reads from several other streams in sequence.
|
||||
// ConcatenatingInputStream is unable to distinguish between end-of-stream
|
||||
// and read errors in the underlying streams, so it assumes any errors mean
|
||||
// end-of-stream. So, if the underlying streams fail for any other reason,
|
||||
// ConcatenatingInputStream may do odd things. It is suggested that you do
|
||||
// not use ConcatenatingInputStream on streams that might produce read errors
|
||||
// other than end-of-stream.
|
||||
class PROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream {
|
||||
public:
|
||||
// All streams passed in as well as the array itself must remain valid
|
||||
// until the ConcatenatingInputStream is destroyed.
|
||||
ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count);
|
||||
~ConcatenatingInputStream() override = default;
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
bool Skip(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
|
||||
private:
|
||||
// As streams are retired, streams_ is incremented and count_ is
|
||||
// decremented.
|
||||
ZeroCopyInputStream* const* streams_;
|
||||
int stream_count_;
|
||||
int64 bytes_retired_; // Bytes read from previous streams.
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__
|
406
include/google/protobuf/io/zero_copy_stream_impl_lite.h
Normal file
406
include/google/protobuf/io/zero_copy_stream_impl_lite.h
Normal file
@ -0,0 +1,406 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// This file contains common implementations of the interfaces defined in
|
||||
// zero_copy_stream.h which are included in the "lite" protobuf library.
|
||||
// These implementations cover I/O on raw arrays and strings, as well as
|
||||
// adaptors which make it easy to implement streams based on traditional
|
||||
// streams. Of course, many users will probably want to write their own
|
||||
// implementations of these interfaces specific to the particular I/O
|
||||
// abstractions they prefer to use, but these should cover the most common
|
||||
// cases.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__
|
||||
#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__
|
||||
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/stubs/callback.h>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/stubs/stl_util.h>
|
||||
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace io {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyInputStream backed by an in-memory array of bytes.
|
||||
class PROTOBUF_EXPORT ArrayInputStream : public ZeroCopyInputStream {
|
||||
public:
|
||||
// Create an InputStream that returns the bytes pointed to by "data".
|
||||
// "data" remains the property of the caller but must remain valid until
|
||||
// the stream is destroyed. If a block_size is given, calls to Next()
|
||||
// will return data blocks no larger than the given size. Otherwise, the
|
||||
// first call to Next() returns the entire array. block_size is mainly
|
||||
// useful for testing; in production you would probably never want to set
|
||||
// it.
|
||||
ArrayInputStream(const void* data, int size, int block_size = -1);
|
||||
~ArrayInputStream() override = default;
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
bool Skip(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
|
||||
private:
|
||||
const uint8* const data_; // The byte array.
|
||||
const int size_; // Total size of the array.
|
||||
const int block_size_; // How many bytes to return at a time.
|
||||
|
||||
int position_;
|
||||
int last_returned_size_; // How many bytes we returned last time Next()
|
||||
// was called (used for error checking only).
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayInputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyOutputStream backed by an in-memory array of bytes.
|
||||
class PROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream {
|
||||
public:
|
||||
// Create an OutputStream that writes to the bytes pointed to by "data".
|
||||
// "data" remains the property of the caller but must remain valid until
|
||||
// the stream is destroyed. If a block_size is given, calls to Next()
|
||||
// will return data blocks no larger than the given size. Otherwise, the
|
||||
// first call to Next() returns the entire array. block_size is mainly
|
||||
// useful for testing; in production you would probably never want to set
|
||||
// it.
|
||||
ArrayOutputStream(void* data, int size, int block_size = -1);
|
||||
~ArrayOutputStream() override = default;
|
||||
|
||||
// implements ZeroCopyOutputStream ---------------------------------
|
||||
bool Next(void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
uint8* const data_; // The byte array.
|
||||
const int size_; // Total size of the array.
|
||||
const int block_size_; // How many bytes to return at a time.
|
||||
|
||||
int position_;
|
||||
int last_returned_size_; // How many bytes we returned last time Next()
|
||||
// was called (used for error checking only).
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayOutputStream);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyOutputStream which appends bytes to a string.
|
||||
class PROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream {
|
||||
public:
|
||||
// Create a StringOutputStream which appends bytes to the given string.
|
||||
// The string remains property of the caller, but it is mutated in arbitrary
|
||||
// ways and MUST NOT be accessed in any way until you're done with the
|
||||
// stream. Either be sure there's no further usage, or (safest) destroy the
|
||||
// stream before using the contents.
|
||||
//
|
||||
// Hint: If you call target->reserve(n) before creating the stream,
|
||||
// the first call to Next() will return at least n bytes of buffer
|
||||
// space.
|
||||
explicit StringOutputStream(std::string* target);
|
||||
~StringOutputStream() override = default;
|
||||
|
||||
// implements ZeroCopyOutputStream ---------------------------------
|
||||
bool Next(void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
static const int kMinimumSize = 16;
|
||||
|
||||
std::string* target_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream);
|
||||
};
|
||||
|
||||
// Note: There is no StringInputStream. Instead, just create an
|
||||
// ArrayInputStream as follows:
|
||||
// ArrayInputStream input(str.data(), str.size());
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A generic traditional input stream interface.
|
||||
//
|
||||
// Lots of traditional input streams (e.g. file descriptors, C stdio
|
||||
// streams, and C++ iostreams) expose an interface where every read
|
||||
// involves copying bytes into a buffer. If you want to take such an
|
||||
// interface and make a ZeroCopyInputStream based on it, simply implement
|
||||
// CopyingInputStream and then use CopyingInputStreamAdaptor.
|
||||
//
|
||||
// CopyingInputStream implementations should avoid buffering if possible.
|
||||
// CopyingInputStreamAdaptor does its own buffering and will read data
|
||||
// in large blocks.
|
||||
class PROTOBUF_EXPORT CopyingInputStream {
|
||||
public:
|
||||
virtual ~CopyingInputStream() {}
|
||||
|
||||
// Reads up to "size" bytes into the given buffer. Returns the number of
|
||||
// bytes read. Read() waits until at least one byte is available, or
|
||||
// returns zero if no bytes will ever become available (EOF), or -1 if a
|
||||
// permanent read error occurred.
|
||||
virtual int Read(void* buffer, int size) = 0;
|
||||
|
||||
// Skips the next "count" bytes of input. Returns the number of bytes
|
||||
// actually skipped. This will always be exactly equal to "count" unless
|
||||
// EOF was reached or a permanent read error occurred.
|
||||
//
|
||||
// The default implementation just repeatedly calls Read() into a scratch
|
||||
// buffer.
|
||||
virtual int Skip(int count);
|
||||
};
|
||||
|
||||
// A ZeroCopyInputStream which reads from a CopyingInputStream. This is
|
||||
// useful for implementing ZeroCopyInputStreams that read from traditional
|
||||
// streams. Note that this class is not really zero-copy.
|
||||
//
|
||||
// If you want to read from file descriptors or C++ istreams, this is
|
||||
// already implemented for you: use FileInputStream or IstreamInputStream
|
||||
// respectively.
|
||||
class PROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream {
|
||||
public:
|
||||
// Creates a stream that reads from the given CopyingInputStream.
|
||||
// If a block_size is given, it specifies the number of bytes that
|
||||
// should be read and returned with each call to Next(). Otherwise,
|
||||
// a reasonable default is used. The caller retains ownership of
|
||||
// copying_stream unless SetOwnsCopyingStream(true) is called.
|
||||
explicit CopyingInputStreamAdaptor(CopyingInputStream* copying_stream,
|
||||
int block_size = -1);
|
||||
~CopyingInputStreamAdaptor() override;
|
||||
|
||||
// Call SetOwnsCopyingStream(true) to tell the CopyingInputStreamAdaptor to
|
||||
// delete the underlying CopyingInputStream when it is destroyed.
|
||||
void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; }
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
bool Skip(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
// Insures that buffer_ is not NULL.
|
||||
void AllocateBufferIfNeeded();
|
||||
// Frees the buffer and resets buffer_used_.
|
||||
void FreeBuffer();
|
||||
|
||||
// The underlying copying stream.
|
||||
CopyingInputStream* copying_stream_;
|
||||
bool owns_copying_stream_;
|
||||
|
||||
// True if we have seen a permanent error from the underlying stream.
|
||||
bool failed_;
|
||||
|
||||
// The current position of copying_stream_, relative to the point where
|
||||
// we started reading.
|
||||
int64 position_;
|
||||
|
||||
// Data is read into this buffer. It may be NULL if no buffer is currently
|
||||
// in use. Otherwise, it points to an array of size buffer_size_.
|
||||
std::unique_ptr<uint8[]> buffer_;
|
||||
const int buffer_size_;
|
||||
|
||||
// Number of valid bytes currently in the buffer (i.e. the size last
|
||||
// returned by Next()). 0 <= buffer_used_ <= buffer_size_.
|
||||
int buffer_used_;
|
||||
|
||||
// Number of bytes in the buffer which were backed up over by a call to
|
||||
// BackUp(). These need to be returned again.
|
||||
// 0 <= backup_bytes_ <= buffer_used_
|
||||
int backup_bytes_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingInputStreamAdaptor);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A generic traditional output stream interface.
|
||||
//
|
||||
// Lots of traditional output streams (e.g. file descriptors, C stdio
|
||||
// streams, and C++ iostreams) expose an interface where every write
|
||||
// involves copying bytes from a buffer. If you want to take such an
|
||||
// interface and make a ZeroCopyOutputStream based on it, simply implement
|
||||
// CopyingOutputStream and then use CopyingOutputStreamAdaptor.
|
||||
//
|
||||
// CopyingOutputStream implementations should avoid buffering if possible.
|
||||
// CopyingOutputStreamAdaptor does its own buffering and will write data
|
||||
// in large blocks.
|
||||
class PROTOBUF_EXPORT CopyingOutputStream {
|
||||
public:
|
||||
virtual ~CopyingOutputStream() {}
|
||||
|
||||
// Writes "size" bytes from the given buffer to the output. Returns true
|
||||
// if successful, false on a write error.
|
||||
virtual bool Write(const void* buffer, int size) = 0;
|
||||
};
|
||||
|
||||
// A ZeroCopyOutputStream which writes to a CopyingOutputStream. This is
|
||||
// useful for implementing ZeroCopyOutputStreams that write to traditional
|
||||
// streams. Note that this class is not really zero-copy.
|
||||
//
|
||||
// If you want to write to file descriptors or C++ ostreams, this is
|
||||
// already implemented for you: use FileOutputStream or OstreamOutputStream
|
||||
// respectively.
|
||||
class PROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream {
|
||||
public:
|
||||
// Creates a stream that writes to the given Unix file descriptor.
|
||||
// If a block_size is given, it specifies the size of the buffers
|
||||
// that should be returned by Next(). Otherwise, a reasonable default
|
||||
// is used.
|
||||
explicit CopyingOutputStreamAdaptor(CopyingOutputStream* copying_stream,
|
||||
int block_size = -1);
|
||||
~CopyingOutputStreamAdaptor() override;
|
||||
|
||||
// Writes all pending data to the underlying stream. Returns false if a
|
||||
// write error occurred on the underlying stream. (The underlying
|
||||
// stream itself is not necessarily flushed.)
|
||||
bool Flush();
|
||||
|
||||
// Call SetOwnsCopyingStream(true) to tell the CopyingOutputStreamAdaptor to
|
||||
// delete the underlying CopyingOutputStream when it is destroyed.
|
||||
void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; }
|
||||
|
||||
// implements ZeroCopyOutputStream ---------------------------------
|
||||
bool Next(void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
private:
|
||||
// Write the current buffer, if it is present.
|
||||
bool WriteBuffer();
|
||||
// Insures that buffer_ is not NULL.
|
||||
void AllocateBufferIfNeeded();
|
||||
// Frees the buffer.
|
||||
void FreeBuffer();
|
||||
|
||||
// The underlying copying stream.
|
||||
CopyingOutputStream* copying_stream_;
|
||||
bool owns_copying_stream_;
|
||||
|
||||
// True if we have seen a permanent error from the underlying stream.
|
||||
bool failed_;
|
||||
|
||||
// The current position of copying_stream_, relative to the point where
|
||||
// we started writing.
|
||||
int64 position_;
|
||||
|
||||
// Data is written from this buffer. It may be NULL if no buffer is
|
||||
// currently in use. Otherwise, it points to an array of size buffer_size_.
|
||||
std::unique_ptr<uint8[]> buffer_;
|
||||
const int buffer_size_;
|
||||
|
||||
// Number of valid bytes currently in the buffer (i.e. the size last
|
||||
// returned by Next()). When BackUp() is called, we just reduce this.
|
||||
// 0 <= buffer_used_ <= buffer_size_.
|
||||
int buffer_used_;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOutputStreamAdaptor);
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// A ZeroCopyInputStream which wraps some other stream and limits it to
|
||||
// a particular byte count.
|
||||
class PROTOBUF_EXPORT LimitingInputStream : public ZeroCopyInputStream {
|
||||
public:
|
||||
LimitingInputStream(ZeroCopyInputStream* input, int64 limit);
|
||||
~LimitingInputStream() override;
|
||||
|
||||
// implements ZeroCopyInputStream ----------------------------------
|
||||
bool Next(const void** data, int* size) override;
|
||||
void BackUp(int count) override;
|
||||
bool Skip(int count) override;
|
||||
int64_t ByteCount() const override;
|
||||
|
||||
|
||||
private:
|
||||
ZeroCopyInputStream* input_;
|
||||
int64 limit_; // Decreases as we go, becomes negative if we overshoot.
|
||||
int64 prior_bytes_read_; // Bytes read on underlying stream at construction
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream);
|
||||
};
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// mutable_string_data() and as_string_data() are workarounds to improve
|
||||
// the performance of writing new data to an existing string. Unfortunately
|
||||
// the methods provided by the string class are suboptimal, and using memcpy()
|
||||
// is mildly annoying because it requires its pointer args to be non-NULL even
|
||||
// if we ask it to copy 0 bytes. Furthermore, string_as_array() has the
|
||||
// property that it always returns NULL if its arg is the empty string, exactly
|
||||
// what we want to avoid if we're using it in conjunction with memcpy()!
|
||||
// With C++11, the desired memcpy() boils down to memcpy(..., &(*s)[0], size),
|
||||
// where s is a string*. Without C++11, &(*s)[0] is not guaranteed to be safe,
|
||||
// so we use string_as_array(), and live with the extra logic that tests whether
|
||||
// *s is empty.
|
||||
|
||||
// Return a pointer to mutable characters underlying the given string. The
|
||||
// return value is valid until the next time the string is resized. We
|
||||
// trust the caller to treat the return value as an array of length s->size().
|
||||
inline char* mutable_string_data(std::string* s) {
|
||||
// This should be simpler & faster than string_as_array() because the latter
|
||||
// is guaranteed to return NULL when *s is empty, so it has to check for that.
|
||||
return &(*s)[0];
|
||||
}
|
||||
|
||||
// as_string_data(s) is equivalent to
|
||||
// ({ char* p = mutable_string_data(s); make_pair(p, p != NULL); })
|
||||
// Sometimes it's faster: in some scenarios p cannot be NULL, and then the
|
||||
// code can avoid that check.
|
||||
inline std::pair<char*, bool> as_string_data(std::string* s) {
|
||||
char* p = mutable_string_data(s);
|
||||
return std::make_pair(p, true);
|
||||
}
|
||||
|
||||
} // namespace io
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__
|
1282
include/google/protobuf/map.h
Normal file
1282
include/google/protobuf/map.h
Normal file
File diff suppressed because it is too large
Load Diff
167
include/google/protobuf/map_entry.h
Normal file
167
include/google/protobuf/map_entry.h
Normal file
@ -0,0 +1,167 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_MAP_ENTRY_H__
|
||||
#define GOOGLE_PROTOBUF_MAP_ENTRY_H__
|
||||
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/map_entry_lite.h>
|
||||
#include <google/protobuf/map_type_handler.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/reflection_ops.h>
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class Arena;
|
||||
namespace internal {
|
||||
template <typename Derived, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
class MapField;
|
||||
}
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// MapEntry is the returned google::protobuf::Message when calling AddMessage of
|
||||
// google::protobuf::Reflection. In order to let it work with generated message
|
||||
// reflection, its in-memory type is the same as generated message with the same
|
||||
// fields. However, in order to decide the in-memory type of key/value, we need
|
||||
// to know both their cpp type in generated api and proto type. In
|
||||
// implementation, all in-memory types have related wire format functions to
|
||||
// support except ArenaStringPtr. Therefore, we need to define another type with
|
||||
// supporting wire format functions. Since this type is only used as return type
|
||||
// of MapEntry accessors, it's named MapEntry accessor type.
|
||||
//
|
||||
// cpp type: the type visible to users in public API.
|
||||
// proto type: WireFormatLite::FieldType of the field.
|
||||
// in-memory type: type of the data member used to stored this field.
|
||||
// MapEntry accessor type: type used in MapEntry getters/mutators to access the
|
||||
// field.
|
||||
//
|
||||
// cpp type | proto type | in-memory type | MapEntry accessor type
|
||||
// int32 TYPE_INT32 int32 int32
|
||||
// int32 TYPE_FIXED32 int32 int32
|
||||
// string TYPE_STRING ArenaStringPtr string
|
||||
// FooEnum TYPE_ENUM int int
|
||||
// FooMessage TYPE_MESSAGE FooMessage* FooMessage
|
||||
//
|
||||
// The in-memory types of primitive types can be inferred from its proto type,
|
||||
// while we need to explicitly specify the cpp type if proto type is
|
||||
// TYPE_MESSAGE to infer the in-memory type. Moreover, default_enum_value is
|
||||
// used to initialize enum field in proto2.
|
||||
template <typename Derived, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
class MapEntry
|
||||
: public MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value> {
|
||||
public:
|
||||
MapEntry() : _internal_metadata_(NULL) {}
|
||||
explicit MapEntry(Arena* arena)
|
||||
: MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value>(arena),
|
||||
_internal_metadata_(arena) {}
|
||||
~MapEntry() {
|
||||
Message::_internal_metadata_.Delete<UnknownFieldSet>();
|
||||
_internal_metadata_.Delete<UnknownFieldSet>();
|
||||
}
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
|
||||
typedef
|
||||
typename MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value>::KeyTypeHandler
|
||||
KeyTypeHandler;
|
||||
typedef typename MapEntryImpl<
|
||||
Derived, Message, Key, Value, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::ValueTypeHandler ValueTypeHandler;
|
||||
size_t SpaceUsedLong() const override {
|
||||
size_t size = sizeof(Derived);
|
||||
size += KeyTypeHandler::SpaceUsedInMapEntryLong(this->key_);
|
||||
size += ValueTypeHandler::SpaceUsedInMapEntryLong(this->value_);
|
||||
return size;
|
||||
}
|
||||
|
||||
InternalMetadata _internal_metadata_;
|
||||
|
||||
private:
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::Arena;
|
||||
template <typename C, typename K, typename V,
|
||||
WireFormatLite::FieldType k_wire_type, WireFormatLite::FieldType,
|
||||
int default_enum>
|
||||
friend class internal::MapField;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry);
|
||||
};
|
||||
|
||||
// Specialization for the full runtime
|
||||
template <typename Derived, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
struct MapEntryHelper<MapEntry<Derived, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value> >
|
||||
: MapEntryHelper<MapEntryLite<Derived, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value> > {
|
||||
explicit MapEntryHelper(const MapPair<Key, Value>& map_pair)
|
||||
: MapEntryHelper<MapEntryLite<Derived, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value> >(
|
||||
map_pair) {}
|
||||
};
|
||||
|
||||
template <typename Derived, typename K, typename V,
|
||||
WireFormatLite::FieldType key, WireFormatLite::FieldType value,
|
||||
int default_enum>
|
||||
struct DeconstructMapEntry<MapEntry<Derived, K, V, key, value, default_enum> > {
|
||||
typedef K Key;
|
||||
typedef V Value;
|
||||
static constexpr WireFormatLite::FieldType kKeyFieldType = key;
|
||||
static constexpr WireFormatLite::FieldType kValueFieldType = value;
|
||||
static constexpr int default_enum_value = default_enum;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__
|
676
include/google/protobuf/map_entry_lite.h
Normal file
676
include/google/protobuf/map_entry_lite.h
Normal file
@ -0,0 +1,676 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__
|
||||
#define GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/stubs/casts.h>
|
||||
#include <google/protobuf/parse_context.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/map.h>
|
||||
#include <google/protobuf/map_type_handler.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
template <typename Derived, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
class MapEntry;
|
||||
template <typename Derived, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
class MapFieldLite;
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// MoveHelper::Move is used to set *dest. It copies *src, or moves it (in
|
||||
// the C++11 sense), or swaps it. *src is left in a sane state for
|
||||
// subsequent destruction, but shouldn't be used for anything.
|
||||
template <bool is_enum, bool is_message, bool is_stringlike, typename T>
|
||||
struct MoveHelper { // primitives
|
||||
static void Move(T* src, T* dest) { *dest = *src; }
|
||||
};
|
||||
|
||||
template <bool is_message, bool is_stringlike, typename T>
|
||||
struct MoveHelper<true, is_message, is_stringlike, T> { // enums
|
||||
static void Move(T* src, T* dest) { *dest = *src; }
|
||||
// T is an enum here, so allow conversions to and from int.
|
||||
static void Move(T* src, int* dest) { *dest = static_cast<int>(*src); }
|
||||
static void Move(int* src, T* dest) { *dest = static_cast<T>(*src); }
|
||||
};
|
||||
|
||||
template <bool is_stringlike, typename T>
|
||||
struct MoveHelper<false, true, is_stringlike, T> { // messages
|
||||
static void Move(T* src, T* dest) { dest->Swap(src); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MoveHelper<false, false, true, T> { // strings and similar
|
||||
static void Move(T* src, T* dest) {
|
||||
#if __cplusplus >= 201103L
|
||||
*dest = std::move(*src);
|
||||
#else
|
||||
dest->swap(*src);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
// Functions for operating on a map entry. Does not contain any representation
|
||||
// (this class is not intended to be instantiated).
|
||||
template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType>
|
||||
struct MapEntryFuncs {
|
||||
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;
|
||||
typedef MapTypeHandler<kValueFieldType, Value> ValueTypeHandler;
|
||||
static const int kKeyFieldNumber = 1;
|
||||
static const int kValueFieldNumber = 2;
|
||||
|
||||
static uint8* InternalSerialize(int field_number, const Key& key,
|
||||
const Value& value, uint8* ptr,
|
||||
io::EpsCopyOutputStream* stream) {
|
||||
ptr = stream->EnsureSpace(ptr);
|
||||
ptr = WireFormatLite::WriteTagToArray(
|
||||
field_number, WireFormatLite::WIRETYPE_LENGTH_DELIMITED, ptr);
|
||||
ptr = io::CodedOutputStream::WriteVarint32ToArray(GetCachedSize(key, value),
|
||||
ptr);
|
||||
|
||||
ptr = KeyTypeHandler::Write(kKeyFieldNumber, key, ptr, stream);
|
||||
return ValueTypeHandler::Write(kValueFieldNumber, value, ptr, stream);
|
||||
}
|
||||
|
||||
static size_t ByteSizeLong(const Key& key, const Value& value) {
|
||||
// Tags for key and value will both be one byte (field numbers 1 and 2).
|
||||
size_t inner_length =
|
||||
2 + KeyTypeHandler::ByteSize(key) + ValueTypeHandler::ByteSize(value);
|
||||
return inner_length + io::CodedOutputStream::VarintSize32(
|
||||
static_cast<uint32>(inner_length));
|
||||
}
|
||||
|
||||
static int GetCachedSize(const Key& key, const Value& value) {
|
||||
// Tags for key and value will both be one byte (field numbers 1 and 2).
|
||||
return 2 + KeyTypeHandler::GetCachedSize(key) +
|
||||
ValueTypeHandler::GetCachedSize(value);
|
||||
}
|
||||
};
|
||||
|
||||
// MapEntryImpl is used to implement parsing and serialization of map entries.
|
||||
// It uses Curious Recursive Template Pattern (CRTP) to provide the type of
|
||||
// the eventual code to the template code.
|
||||
template <typename Derived, typename Base, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
class MapEntryImpl : public Base {
|
||||
public:
|
||||
typedef MapEntryFuncs<Key, Value, kKeyFieldType, kValueFieldType> Funcs;
|
||||
|
||||
protected:
|
||||
// Provide utilities to parse/serialize key/value. Provide utilities to
|
||||
// manipulate internal stored type.
|
||||
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;
|
||||
typedef MapTypeHandler<kValueFieldType, Value> ValueTypeHandler;
|
||||
|
||||
// Define internal memory layout. Strings and messages are stored as
|
||||
// pointers, while other types are stored as values.
|
||||
typedef typename KeyTypeHandler::TypeOnMemory KeyOnMemory;
|
||||
typedef typename ValueTypeHandler::TypeOnMemory ValueOnMemory;
|
||||
|
||||
// Enum type cannot be used for MapTypeHandler::Read. Define a type
|
||||
// which will replace Enum with int.
|
||||
typedef typename KeyTypeHandler::MapEntryAccessorType KeyMapEntryAccessorType;
|
||||
typedef
|
||||
typename ValueTypeHandler::MapEntryAccessorType ValueMapEntryAccessorType;
|
||||
|
||||
// Constants for field number.
|
||||
static const int kKeyFieldNumber = 1;
|
||||
static const int kValueFieldNumber = 2;
|
||||
|
||||
// Constants for field tag.
|
||||
static const uint8 kKeyTag =
|
||||
GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(kKeyFieldNumber, KeyTypeHandler::kWireType);
|
||||
static const uint8 kValueTag = GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(
|
||||
kValueFieldNumber, ValueTypeHandler::kWireType);
|
||||
static const size_t kTagSize = 1;
|
||||
|
||||
public:
|
||||
// Work-around for a compiler bug (see repeated_field.h).
|
||||
typedef void MapEntryHasMergeTypeTrait;
|
||||
typedef Derived EntryType;
|
||||
typedef Key EntryKeyType;
|
||||
typedef Value EntryValueType;
|
||||
static const WireFormatLite::FieldType kEntryKeyFieldType = kKeyFieldType;
|
||||
static const WireFormatLite::FieldType kEntryValueFieldType = kValueFieldType;
|
||||
static const int kEntryDefaultEnumValue = default_enum_value;
|
||||
|
||||
MapEntryImpl() {
|
||||
KeyTypeHandler::Initialize(&key_, NULL);
|
||||
ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value,
|
||||
NULL);
|
||||
_has_bits_[0] = 0;
|
||||
}
|
||||
|
||||
explicit MapEntryImpl(Arena* arena) : Base(arena) {
|
||||
KeyTypeHandler::Initialize(&key_, arena);
|
||||
ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value,
|
||||
arena);
|
||||
_has_bits_[0] = 0;
|
||||
}
|
||||
|
||||
~MapEntryImpl() {
|
||||
if (Base::GetArena() != NULL) return;
|
||||
KeyTypeHandler::DeleteNoArena(key_);
|
||||
ValueTypeHandler::DeleteNoArena(value_);
|
||||
}
|
||||
|
||||
// accessors ======================================================
|
||||
|
||||
virtual inline const KeyMapEntryAccessorType& key() const {
|
||||
return KeyTypeHandler::GetExternalReference(key_);
|
||||
}
|
||||
virtual inline const ValueMapEntryAccessorType& value() const {
|
||||
return ValueTypeHandler::DefaultIfNotInitialized(
|
||||
value_, Derived::internal_default_instance()->value_);
|
||||
}
|
||||
inline KeyMapEntryAccessorType* mutable_key() {
|
||||
set_has_key();
|
||||
return KeyTypeHandler::EnsureMutable(&key_, Base::GetArena());
|
||||
}
|
||||
inline ValueMapEntryAccessorType* mutable_value() {
|
||||
set_has_value();
|
||||
return ValueTypeHandler::EnsureMutable(&value_, Base::GetArena());
|
||||
}
|
||||
|
||||
// implements MessageLite =========================================
|
||||
|
||||
// MapEntryImpl is for implementation only and this function isn't called
|
||||
// anywhere. Just provide a fake implementation here for MessageLite.
|
||||
std::string GetTypeName() const override { return ""; }
|
||||
|
||||
void CheckTypeAndMergeFrom(const MessageLite& other) override {
|
||||
MergeFromInternal(*::google::protobuf::internal::DownCast<const Derived*>(&other));
|
||||
}
|
||||
|
||||
const char* _InternalParse(const char* ptr, ParseContext* ctx) final {
|
||||
while (!ctx->Done(&ptr)) {
|
||||
uint32 tag;
|
||||
ptr = ReadTag(ptr, &tag);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
if (tag == kKeyTag) {
|
||||
set_has_key();
|
||||
KeyMapEntryAccessorType* key = mutable_key();
|
||||
ptr = KeyTypeHandler::Read(ptr, ctx, key);
|
||||
if (!Derived::ValidateKey(key)) return nullptr;
|
||||
} else if (tag == kValueTag) {
|
||||
set_has_value();
|
||||
ValueMapEntryAccessorType* value = mutable_value();
|
||||
ptr = ValueTypeHandler::Read(ptr, ctx, value);
|
||||
if (!Derived::ValidateValue(value)) return nullptr;
|
||||
} else {
|
||||
if (tag == 0 || WireFormatLite::GetTagWireType(tag) ==
|
||||
WireFormatLite::WIRETYPE_END_GROUP) {
|
||||
ctx->SetLastTag(tag);
|
||||
return ptr;
|
||||
}
|
||||
ptr = UnknownFieldParse(tag, static_cast<std::string*>(nullptr), ptr,
|
||||
ctx);
|
||||
}
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
size_t ByteSizeLong() const override {
|
||||
size_t size = 0;
|
||||
size += has_key() ? kTagSize +
|
||||
static_cast<size_t>(KeyTypeHandler::ByteSize(key()))
|
||||
: 0;
|
||||
size += has_value()
|
||||
? kTagSize +
|
||||
static_cast<size_t>(ValueTypeHandler::ByteSize(value()))
|
||||
: 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
::google::protobuf::uint8* _InternalSerialize(::google::protobuf::uint8* ptr,
|
||||
io::EpsCopyOutputStream* stream) const override {
|
||||
ptr = KeyTypeHandler::Write(kKeyFieldNumber, key(), ptr, stream);
|
||||
return ValueTypeHandler::Write(kValueFieldNumber, value(), ptr, stream);
|
||||
}
|
||||
|
||||
// Don't override SerializeWithCachedSizesToArray. Use MessageLite's.
|
||||
|
||||
int GetCachedSize() const override {
|
||||
int size = 0;
|
||||
size += has_key() ? static_cast<int>(kTagSize) +
|
||||
KeyTypeHandler::GetCachedSize(key())
|
||||
: 0;
|
||||
size += has_value() ? static_cast<int>(kTagSize) +
|
||||
ValueTypeHandler::GetCachedSize(value())
|
||||
: 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
bool IsInitialized() const override {
|
||||
return ValueTypeHandler::IsInitialized(value_);
|
||||
}
|
||||
|
||||
Base* New() const override {
|
||||
Derived* entry = new Derived;
|
||||
return entry;
|
||||
}
|
||||
|
||||
Base* New(Arena* arena) const override {
|
||||
Derived* entry = Arena::CreateMessage<Derived>(arena);
|
||||
return entry;
|
||||
}
|
||||
|
||||
protected:
|
||||
// We can't declare this function directly here as it would hide the other
|
||||
// overload (const Message&).
|
||||
void MergeFromInternal(const MapEntryImpl& from) {
|
||||
if (from._has_bits_[0]) {
|
||||
if (from.has_key()) {
|
||||
KeyTypeHandler::EnsureMutable(&key_, Base::GetArena());
|
||||
KeyTypeHandler::Merge(from.key(), &key_, Base::GetArena());
|
||||
set_has_key();
|
||||
}
|
||||
if (from.has_value()) {
|
||||
ValueTypeHandler::EnsureMutable(&value_, Base::GetArena());
|
||||
ValueTypeHandler::Merge(from.value(), &value_, Base::GetArena());
|
||||
set_has_value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void Clear() override {
|
||||
KeyTypeHandler::Clear(&key_, Base::GetArena());
|
||||
ValueTypeHandler::ClearMaybeByDefaultEnum(&value_, Base::GetArena(),
|
||||
default_enum_value);
|
||||
clear_has_key();
|
||||
clear_has_value();
|
||||
}
|
||||
|
||||
static void InitAsDefaultInstance() {
|
||||
Derived* d = const_cast<Derived*>(Derived::internal_default_instance());
|
||||
KeyTypeHandler::AssignDefaultValue(&d->key_);
|
||||
ValueTypeHandler::AssignDefaultValue(&d->value_);
|
||||
}
|
||||
|
||||
// Parsing using MergePartialFromCodedStream, above, is not as
|
||||
// efficient as it could be. This helper class provides a speedier way.
|
||||
template <typename MapField, typename Map>
|
||||
class Parser {
|
||||
public:
|
||||
explicit Parser(MapField* mf) : mf_(mf), map_(mf->MutableMap()) {}
|
||||
~Parser() {
|
||||
if (entry_ != nullptr && entry_->GetArena() == nullptr) delete entry_;
|
||||
}
|
||||
|
||||
// This does what the typical MergePartialFromCodedStream() is expected to
|
||||
// do, with the additional side-effect that if successful (i.e., if true is
|
||||
// going to be its return value) it inserts the key-value pair into map_.
|
||||
bool MergePartialFromCodedStream(io::CodedInputStream* input) {
|
||||
// Look for the expected thing: a key and then a value. If it fails,
|
||||
// invoke the enclosing class's MergePartialFromCodedStream, or return
|
||||
// false if that would be pointless.
|
||||
if (input->ExpectTag(kKeyTag)) {
|
||||
if (!KeyTypeHandler::Read(input, &key_)) {
|
||||
return false;
|
||||
}
|
||||
// Peek at the next byte to see if it is kValueTag. If not, bail out.
|
||||
const void* data;
|
||||
int size;
|
||||
input->GetDirectBufferPointerInline(&data, &size);
|
||||
// We could use memcmp here, but we don't bother. The tag is one byte.
|
||||
static_assert(kTagSize == 1, "tag size must be 1");
|
||||
if (size > 0 && *reinterpret_cast<const char*>(data) == kValueTag) {
|
||||
typename Map::size_type map_size = map_->size();
|
||||
value_ptr_ = &(*map_)[key_];
|
||||
if (PROTOBUF_PREDICT_TRUE(map_size != map_->size())) {
|
||||
// We created a new key-value pair. Fill in the value.
|
||||
typedef
|
||||
typename MapIf<ValueTypeHandler::kIsEnum, int*, Value*>::type T;
|
||||
input->Skip(kTagSize); // Skip kValueTag.
|
||||
if (!ValueTypeHandler::Read(input,
|
||||
reinterpret_cast<T>(value_ptr_))) {
|
||||
map_->erase(key_); // Failure! Undo insertion.
|
||||
return false;
|
||||
}
|
||||
if (input->ExpectAtEnd()) return true;
|
||||
return ReadBeyondKeyValuePair(input);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
key_ = Key();
|
||||
}
|
||||
|
||||
NewEntry();
|
||||
*entry_->mutable_key() = key_;
|
||||
const bool result = entry_->MergePartialFromCodedStream(input);
|
||||
if (result) UseKeyAndValueFromEntry();
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* _InternalParse(const char* ptr, ParseContext* ctx) {
|
||||
if (PROTOBUF_PREDICT_TRUE(!ctx->Done(&ptr) && *ptr == kKeyTag)) {
|
||||
ptr = KeyTypeHandler::Read(ptr + 1, ctx, &key_);
|
||||
if (PROTOBUF_PREDICT_FALSE(!ptr || !Derived::ValidateKey(&key_))) {
|
||||
return nullptr;
|
||||
}
|
||||
if (PROTOBUF_PREDICT_TRUE(!ctx->Done(&ptr) && *ptr == kValueTag)) {
|
||||
typename Map::size_type map_size = map_->size();
|
||||
value_ptr_ = &(*map_)[key_];
|
||||
if (PROTOBUF_PREDICT_TRUE(map_size != map_->size())) {
|
||||
using T =
|
||||
typename MapIf<ValueTypeHandler::kIsEnum, int*, Value*>::type;
|
||||
ptr = ValueTypeHandler::Read(ptr + 1, ctx,
|
||||
reinterpret_cast<T>(value_ptr_));
|
||||
if (PROTOBUF_PREDICT_FALSE(!ptr ||
|
||||
!Derived::ValidateValue(value_ptr_))) {
|
||||
map_->erase(key_); // Failure! Undo insertion.
|
||||
return nullptr;
|
||||
}
|
||||
if (PROTOBUF_PREDICT_TRUE(ctx->Done(&ptr))) return ptr;
|
||||
if (!ptr) return nullptr;
|
||||
NewEntry();
|
||||
ValueMover::Move(value_ptr_, entry_->mutable_value());
|
||||
map_->erase(key_);
|
||||
goto move_key;
|
||||
}
|
||||
} else {
|
||||
if (!ptr) return nullptr;
|
||||
}
|
||||
NewEntry();
|
||||
move_key:
|
||||
KeyMover::Move(&key_, entry_->mutable_key());
|
||||
} else {
|
||||
if (!ptr) return nullptr;
|
||||
NewEntry();
|
||||
}
|
||||
ptr = entry_->_InternalParse(ptr, ctx);
|
||||
if (ptr) UseKeyAndValueFromEntry();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename UnknownType>
|
||||
const char* ParseWithEnumValidation(const char* ptr, ParseContext* ctx,
|
||||
bool (*is_valid)(int), uint32 field_num,
|
||||
InternalMetadata* metadata) {
|
||||
auto entry = NewEntry();
|
||||
ptr = entry->_InternalParse(ptr, ctx);
|
||||
if (!ptr) return nullptr;
|
||||
if (is_valid(entry->value())) {
|
||||
UseKeyAndValueFromEntry();
|
||||
} else {
|
||||
WriteLengthDelimited(field_num, entry->SerializeAsString(),
|
||||
metadata->mutable_unknown_fields<UnknownType>());
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
MapEntryImpl* NewEntry() { return entry_ = mf_->NewEntry(); }
|
||||
|
||||
const Key& key() const { return key_; }
|
||||
const Value& value() const { return *value_ptr_; }
|
||||
|
||||
const Key& entry_key() const { return entry_->key(); }
|
||||
const Value& entry_value() const { return entry_->value(); }
|
||||
|
||||
private:
|
||||
void UseKeyAndValueFromEntry() {
|
||||
// Update key_ in case we need it later (because key() is called).
|
||||
// This is potentially inefficient, especially if the key is
|
||||
// expensive to copy (e.g., a long string), but this is a cold
|
||||
// path, so it's not a big deal.
|
||||
key_ = entry_->key();
|
||||
value_ptr_ = &(*map_)[key_];
|
||||
ValueMover::Move(entry_->mutable_value(), value_ptr_);
|
||||
}
|
||||
|
||||
// After reading a key and value successfully, and inserting that data
|
||||
// into map_, we are not at the end of the input. This is unusual, but
|
||||
// allowed by the spec.
|
||||
bool ReadBeyondKeyValuePair(io::CodedInputStream* input) PROTOBUF_COLD {
|
||||
NewEntry();
|
||||
ValueMover::Move(value_ptr_, entry_->mutable_value());
|
||||
map_->erase(key_);
|
||||
KeyMover::Move(&key_, entry_->mutable_key());
|
||||
const bool result = entry_->MergePartialFromCodedStream(input);
|
||||
if (result) UseKeyAndValueFromEntry();
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef MoveHelper<KeyTypeHandler::kIsEnum, KeyTypeHandler::kIsMessage,
|
||||
KeyTypeHandler::kWireType ==
|
||||
WireFormatLite::WIRETYPE_LENGTH_DELIMITED,
|
||||
Key>
|
||||
KeyMover;
|
||||
typedef MoveHelper<ValueTypeHandler::kIsEnum, ValueTypeHandler::kIsMessage,
|
||||
ValueTypeHandler::kWireType ==
|
||||
WireFormatLite::WIRETYPE_LENGTH_DELIMITED,
|
||||
Value>
|
||||
ValueMover;
|
||||
|
||||
MapField* const mf_;
|
||||
Map* const map_;
|
||||
Key key_;
|
||||
Value* value_ptr_;
|
||||
MapEntryImpl* entry_ = nullptr;
|
||||
};
|
||||
|
||||
protected:
|
||||
void set_has_key() { _has_bits_[0] |= 0x00000001u; }
|
||||
bool has_key() const { return (_has_bits_[0] & 0x00000001u) != 0; }
|
||||
void clear_has_key() { _has_bits_[0] &= ~0x00000001u; }
|
||||
void set_has_value() { _has_bits_[0] |= 0x00000002u; }
|
||||
bool has_value() const { return (_has_bits_[0] & 0x00000002u) != 0; }
|
||||
void clear_has_value() { _has_bits_[0] &= ~0x00000002u; }
|
||||
|
||||
public:
|
||||
inline Arena* GetArena() const { return Base::GetArena(); }
|
||||
|
||||
public: // Needed for constructing tables
|
||||
KeyOnMemory key_;
|
||||
ValueOnMemory value_;
|
||||
uint32 _has_bits_[1];
|
||||
|
||||
private:
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::Arena;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
template <typename C, typename K, typename V, WireFormatLite::FieldType,
|
||||
WireFormatLite::FieldType, int>
|
||||
friend class internal::MapEntry;
|
||||
template <typename C, typename K, typename V, WireFormatLite::FieldType,
|
||||
WireFormatLite::FieldType, int>
|
||||
friend class internal::MapFieldLite;
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryImpl);
|
||||
};
|
||||
|
||||
template <typename T, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
class MapEntryLite
|
||||
: public MapEntryImpl<T, MessageLite, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value> {
|
||||
public:
|
||||
typedef MapEntryImpl<T, MessageLite, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value>
|
||||
SuperType;
|
||||
MapEntryLite() {}
|
||||
explicit MapEntryLite(Arena* arena) : SuperType(arena) {}
|
||||
~MapEntryLite() { MessageLite::_internal_metadata_.Delete<std::string>(); }
|
||||
void MergeFrom(const MapEntryLite& other) { MergeFromInternal(other); }
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite);
|
||||
};
|
||||
// The completely unprincipled and unwieldy use of template parameters in
|
||||
// the map code necessitates wrappers to make the code a little bit more
|
||||
// manageable.
|
||||
template <typename Derived>
|
||||
struct DeconstructMapEntry;
|
||||
|
||||
template <typename T, typename K, typename V, WireFormatLite::FieldType key,
|
||||
WireFormatLite::FieldType value, int default_enum>
|
||||
struct DeconstructMapEntry<MapEntryLite<T, K, V, key, value, default_enum> > {
|
||||
typedef K Key;
|
||||
typedef V Value;
|
||||
static const WireFormatLite::FieldType kKeyFieldType = key;
|
||||
static const WireFormatLite::FieldType kValueFieldType = value;
|
||||
static const int default_enum_value = default_enum;
|
||||
};
|
||||
|
||||
// Helpers for deterministic serialization =============================
|
||||
|
||||
// This struct can be used with any generic sorting algorithm. If the Key
|
||||
// type is relatively small and easy to copy then copying Keys into an
|
||||
// array of SortItems can be beneficial. Then all the data the sorting
|
||||
// algorithm needs to touch is in that one array.
|
||||
template <typename Key, typename PtrToKeyValuePair>
|
||||
struct SortItem {
|
||||
SortItem() {}
|
||||
explicit SortItem(PtrToKeyValuePair p) : first(p->first), second(p) {}
|
||||
|
||||
Key first;
|
||||
PtrToKeyValuePair second;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CompareByFirstField {
|
||||
bool operator()(const T& a, const T& b) const { return a.first < b.first; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CompareByDerefFirst {
|
||||
bool operator()(const T& a, const T& b) const { return a->first < b->first; }
|
||||
};
|
||||
|
||||
// Helper for table driven serialization
|
||||
|
||||
template <WireFormatLite::FieldType FieldType>
|
||||
struct FromHelper {
|
||||
template <typename T>
|
||||
static const T& From(const T& x) {
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct FromHelper<WireFormatLite::TYPE_STRING> {
|
||||
static ArenaStringPtr From(const std::string& x) {
|
||||
ArenaStringPtr res;
|
||||
TaggedPtr<std::string> ptr;
|
||||
ptr.Set(const_cast<std::string*>(&x));
|
||||
res.UnsafeSetTaggedPointer(ptr);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct FromHelper<WireFormatLite::TYPE_BYTES> {
|
||||
static ArenaStringPtr From(const std::string& x) {
|
||||
ArenaStringPtr res;
|
||||
TaggedPtr<std::string> ptr;
|
||||
ptr.Set(const_cast<std::string*>(&x));
|
||||
res.UnsafeSetTaggedPointer(ptr);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct FromHelper<WireFormatLite::TYPE_MESSAGE> {
|
||||
template <typename T>
|
||||
static T* From(const T& x) {
|
||||
return const_cast<T*>(&x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename MapEntryType>
|
||||
struct MapEntryHelper;
|
||||
|
||||
template <typename T, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
struct MapEntryHelper<MapEntryLite<T, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value> > {
|
||||
// Provide utilities to parse/serialize key/value. Provide utilities to
|
||||
// manipulate internal stored type.
|
||||
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;
|
||||
typedef MapTypeHandler<kValueFieldType, Value> ValueTypeHandler;
|
||||
|
||||
// Define internal memory layout. Strings and messages are stored as
|
||||
// pointers, while other types are stored as values.
|
||||
typedef typename KeyTypeHandler::TypeOnMemory KeyOnMemory;
|
||||
typedef typename ValueTypeHandler::TypeOnMemory ValueOnMemory;
|
||||
|
||||
explicit MapEntryHelper(const MapPair<Key, Value>& map_pair)
|
||||
: _has_bits_(3),
|
||||
_cached_size_(2 + KeyTypeHandler::GetCachedSize(map_pair.first) +
|
||||
ValueTypeHandler::GetCachedSize(map_pair.second)),
|
||||
key_(FromHelper<kKeyFieldType>::From(map_pair.first)),
|
||||
value_(FromHelper<kValueFieldType>::From(map_pair.second)) {}
|
||||
|
||||
// Purposely not following the style guide naming. These are the names
|
||||
// the proto compiler would generate given the map entry descriptor.
|
||||
// The proto compiler generates the offsets in this struct as if this was
|
||||
// a regular message. This way the table driven code barely notices it's
|
||||
// dealing with a map field.
|
||||
uint32 _has_bits_; // NOLINT
|
||||
uint32 _cached_size_; // NOLINT
|
||||
KeyOnMemory key_; // NOLINT
|
||||
ValueOnMemory value_; // NOLINT
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__
|
835
include/google/protobuf/map_field.h
Normal file
835
include/google/protobuf/map_field.h
Normal file
@ -0,0 +1,835 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_MAP_FIELD_H__
|
||||
#define GOOGLE_PROTOBUF_MAP_FIELD_H__
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/map_entry.h>
|
||||
#include <google/protobuf/map_field_lite.h>
|
||||
#include <google/protobuf/map_type_handler.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/stubs/mutex.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/repeated_field.h>
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class DynamicMessage;
|
||||
class MapIterator;
|
||||
|
||||
#define TYPE_CHECK(EXPECTEDTYPE, METHOD) \
|
||||
if (type() != EXPECTEDTYPE) { \
|
||||
GOOGLE_LOG(FATAL) << "Protocol Buffer map usage error:\n" \
|
||||
<< METHOD << " type does not match\n" \
|
||||
<< " Expected : " \
|
||||
<< FieldDescriptor::CppTypeName(EXPECTEDTYPE) << "\n" \
|
||||
<< " Actual : " << FieldDescriptor::CppTypeName(type()); \
|
||||
}
|
||||
|
||||
// MapKey is an union type for representing any possible
|
||||
// map key.
|
||||
class PROTOBUF_EXPORT MapKey {
|
||||
public:
|
||||
MapKey() : type_(0) {}
|
||||
MapKey(const MapKey& other) : type_(0) { CopyFrom(other); }
|
||||
|
||||
MapKey& operator=(const MapKey& other) {
|
||||
CopyFrom(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~MapKey() {
|
||||
if (type_ == FieldDescriptor::CPPTYPE_STRING) {
|
||||
val_.string_value_.Destruct();
|
||||
}
|
||||
}
|
||||
|
||||
FieldDescriptor::CppType type() const {
|
||||
if (type_ == 0) {
|
||||
GOOGLE_LOG(FATAL) << "Protocol Buffer map usage error:\n"
|
||||
<< "MapKey::type MapKey is not initialized. "
|
||||
<< "Call set methods to initialize MapKey.";
|
||||
}
|
||||
return (FieldDescriptor::CppType)type_;
|
||||
}
|
||||
|
||||
void SetInt64Value(int64 value) {
|
||||
SetType(FieldDescriptor::CPPTYPE_INT64);
|
||||
val_.int64_value_ = value;
|
||||
}
|
||||
void SetUInt64Value(uint64 value) {
|
||||
SetType(FieldDescriptor::CPPTYPE_UINT64);
|
||||
val_.uint64_value_ = value;
|
||||
}
|
||||
void SetInt32Value(int32 value) {
|
||||
SetType(FieldDescriptor::CPPTYPE_INT32);
|
||||
val_.int32_value_ = value;
|
||||
}
|
||||
void SetUInt32Value(uint32 value) {
|
||||
SetType(FieldDescriptor::CPPTYPE_UINT32);
|
||||
val_.uint32_value_ = value;
|
||||
}
|
||||
void SetBoolValue(bool value) {
|
||||
SetType(FieldDescriptor::CPPTYPE_BOOL);
|
||||
val_.bool_value_ = value;
|
||||
}
|
||||
void SetStringValue(std::string val) {
|
||||
SetType(FieldDescriptor::CPPTYPE_STRING);
|
||||
*val_.string_value_.get_mutable() = std::move(val);
|
||||
}
|
||||
|
||||
int64 GetInt64Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, "MapKey::GetInt64Value");
|
||||
return val_.int64_value_;
|
||||
}
|
||||
uint64 GetUInt64Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, "MapKey::GetUInt64Value");
|
||||
return val_.uint64_value_;
|
||||
}
|
||||
int32 GetInt32Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, "MapKey::GetInt32Value");
|
||||
return val_.int32_value_;
|
||||
}
|
||||
uint32 GetUInt32Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, "MapKey::GetUInt32Value");
|
||||
return val_.uint32_value_;
|
||||
}
|
||||
bool GetBoolValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, "MapKey::GetBoolValue");
|
||||
return val_.bool_value_;
|
||||
}
|
||||
const std::string& GetStringValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, "MapKey::GetStringValue");
|
||||
return val_.string_value_.get();
|
||||
}
|
||||
|
||||
bool operator<(const MapKey& other) const {
|
||||
if (type_ != other.type_) {
|
||||
// We could define a total order that handles this case, but
|
||||
// there currently no need. So, for now, fail.
|
||||
GOOGLE_LOG(FATAL) << "Unsupported: type mismatch";
|
||||
}
|
||||
switch (type()) {
|
||||
case FieldDescriptor::CPPTYPE_DOUBLE:
|
||||
case FieldDescriptor::CPPTYPE_FLOAT:
|
||||
case FieldDescriptor::CPPTYPE_ENUM:
|
||||
case FieldDescriptor::CPPTYPE_MESSAGE:
|
||||
GOOGLE_LOG(FATAL) << "Unsupported";
|
||||
return false;
|
||||
case FieldDescriptor::CPPTYPE_STRING:
|
||||
return val_.string_value_.get() < other.val_.string_value_.get();
|
||||
case FieldDescriptor::CPPTYPE_INT64:
|
||||
return val_.int64_value_ < other.val_.int64_value_;
|
||||
case FieldDescriptor::CPPTYPE_INT32:
|
||||
return val_.int32_value_ < other.val_.int32_value_;
|
||||
case FieldDescriptor::CPPTYPE_UINT64:
|
||||
return val_.uint64_value_ < other.val_.uint64_value_;
|
||||
case FieldDescriptor::CPPTYPE_UINT32:
|
||||
return val_.uint32_value_ < other.val_.uint32_value_;
|
||||
case FieldDescriptor::CPPTYPE_BOOL:
|
||||
return val_.bool_value_ < other.val_.bool_value_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const MapKey& other) const {
|
||||
if (type_ != other.type_) {
|
||||
// To be consistent with operator<, we don't allow this either.
|
||||
GOOGLE_LOG(FATAL) << "Unsupported: type mismatch";
|
||||
}
|
||||
switch (type()) {
|
||||
case FieldDescriptor::CPPTYPE_DOUBLE:
|
||||
case FieldDescriptor::CPPTYPE_FLOAT:
|
||||
case FieldDescriptor::CPPTYPE_ENUM:
|
||||
case FieldDescriptor::CPPTYPE_MESSAGE:
|
||||
GOOGLE_LOG(FATAL) << "Unsupported";
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_STRING:
|
||||
return val_.string_value_.get() == other.val_.string_value_.get();
|
||||
case FieldDescriptor::CPPTYPE_INT64:
|
||||
return val_.int64_value_ == other.val_.int64_value_;
|
||||
case FieldDescriptor::CPPTYPE_INT32:
|
||||
return val_.int32_value_ == other.val_.int32_value_;
|
||||
case FieldDescriptor::CPPTYPE_UINT64:
|
||||
return val_.uint64_value_ == other.val_.uint64_value_;
|
||||
case FieldDescriptor::CPPTYPE_UINT32:
|
||||
return val_.uint32_value_ == other.val_.uint32_value_;
|
||||
case FieldDescriptor::CPPTYPE_BOOL:
|
||||
return val_.bool_value_ == other.val_.bool_value_;
|
||||
}
|
||||
GOOGLE_LOG(FATAL) << "Can't get here.";
|
||||
return false;
|
||||
}
|
||||
|
||||
void CopyFrom(const MapKey& other) {
|
||||
SetType(other.type());
|
||||
switch (type_) {
|
||||
case FieldDescriptor::CPPTYPE_DOUBLE:
|
||||
case FieldDescriptor::CPPTYPE_FLOAT:
|
||||
case FieldDescriptor::CPPTYPE_ENUM:
|
||||
case FieldDescriptor::CPPTYPE_MESSAGE:
|
||||
GOOGLE_LOG(FATAL) << "Unsupported";
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_STRING:
|
||||
*val_.string_value_.get_mutable() = other.val_.string_value_.get();
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_INT64:
|
||||
val_.int64_value_ = other.val_.int64_value_;
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_INT32:
|
||||
val_.int32_value_ = other.val_.int32_value_;
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_UINT64:
|
||||
val_.uint64_value_ = other.val_.uint64_value_;
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_UINT32:
|
||||
val_.uint32_value_ = other.val_.uint32_value_;
|
||||
break;
|
||||
case FieldDescriptor::CPPTYPE_BOOL:
|
||||
val_.bool_value_ = other.val_.bool_value_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename K, typename V>
|
||||
friend class internal::TypeDefinedMapFieldBase;
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::MapIterator;
|
||||
friend class internal::DynamicMapField;
|
||||
|
||||
union KeyValue {
|
||||
KeyValue() {}
|
||||
internal::ExplicitlyConstructed<std::string> string_value_;
|
||||
int64 int64_value_;
|
||||
int32 int32_value_;
|
||||
uint64 uint64_value_;
|
||||
uint32 uint32_value_;
|
||||
bool bool_value_;
|
||||
} val_;
|
||||
|
||||
void SetType(FieldDescriptor::CppType type) {
|
||||
if (type_ == type) return;
|
||||
if (type_ == FieldDescriptor::CPPTYPE_STRING) {
|
||||
val_.string_value_.Destruct();
|
||||
}
|
||||
type_ = type;
|
||||
if (type_ == FieldDescriptor::CPPTYPE_STRING) {
|
||||
val_.string_value_.DefaultConstruct();
|
||||
}
|
||||
}
|
||||
|
||||
// type_ is 0 or a valid FieldDescriptor::CppType.
|
||||
int type_;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
class ContendedMapCleanTest;
|
||||
class GeneratedMessageReflection;
|
||||
class MapFieldAccessor;
|
||||
|
||||
// This class provides access to map field using reflection, which is the same
|
||||
// as those provided for RepeatedPtrField<Message>. It is used for internal
|
||||
// reflection implentation only. Users should never use this directly.
|
||||
class PROTOBUF_EXPORT MapFieldBase {
|
||||
public:
|
||||
MapFieldBase()
|
||||
: arena_(NULL), repeated_field_(NULL), state_(STATE_MODIFIED_MAP) {}
|
||||
explicit MapFieldBase(Arena* arena)
|
||||
: arena_(arena), repeated_field_(NULL), state_(STATE_MODIFIED_MAP) {
|
||||
// Mutex's destructor needs to be called explicitly to release resources
|
||||
// acquired in its constructor.
|
||||
if (arena) {
|
||||
arena->OwnDestructor(&mutex_);
|
||||
}
|
||||
}
|
||||
virtual ~MapFieldBase();
|
||||
|
||||
// Returns reference to internal repeated field. Data written using
|
||||
// Map's api prior to calling this function is guarantted to be
|
||||
// included in repeated field.
|
||||
const RepeatedPtrFieldBase& GetRepeatedField() const;
|
||||
|
||||
// Like above. Returns mutable pointer to the internal repeated field.
|
||||
RepeatedPtrFieldBase* MutableRepeatedField();
|
||||
|
||||
// Pure virtual map APIs for Map Reflection.
|
||||
virtual bool ContainsMapKey(const MapKey& map_key) const = 0;
|
||||
virtual bool InsertOrLookupMapValue(const MapKey& map_key,
|
||||
MapValueRef* val) = 0;
|
||||
// Returns whether changes to the map are reflected in the repeated field.
|
||||
bool IsRepeatedFieldValid() const;
|
||||
// Insures operations after won't get executed before calling this.
|
||||
bool IsMapValid() const;
|
||||
virtual bool DeleteMapValue(const MapKey& map_key) = 0;
|
||||
virtual bool EqualIterator(const MapIterator& a,
|
||||
const MapIterator& b) const = 0;
|
||||
virtual void MapBegin(MapIterator* map_iter) const = 0;
|
||||
virtual void MapEnd(MapIterator* map_iter) const = 0;
|
||||
virtual void MergeFrom(const MapFieldBase& other) = 0;
|
||||
virtual void Swap(MapFieldBase* other) = 0;
|
||||
// Sync Map with repeated field and returns the size of map.
|
||||
virtual int size() const = 0;
|
||||
virtual void Clear() = 0;
|
||||
|
||||
// Returns the number of bytes used by the repeated field, excluding
|
||||
// sizeof(*this)
|
||||
size_t SpaceUsedExcludingSelfLong() const;
|
||||
|
||||
int SpaceUsedExcludingSelf() const {
|
||||
return internal::ToIntSize(SpaceUsedExcludingSelfLong());
|
||||
}
|
||||
|
||||
protected:
|
||||
// Gets the size of space used by map field.
|
||||
virtual size_t SpaceUsedExcludingSelfNoLock() const;
|
||||
|
||||
// Synchronizes the content in Map to RepeatedPtrField if there is any change
|
||||
// to Map after last synchronization.
|
||||
void SyncRepeatedFieldWithMap() const;
|
||||
virtual void SyncRepeatedFieldWithMapNoLock() const;
|
||||
|
||||
// Synchronizes the content in RepeatedPtrField to Map if there is any change
|
||||
// to RepeatedPtrField after last synchronization.
|
||||
void SyncMapWithRepeatedField() const;
|
||||
virtual void SyncMapWithRepeatedFieldNoLock() const {}
|
||||
|
||||
// Tells MapFieldBase that there is new change to Map.
|
||||
void SetMapDirty();
|
||||
|
||||
// Tells MapFieldBase that there is new change to RepeatedPTrField.
|
||||
void SetRepeatedDirty();
|
||||
|
||||
// Provides derived class the access to repeated field.
|
||||
void* MutableRepeatedPtrField() const;
|
||||
|
||||
enum State {
|
||||
STATE_MODIFIED_MAP = 0, // map has newly added data that has not been
|
||||
// synchronized to repeated field
|
||||
STATE_MODIFIED_REPEATED = 1, // repeated field has newly added data that
|
||||
// has not been synchronized to map
|
||||
CLEAN = 2, // data in map and repeated field are same
|
||||
};
|
||||
|
||||
Arena* arena_;
|
||||
mutable RepeatedPtrField<Message>* repeated_field_;
|
||||
|
||||
mutable internal::WrappedMutex
|
||||
mutex_; // The thread to synchronize map and repeated field
|
||||
// needs to get lock first;
|
||||
mutable std::atomic<State> state_;
|
||||
|
||||
private:
|
||||
friend class ContendedMapCleanTest;
|
||||
friend class GeneratedMessageReflection;
|
||||
friend class MapFieldAccessor;
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::DynamicMessage;
|
||||
|
||||
// Virtual helper methods for MapIterator. MapIterator doesn't have the
|
||||
// type helper for key and value. Call these help methods to deal with
|
||||
// different types. Real helper methods are implemented in
|
||||
// TypeDefinedMapFieldBase.
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::MapIterator;
|
||||
// Allocate map<...>::iterator for MapIterator.
|
||||
virtual void InitializeIterator(MapIterator* map_iter) const = 0;
|
||||
|
||||
// DeleteIterator() is called by the destructor of MapIterator only.
|
||||
// It deletes map<...>::iterator for MapIterator.
|
||||
virtual void DeleteIterator(MapIterator* map_iter) const = 0;
|
||||
|
||||
// Copy the map<...>::iterator from other_iterator to
|
||||
// this_iterator.
|
||||
virtual void CopyIterator(MapIterator* this_iterator,
|
||||
const MapIterator& other_iterator) const = 0;
|
||||
|
||||
// IncreaseIterator() is called by operator++() of MapIterator only.
|
||||
// It implements the ++ operator of MapIterator.
|
||||
virtual void IncreaseIterator(MapIterator* map_iter) const = 0;
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldBase);
|
||||
};
|
||||
|
||||
// This class provides common Map Reflection implementations for generated
|
||||
// message and dynamic message.
|
||||
template <typename Key, typename T>
|
||||
class TypeDefinedMapFieldBase : public MapFieldBase {
|
||||
public:
|
||||
TypeDefinedMapFieldBase() {}
|
||||
explicit TypeDefinedMapFieldBase(Arena* arena) : MapFieldBase(arena) {}
|
||||
~TypeDefinedMapFieldBase() override {}
|
||||
void MapBegin(MapIterator* map_iter) const override;
|
||||
void MapEnd(MapIterator* map_iter) const override;
|
||||
bool EqualIterator(const MapIterator& a, const MapIterator& b) const override;
|
||||
|
||||
virtual const Map<Key, T>& GetMap() const = 0;
|
||||
virtual Map<Key, T>* MutableMap() = 0;
|
||||
|
||||
protected:
|
||||
typename Map<Key, T>::const_iterator& InternalGetIterator(
|
||||
const MapIterator* map_iter) const;
|
||||
|
||||
private:
|
||||
void InitializeIterator(MapIterator* map_iter) const override;
|
||||
void DeleteIterator(MapIterator* map_iter) const override;
|
||||
void CopyIterator(MapIterator* this_iteratorm,
|
||||
const MapIterator& that_iterator) const override;
|
||||
void IncreaseIterator(MapIterator* map_iter) const override;
|
||||
|
||||
virtual void SetMapIteratorValue(MapIterator* map_iter) const = 0;
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeDefinedMapFieldBase);
|
||||
};
|
||||
|
||||
// This class provides access to map field using generated api. It is used for
|
||||
// internal generated message implentation only. Users should never use this
|
||||
// directly.
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value = 0>
|
||||
class MapField : public TypeDefinedMapFieldBase<Key, T> {
|
||||
// Provide utilities to parse/serialize key/value. Provide utilities to
|
||||
// manipulate internal stored type.
|
||||
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;
|
||||
typedef MapTypeHandler<kValueFieldType, T> ValueTypeHandler;
|
||||
|
||||
// Define message type for internal repeated field.
|
||||
typedef Derived EntryType;
|
||||
|
||||
// Define abbreviation for parent MapFieldLite
|
||||
typedef MapFieldLite<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>
|
||||
MapFieldLiteType;
|
||||
|
||||
// Enum needs to be handled differently from other types because it has
|
||||
// different exposed type in Map's api and repeated field's api. For
|
||||
// details see the comment in the implementation of
|
||||
// SyncMapWithRepeatedFieldNoLock.
|
||||
static constexpr bool kIsValueEnum = ValueTypeHandler::kIsEnum;
|
||||
typedef typename MapIf<kIsValueEnum, T, const T&>::type CastValueType;
|
||||
|
||||
public:
|
||||
typedef typename Derived::SuperType EntryTypeTrait;
|
||||
typedef Map<Key, T> MapType;
|
||||
|
||||
MapField() {}
|
||||
explicit MapField(Arena* arena)
|
||||
: TypeDefinedMapFieldBase<Key, T>(arena), impl_(arena) {}
|
||||
|
||||
// Implement MapFieldBase
|
||||
bool ContainsMapKey(const MapKey& map_key) const override;
|
||||
bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val) override;
|
||||
bool DeleteMapValue(const MapKey& map_key) override;
|
||||
|
||||
const Map<Key, T>& GetMap() const override {
|
||||
MapFieldBase::SyncMapWithRepeatedField();
|
||||
return impl_.GetMap();
|
||||
}
|
||||
|
||||
Map<Key, T>* MutableMap() override {
|
||||
MapFieldBase::SyncMapWithRepeatedField();
|
||||
Map<Key, T>* result = impl_.MutableMap();
|
||||
MapFieldBase::SetMapDirty();
|
||||
return result;
|
||||
}
|
||||
|
||||
int size() const override;
|
||||
void Clear() override;
|
||||
void MergeFrom(const MapFieldBase& other) override;
|
||||
void Swap(MapFieldBase* other) override;
|
||||
|
||||
// Used in the implementation of parsing. Caller should take the ownership iff
|
||||
// arena_ is NULL.
|
||||
EntryType* NewEntry() const { return impl_.NewEntry(); }
|
||||
// Used in the implementation of serializing enum value type. Caller should
|
||||
// take the ownership iff arena_ is NULL.
|
||||
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const {
|
||||
return impl_.NewEnumEntryWrapper(key, t);
|
||||
}
|
||||
// Used in the implementation of serializing other value types. Caller should
|
||||
// take the ownership iff arena_ is NULL.
|
||||
EntryType* NewEntryWrapper(const Key& key, const T& t) const {
|
||||
return impl_.NewEntryWrapper(key, t);
|
||||
}
|
||||
|
||||
const char* _InternalParse(const char* ptr, ParseContext* ctx) {
|
||||
return impl_._InternalParse(ptr, ctx);
|
||||
}
|
||||
template <typename UnknownType>
|
||||
const char* ParseWithEnumValidation(const char* ptr, ParseContext* ctx,
|
||||
bool (*is_valid)(int), uint32 field_num,
|
||||
InternalMetadata* metadata) {
|
||||
return impl_.template ParseWithEnumValidation<UnknownType>(
|
||||
ptr, ctx, is_valid, field_num, metadata);
|
||||
}
|
||||
|
||||
private:
|
||||
MapFieldLiteType impl_;
|
||||
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
|
||||
// Implements MapFieldBase
|
||||
void SyncRepeatedFieldWithMapNoLock() const override;
|
||||
void SyncMapWithRepeatedFieldNoLock() const override;
|
||||
size_t SpaceUsedExcludingSelfNoLock() const override;
|
||||
|
||||
void SetMapIteratorValue(MapIterator* map_iter) const override;
|
||||
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::Arena;
|
||||
friend class MapFieldStateTest; // For testing, it needs raw access to impl_
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapField);
|
||||
};
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType key_wire_type,
|
||||
WireFormatLite::FieldType value_wire_type, int default_enum_value>
|
||||
bool AllAreInitialized(
|
||||
const MapField<Derived, Key, T, key_wire_type, value_wire_type,
|
||||
default_enum_value>& field) {
|
||||
const auto& t = field.GetMap();
|
||||
for (typename Map<Key, T>::const_iterator it = t.begin(); it != t.end();
|
||||
++it) {
|
||||
if (!it->second.IsInitialized()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
struct MapEntryToMapField<MapEntry<T, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value>> {
|
||||
typedef MapField<T, Key, Value, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>
|
||||
MapFieldType;
|
||||
};
|
||||
|
||||
class PROTOBUF_EXPORT DynamicMapField
|
||||
: public TypeDefinedMapFieldBase<MapKey, MapValueRef> {
|
||||
public:
|
||||
explicit DynamicMapField(const Message* default_entry);
|
||||
DynamicMapField(const Message* default_entry, Arena* arena);
|
||||
~DynamicMapField() override;
|
||||
|
||||
// Implement MapFieldBase
|
||||
bool ContainsMapKey(const MapKey& map_key) const override;
|
||||
bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val) override;
|
||||
bool DeleteMapValue(const MapKey& map_key) override;
|
||||
void MergeFrom(const MapFieldBase& other) override;
|
||||
void Swap(MapFieldBase* other) override;
|
||||
|
||||
const Map<MapKey, MapValueRef>& GetMap() const override;
|
||||
Map<MapKey, MapValueRef>* MutableMap() override;
|
||||
|
||||
int size() const override;
|
||||
void Clear() override;
|
||||
|
||||
private:
|
||||
Map<MapKey, MapValueRef> map_;
|
||||
const Message* default_entry_;
|
||||
|
||||
void AllocateMapValue(MapValueRef* map_val);
|
||||
|
||||
// Implements MapFieldBase
|
||||
void SyncRepeatedFieldWithMapNoLock() const override;
|
||||
void SyncMapWithRepeatedFieldNoLock() const override;
|
||||
size_t SpaceUsedExcludingSelfNoLock() const override;
|
||||
void SetMapIteratorValue(MapIterator* map_iter) const override;
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMapField);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// MapValueRef points to a map value.
|
||||
class PROTOBUF_EXPORT MapValueRef {
|
||||
public:
|
||||
MapValueRef() : data_(NULL), type_(0) {}
|
||||
|
||||
void SetInt64Value(int64 value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, "MapValueRef::SetInt64Value");
|
||||
*reinterpret_cast<int64*>(data_) = value;
|
||||
}
|
||||
void SetUInt64Value(uint64 value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, "MapValueRef::SetUInt64Value");
|
||||
*reinterpret_cast<uint64*>(data_) = value;
|
||||
}
|
||||
void SetInt32Value(int32 value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, "MapValueRef::SetInt32Value");
|
||||
*reinterpret_cast<int32*>(data_) = value;
|
||||
}
|
||||
void SetUInt32Value(uint32 value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, "MapValueRef::SetUInt32Value");
|
||||
*reinterpret_cast<uint32*>(data_) = value;
|
||||
}
|
||||
void SetBoolValue(bool value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, "MapValueRef::SetBoolValue");
|
||||
*reinterpret_cast<bool*>(data_) = value;
|
||||
}
|
||||
// TODO(jieluo) - Checks that enum is member.
|
||||
void SetEnumValue(int value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, "MapValueRef::SetEnumValue");
|
||||
*reinterpret_cast<int*>(data_) = value;
|
||||
}
|
||||
void SetStringValue(const std::string& value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, "MapValueRef::SetStringValue");
|
||||
*reinterpret_cast<std::string*>(data_) = value;
|
||||
}
|
||||
void SetFloatValue(float value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, "MapValueRef::SetFloatValue");
|
||||
*reinterpret_cast<float*>(data_) = value;
|
||||
}
|
||||
void SetDoubleValue(double value) {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, "MapValueRef::SetDoubleValue");
|
||||
*reinterpret_cast<double*>(data_) = value;
|
||||
}
|
||||
|
||||
int64 GetInt64Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, "MapValueRef::GetInt64Value");
|
||||
return *reinterpret_cast<int64*>(data_);
|
||||
}
|
||||
uint64 GetUInt64Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, "MapValueRef::GetUInt64Value");
|
||||
return *reinterpret_cast<uint64*>(data_);
|
||||
}
|
||||
int32 GetInt32Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, "MapValueRef::GetInt32Value");
|
||||
return *reinterpret_cast<int32*>(data_);
|
||||
}
|
||||
uint32 GetUInt32Value() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, "MapValueRef::GetUInt32Value");
|
||||
return *reinterpret_cast<uint32*>(data_);
|
||||
}
|
||||
bool GetBoolValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, "MapValueRef::GetBoolValue");
|
||||
return *reinterpret_cast<bool*>(data_);
|
||||
}
|
||||
int GetEnumValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, "MapValueRef::GetEnumValue");
|
||||
return *reinterpret_cast<int*>(data_);
|
||||
}
|
||||
const std::string& GetStringValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, "MapValueRef::GetStringValue");
|
||||
return *reinterpret_cast<std::string*>(data_);
|
||||
}
|
||||
float GetFloatValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, "MapValueRef::GetFloatValue");
|
||||
return *reinterpret_cast<float*>(data_);
|
||||
}
|
||||
double GetDoubleValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, "MapValueRef::GetDoubleValue");
|
||||
return *reinterpret_cast<double*>(data_);
|
||||
}
|
||||
|
||||
const Message& GetMessageValue() const {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE,
|
||||
"MapValueRef::GetMessageValue");
|
||||
return *reinterpret_cast<Message*>(data_);
|
||||
}
|
||||
|
||||
Message* MutableMessageValue() {
|
||||
TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE,
|
||||
"MapValueRef::MutableMessageValue");
|
||||
return reinterpret_cast<Message*>(data_);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Derived, typename K, typename V,
|
||||
internal::WireFormatLite::FieldType key_wire_type,
|
||||
internal::WireFormatLite::FieldType value_wire_type,
|
||||
int default_enum_value>
|
||||
friend class internal::MapField;
|
||||
template <typename K, typename V>
|
||||
friend class internal::TypeDefinedMapFieldBase;
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::MapIterator;
|
||||
friend class Reflection;
|
||||
friend class internal::DynamicMapField;
|
||||
|
||||
void SetType(FieldDescriptor::CppType type) { type_ = type; }
|
||||
|
||||
FieldDescriptor::CppType type() const {
|
||||
if (type_ == 0 || data_ == NULL) {
|
||||
GOOGLE_LOG(FATAL) << "Protocol Buffer map usage error:\n"
|
||||
<< "MapValueRef::type MapValueRef is not initialized.";
|
||||
}
|
||||
return (FieldDescriptor::CppType)type_;
|
||||
}
|
||||
void SetValue(const void* val) { data_ = const_cast<void*>(val); }
|
||||
void CopyFrom(const MapValueRef& other) {
|
||||
type_ = other.type_;
|
||||
data_ = other.data_;
|
||||
}
|
||||
// Only used in DynamicMapField
|
||||
void DeleteData() {
|
||||
switch (type_) {
|
||||
#define HANDLE_TYPE(CPPTYPE, TYPE) \
|
||||
case FieldDescriptor::CPPTYPE_##CPPTYPE: { \
|
||||
delete reinterpret_cast<TYPE*>(data_); \
|
||||
break; \
|
||||
}
|
||||
HANDLE_TYPE(INT32, int32);
|
||||
HANDLE_TYPE(INT64, int64);
|
||||
HANDLE_TYPE(UINT32, uint32);
|
||||
HANDLE_TYPE(UINT64, uint64);
|
||||
HANDLE_TYPE(DOUBLE, double);
|
||||
HANDLE_TYPE(FLOAT, float);
|
||||
HANDLE_TYPE(BOOL, bool);
|
||||
HANDLE_TYPE(STRING, std::string);
|
||||
HANDLE_TYPE(ENUM, int32);
|
||||
HANDLE_TYPE(MESSAGE, Message);
|
||||
#undef HANDLE_TYPE
|
||||
}
|
||||
}
|
||||
// data_ point to a map value. MapValueRef does not
|
||||
// own this value.
|
||||
void* data_;
|
||||
// type_ is 0 or a valid FieldDescriptor::CppType.
|
||||
int type_;
|
||||
};
|
||||
|
||||
#undef TYPE_CHECK
|
||||
|
||||
class PROTOBUF_EXPORT MapIterator {
|
||||
public:
|
||||
MapIterator(Message* message, const FieldDescriptor* field) {
|
||||
const Reflection* reflection = message->GetReflection();
|
||||
map_ = reflection->MutableMapData(message, field);
|
||||
key_.SetType(field->message_type()->FindFieldByName("key")->cpp_type());
|
||||
value_.SetType(field->message_type()->FindFieldByName("value")->cpp_type());
|
||||
map_->InitializeIterator(this);
|
||||
}
|
||||
MapIterator(const MapIterator& other) {
|
||||
map_ = other.map_;
|
||||
map_->InitializeIterator(this);
|
||||
map_->CopyIterator(this, other);
|
||||
}
|
||||
~MapIterator() { map_->DeleteIterator(this); }
|
||||
MapIterator& operator=(const MapIterator& other) {
|
||||
map_ = other.map_;
|
||||
map_->CopyIterator(this, other);
|
||||
return *this;
|
||||
}
|
||||
friend bool operator==(const MapIterator& a, const MapIterator& b) {
|
||||
return a.map_->EqualIterator(a, b);
|
||||
}
|
||||
friend bool operator!=(const MapIterator& a, const MapIterator& b) {
|
||||
return !a.map_->EqualIterator(a, b);
|
||||
}
|
||||
MapIterator& operator++() {
|
||||
map_->IncreaseIterator(this);
|
||||
return *this;
|
||||
}
|
||||
MapIterator operator++(int) {
|
||||
// iter_ is copied from Map<...>::iterator, no need to
|
||||
// copy from its self again. Use the same implementation
|
||||
// with operator++()
|
||||
map_->IncreaseIterator(this);
|
||||
return *this;
|
||||
}
|
||||
const MapKey& GetKey() { return key_; }
|
||||
const MapValueRef& GetValueRef() { return value_; }
|
||||
MapValueRef* MutableValueRef() {
|
||||
map_->SetMapDirty();
|
||||
return &value_;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Key, typename T>
|
||||
friend class internal::TypeDefinedMapFieldBase;
|
||||
friend class internal::DynamicMapField;
|
||||
template <typename Derived, typename Key, typename T,
|
||||
internal::WireFormatLite::FieldType kKeyFieldType,
|
||||
internal::WireFormatLite::FieldType kValueFieldType,
|
||||
int default_enum_value>
|
||||
friend class internal::MapField;
|
||||
|
||||
// reinterpret_cast from heap-allocated Map<...>::iterator*. MapIterator owns
|
||||
// the iterator. It is allocated by MapField<...>::InitializeIterator() called
|
||||
// in constructor and deleted by MapField<...>::DeleteIterator() called in
|
||||
// destructor.
|
||||
void* iter_;
|
||||
// Point to a MapField to call helper methods implemented in MapField.
|
||||
// MapIterator does not own this object.
|
||||
internal::MapFieldBase* map_;
|
||||
MapKey key_;
|
||||
MapValueRef value_;
|
||||
};
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START
|
||||
template <>
|
||||
struct hash<::PROTOBUF_NAMESPACE_ID::MapKey> {
|
||||
size_t operator()(const ::PROTOBUF_NAMESPACE_ID::MapKey& map_key) const {
|
||||
switch (map_key.type()) {
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_DOUBLE:
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_FLOAT:
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_ENUM:
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_MESSAGE:
|
||||
GOOGLE_LOG(FATAL) << "Unsupported";
|
||||
break;
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_STRING:
|
||||
return hash<std::string>()(map_key.GetStringValue());
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_INT64:
|
||||
return hash<int64>()(map_key.GetInt64Value());
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_INT32:
|
||||
return hash<int32>()(map_key.GetInt32Value());
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_UINT64:
|
||||
return hash<uint64>()(map_key.GetUInt64Value());
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_UINT32:
|
||||
return hash<uint32>()(map_key.GetUInt32Value());
|
||||
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_BOOL:
|
||||
return hash<bool>()(map_key.GetBoolValue());
|
||||
}
|
||||
GOOGLE_LOG(FATAL) << "Can't get here.";
|
||||
return 0;
|
||||
}
|
||||
bool operator()(const ::PROTOBUF_NAMESPACE_ID::MapKey& map_key1,
|
||||
const ::PROTOBUF_NAMESPACE_ID::MapKey& map_key2) const {
|
||||
return map_key1 < map_key2;
|
||||
}
|
||||
};
|
||||
GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_MAP_FIELD_H__
|
357
include/google/protobuf/map_field_inl.h
Normal file
357
include/google/protobuf/map_field_inl.h
Normal file
@ -0,0 +1,357 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
|
||||
#define GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <google/protobuf/stubs/casts.h>
|
||||
#include <google/protobuf/map.h>
|
||||
#include <google/protobuf/map_field.h>
|
||||
#include <google/protobuf/map_type_handler.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
// UnwrapMapKey template
|
||||
template <typename T>
|
||||
T UnwrapMapKey(const MapKey& map_key);
|
||||
template <>
|
||||
inline int32 UnwrapMapKey<int32>(const MapKey& map_key) {
|
||||
return map_key.GetInt32Value();
|
||||
}
|
||||
template <>
|
||||
inline uint32 UnwrapMapKey<uint32>(const MapKey& map_key) {
|
||||
return map_key.GetUInt32Value();
|
||||
}
|
||||
template <>
|
||||
inline int64 UnwrapMapKey<int64>(const MapKey& map_key) {
|
||||
return map_key.GetInt64Value();
|
||||
}
|
||||
template <>
|
||||
inline uint64 UnwrapMapKey<uint64>(const MapKey& map_key) {
|
||||
return map_key.GetUInt64Value();
|
||||
}
|
||||
template <>
|
||||
inline bool UnwrapMapKey<bool>(const MapKey& map_key) {
|
||||
return map_key.GetBoolValue();
|
||||
}
|
||||
template <>
|
||||
inline std::string UnwrapMapKey<std::string>(const MapKey& map_key) {
|
||||
return map_key.GetStringValue();
|
||||
}
|
||||
|
||||
// SetMapKey template
|
||||
template <typename T>
|
||||
inline void SetMapKey(MapKey* map_key, const T& value);
|
||||
template <>
|
||||
inline void SetMapKey<int32>(MapKey* map_key, const int32& value) {
|
||||
map_key->SetInt32Value(value);
|
||||
}
|
||||
template <>
|
||||
inline void SetMapKey<uint32>(MapKey* map_key, const uint32& value) {
|
||||
map_key->SetUInt32Value(value);
|
||||
}
|
||||
template <>
|
||||
inline void SetMapKey<int64>(MapKey* map_key, const int64& value) {
|
||||
map_key->SetInt64Value(value);
|
||||
}
|
||||
template <>
|
||||
inline void SetMapKey<uint64>(MapKey* map_key, const uint64& value) {
|
||||
map_key->SetUInt64Value(value);
|
||||
}
|
||||
template <>
|
||||
inline void SetMapKey<bool>(MapKey* map_key, const bool& value) {
|
||||
map_key->SetBoolValue(value);
|
||||
}
|
||||
template <>
|
||||
inline void SetMapKey<std::string>(MapKey* map_key, const std::string& value) {
|
||||
map_key->SetStringValue(value);
|
||||
}
|
||||
|
||||
// ------------------------TypeDefinedMapFieldBase---------------
|
||||
template <typename Key, typename T>
|
||||
typename Map<Key, T>::const_iterator&
|
||||
TypeDefinedMapFieldBase<Key, T>::InternalGetIterator(
|
||||
const MapIterator* map_iter) const {
|
||||
return *reinterpret_cast<typename Map<Key, T>::const_iterator*>(
|
||||
map_iter->iter_);
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
void TypeDefinedMapFieldBase<Key, T>::MapBegin(MapIterator* map_iter) const {
|
||||
InternalGetIterator(map_iter) = GetMap().begin();
|
||||
SetMapIteratorValue(map_iter);
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
void TypeDefinedMapFieldBase<Key, T>::MapEnd(MapIterator* map_iter) const {
|
||||
InternalGetIterator(map_iter) = GetMap().end();
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
bool TypeDefinedMapFieldBase<Key, T>::EqualIterator(
|
||||
const MapIterator& a, const MapIterator& b) const {
|
||||
return InternalGetIterator(&a) == InternalGetIterator(&b);
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
void TypeDefinedMapFieldBase<Key, T>::IncreaseIterator(
|
||||
MapIterator* map_iter) const {
|
||||
++InternalGetIterator(map_iter);
|
||||
SetMapIteratorValue(map_iter);
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
void TypeDefinedMapFieldBase<Key, T>::InitializeIterator(
|
||||
MapIterator* map_iter) const {
|
||||
map_iter->iter_ = new typename Map<Key, T>::const_iterator;
|
||||
GOOGLE_CHECK(map_iter->iter_ != NULL);
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
void TypeDefinedMapFieldBase<Key, T>::DeleteIterator(
|
||||
MapIterator* map_iter) const {
|
||||
delete reinterpret_cast<typename Map<Key, T>::const_iterator*>(
|
||||
map_iter->iter_);
|
||||
}
|
||||
|
||||
template <typename Key, typename T>
|
||||
void TypeDefinedMapFieldBase<Key, T>::CopyIterator(
|
||||
MapIterator* this_iter, const MapIterator& that_iter) const {
|
||||
InternalGetIterator(this_iter) = InternalGetIterator(&that_iter);
|
||||
this_iter->key_.SetType(that_iter.key_.type());
|
||||
// MapValueRef::type() fails when containing data is null. However, if
|
||||
// this_iter points to MapEnd, data can be null.
|
||||
this_iter->value_.SetType(
|
||||
static_cast<FieldDescriptor::CppType>(that_iter.value_.type_));
|
||||
SetMapIteratorValue(this_iter);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
int MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::size() const {
|
||||
MapFieldBase::SyncMapWithRepeatedField();
|
||||
return static_cast<int>(impl_.GetMap().size());
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::Clear() {
|
||||
if (this->MapFieldBase::repeated_field_ != nullptr) {
|
||||
RepeatedPtrField<EntryType>* repeated_field =
|
||||
reinterpret_cast<RepeatedPtrField<EntryType>*>(
|
||||
this->MapFieldBase::repeated_field_);
|
||||
repeated_field->Clear();
|
||||
}
|
||||
|
||||
impl_.MutableMap()->clear();
|
||||
// Data in map and repeated field are both empty, but we can't set status
|
||||
// CLEAN. Because clear is a generated API, we cannot invalidate previous
|
||||
// reference to map.
|
||||
MapFieldBase::SetMapDirty();
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::SetMapIteratorValue(MapIterator* map_iter)
|
||||
const {
|
||||
const Map<Key, T>& map = impl_.GetMap();
|
||||
typename Map<Key, T>::const_iterator iter =
|
||||
TypeDefinedMapFieldBase<Key, T>::InternalGetIterator(map_iter);
|
||||
if (iter == map.end()) return;
|
||||
SetMapKey(&map_iter->key_, iter->first);
|
||||
map_iter->value_.SetValue(&iter->second);
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
bool MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::ContainsMapKey(const MapKey& map_key) const {
|
||||
const Map<Key, T>& map = impl_.GetMap();
|
||||
const Key& key = UnwrapMapKey<Key>(map_key);
|
||||
typename Map<Key, T>::const_iterator iter = map.find(key);
|
||||
return iter != map.end();
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
bool MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::InsertOrLookupMapValue(const MapKey& map_key,
|
||||
MapValueRef* val) {
|
||||
// Always use mutable map because users may change the map value by
|
||||
// MapValueRef.
|
||||
Map<Key, T>* map = MutableMap();
|
||||
const Key& key = UnwrapMapKey<Key>(map_key);
|
||||
typename Map<Key, T>::iterator iter = map->find(key);
|
||||
if (map->end() == iter) {
|
||||
val->SetValue(&((*map)[key]));
|
||||
return true;
|
||||
}
|
||||
// Key is already in the map. Make sure (*map)[key] is not called.
|
||||
// [] may reorder the map and iterators.
|
||||
val->SetValue(&(iter->second));
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
bool MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::DeleteMapValue(const MapKey& map_key) {
|
||||
const Key& key = UnwrapMapKey<Key>(map_key);
|
||||
return MutableMap()->erase(key);
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::MergeFrom(const MapFieldBase& other) {
|
||||
MapFieldBase::SyncMapWithRepeatedField();
|
||||
const MapField& other_field = static_cast<const MapField&>(other);
|
||||
other_field.SyncMapWithRepeatedField();
|
||||
impl_.MergeFrom(other_field.impl_);
|
||||
MapFieldBase::SetMapDirty();
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::Swap(MapFieldBase* other) {
|
||||
MapField* other_field = down_cast<MapField*>(other);
|
||||
std::swap(this->MapFieldBase::repeated_field_, other_field->repeated_field_);
|
||||
impl_.Swap(&other_field->impl_);
|
||||
// a relaxed swap of the atomic
|
||||
auto other_state = other_field->state_.load(std::memory_order_relaxed);
|
||||
auto this_state = this->MapFieldBase::state_.load(std::memory_order_relaxed);
|
||||
other_field->state_.store(this_state, std::memory_order_relaxed);
|
||||
this->MapFieldBase::state_.store(other_state, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::SyncRepeatedFieldWithMapNoLock() const {
|
||||
if (this->MapFieldBase::repeated_field_ == NULL) {
|
||||
if (this->MapFieldBase::arena_ == NULL) {
|
||||
this->MapFieldBase::repeated_field_ = new RepeatedPtrField<Message>();
|
||||
} else {
|
||||
this->MapFieldBase::repeated_field_ =
|
||||
Arena::CreateMessage<RepeatedPtrField<Message> >(
|
||||
this->MapFieldBase::arena_);
|
||||
}
|
||||
}
|
||||
const Map<Key, T>& map = impl_.GetMap();
|
||||
RepeatedPtrField<EntryType>* repeated_field =
|
||||
reinterpret_cast<RepeatedPtrField<EntryType>*>(
|
||||
this->MapFieldBase::repeated_field_);
|
||||
|
||||
repeated_field->Clear();
|
||||
|
||||
// The only way we can get at this point is through reflection and the
|
||||
// only way we can get the reflection object is by having called GetReflection
|
||||
// on the encompassing field. So that type must have existed and hence we
|
||||
// know that this MapEntry default_type has also already been constructed.
|
||||
// So it's safe to just call internal_default_instance().
|
||||
const Message* default_entry = Derived::internal_default_instance();
|
||||
for (typename Map<Key, T>::const_iterator it = map.begin(); it != map.end();
|
||||
++it) {
|
||||
EntryType* new_entry =
|
||||
down_cast<EntryType*>(default_entry->New(this->MapFieldBase::arena_));
|
||||
repeated_field->AddAllocated(new_entry);
|
||||
(*new_entry->mutable_key()) = it->first;
|
||||
(*new_entry->mutable_value()) = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::SyncMapWithRepeatedFieldNoLock() const {
|
||||
Map<Key, T>* map = const_cast<MapField*>(this)->impl_.MutableMap();
|
||||
RepeatedPtrField<EntryType>* repeated_field =
|
||||
reinterpret_cast<RepeatedPtrField<EntryType>*>(
|
||||
this->MapFieldBase::repeated_field_);
|
||||
GOOGLE_CHECK(this->MapFieldBase::repeated_field_ != NULL);
|
||||
map->clear();
|
||||
for (typename RepeatedPtrField<EntryType>::iterator it =
|
||||
repeated_field->begin();
|
||||
it != repeated_field->end(); ++it) {
|
||||
// Cast is needed because Map's api and internal storage is different when
|
||||
// value is enum. For enum, we cannot cast an int to enum. Thus, we have to
|
||||
// copy value. For other types, they have same exposed api type and internal
|
||||
// stored type. We should not introduce value copy for them. We achieve this
|
||||
// by casting to value for enum while casting to reference for other types.
|
||||
(*map)[it->key()] = static_cast<CastValueType>(it->value());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
size_t MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>::SpaceUsedExcludingSelfNoLock() const {
|
||||
size_t size = 0;
|
||||
if (this->MapFieldBase::repeated_field_ != NULL) {
|
||||
size += this->MapFieldBase::repeated_field_->SpaceUsedExcludingSelfLong();
|
||||
}
|
||||
Map<Key, T>* map = const_cast<MapField*>(this)->impl_.MutableMap();
|
||||
size += sizeof(*map);
|
||||
for (typename Map<Key, T>::iterator it = map->begin(); it != map->end();
|
||||
++it) {
|
||||
size += KeyTypeHandler::SpaceUsedInMapLong(it->first);
|
||||
size += ValueTypeHandler::SpaceUsedInMapLong(it->second);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_MAP_FIELD_INL_H__
|
190
include/google/protobuf/map_field_lite.h
Normal file
190
include/google/protobuf/map_field_lite.h
Normal file
@ -0,0 +1,190 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__
|
||||
#define GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__
|
||||
|
||||
#include <type_traits>
|
||||
#include <google/protobuf/parse_context.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/map.h>
|
||||
#include <google/protobuf/map_entry_lite.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// This class provides access to map field using generated api. It is used for
|
||||
// internal generated message implentation only. Users should never use this
|
||||
// directly.
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType key_wire_type,
|
||||
WireFormatLite::FieldType value_wire_type, int default_enum_value = 0>
|
||||
class MapFieldLite {
|
||||
// Define message type for internal repeated field.
|
||||
typedef Derived EntryType;
|
||||
|
||||
public:
|
||||
typedef Map<Key, T> MapType;
|
||||
typedef EntryType EntryTypeTrait;
|
||||
|
||||
MapFieldLite() { SetDefaultEnumValue(); }
|
||||
|
||||
explicit MapFieldLite(Arena* arena) : map_(arena) { SetDefaultEnumValue(); }
|
||||
|
||||
// Accessors
|
||||
const Map<Key, T>& GetMap() const { return map_; }
|
||||
Map<Key, T>* MutableMap() { return &map_; }
|
||||
|
||||
// Convenient methods for generated message implementation.
|
||||
int size() const { return static_cast<int>(map_.size()); }
|
||||
void Clear() { return map_.clear(); }
|
||||
void MergeFrom(const MapFieldLite& other) {
|
||||
for (typename Map<Key, T>::const_iterator it = other.map_.begin();
|
||||
it != other.map_.end(); ++it) {
|
||||
map_[it->first] = it->second;
|
||||
}
|
||||
}
|
||||
void Swap(MapFieldLite* other) { map_.swap(other->map_); }
|
||||
|
||||
// Set default enum value only for proto2 map field whose value is enum type.
|
||||
void SetDefaultEnumValue() {
|
||||
MutableMap()->SetDefaultEnumValue(default_enum_value);
|
||||
}
|
||||
|
||||
// Used in the implementation of parsing. Caller should take the ownership iff
|
||||
// arena_ is NULL.
|
||||
EntryType* NewEntry() const {
|
||||
return Arena::CreateMessage<EntryType>(map_.arena_);
|
||||
}
|
||||
// Used in the implementation of serializing enum value type. Caller should
|
||||
// take the ownership iff arena_ is NULL.
|
||||
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const {
|
||||
return EntryType::EnumWrap(key, t, map_.arena_);
|
||||
}
|
||||
// Used in the implementation of serializing other value types. Caller should
|
||||
// take the ownership iff arena_ is NULL.
|
||||
EntryType* NewEntryWrapper(const Key& key, const T& t) const {
|
||||
return EntryType::Wrap(key, t, map_.arena_);
|
||||
}
|
||||
|
||||
const char* _InternalParse(const char* ptr, ParseContext* ctx) {
|
||||
typename Derived::template Parser<MapFieldLite, Map<Key, T>> parser(this);
|
||||
return parser._InternalParse(ptr, ctx);
|
||||
}
|
||||
|
||||
template <typename UnknownType>
|
||||
const char* ParseWithEnumValidation(const char* ptr, ParseContext* ctx,
|
||||
bool (*is_valid)(int), uint32 field_num,
|
||||
InternalMetadata* metadata) {
|
||||
typename Derived::template Parser<MapFieldLite, Map<Key, T>> parser(this);
|
||||
return parser.template ParseWithEnumValidation<UnknownType>(
|
||||
ptr, ctx, is_valid, field_num, metadata);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef void DestructorSkippable_;
|
||||
|
||||
Map<Key, T> map_;
|
||||
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::Arena;
|
||||
};
|
||||
|
||||
template <typename UnknownType, typename T>
|
||||
struct EnumParseWrapper {
|
||||
const char* _InternalParse(const char* ptr, ParseContext* ctx) {
|
||||
return map_field->template ParseWithEnumValidation<UnknownType>(
|
||||
ptr, ctx, is_valid, field_num, metadata);
|
||||
}
|
||||
T* map_field;
|
||||
bool (*is_valid)(int);
|
||||
uint32 field_num;
|
||||
InternalMetadata* metadata;
|
||||
};
|
||||
|
||||
// Helper function because the typenames of maps are horrendous to print. This
|
||||
// leverages compiler type deduction, to keep all type data out of the
|
||||
// generated code
|
||||
template <typename UnknownType, typename T>
|
||||
EnumParseWrapper<UnknownType, T> InitEnumParseWrapper(
|
||||
T* map_field, bool (*is_valid)(int), uint32 field_num,
|
||||
InternalMetadata* metadata) {
|
||||
return EnumParseWrapper<UnknownType, T>{map_field, is_valid, field_num,
|
||||
metadata};
|
||||
}
|
||||
|
||||
// True if IsInitialized() is true for value field in all elements of t. T is
|
||||
// expected to be message. It's useful to have this helper here to keep the
|
||||
// protobuf compiler from ever having to emit loops in IsInitialized() methods.
|
||||
// We want the C++ compiler to inline this or not as it sees fit.
|
||||
template <typename Derived, typename Key, typename T,
|
||||
WireFormatLite::FieldType key_wire_type,
|
||||
WireFormatLite::FieldType value_wire_type, int default_enum_value>
|
||||
bool AllAreInitialized(
|
||||
const MapFieldLite<Derived, Key, T, key_wire_type, value_wire_type,
|
||||
default_enum_value>& field) {
|
||||
const auto& t = field.GetMap();
|
||||
for (typename Map<Key, T>::const_iterator it = t.begin(); it != t.end();
|
||||
++it) {
|
||||
if (!it->second.IsInitialized()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename MEntry>
|
||||
struct MapEntryToMapField : MapEntryToMapField<typename MEntry::SuperType> {};
|
||||
|
||||
template <typename T, typename Key, typename Value,
|
||||
WireFormatLite::FieldType kKeyFieldType,
|
||||
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
|
||||
struct MapEntryToMapField<MapEntryLite<T, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value>> {
|
||||
typedef MapFieldLite<MapEntryLite<T, Key, Value, kKeyFieldType,
|
||||
kValueFieldType, default_enum_value>,
|
||||
Key, Value, kKeyFieldType, kValueFieldType,
|
||||
default_enum_value>
|
||||
MapFieldType;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__
|
807
include/google/protobuf/map_type_handler.h
Normal file
807
include/google/protobuf/map_type_handler.h
Normal file
@ -0,0 +1,807 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_TYPE_HANDLER_H__
|
||||
#define GOOGLE_PROTOBUF_TYPE_HANDLER_H__
|
||||
|
||||
#include <google/protobuf/parse_context.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// Used for compile time type selection. MapIf::type will be TrueType if Flag is
|
||||
// true and FalseType otherwise.
|
||||
template <bool Flag, typename TrueType, typename FalseType>
|
||||
struct MapIf;
|
||||
|
||||
template <typename TrueType, typename FalseType>
|
||||
struct MapIf<true, TrueType, FalseType> {
|
||||
typedef TrueType type;
|
||||
};
|
||||
|
||||
template <typename TrueType, typename FalseType>
|
||||
struct MapIf<false, TrueType, FalseType> {
|
||||
typedef FalseType type;
|
||||
};
|
||||
|
||||
// In proto2 Map, enum needs to be initialized to given default value, while
|
||||
// other types' default value can be inferred from the type.
|
||||
template <bool IsEnum, typename Type>
|
||||
class MapValueInitializer {
|
||||
public:
|
||||
static inline void Initialize(Type& type, int default_enum_value);
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
class MapValueInitializer<true, Type> {
|
||||
public:
|
||||
static inline void Initialize(Type& value, int default_enum_value) {
|
||||
value = static_cast<Type>(default_enum_value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
class MapValueInitializer<false, Type> {
|
||||
public:
|
||||
static inline void Initialize(Type& /* value */,
|
||||
int /* default_enum_value */) {}
|
||||
};
|
||||
|
||||
template <typename Type, bool is_arena_constructable>
|
||||
class MapArenaMessageCreator {
|
||||
public:
|
||||
// Use arena to create message if Type is arena constructable. Otherwise,
|
||||
// create the message on heap.
|
||||
static inline Type* CreateMessage(Arena* arena);
|
||||
};
|
||||
template <typename Type>
|
||||
class MapArenaMessageCreator<Type, true> {
|
||||
public:
|
||||
static inline Type* CreateMessage(Arena* arena) {
|
||||
return Arena::CreateMessage<Type>(arena);
|
||||
}
|
||||
};
|
||||
template <typename Type>
|
||||
class MapArenaMessageCreator<Type, false> {
|
||||
public:
|
||||
static inline Type* CreateMessage(Arena* arena) {
|
||||
return Arena::Create<Type>(arena);
|
||||
}
|
||||
};
|
||||
|
||||
// Define constants for given wire field type
|
||||
template <WireFormatLite::FieldType field_type, typename Type>
|
||||
class MapWireFieldTypeTraits {};
|
||||
|
||||
#define TYPE_TRAITS(FieldType, CType, WireFormatType, IsMessage, IsEnum) \
|
||||
template <typename Type> \
|
||||
class MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, Type> { \
|
||||
public: \
|
||||
static const bool kIsMessage = IsMessage; \
|
||||
static const bool kIsEnum = IsEnum; \
|
||||
typedef typename MapIf<kIsMessage, Type*, CType>::type TypeOnMemory; \
|
||||
typedef typename MapIf<kIsEnum, int, Type>::type MapEntryAccessorType; \
|
||||
static const WireFormatLite::WireType kWireType = \
|
||||
WireFormatLite::WIRETYPE_##WireFormatType; \
|
||||
};
|
||||
|
||||
TYPE_TRAITS(MESSAGE, Type, LENGTH_DELIMITED, true, false)
|
||||
TYPE_TRAITS(STRING, ArenaStringPtr, LENGTH_DELIMITED, false, false)
|
||||
TYPE_TRAITS(BYTES, ArenaStringPtr, LENGTH_DELIMITED, false, false)
|
||||
TYPE_TRAITS(INT64, int64, VARINT, false, false)
|
||||
TYPE_TRAITS(UINT64, uint64, VARINT, false, false)
|
||||
TYPE_TRAITS(INT32, int32, VARINT, false, false)
|
||||
TYPE_TRAITS(UINT32, uint32, VARINT, false, false)
|
||||
TYPE_TRAITS(SINT64, int64, VARINT, false, false)
|
||||
TYPE_TRAITS(SINT32, int32, VARINT, false, false)
|
||||
TYPE_TRAITS(ENUM, int, VARINT, false, true)
|
||||
TYPE_TRAITS(DOUBLE, double, FIXED64, false, false)
|
||||
TYPE_TRAITS(FLOAT, float, FIXED32, false, false)
|
||||
TYPE_TRAITS(FIXED64, uint64, FIXED64, false, false)
|
||||
TYPE_TRAITS(FIXED32, uint32, FIXED32, false, false)
|
||||
TYPE_TRAITS(SFIXED64, int64, FIXED64, false, false)
|
||||
TYPE_TRAITS(SFIXED32, int32, FIXED32, false, false)
|
||||
TYPE_TRAITS(BOOL, bool, VARINT, false, false)
|
||||
|
||||
#undef TYPE_TRAITS
|
||||
|
||||
template <WireFormatLite::FieldType field_type, typename Type>
|
||||
class MapTypeHandler {};
|
||||
|
||||
template <typename Type>
|
||||
class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> {
|
||||
public:
|
||||
// Enum type cannot be used for MapTypeHandler::Read. Define a type which will
|
||||
// replace Enum with int.
|
||||
typedef typename MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE,
|
||||
Type>::MapEntryAccessorType
|
||||
MapEntryAccessorType;
|
||||
// Internal stored type in MapEntryLite for given wire field type.
|
||||
typedef typename MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE,
|
||||
Type>::TypeOnMemory TypeOnMemory;
|
||||
// Corresponding wire type for field type.
|
||||
static constexpr WireFormatLite::WireType kWireType =
|
||||
MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kWireType;
|
||||
// Whether wire type is for message.
|
||||
static constexpr bool kIsMessage =
|
||||
MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsMessage;
|
||||
// Whether wire type is for enum.
|
||||
static constexpr bool kIsEnum =
|
||||
MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsEnum;
|
||||
|
||||
// Functions used in parsing and serialization. ===================
|
||||
static inline size_t ByteSize(const MapEntryAccessorType& value);
|
||||
static inline int GetCachedSize(const MapEntryAccessorType& value);
|
||||
static inline bool Read(io::CodedInputStream* input,
|
||||
MapEntryAccessorType* value);
|
||||
static inline const char* Read(const char* ptr, ParseContext* ctx,
|
||||
MapEntryAccessorType* value);
|
||||
|
||||
static inline uint8* Write(int field, const MapEntryAccessorType& value,
|
||||
uint8* ptr, io::EpsCopyOutputStream* stream);
|
||||
|
||||
// Functions to manipulate data on memory. ========================
|
||||
static inline const Type& GetExternalReference(const Type* value);
|
||||
static inline void DeleteNoArena(const Type* x);
|
||||
static inline void Merge(const Type& from, Type** to, Arena* arena);
|
||||
static inline void Clear(Type** value, Arena* arena);
|
||||
static inline void ClearMaybeByDefaultEnum(Type** value, Arena* arena,
|
||||
int default_enum_value);
|
||||
static inline void Initialize(Type** x, Arena* arena);
|
||||
|
||||
static inline void InitializeMaybeByDefaultEnum(Type** x,
|
||||
int default_enum_value,
|
||||
Arena* arena);
|
||||
static inline Type* EnsureMutable(Type** value, Arena* arena);
|
||||
// SpaceUsedInMapEntry: Return bytes used by value in MapEntry, excluding
|
||||
// those already calculate in sizeof(MapField).
|
||||
static inline size_t SpaceUsedInMapEntryLong(const Type* value);
|
||||
// Return bytes used by value in Map.
|
||||
static inline size_t SpaceUsedInMapLong(const Type& value);
|
||||
// Assign default value to given instance.
|
||||
static inline void AssignDefaultValue(Type** value);
|
||||
// Return default instance if value is not initialized when calling const
|
||||
// reference accessor.
|
||||
static inline const Type& DefaultIfNotInitialized(const Type* value,
|
||||
const Type* default_value);
|
||||
// Check if all required fields have values set.
|
||||
static inline bool IsInitialized(Type* value);
|
||||
};
|
||||
|
||||
#define MAP_HANDLER(FieldType) \
|
||||
template <typename Type> \
|
||||
class MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type> { \
|
||||
public: \
|
||||
typedef typename MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType \
|
||||
MapEntryAccessorType; \
|
||||
typedef typename MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::TypeOnMemory TypeOnMemory; \
|
||||
static const WireFormatLite::WireType kWireType = \
|
||||
MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::kWireType; \
|
||||
static const bool kIsMessage = \
|
||||
MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::kIsMessage; \
|
||||
static const bool kIsEnum = \
|
||||
MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::kIsEnum; \
|
||||
static inline int ByteSize(const MapEntryAccessorType& value); \
|
||||
static inline int GetCachedSize(const MapEntryAccessorType& value); \
|
||||
static inline bool Read(io::CodedInputStream* input, \
|
||||
MapEntryAccessorType* value); \
|
||||
static inline const char* Read(const char* begin, ParseContext* ctx, \
|
||||
MapEntryAccessorType* value); \
|
||||
static inline uint8* Write(int field, const MapEntryAccessorType& value, \
|
||||
uint8* ptr, io::EpsCopyOutputStream* stream); \
|
||||
static inline const MapEntryAccessorType& GetExternalReference( \
|
||||
const TypeOnMemory& value); \
|
||||
static inline void DeleteNoArena(const TypeOnMemory& x); \
|
||||
static inline void Merge(const MapEntryAccessorType& from, \
|
||||
TypeOnMemory* to, Arena* arena); \
|
||||
static inline void Clear(TypeOnMemory* value, Arena* arena); \
|
||||
static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \
|
||||
Arena* arena, \
|
||||
int default_enum); \
|
||||
static inline size_t SpaceUsedInMapEntryLong(const TypeOnMemory& value); \
|
||||
static inline size_t SpaceUsedInMapLong(const TypeOnMemory& value); \
|
||||
static inline size_t SpaceUsedInMapLong(const std::string& value); \
|
||||
static inline void AssignDefaultValue(TypeOnMemory* value); \
|
||||
static inline const MapEntryAccessorType& DefaultIfNotInitialized( \
|
||||
const TypeOnMemory& value, const TypeOnMemory& default_value); \
|
||||
static inline bool IsInitialized(const TypeOnMemory& value); \
|
||||
static void DeleteNoArena(TypeOnMemory& value); \
|
||||
static inline void Initialize(TypeOnMemory* value, Arena* arena); \
|
||||
static inline void InitializeMaybeByDefaultEnum(TypeOnMemory* value, \
|
||||
int default_enum_value, \
|
||||
Arena* arena); \
|
||||
static inline MapEntryAccessorType* EnsureMutable(TypeOnMemory* value, \
|
||||
Arena* arena); \
|
||||
};
|
||||
MAP_HANDLER(STRING)
|
||||
MAP_HANDLER(BYTES)
|
||||
MAP_HANDLER(INT64)
|
||||
MAP_HANDLER(UINT64)
|
||||
MAP_HANDLER(INT32)
|
||||
MAP_HANDLER(UINT32)
|
||||
MAP_HANDLER(SINT64)
|
||||
MAP_HANDLER(SINT32)
|
||||
MAP_HANDLER(ENUM)
|
||||
MAP_HANDLER(DOUBLE)
|
||||
MAP_HANDLER(FLOAT)
|
||||
MAP_HANDLER(FIXED64)
|
||||
MAP_HANDLER(FIXED32)
|
||||
MAP_HANDLER(SFIXED64)
|
||||
MAP_HANDLER(SFIXED32)
|
||||
MAP_HANDLER(BOOL)
|
||||
#undef MAP_HANDLER
|
||||
|
||||
template <typename Type>
|
||||
inline size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize(
|
||||
const MapEntryAccessorType& value) {
|
||||
return WireFormatLite::MessageSizeNoVirtual(value);
|
||||
}
|
||||
|
||||
#define GOOGLE_PROTOBUF_BYTE_SIZE(FieldType, DeclaredType) \
|
||||
template <typename Type> \
|
||||
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \
|
||||
const MapEntryAccessorType& value) { \
|
||||
return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \
|
||||
}
|
||||
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(STRING, String)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(BYTES, Bytes)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(INT64, Int64)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(UINT64, UInt64)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(INT32, Int32)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(UINT32, UInt32)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(SINT64, SInt64)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(SINT32, SInt32)
|
||||
GOOGLE_PROTOBUF_BYTE_SIZE(ENUM, Enum)
|
||||
|
||||
#undef GOOGLE_PROTOBUF_BYTE_SIZE
|
||||
|
||||
#define FIXED_BYTE_SIZE(FieldType, DeclaredType) \
|
||||
template <typename Type> \
|
||||
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \
|
||||
const MapEntryAccessorType& /* value */) { \
|
||||
return WireFormatLite::k##DeclaredType##Size; \
|
||||
}
|
||||
|
||||
FIXED_BYTE_SIZE(DOUBLE, Double)
|
||||
FIXED_BYTE_SIZE(FLOAT, Float)
|
||||
FIXED_BYTE_SIZE(FIXED64, Fixed64)
|
||||
FIXED_BYTE_SIZE(FIXED32, Fixed32)
|
||||
FIXED_BYTE_SIZE(SFIXED64, SFixed64)
|
||||
FIXED_BYTE_SIZE(SFIXED32, SFixed32)
|
||||
FIXED_BYTE_SIZE(BOOL, Bool)
|
||||
|
||||
#undef FIXED_BYTE_SIZE
|
||||
|
||||
template <typename Type>
|
||||
inline int MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize(
|
||||
const MapEntryAccessorType& value) {
|
||||
return static_cast<int>(WireFormatLite::LengthDelimitedSize(
|
||||
static_cast<size_t>(value.GetCachedSize())));
|
||||
}
|
||||
|
||||
#define GET_CACHED_SIZE(FieldType, DeclaredType) \
|
||||
template <typename Type> \
|
||||
inline int \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \
|
||||
const MapEntryAccessorType& value) { \
|
||||
return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \
|
||||
}
|
||||
|
||||
GET_CACHED_SIZE(STRING, String)
|
||||
GET_CACHED_SIZE(BYTES, Bytes)
|
||||
GET_CACHED_SIZE(INT64, Int64)
|
||||
GET_CACHED_SIZE(UINT64, UInt64)
|
||||
GET_CACHED_SIZE(INT32, Int32)
|
||||
GET_CACHED_SIZE(UINT32, UInt32)
|
||||
GET_CACHED_SIZE(SINT64, SInt64)
|
||||
GET_CACHED_SIZE(SINT32, SInt32)
|
||||
GET_CACHED_SIZE(ENUM, Enum)
|
||||
|
||||
#undef GET_CACHED_SIZE
|
||||
|
||||
#define GET_FIXED_CACHED_SIZE(FieldType, DeclaredType) \
|
||||
template <typename Type> \
|
||||
inline int \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \
|
||||
const MapEntryAccessorType& /* value */) { \
|
||||
return WireFormatLite::k##DeclaredType##Size; \
|
||||
}
|
||||
|
||||
GET_FIXED_CACHED_SIZE(DOUBLE, Double)
|
||||
GET_FIXED_CACHED_SIZE(FLOAT, Float)
|
||||
GET_FIXED_CACHED_SIZE(FIXED64, Fixed64)
|
||||
GET_FIXED_CACHED_SIZE(FIXED32, Fixed32)
|
||||
GET_FIXED_CACHED_SIZE(SFIXED64, SFixed64)
|
||||
GET_FIXED_CACHED_SIZE(SFIXED32, SFixed32)
|
||||
GET_FIXED_CACHED_SIZE(BOOL, Bool)
|
||||
|
||||
#undef GET_FIXED_CACHED_SIZE
|
||||
|
||||
template <typename Type>
|
||||
inline uint8* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Write(
|
||||
int field, const MapEntryAccessorType& value, uint8* ptr,
|
||||
io::EpsCopyOutputStream* stream) {
|
||||
ptr = stream->EnsureSpace(ptr);
|
||||
return WireFormatLite::InternalWriteMessage(field, value, ptr, stream);
|
||||
}
|
||||
|
||||
#define WRITE_METHOD(FieldType, DeclaredType) \
|
||||
template <typename Type> \
|
||||
inline uint8* MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Write( \
|
||||
int field, const MapEntryAccessorType& value, uint8* ptr, \
|
||||
io::EpsCopyOutputStream* stream) { \
|
||||
ptr = stream->EnsureSpace(ptr); \
|
||||
return stream->Write##DeclaredType(field, value, ptr); \
|
||||
}
|
||||
|
||||
WRITE_METHOD(STRING, String)
|
||||
WRITE_METHOD(BYTES, Bytes)
|
||||
|
||||
#undef WRITE_METHOD
|
||||
#define WRITE_METHOD(FieldType, DeclaredType) \
|
||||
template <typename Type> \
|
||||
inline uint8* MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Write( \
|
||||
int field, const MapEntryAccessorType& value, uint8* ptr, \
|
||||
io::EpsCopyOutputStream* stream) { \
|
||||
ptr = stream->EnsureSpace(ptr); \
|
||||
return WireFormatLite::Write##DeclaredType##ToArray(field, value, ptr); \
|
||||
}
|
||||
|
||||
WRITE_METHOD(INT64, Int64)
|
||||
WRITE_METHOD(UINT64, UInt64)
|
||||
WRITE_METHOD(INT32, Int32)
|
||||
WRITE_METHOD(UINT32, UInt32)
|
||||
WRITE_METHOD(SINT64, SInt64)
|
||||
WRITE_METHOD(SINT32, SInt32)
|
||||
WRITE_METHOD(ENUM, Enum)
|
||||
WRITE_METHOD(DOUBLE, Double)
|
||||
WRITE_METHOD(FLOAT, Float)
|
||||
WRITE_METHOD(FIXED64, Fixed64)
|
||||
WRITE_METHOD(FIXED32, Fixed32)
|
||||
WRITE_METHOD(SFIXED64, SFixed64)
|
||||
WRITE_METHOD(SFIXED32, SFixed32)
|
||||
WRITE_METHOD(BOOL, Bool)
|
||||
|
||||
#undef WRITE_METHOD
|
||||
|
||||
template <typename Type>
|
||||
inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Read(
|
||||
io::CodedInputStream* input, MapEntryAccessorType* value) {
|
||||
return WireFormatLite::ReadMessageNoVirtual(input, value);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline bool MapTypeHandler<WireFormatLite::TYPE_STRING, Type>::Read(
|
||||
io::CodedInputStream* input, MapEntryAccessorType* value) {
|
||||
return WireFormatLite::ReadString(input, value);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline bool MapTypeHandler<WireFormatLite::TYPE_BYTES, Type>::Read(
|
||||
io::CodedInputStream* input, MapEntryAccessorType* value) {
|
||||
return WireFormatLite::ReadBytes(input, value);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
const char* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Read(
|
||||
const char* ptr, ParseContext* ctx, MapEntryAccessorType* value) {
|
||||
return ctx->ParseMessage(value, ptr);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
const char* MapTypeHandler<WireFormatLite::TYPE_STRING, Type>::Read(
|
||||
const char* ptr, ParseContext* ctx, MapEntryAccessorType* value) {
|
||||
int size = ReadSize(&ptr);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
return ctx->ReadString(ptr, size, value);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
const char* MapTypeHandler<WireFormatLite::TYPE_BYTES, Type>::Read(
|
||||
const char* ptr, ParseContext* ctx, MapEntryAccessorType* value) {
|
||||
int size = ReadSize(&ptr);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
return ctx->ReadString(ptr, size, value);
|
||||
}
|
||||
|
||||
inline const char* ReadINT64(const char* ptr, int64* value) {
|
||||
return VarintParse(ptr, reinterpret_cast<uint64*>(value));
|
||||
}
|
||||
inline const char* ReadUINT64(const char* ptr, uint64* value) {
|
||||
return VarintParse(ptr, value);
|
||||
}
|
||||
inline const char* ReadINT32(const char* ptr, int32* value) {
|
||||
return VarintParse(ptr, reinterpret_cast<uint32*>(value));
|
||||
}
|
||||
inline const char* ReadUINT32(const char* ptr, uint32* value) {
|
||||
return VarintParse(ptr, value);
|
||||
}
|
||||
inline const char* ReadSINT64(const char* ptr, int64* value) {
|
||||
*value = ReadVarintZigZag64(&ptr);
|
||||
return ptr;
|
||||
}
|
||||
inline const char* ReadSINT32(const char* ptr, int32* value) {
|
||||
*value = ReadVarintZigZag32(&ptr);
|
||||
return ptr;
|
||||
}
|
||||
template <typename E>
|
||||
inline const char* ReadENUM(const char* ptr, E* value) {
|
||||
*value = static_cast<E>(ReadVarint32(&ptr));
|
||||
return ptr;
|
||||
}
|
||||
inline const char* ReadBOOL(const char* ptr, bool* value) {
|
||||
*value = static_cast<bool>(ReadVarint32(&ptr));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
inline const char* ReadUnaligned(const char* ptr, F* value) {
|
||||
*value = UnalignedLoad<F>(ptr);
|
||||
return ptr + sizeof(F);
|
||||
}
|
||||
inline const char* ReadFLOAT(const char* ptr, float* value) {
|
||||
return ReadUnaligned(ptr, value);
|
||||
}
|
||||
inline const char* ReadDOUBLE(const char* ptr, double* value) {
|
||||
return ReadUnaligned(ptr, value);
|
||||
}
|
||||
inline const char* ReadFIXED64(const char* ptr, uint64* value) {
|
||||
return ReadUnaligned(ptr, value);
|
||||
}
|
||||
inline const char* ReadFIXED32(const char* ptr, uint32* value) {
|
||||
return ReadUnaligned(ptr, value);
|
||||
}
|
||||
inline const char* ReadSFIXED64(const char* ptr, int64* value) {
|
||||
return ReadUnaligned(ptr, value);
|
||||
}
|
||||
inline const char* ReadSFIXED32(const char* ptr, int32* value) {
|
||||
return ReadUnaligned(ptr, value);
|
||||
}
|
||||
|
||||
#define READ_METHOD(FieldType) \
|
||||
template <typename Type> \
|
||||
inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Read( \
|
||||
io::CodedInputStream* input, MapEntryAccessorType* value) { \
|
||||
return WireFormatLite::ReadPrimitive<TypeOnMemory, \
|
||||
WireFormatLite::TYPE_##FieldType>( \
|
||||
input, value); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
const char* MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Read( \
|
||||
const char* begin, ParseContext* ctx, MapEntryAccessorType* value) { \
|
||||
(void)ctx; \
|
||||
return Read##FieldType(begin, value); \
|
||||
}
|
||||
|
||||
READ_METHOD(INT64)
|
||||
READ_METHOD(UINT64)
|
||||
READ_METHOD(INT32)
|
||||
READ_METHOD(UINT32)
|
||||
READ_METHOD(SINT64)
|
||||
READ_METHOD(SINT32)
|
||||
READ_METHOD(ENUM)
|
||||
READ_METHOD(DOUBLE)
|
||||
READ_METHOD(FLOAT)
|
||||
READ_METHOD(FIXED64)
|
||||
READ_METHOD(FIXED32)
|
||||
READ_METHOD(SFIXED64)
|
||||
READ_METHOD(SFIXED32)
|
||||
READ_METHOD(BOOL)
|
||||
|
||||
#undef READ_METHOD
|
||||
|
||||
// Definition for message handler
|
||||
|
||||
template <typename Type>
|
||||
inline const Type&
|
||||
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetExternalReference(
|
||||
const Type* value) {
|
||||
return *value;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
|
||||
Type>::SpaceUsedInMapEntryLong(const Type* value) {
|
||||
return value->SpaceUsedLong();
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::SpaceUsedInMapLong(
|
||||
const Type& value) {
|
||||
return value.SpaceUsedLong();
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Clear(
|
||||
Type** value, Arena* /* arena */) {
|
||||
if (*value != NULL) (*value)->Clear();
|
||||
}
|
||||
template <typename Type>
|
||||
inline void
|
||||
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ClearMaybeByDefaultEnum(
|
||||
Type** value, Arena* /* arena */, int /* default_enum_value */) {
|
||||
if (*value != NULL) (*value)->Clear();
|
||||
}
|
||||
template <typename Type>
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Merge(
|
||||
const Type& from, Type** to, Arena* /* arena */) {
|
||||
(*to)->MergeFrom(from);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::DeleteNoArena(
|
||||
const Type* ptr) {
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
|
||||
Type>::AssignDefaultValue(Type** value) {
|
||||
*value = const_cast<Type*>(Type::internal_default_instance());
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Initialize(
|
||||
Type** x, Arena* /* arena */) {
|
||||
*x = NULL;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::
|
||||
InitializeMaybeByDefaultEnum(Type** x, int /* default_enum_value */,
|
||||
Arena* /* arena */) {
|
||||
*x = NULL;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::EnsureMutable(
|
||||
Type** value, Arena* arena) {
|
||||
if (*value == NULL) {
|
||||
*value = MapArenaMessageCreator<
|
||||
Type,
|
||||
Arena::is_arena_constructable<Type>::type::value>::CreateMessage(arena);
|
||||
}
|
||||
return *value;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline const Type&
|
||||
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::DefaultIfNotInitialized(
|
||||
const Type* value, const Type* default_value) {
|
||||
return value != NULL ? *value : *default_value;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::IsInitialized(
|
||||
Type* value) {
|
||||
return value ? value->IsInitialized() : false;
|
||||
}
|
||||
|
||||
// Definition for string/bytes handler
|
||||
|
||||
#define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \
|
||||
template <typename Type> \
|
||||
inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType& \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::GetExternalReference(const TypeOnMemory& value) { \
|
||||
return value.Get(); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline size_t \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::SpaceUsedInMapEntryLong(const TypeOnMemory& value) { \
|
||||
return sizeof(value); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline size_t \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \
|
||||
const TypeOnMemory& value) { \
|
||||
return sizeof(value); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline size_t \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \
|
||||
const std::string& value) { \
|
||||
return sizeof(value); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \
|
||||
TypeOnMemory* value, Arena* arena) { \
|
||||
value->ClearToEmpty(&internal::GetEmptyStringAlreadyInited(), arena); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \
|
||||
int /* default_enum */) { \
|
||||
Clear(value, arena); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \
|
||||
const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \
|
||||
to->Set(&internal::GetEmptyStringAlreadyInited(), from, arena); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \
|
||||
TypeOnMemory& value) { \
|
||||
value.DestroyNoArena(&internal::GetEmptyStringAlreadyInited()); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::AssignDefaultValue( \
|
||||
TypeOnMemory* /* value */) {} \
|
||||
template <typename Type> \
|
||||
inline void \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \
|
||||
TypeOnMemory* value, Arena* /* arena */) { \
|
||||
value->UnsafeSetDefault(&internal::GetEmptyStringAlreadyInited()); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
InitializeMaybeByDefaultEnum( \
|
||||
TypeOnMemory* value, int /* default_enum_value */, Arena* arena) { \
|
||||
Initialize(value, arena); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType* \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \
|
||||
TypeOnMemory* value, Arena* arena) { \
|
||||
return value->Mutable(&internal::GetEmptyStringAlreadyInited(), arena); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType& \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
DefaultIfNotInitialized(const TypeOnMemory& value, \
|
||||
const TypeOnMemory& /* default_value */) { \
|
||||
return value.Get(); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline bool \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::IsInitialized( \
|
||||
const TypeOnMemory& /* value */) { \
|
||||
return true; \
|
||||
}
|
||||
STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING)
|
||||
STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES)
|
||||
#undef STRING_OR_BYTES_HANDLER_FUNCTIONS
|
||||
|
||||
#define PRIMITIVE_HANDLER_FUNCTIONS(FieldType) \
|
||||
template <typename Type> \
|
||||
inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType& \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::GetExternalReference(const TypeOnMemory& value) { \
|
||||
return value; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline size_t MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
SpaceUsedInMapEntryLong(const TypeOnMemory& /* value */) { \
|
||||
return 0; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline size_t \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \
|
||||
const TypeOnMemory& /* value */) { \
|
||||
return sizeof(Type); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \
|
||||
TypeOnMemory* value, Arena* /* arena */) { \
|
||||
*value = 0; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* /* arena */, \
|
||||
int default_enum_value) { \
|
||||
*value = static_cast<TypeOnMemory>(default_enum_value); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \
|
||||
const MapEntryAccessorType& from, TypeOnMemory* to, \
|
||||
Arena* /* arena */) { \
|
||||
*to = from; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::DeleteNoArena(TypeOnMemory& /* x */) {} \
|
||||
template <typename Type> \
|
||||
inline void \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::AssignDefaultValue( \
|
||||
TypeOnMemory* /* value */) {} \
|
||||
template <typename Type> \
|
||||
inline void \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \
|
||||
TypeOnMemory* value, Arena* /* arena */) { \
|
||||
*value = 0; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
InitializeMaybeByDefaultEnum( \
|
||||
TypeOnMemory* value, int default_enum_value, Arena* /* arena */) { \
|
||||
*value = static_cast<TypeOnMemory>(default_enum_value); \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType* \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \
|
||||
TypeOnMemory* value, Arena* /* arena */) { \
|
||||
return value; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
||||
Type>::MapEntryAccessorType& \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
|
||||
DefaultIfNotInitialized(const TypeOnMemory& value, \
|
||||
const TypeOnMemory& /* default_value */) { \
|
||||
return value; \
|
||||
} \
|
||||
template <typename Type> \
|
||||
inline bool \
|
||||
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::IsInitialized( \
|
||||
const TypeOnMemory& /* value */) { \
|
||||
return true; \
|
||||
}
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(INT64)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(UINT64)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(INT32)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(UINT32)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(SINT64)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(SINT32)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(ENUM)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(DOUBLE)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(FLOAT)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(FIXED64)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(FIXED32)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(SFIXED64)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(SFIXED32)
|
||||
PRIMITIVE_HANDLER_FUNCTIONS(BOOL)
|
||||
#undef PRIMITIVE_HANDLER_FUNCTIONS
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_TYPE_HANDLER_H__
|
1322
include/google/protobuf/message.h
Normal file
1322
include/google/protobuf/message.h
Normal file
File diff suppressed because it is too large
Load Diff
591
include/google/protobuf/message_lite.h
Normal file
591
include/google/protobuf/message_lite.h
Normal file
@ -0,0 +1,591 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Authors: wink@google.com (Wink Saville),
|
||||
// kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// Defines MessageLite, the abstract interface implemented by all (lite
|
||||
// and non-lite) protocol message objects.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__
|
||||
#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__
|
||||
|
||||
#include <climits>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/stubs/logging.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/stubs/once.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
template <typename T>
|
||||
class RepeatedPtrField;
|
||||
|
||||
namespace io {
|
||||
|
||||
class CodedInputStream;
|
||||
class CodedOutputStream;
|
||||
class ZeroCopyInputStream;
|
||||
class ZeroCopyOutputStream;
|
||||
|
||||
} // namespace io
|
||||
namespace internal {
|
||||
|
||||
// See parse_context.h for explanation
|
||||
class ParseContext;
|
||||
|
||||
class RepeatedPtrFieldBase;
|
||||
class WireFormatLite;
|
||||
class WeakFieldMap;
|
||||
|
||||
// We compute sizes as size_t but cache them as int. This function converts a
|
||||
// computed size to a cached size. Since we don't proceed with serialization
|
||||
// if the total size was > INT_MAX, it is not important what this function
|
||||
// returns for inputs > INT_MAX. However this case should not error or
|
||||
// GOOGLE_CHECK-fail, because the full size_t resolution is still returned from
|
||||
// ByteSizeLong() and checked against INT_MAX; we can catch the overflow
|
||||
// there.
|
||||
inline int ToCachedSize(size_t size) { return static_cast<int>(size); }
|
||||
|
||||
// We mainly calculate sizes in terms of size_t, but some functions that
|
||||
// compute sizes return "int". These int sizes are expected to always be
|
||||
// positive. This function is more efficient than casting an int to size_t
|
||||
// directly on 64-bit platforms because it avoids making the compiler emit a
|
||||
// sign extending instruction, which we don't want and don't want to pay for.
|
||||
inline size_t FromIntSize(int size) {
|
||||
// Convert to unsigned before widening so sign extension is not necessary.
|
||||
return static_cast<unsigned int>(size);
|
||||
}
|
||||
|
||||
// For cases where a legacy function returns an integer size. We GOOGLE_DCHECK()
|
||||
// that the conversion will fit within an integer; if this is false then we
|
||||
// are losing information.
|
||||
inline int ToIntSize(size_t size) {
|
||||
GOOGLE_DCHECK_LE(size, static_cast<size_t>(INT_MAX));
|
||||
return static_cast<int>(size);
|
||||
}
|
||||
|
||||
// This type wraps a variable whose constructor and destructor are explicitly
|
||||
// called. It is particularly useful for a global variable, without its
|
||||
// constructor and destructor run on start and end of the program lifetime.
|
||||
// This circumvents the initial construction order fiasco, while keeping
|
||||
// the address of the empty string a compile time constant.
|
||||
//
|
||||
// Pay special attention to the initialization state of the object.
|
||||
// 1. The object is "uninitialized" to begin with.
|
||||
// 2. Call Construct() or DefaultConstruct() only if the object is
|
||||
// uninitialized. After the call, the object becomes "initialized".
|
||||
// 3. Call get() and get_mutable() only if the object is initialized.
|
||||
// 4. Call Destruct() only if the object is initialized.
|
||||
// After the call, the object becomes uninitialized.
|
||||
template <typename T>
|
||||
class ExplicitlyConstructed {
|
||||
public:
|
||||
void DefaultConstruct() { new (&union_) T(); }
|
||||
|
||||
template <typename... Args>
|
||||
void Construct(Args&&... args) {
|
||||
new (&union_) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void Destruct() { get_mutable()->~T(); }
|
||||
|
||||
constexpr const T& get() const { return reinterpret_cast<const T&>(union_); }
|
||||
T* get_mutable() { return reinterpret_cast<T*>(&union_); }
|
||||
|
||||
private:
|
||||
// Prefer c++14 aligned_storage, but for compatibility this will do.
|
||||
union AlignedUnion {
|
||||
char space[sizeof(T)];
|
||||
int64 align_to_int64;
|
||||
void* align_to_ptr;
|
||||
} union_;
|
||||
};
|
||||
|
||||
// Default empty string object. Don't use this directly. Instead, call
|
||||
// GetEmptyString() to get the reference.
|
||||
PROTOBUF_EXPORT extern ExplicitlyConstructed<std::string>
|
||||
fixed_address_empty_string;
|
||||
|
||||
|
||||
PROTOBUF_EXPORT inline const std::string& GetEmptyStringAlreadyInited() {
|
||||
return fixed_address_empty_string.get();
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str);
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Interface to light weight protocol messages.
|
||||
//
|
||||
// This interface is implemented by all protocol message objects. Non-lite
|
||||
// messages additionally implement the Message interface, which is a
|
||||
// subclass of MessageLite. Use MessageLite instead when you only need
|
||||
// the subset of features which it supports -- namely, nothing that uses
|
||||
// descriptors or reflection. You can instruct the protocol compiler
|
||||
// to generate classes which implement only MessageLite, not the full
|
||||
// Message interface, by adding the following line to the .proto file:
|
||||
//
|
||||
// option optimize_for = LITE_RUNTIME;
|
||||
//
|
||||
// This is particularly useful on resource-constrained systems where
|
||||
// the full protocol buffers runtime library is too big.
|
||||
//
|
||||
// Note that on non-constrained systems (e.g. servers) when you need
|
||||
// to link in lots of protocol definitions, a better way to reduce
|
||||
// total code footprint is to use optimize_for = CODE_SIZE. This
|
||||
// will make the generated code smaller while still supporting all the
|
||||
// same features (at the expense of speed). optimize_for = LITE_RUNTIME
|
||||
// is best when you only have a small number of message types linked
|
||||
// into your binary, in which case the size of the protocol buffers
|
||||
// runtime itself is the biggest problem.
|
||||
//
|
||||
// Users must not derive from this class. Only the protocol compiler and
|
||||
// the internal library are allowed to create subclasses.
|
||||
class PROTOBUF_EXPORT MessageLite {
|
||||
public:
|
||||
inline MessageLite() {}
|
||||
virtual ~MessageLite() = default;
|
||||
|
||||
// Basic Operations ------------------------------------------------
|
||||
|
||||
// Get the name of this message type, e.g. "foo.bar.BazProto".
|
||||
virtual std::string GetTypeName() const = 0;
|
||||
|
||||
// Construct a new instance of the same type. Ownership is passed to the
|
||||
// caller.
|
||||
virtual MessageLite* New() const = 0;
|
||||
|
||||
// Construct a new instance on the arena. Ownership is passed to the caller
|
||||
// if arena is a NULL. Default implementation for backwards compatibility.
|
||||
virtual MessageLite* New(Arena* arena) const;
|
||||
|
||||
// Get the arena, if any, associated with this message. Virtual method
|
||||
// required for generic operations but most arena-related operations should
|
||||
// use the GetArena() generated-code method. Default implementation
|
||||
// to reduce code size by avoiding the need for per-type implementations
|
||||
// when types do not implement arena support.
|
||||
Arena* GetArena() const { return _internal_metadata_.arena(); }
|
||||
|
||||
// Get a pointer that may be equal to this message's arena, or may not be.
|
||||
// If the value returned by this method is equal to some arena pointer, then
|
||||
// this message is on that arena; however, if this message is on some arena,
|
||||
// this method may or may not return that arena's pointer. As a tradeoff,
|
||||
// this method may be more efficient than GetArena(). The intent is to allow
|
||||
// underlying representations that use e.g. tagged pointers to sometimes
|
||||
// store the arena pointer directly, and sometimes in a more indirect way,
|
||||
// and allow a fastpath comparison against the arena pointer when it's easy
|
||||
// to obtain.
|
||||
void* GetMaybeArenaPointer() const {
|
||||
return _internal_metadata_.raw_arena_ptr();
|
||||
}
|
||||
|
||||
// Clear all fields of the message and set them to their default values.
|
||||
// Clear() avoids freeing memory, assuming that any memory allocated
|
||||
// to hold parts of the message will be needed again to hold the next
|
||||
// message. If you actually want to free the memory used by a Message,
|
||||
// you must delete it.
|
||||
virtual void Clear() = 0;
|
||||
|
||||
// Quickly check if all required fields have values set.
|
||||
virtual bool IsInitialized() const = 0;
|
||||
|
||||
// This is not implemented for Lite messages -- it just returns "(cannot
|
||||
// determine missing fields for lite message)". However, it is implemented
|
||||
// for full messages. See message.h.
|
||||
virtual std::string InitializationErrorString() const;
|
||||
|
||||
// If |other| is the exact same class as this, calls MergeFrom(). Otherwise,
|
||||
// results are undefined (probably crash).
|
||||
virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0;
|
||||
|
||||
// These methods return a human-readable summary of the message. Note that
|
||||
// since the MessageLite interface does not support reflection, there is very
|
||||
// little information that these methods can provide. They are shadowed by
|
||||
// methods of the same name on the Message interface which provide much more
|
||||
// information. The methods here are intended primarily to facilitate code
|
||||
// reuse for logic that needs to interoperate with both full and lite protos.
|
||||
//
|
||||
// The format of the returned string is subject to change, so please do not
|
||||
// assume it will remain stable over time.
|
||||
std::string DebugString() const;
|
||||
std::string ShortDebugString() const { return DebugString(); }
|
||||
// MessageLite::DebugString is already Utf8 Safe. This is to add compatibility
|
||||
// with Message.
|
||||
std::string Utf8DebugString() const { return DebugString(); }
|
||||
|
||||
// Parsing ---------------------------------------------------------
|
||||
// Methods for parsing in protocol buffer format. Most of these are
|
||||
// just simple wrappers around MergeFromCodedStream(). Clear() will be
|
||||
// called before merging the input.
|
||||
|
||||
// Fill the message with a protocol buffer parsed from the given input
|
||||
// stream. Returns false on a read error or if the input is in the wrong
|
||||
// format. A successful return does not indicate the entire input is
|
||||
// consumed, ensure you call ConsumedEntireMessage() to check that if
|
||||
// applicable.
|
||||
bool ParseFromCodedStream(io::CodedInputStream* input);
|
||||
// Like ParseFromCodedStream(), but accepts messages that are missing
|
||||
// required fields.
|
||||
bool ParsePartialFromCodedStream(io::CodedInputStream* input);
|
||||
// Read a protocol buffer from the given zero-copy input stream. If
|
||||
// successful, the entire input will be consumed.
|
||||
bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input);
|
||||
// Like ParseFromZeroCopyStream(), but accepts messages that are missing
|
||||
// required fields.
|
||||
bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input);
|
||||
// Parse a protocol buffer from a file descriptor. If successful, the entire
|
||||
// input will be consumed.
|
||||
bool ParseFromFileDescriptor(int file_descriptor);
|
||||
// Like ParseFromFileDescriptor(), but accepts messages that are missing
|
||||
// required fields.
|
||||
bool ParsePartialFromFileDescriptor(int file_descriptor);
|
||||
// Parse a protocol buffer from a C++ istream. If successful, the entire
|
||||
// input will be consumed.
|
||||
bool ParseFromIstream(std::istream* input);
|
||||
// Like ParseFromIstream(), but accepts messages that are missing
|
||||
// required fields.
|
||||
bool ParsePartialFromIstream(std::istream* input);
|
||||
// Read a protocol buffer from the given zero-copy input stream, expecting
|
||||
// the message to be exactly "size" bytes long. If successful, exactly
|
||||
// this many bytes will have been consumed from the input.
|
||||
bool MergePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input,
|
||||
int size);
|
||||
// Like ParseFromBoundedZeroCopyStream(), but accepts messages that are
|
||||
// missing required fields.
|
||||
bool MergeFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size);
|
||||
bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size);
|
||||
// Like ParseFromBoundedZeroCopyStream(), but accepts messages that are
|
||||
// missing required fields.
|
||||
bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input,
|
||||
int size);
|
||||
// Parses a protocol buffer contained in a string. Returns true on success.
|
||||
// This function takes a string in the (non-human-readable) binary wire
|
||||
// format, matching the encoding output by MessageLite::SerializeToString().
|
||||
// If you'd like to convert a human-readable string into a protocol buffer
|
||||
// object, see google::protobuf::TextFormat::ParseFromString().
|
||||
bool ParseFromString(const std::string& data);
|
||||
// Like ParseFromString(), but accepts messages that are missing
|
||||
// required fields.
|
||||
bool ParsePartialFromString(const std::string& data);
|
||||
// Parse a protocol buffer contained in an array of bytes.
|
||||
bool ParseFromArray(const void* data, int size);
|
||||
// Like ParseFromArray(), but accepts messages that are missing
|
||||
// required fields.
|
||||
bool ParsePartialFromArray(const void* data, int size);
|
||||
|
||||
|
||||
// Reads a protocol buffer from the stream and merges it into this
|
||||
// Message. Singular fields read from the what is
|
||||
// already in the Message and repeated fields are appended to those
|
||||
// already present.
|
||||
//
|
||||
// It is the responsibility of the caller to call input->LastTagWas()
|
||||
// (for groups) or input->ConsumedEntireMessage() (for non-groups) after
|
||||
// this returns to verify that the message's end was delimited correctly.
|
||||
//
|
||||
// ParseFromCodedStream() is implemented as Clear() followed by
|
||||
// MergeFromCodedStream().
|
||||
bool MergeFromCodedStream(io::CodedInputStream* input);
|
||||
|
||||
// Like MergeFromCodedStream(), but succeeds even if required fields are
|
||||
// missing in the input.
|
||||
//
|
||||
// MergeFromCodedStream() is just implemented as MergePartialFromCodedStream()
|
||||
// followed by IsInitialized().
|
||||
bool MergePartialFromCodedStream(io::CodedInputStream* input);
|
||||
|
||||
// Merge a protocol buffer contained in a string.
|
||||
bool MergeFromString(const std::string& data);
|
||||
|
||||
|
||||
// Serialization ---------------------------------------------------
|
||||
// Methods for serializing in protocol buffer format. Most of these
|
||||
// are just simple wrappers around ByteSize() and SerializeWithCachedSizes().
|
||||
|
||||
// Write a protocol buffer of this message to the given output. Returns
|
||||
// false on a write error. If the message is missing required fields,
|
||||
// this may GOOGLE_CHECK-fail.
|
||||
bool SerializeToCodedStream(io::CodedOutputStream* output) const;
|
||||
// Like SerializeToCodedStream(), but allows missing required fields.
|
||||
bool SerializePartialToCodedStream(io::CodedOutputStream* output) const;
|
||||
// Write the message to the given zero-copy output stream. All required
|
||||
// fields must be set.
|
||||
bool SerializeToZeroCopyStream(io::ZeroCopyOutputStream* output) const;
|
||||
// Like SerializeToZeroCopyStream(), but allows missing required fields.
|
||||
bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const;
|
||||
// Serialize the message and store it in the given string. All required
|
||||
// fields must be set.
|
||||
bool SerializeToString(std::string* output) const;
|
||||
// Like SerializeToString(), but allows missing required fields.
|
||||
bool SerializePartialToString(std::string* output) const;
|
||||
// Serialize the message and store it in the given byte array. All required
|
||||
// fields must be set.
|
||||
bool SerializeToArray(void* data, int size) const;
|
||||
// Like SerializeToArray(), but allows missing required fields.
|
||||
bool SerializePartialToArray(void* data, int size) const;
|
||||
|
||||
// Make a string encoding the message. Is equivalent to calling
|
||||
// SerializeToString() on a string and using that. Returns the empty
|
||||
// string if SerializeToString() would have returned an error.
|
||||
// Note: If you intend to generate many such strings, you may
|
||||
// reduce heap fragmentation by instead re-using the same string
|
||||
// object with calls to SerializeToString().
|
||||
std::string SerializeAsString() const;
|
||||
// Like SerializeAsString(), but allows missing required fields.
|
||||
std::string SerializePartialAsString() const;
|
||||
|
||||
// Serialize the message and write it to the given file descriptor. All
|
||||
// required fields must be set.
|
||||
bool SerializeToFileDescriptor(int file_descriptor) const;
|
||||
// Like SerializeToFileDescriptor(), but allows missing required fields.
|
||||
bool SerializePartialToFileDescriptor(int file_descriptor) const;
|
||||
// Serialize the message and write it to the given C++ ostream. All
|
||||
// required fields must be set.
|
||||
bool SerializeToOstream(std::ostream* output) const;
|
||||
// Like SerializeToOstream(), but allows missing required fields.
|
||||
bool SerializePartialToOstream(std::ostream* output) const;
|
||||
|
||||
// Like SerializeToString(), but appends to the data to the string's
|
||||
// existing contents. All required fields must be set.
|
||||
bool AppendToString(std::string* output) const;
|
||||
// Like AppendToString(), but allows missing required fields.
|
||||
bool AppendPartialToString(std::string* output) const;
|
||||
|
||||
|
||||
// Computes the serialized size of the message. This recursively calls
|
||||
// ByteSizeLong() on all embedded messages.
|
||||
//
|
||||
// ByteSizeLong() is generally linear in the number of fields defined for the
|
||||
// proto.
|
||||
virtual size_t ByteSizeLong() const = 0;
|
||||
|
||||
// Legacy ByteSize() API.
|
||||
PROTOBUF_DEPRECATED_MSG("Please use ByteSizeLong() instead")
|
||||
int ByteSize() const { return internal::ToIntSize(ByteSizeLong()); }
|
||||
|
||||
// Serializes the message without recomputing the size. The message must not
|
||||
// have changed since the last call to ByteSize(), and the value returned by
|
||||
// ByteSize must be non-negative. Otherwise the results are undefined.
|
||||
void SerializeWithCachedSizes(io::CodedOutputStream* output) const {
|
||||
output->SetCur(_InternalSerialize(output->Cur(), output->EpsCopy()));
|
||||
}
|
||||
|
||||
// Functions below here are not part of the public interface. It isn't
|
||||
// enforced, but they should be treated as private, and will be private
|
||||
// at some future time. Unfortunately the implementation of the "friend"
|
||||
// keyword in GCC is broken at the moment, but we expect it will be fixed.
|
||||
|
||||
// Like SerializeWithCachedSizes, but writes directly to *target, returning
|
||||
// a pointer to the byte immediately after the last byte written. "target"
|
||||
// must point at a byte array of at least ByteSize() bytes. Whether to use
|
||||
// deterministic serialization, e.g., maps in sorted order, is determined by
|
||||
// CodedOutputStream::IsDefaultSerializationDeterministic().
|
||||
uint8* SerializeWithCachedSizesToArray(uint8* target) const;
|
||||
|
||||
// Returns the result of the last call to ByteSize(). An embedded message's
|
||||
// size is needed both to serialize it (because embedded messages are
|
||||
// length-delimited) and to compute the outer message's size. Caching
|
||||
// the size avoids computing it multiple times.
|
||||
//
|
||||
// ByteSize() does not automatically use the cached size when available
|
||||
// because this would require invalidating it every time the message was
|
||||
// modified, which would be too hard and expensive. (E.g. if a deeply-nested
|
||||
// sub-message is changed, all of its parents' cached sizes would need to be
|
||||
// invalidated, which is too much work for an otherwise inlined setter
|
||||
// method.)
|
||||
virtual int GetCachedSize() const = 0;
|
||||
|
||||
virtual const char* _InternalParse(const char* /*ptr*/,
|
||||
internal::ParseContext* /*ctx*/) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename T>
|
||||
static T* CreateMaybeMessage(Arena* arena) {
|
||||
return Arena::CreateMaybeMessage<T>(arena);
|
||||
}
|
||||
|
||||
inline explicit MessageLite(Arena* arena) : _internal_metadata_(arena) {}
|
||||
|
||||
internal::InternalMetadata _internal_metadata_;
|
||||
|
||||
public:
|
||||
enum ParseFlags {
|
||||
kMerge = 0,
|
||||
kParse = 1,
|
||||
kMergePartial = 2,
|
||||
kParsePartial = 3,
|
||||
kMergeWithAliasing = 4,
|
||||
kParseWithAliasing = 5,
|
||||
kMergePartialWithAliasing = 6,
|
||||
kParsePartialWithAliasing = 7
|
||||
};
|
||||
|
||||
template <ParseFlags flags, typename T>
|
||||
bool ParseFrom(const T& input);
|
||||
|
||||
// Fast path when conditions match (ie. non-deterministic)
|
||||
// uint8* _InternalSerialize(uint8* ptr) const;
|
||||
virtual uint8* _InternalSerialize(uint8* ptr,
|
||||
io::EpsCopyOutputStream* stream) const = 0;
|
||||
|
||||
// Identical to IsInitialized() except that it logs an error message.
|
||||
bool IsInitializedWithErrors() const {
|
||||
if (IsInitialized()) return true;
|
||||
LogInitializationErrorMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
// TODO(gerbens) make this a pure abstract function
|
||||
virtual const void* InternalGetTable() const { return NULL; }
|
||||
|
||||
friend class internal::WireFormatLite;
|
||||
friend class Message;
|
||||
friend class internal::WeakFieldMap;
|
||||
|
||||
void LogInitializationErrorMessage() const;
|
||||
|
||||
bool MergeFromImpl(io::CodedInputStream* input, ParseFlags parse_flags);
|
||||
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite);
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <bool alias>
|
||||
bool MergeFromImpl(StringPiece input, MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
extern template bool MergeFromImpl<false>(StringPiece input,
|
||||
MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
extern template bool MergeFromImpl<true>(StringPiece input,
|
||||
MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
|
||||
template <bool alias>
|
||||
bool MergeFromImpl(io::ZeroCopyInputStream* input, MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
extern template bool MergeFromImpl<false>(io::ZeroCopyInputStream* input,
|
||||
MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
extern template bool MergeFromImpl<true>(io::ZeroCopyInputStream* input,
|
||||
MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
|
||||
struct BoundedZCIS {
|
||||
io::ZeroCopyInputStream* zcis;
|
||||
int limit;
|
||||
};
|
||||
|
||||
template <bool alias>
|
||||
bool MergeFromImpl(BoundedZCIS input, MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
extern template bool MergeFromImpl<false>(BoundedZCIS input, MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
extern template bool MergeFromImpl<true>(BoundedZCIS input, MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags);
|
||||
|
||||
template <typename T>
|
||||
struct SourceWrapper;
|
||||
|
||||
template <bool alias, typename T>
|
||||
bool MergeFromImpl(const SourceWrapper<T>& input, MessageLite* msg,
|
||||
MessageLite::ParseFlags parse_flags) {
|
||||
return input.template MergeInto<alias>(msg, parse_flags);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <MessageLite::ParseFlags flags, typename T>
|
||||
bool MessageLite::ParseFrom(const T& input) {
|
||||
if (flags & kParse) Clear();
|
||||
constexpr bool alias = (flags & kMergeWithAliasing) != 0;
|
||||
return internal::MergeFromImpl<alias>(input, this, flags);
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Shutdown support.
|
||||
|
||||
|
||||
// Shut down the entire protocol buffers library, deleting all static-duration
|
||||
// objects allocated by the library or by generated .pb.cc files.
|
||||
//
|
||||
// There are two reasons you might want to call this:
|
||||
// * You use a draconian definition of "memory leak" in which you expect
|
||||
// every single malloc() to have a corresponding free(), even for objects
|
||||
// which live until program exit.
|
||||
// * You are writing a dynamically-loaded library which needs to clean up
|
||||
// after itself when the library is unloaded.
|
||||
//
|
||||
// It is safe to call this multiple times. However, it is not safe to use
|
||||
// any other part of the protocol buffers library after
|
||||
// ShutdownProtobufLibrary() has been called. Furthermore this call is not
|
||||
// thread safe, user needs to synchronize multiple calls.
|
||||
PROTOBUF_EXPORT void ShutdownProtobufLibrary();
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Register a function to be called when ShutdownProtocolBuffers() is called.
|
||||
PROTOBUF_EXPORT void OnShutdown(void (*func)());
|
||||
// Run an arbitrary function on an arg
|
||||
PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg);
|
||||
|
||||
template <typename T>
|
||||
T* OnShutdownDelete(T* p) {
|
||||
OnShutdownRun([](const void* pp) { delete static_cast<const T*>(pp); }, p);
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__
|
36
include/google/protobuf/metadata.h
Normal file
36
include/google/protobuf/metadata.h
Normal file
@ -0,0 +1,36 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_METADATA_H__
|
||||
#define GOOGLE_PROTOBUF_METADATA_H__
|
||||
|
||||
// TODO(b/151117630): Remove this file and all instances where it gets imported.
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_METADATA_H__
|
248
include/google/protobuf/metadata_lite.h
Normal file
248
include/google/protobuf/metadata_lite.h
Normal file
@ -0,0 +1,248 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_METADATA_LITE_H__
|
||||
#define GOOGLE_PROTOBUF_METADATA_LITE_H__
|
||||
|
||||
#include <string>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/port.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// This is the representation for messages that support arena allocation. It
|
||||
// uses a tagged pointer to either store the Arena pointer, if there are no
|
||||
// unknown fields, or a pointer to a block of memory with both the Arena pointer
|
||||
// and the UnknownFieldSet, if there are unknown fields. This optimization
|
||||
// allows for "zero-overhead" storage of the Arena pointer, relative to the
|
||||
// above baseline implementation.
|
||||
//
|
||||
// The tagged pointer uses the LSB to disambiguate cases, and uses bit 0 == 0 to
|
||||
// indicate an arena pointer and bit 0 == 1 to indicate a UFS+Arena-container
|
||||
// pointer.
|
||||
class InternalMetadata {
|
||||
public:
|
||||
InternalMetadata() : ptr_(nullptr) {}
|
||||
explicit InternalMetadata(Arena* arena) : ptr_(arena) {}
|
||||
|
||||
template <typename T>
|
||||
void Delete() {
|
||||
// Note that Delete<> should be called not more than once.
|
||||
if (have_unknown_fields() && arena() == NULL) {
|
||||
delete PtrValue<Container<T>>();
|
||||
}
|
||||
}
|
||||
|
||||
PROTOBUF_ALWAYS_INLINE Arena* arena() const {
|
||||
if (PROTOBUF_PREDICT_FALSE(have_unknown_fields())) {
|
||||
return PtrValue<ContainerBase>()->arena;
|
||||
} else {
|
||||
return PtrValue<Arena>();
|
||||
}
|
||||
}
|
||||
|
||||
PROTOBUF_ALWAYS_INLINE bool have_unknown_fields() const {
|
||||
return PtrTag() == kTagContainer;
|
||||
}
|
||||
|
||||
PROTOBUF_ALWAYS_INLINE void* raw_arena_ptr() const { return ptr_; }
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE const T& unknown_fields(
|
||||
const T& (*default_instance)()) const {
|
||||
if (PROTOBUF_PREDICT_FALSE(have_unknown_fields())) {
|
||||
return PtrValue<Container<T>>()->unknown_fields;
|
||||
} else {
|
||||
return default_instance();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE T* mutable_unknown_fields() {
|
||||
if (PROTOBUF_PREDICT_TRUE(have_unknown_fields())) {
|
||||
return &PtrValue<Container<T>>()->unknown_fields;
|
||||
} else {
|
||||
return mutable_unknown_fields_slow<T>();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void Swap(InternalMetadata* other) {
|
||||
// Semantics here are that we swap only the unknown fields, not the arena
|
||||
// pointer. We cannot simply swap ptr_ with other->ptr_ because we need to
|
||||
// maintain our own arena ptr. Also, our ptr_ and other's ptr_ may be in
|
||||
// different states (direct arena pointer vs. container with UFS) so we
|
||||
// cannot simply swap ptr_ and then restore the arena pointers. We reuse
|
||||
// UFS's swap implementation instead.
|
||||
if (have_unknown_fields() || other->have_unknown_fields()) {
|
||||
DoSwap<T>(other->mutable_unknown_fields<T>());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void MergeFrom(const InternalMetadata& other) {
|
||||
if (other.have_unknown_fields()) {
|
||||
DoMergeFrom<T>(other.unknown_fields<T>(nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_ALWAYS_INLINE void Clear() {
|
||||
if (have_unknown_fields()) {
|
||||
DoClear<T>();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void* ptr_;
|
||||
|
||||
// Tagged pointer implementation.
|
||||
enum {
|
||||
// ptr_ is an Arena*.
|
||||
kTagArena = 0,
|
||||
// ptr_ is a Container*.
|
||||
kTagContainer = 1,
|
||||
};
|
||||
static constexpr intptr_t kPtrTagMask = 1;
|
||||
static constexpr intptr_t kPtrValueMask = ~kPtrTagMask;
|
||||
|
||||
// Accessors for pointer tag and pointer value.
|
||||
PROTOBUF_ALWAYS_INLINE int PtrTag() const {
|
||||
return reinterpret_cast<intptr_t>(ptr_) & kPtrTagMask;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
U* PtrValue() const {
|
||||
return reinterpret_cast<U*>(reinterpret_cast<intptr_t>(ptr_) &
|
||||
kPtrValueMask);
|
||||
}
|
||||
|
||||
// If ptr_'s tag is kTagContainer, it points to an instance of this struct.
|
||||
struct ContainerBase {
|
||||
Arena* arena;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Container : public ContainerBase {
|
||||
T unknown_fields;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_NOINLINE T* mutable_unknown_fields_slow() {
|
||||
Arena* my_arena = arena();
|
||||
Container<T>* container = Arena::Create<Container<T>>(my_arena);
|
||||
// Two-step assignment works around a bug in clang's static analyzer:
|
||||
// https://bugs.llvm.org/show_bug.cgi?id=34198.
|
||||
ptr_ = container;
|
||||
ptr_ = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(ptr_) |
|
||||
kTagContainer);
|
||||
container->arena = my_arena;
|
||||
return &(container->unknown_fields);
|
||||
}
|
||||
|
||||
// Templated functions.
|
||||
|
||||
template <typename T>
|
||||
void DoClear() {
|
||||
mutable_unknown_fields<T>()->Clear();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DoMergeFrom(const T& other) {
|
||||
mutable_unknown_fields<T>()->MergeFrom(other);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DoSwap(T* other) {
|
||||
mutable_unknown_fields<T>()->Swap(other);
|
||||
}
|
||||
};
|
||||
|
||||
// String Template specializations.
|
||||
|
||||
template <>
|
||||
inline void InternalMetadata::DoClear<std::string>() {
|
||||
mutable_unknown_fields<std::string>()->clear();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void InternalMetadata::DoMergeFrom<std::string>(
|
||||
const std::string& other) {
|
||||
mutable_unknown_fields<std::string>()->append(other);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void InternalMetadata::DoSwap<std::string>(std::string* other) {
|
||||
mutable_unknown_fields<std::string>()->swap(*other);
|
||||
}
|
||||
|
||||
// This helper RAII class is needed to efficiently parse unknown fields. We
|
||||
// should only call mutable_unknown_fields if there are actual unknown fields.
|
||||
// The obvious thing to just use a stack string and swap it at the end of
|
||||
// the parse won't work, because the destructor of StringOutputStream needs to
|
||||
// be called before we can modify the string (it check-fails). Using
|
||||
// LiteUnknownFieldSetter setter(&_internal_metadata_);
|
||||
// StringOutputStream stream(setter.buffer());
|
||||
// guarantees that the string is only swapped after stream is destroyed.
|
||||
class PROTOBUF_EXPORT LiteUnknownFieldSetter {
|
||||
public:
|
||||
explicit LiteUnknownFieldSetter(InternalMetadata* metadata)
|
||||
: metadata_(metadata) {
|
||||
if (metadata->have_unknown_fields()) {
|
||||
buffer_.swap(*metadata->mutable_unknown_fields<std::string>());
|
||||
}
|
||||
}
|
||||
~LiteUnknownFieldSetter() {
|
||||
if (!buffer_.empty())
|
||||
metadata_->mutable_unknown_fields<std::string>()->swap(buffer_);
|
||||
}
|
||||
std::string* buffer() { return &buffer_; }
|
||||
|
||||
private:
|
||||
InternalMetadata* metadata_;
|
||||
std::string buffer_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_METADATA_LITE_H__
|
809
include/google/protobuf/parse_context.h
Normal file
809
include/google/protobuf/parse_context.h
Normal file
@ -0,0 +1,809 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_PARSE_CONTEXT_H__
|
||||
#define GOOGLE_PROTOBUF_PARSE_CONTEXT_H__
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/implicit_weak_message.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/port.h>
|
||||
#include <google/protobuf/repeated_field.h>
|
||||
#include <google/protobuf/wire_format_lite.h>
|
||||
#include <google/protobuf/stubs/strutil.h>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
class UnknownFieldSet;
|
||||
class DescriptorPool;
|
||||
class MessageFactory;
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Template code below needs to know about the existence of these functions.
|
||||
PROTOBUF_EXPORT void WriteVarint(uint32 num, uint64 val, std::string* s);
|
||||
PROTOBUF_EXPORT void WriteLengthDelimited(uint32 num, StringPiece val,
|
||||
std::string* s);
|
||||
// Inline because it is just forwarding to s->WriteVarint
|
||||
inline void WriteVarint(uint32 num, uint64 val, UnknownFieldSet* s);
|
||||
inline void WriteLengthDelimited(uint32 num, StringPiece val,
|
||||
UnknownFieldSet* s);
|
||||
|
||||
|
||||
// The basic abstraction the parser is designed for is a slight modification
|
||||
// of the ZeroCopyInputStream (ZCIS) abstraction. A ZCIS presents a serialized
|
||||
// stream as a series of buffers that concatenate to the full stream.
|
||||
// Pictorially a ZCIS presents a stream in chunks like so
|
||||
// [---------------------------------------------------------------]
|
||||
// [---------------------] chunk 1
|
||||
// [----------------------------] chunk 2
|
||||
// chunk 3 [--------------]
|
||||
//
|
||||
// Where the '-' represent the bytes which are vertically lined up with the
|
||||
// bytes of the stream. The proto parser requires its input to be presented
|
||||
// similarly with the extra
|
||||
// property that each chunk has kSlopBytes past its end that overlaps with the
|
||||
// first kSlopBytes of the next chunk, or if there is no next chunk at least its
|
||||
// still valid to read those bytes. Again, pictorially, we now have
|
||||
//
|
||||
// [---------------------------------------------------------------]
|
||||
// [-------------------....] chunk 1
|
||||
// [------------------------....] chunk 2
|
||||
// chunk 3 [------------------..**]
|
||||
// chunk 4 [--****]
|
||||
// Here '-' mean the bytes of the stream or chunk and '.' means bytes past the
|
||||
// chunk that match up with the start of the next chunk. Above each chunk has
|
||||
// 4 '.' after the chunk. In the case these 'overflow' bytes represents bytes
|
||||
// past the stream, indicated by '*' above, their values are unspecified. It is
|
||||
// still legal to read them (ie. should not segfault). Reading past the
|
||||
// end should be detected by the user and indicated as an error.
|
||||
//
|
||||
// The reason for this, admittedly, unconventional invariant is to ruthlessly
|
||||
// optimize the protobuf parser. Having an overlap helps in two important ways.
|
||||
// Firstly it alleviates having to performing bounds checks if a piece of code
|
||||
// is guaranteed to not read more than kSlopBytes. Secondly, and more
|
||||
// importantly, the protobuf wireformat is such that reading a key/value pair is
|
||||
// always less than 16 bytes. This removes the need to change to next buffer in
|
||||
// the middle of reading primitive values. Hence there is no need to store and
|
||||
// load the current position.
|
||||
|
||||
class PROTOBUF_EXPORT EpsCopyInputStream {
|
||||
public:
|
||||
enum { kSlopBytes = 16, kMaxCordBytesToCopy = 512 };
|
||||
|
||||
explicit EpsCopyInputStream(bool enable_aliasing)
|
||||
: aliasing_(enable_aliasing ? kOnPatch : kNoAliasing) {}
|
||||
|
||||
void BackUp(const char* ptr) {
|
||||
GOOGLE_DCHECK(ptr <= buffer_end_ + kSlopBytes);
|
||||
int count;
|
||||
if (next_chunk_ == buffer_) {
|
||||
count = static_cast<int>(buffer_end_ + kSlopBytes - ptr);
|
||||
} else {
|
||||
count = size_ + static_cast<int>(buffer_end_ - ptr);
|
||||
}
|
||||
if (count > 0) StreamBackUp(count);
|
||||
}
|
||||
|
||||
// If return value is negative it's an error
|
||||
PROTOBUF_MUST_USE_RESULT int PushLimit(const char* ptr, int limit) {
|
||||
GOOGLE_DCHECK(limit >= 0 && limit <= INT_MAX - kSlopBytes);
|
||||
// This add is safe due to the invariant above, because
|
||||
// ptr - buffer_end_ <= kSlopBytes.
|
||||
limit += static_cast<int>(ptr - buffer_end_);
|
||||
limit_end_ = buffer_end_ + (std::min)(0, limit);
|
||||
auto old_limit = limit_;
|
||||
limit_ = limit;
|
||||
return old_limit - limit;
|
||||
}
|
||||
|
||||
PROTOBUF_MUST_USE_RESULT bool PopLimit(int delta) {
|
||||
if (PROTOBUF_PREDICT_FALSE(!EndedAtLimit())) return false;
|
||||
limit_ = limit_ + delta;
|
||||
// TODO(gerbens) We could remove this line and hoist the code to
|
||||
// DoneFallback. Study the perf/bin-size effects.
|
||||
limit_end_ = buffer_end_ + (std::min)(0, limit_);
|
||||
return true;
|
||||
}
|
||||
|
||||
PROTOBUF_MUST_USE_RESULT const char* Skip(const char* ptr, int size) {
|
||||
if (size <= buffer_end_ + kSlopBytes - ptr) {
|
||||
return ptr + size;
|
||||
}
|
||||
return SkipFallback(ptr, size);
|
||||
}
|
||||
PROTOBUF_MUST_USE_RESULT const char* ReadString(const char* ptr, int size,
|
||||
std::string* s) {
|
||||
if (size <= buffer_end_ + kSlopBytes - ptr) {
|
||||
s->assign(ptr, size);
|
||||
return ptr + size;
|
||||
}
|
||||
return ReadStringFallback(ptr, size, s);
|
||||
}
|
||||
PROTOBUF_MUST_USE_RESULT const char* AppendString(const char* ptr, int size,
|
||||
std::string* s) {
|
||||
if (size <= buffer_end_ + kSlopBytes - ptr) {
|
||||
s->append(ptr, size);
|
||||
return ptr + size;
|
||||
}
|
||||
return AppendStringFallback(ptr, size, s);
|
||||
}
|
||||
|
||||
template <typename Tag, typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* ReadRepeatedFixed(const char* ptr,
|
||||
Tag expected_tag,
|
||||
RepeatedField<T>* out);
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* ReadPackedFixed(const char* ptr,
|
||||
int size,
|
||||
RepeatedField<T>* out);
|
||||
template <typename Add>
|
||||
PROTOBUF_MUST_USE_RESULT const char* ReadPackedVarint(const char* ptr,
|
||||
Add add);
|
||||
|
||||
uint32 LastTag() const { return last_tag_minus_1_ + 1; }
|
||||
bool ConsumeEndGroup(uint32 start_tag) {
|
||||
bool res = last_tag_minus_1_ == start_tag;
|
||||
last_tag_minus_1_ = 0;
|
||||
return res;
|
||||
}
|
||||
bool EndedAtLimit() const { return last_tag_minus_1_ == 0; }
|
||||
bool EndedAtEndOfStream() const { return last_tag_minus_1_ == 1; }
|
||||
void SetLastTag(uint32 tag) { last_tag_minus_1_ = tag - 1; }
|
||||
void SetEndOfStream() { last_tag_minus_1_ = 1; }
|
||||
bool IsExceedingLimit(const char* ptr) {
|
||||
return ptr > limit_end_ &&
|
||||
(next_chunk_ == nullptr || ptr - buffer_end_ > limit_);
|
||||
}
|
||||
int BytesUntilLimit(const char* ptr) const {
|
||||
return limit_ + static_cast<int>(buffer_end_ - ptr);
|
||||
}
|
||||
// Returns true if more data is available, if false is returned one has to
|
||||
// call Done for further checks.
|
||||
bool DataAvailable(const char* ptr) { return ptr < limit_end_; }
|
||||
|
||||
protected:
|
||||
// Returns true is limit (either an explicit limit or end of stream) is
|
||||
// reached. It aligns *ptr across buffer seams.
|
||||
// If limit is exceeded it returns true and ptr is set to null.
|
||||
bool DoneWithCheck(const char** ptr, int d) {
|
||||
GOOGLE_DCHECK(*ptr);
|
||||
if (PROTOBUF_PREDICT_TRUE(*ptr < limit_end_)) return false;
|
||||
// No need to fetch buffer if we ended on a limit in the slop region
|
||||
if ((*ptr - buffer_end_) == limit_) return true;
|
||||
auto res = DoneFallback(*ptr, d);
|
||||
*ptr = res.first;
|
||||
return res.second;
|
||||
}
|
||||
|
||||
const char* InitFrom(StringPiece flat) {
|
||||
overall_limit_ = 0;
|
||||
if (flat.size() > kSlopBytes) {
|
||||
limit_ = kSlopBytes;
|
||||
limit_end_ = buffer_end_ = flat.data() + flat.size() - kSlopBytes;
|
||||
next_chunk_ = buffer_;
|
||||
if (aliasing_ == kOnPatch) aliasing_ = kNoDelta;
|
||||
return flat.data();
|
||||
} else {
|
||||
std::memcpy(buffer_, flat.data(), flat.size());
|
||||
limit_ = 0;
|
||||
limit_end_ = buffer_end_ = buffer_ + flat.size();
|
||||
next_chunk_ = nullptr;
|
||||
if (aliasing_ == kOnPatch) {
|
||||
aliasing_ = reinterpret_cast<std::uintptr_t>(flat.data()) -
|
||||
reinterpret_cast<std::uintptr_t>(buffer_);
|
||||
}
|
||||
return buffer_;
|
||||
}
|
||||
}
|
||||
|
||||
const char* InitFrom(io::ZeroCopyInputStream* zcis);
|
||||
|
||||
const char* InitFrom(io::ZeroCopyInputStream* zcis, int limit) {
|
||||
if (limit == -1) return InitFrom(zcis);
|
||||
overall_limit_ = limit;
|
||||
auto res = InitFrom(zcis);
|
||||
limit_ = limit - static_cast<int>(buffer_end_ - res);
|
||||
limit_end_ = buffer_end_ + (std::min)(0, limit_);
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
const char* limit_end_; // buffer_end_ + min(limit_, 0)
|
||||
const char* buffer_end_;
|
||||
const char* next_chunk_;
|
||||
int size_;
|
||||
int limit_; // relative to buffer_end_;
|
||||
io::ZeroCopyInputStream* zcis_ = nullptr;
|
||||
char buffer_[2 * kSlopBytes] = {};
|
||||
enum { kNoAliasing = 0, kOnPatch = 1, kNoDelta = 2 };
|
||||
std::uintptr_t aliasing_ = kNoAliasing;
|
||||
// This variable is used to communicate how the parse ended, in order to
|
||||
// completely verify the parsed data. A wire-format parse can end because of
|
||||
// one of the following conditions:
|
||||
// 1) A parse can end on a pushed limit.
|
||||
// 2) A parse can end on End Of Stream (EOS).
|
||||
// 3) A parse can end on 0 tag (only valid for toplevel message).
|
||||
// 4) A parse can end on an end-group tag.
|
||||
// This variable should always be set to 0, which indicates case 1. If the
|
||||
// parse terminated due to EOS (case 2), it's set to 1. In case the parse
|
||||
// ended due to a terminating tag (case 3 and 4) it's set to (tag - 1).
|
||||
// This var doesn't really belong in EpsCopyInputStream and should be part of
|
||||
// the ParseContext, but case 2 is most easily and optimally implemented in
|
||||
// DoneFallback.
|
||||
uint32 last_tag_minus_1_ = 0;
|
||||
int overall_limit_ = INT_MAX; // Overall limit independent of pushed limits.
|
||||
// Pretty random large number that seems like a safe allocation on most
|
||||
// systems. TODO(gerbens) do we need to set this as build flag?
|
||||
enum { kSafeStringSize = 50000000 };
|
||||
|
||||
std::pair<const char*, bool> DoneFallback(const char* ptr, int d);
|
||||
const char* Next(int overrun, int d);
|
||||
const char* SkipFallback(const char* ptr, int size);
|
||||
const char* AppendStringFallback(const char* ptr, int size, std::string* str);
|
||||
const char* ReadStringFallback(const char* ptr, int size, std::string* str);
|
||||
bool StreamNext(const void** data) {
|
||||
bool res = zcis_->Next(data, &size_);
|
||||
if (res) overall_limit_ -= size_;
|
||||
return res;
|
||||
}
|
||||
void StreamBackUp(int count) {
|
||||
zcis_->BackUp(count);
|
||||
overall_limit_ += count;
|
||||
}
|
||||
|
||||
template <typename A>
|
||||
const char* AppendSize(const char* ptr, int size, const A& append) {
|
||||
int chunk_size = buffer_end_ + kSlopBytes - ptr;
|
||||
do {
|
||||
GOOGLE_DCHECK(size > chunk_size);
|
||||
append(ptr, chunk_size);
|
||||
ptr += chunk_size;
|
||||
size -= chunk_size;
|
||||
// DoneFallBack asserts it isn't called when exactly on the limit. If this
|
||||
// happens we fail the parse, as we are at the limit and still more bytes
|
||||
// to read.
|
||||
if (limit_ == kSlopBytes) return nullptr;
|
||||
auto res = DoneFallback(ptr, -1);
|
||||
if (res.second) return nullptr; // If done we passed the limit
|
||||
ptr = res.first;
|
||||
chunk_size = buffer_end_ + kSlopBytes - ptr;
|
||||
} while (size > chunk_size);
|
||||
append(ptr, size);
|
||||
return ptr + size;
|
||||
}
|
||||
|
||||
// AppendUntilEnd appends data until a limit (either a PushLimit or end of
|
||||
// stream. Normal payloads are from length delimited fields which have an
|
||||
// explicit size. Reading until limit only comes when the string takes
|
||||
// the place of a protobuf, ie RawMessage/StringRawMessage, lazy fields and
|
||||
// implicit weak messages. We keep these methods private and friend them.
|
||||
template <typename A>
|
||||
const char* AppendUntilEnd(const char* ptr, const A& append) {
|
||||
while (!DoneWithCheck(&ptr, -1)) {
|
||||
append(ptr, limit_end_ - ptr);
|
||||
ptr = limit_end_;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PROTOBUF_MUST_USE_RESULT const char* AppendString(const char* ptr,
|
||||
std::string* str) {
|
||||
return AppendUntilEnd(
|
||||
ptr, [str](const char* p, ptrdiff_t s) { str->append(p, s); });
|
||||
}
|
||||
friend class ImplicitWeakMessage;
|
||||
};
|
||||
|
||||
// ParseContext holds all data that is global to the entire parse. Most
|
||||
// importantly it contains the input stream, but also recursion depth and also
|
||||
// stores the end group tag, in case a parser ended on a endgroup, to verify
|
||||
// matching start/end group tags.
|
||||
class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream {
|
||||
public:
|
||||
struct Data {
|
||||
const DescriptorPool* pool = nullptr;
|
||||
MessageFactory* factory = nullptr;
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
ParseContext(int depth, bool aliasing, const char** start, T&&... args)
|
||||
: EpsCopyInputStream(aliasing), depth_(depth) {
|
||||
*start = InitFrom(std::forward<T>(args)...);
|
||||
}
|
||||
|
||||
void TrackCorrectEnding() { group_depth_ = 0; }
|
||||
|
||||
bool Done(const char** ptr) { return DoneWithCheck(ptr, group_depth_); }
|
||||
bool DoneNoSlopCheck(const char** ptr) { return DoneWithCheck(ptr, -1); }
|
||||
|
||||
int depth() const { return depth_; }
|
||||
|
||||
Data& data() { return data_; }
|
||||
const Data& data() const { return data_; }
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* ParseMessage(T* msg, const char* ptr);
|
||||
// We outline when the type is generic and we go through a virtual
|
||||
const char* ParseMessage(MessageLite* msg, const char* ptr);
|
||||
const char* ParseMessage(Message* msg, const char* ptr);
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT PROTOBUF_ALWAYS_INLINE const char* ParseGroup(
|
||||
T* msg, const char* ptr, uint32 tag) {
|
||||
if (--depth_ < 0) return nullptr;
|
||||
group_depth_++;
|
||||
ptr = msg->_InternalParse(ptr, this);
|
||||
group_depth_--;
|
||||
depth_++;
|
||||
if (PROTOBUF_PREDICT_FALSE(!ConsumeEndGroup(tag))) return nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
// The context keeps an internal stack to keep track of the recursive
|
||||
// part of the parse state.
|
||||
// Current depth of the active parser, depth counts down.
|
||||
// This is used to limit recursion depth (to prevent overflow on malicious
|
||||
// data), but is also used to index in stack_ to store the current state.
|
||||
int depth_;
|
||||
// Unfortunately necessary for the fringe case of ending on 0 or end-group tag
|
||||
// in the last kSlopBytes of a ZeroCopyInputStream chunk.
|
||||
int group_depth_ = INT_MIN;
|
||||
Data data_;
|
||||
};
|
||||
|
||||
template <uint32 tag>
|
||||
bool ExpectTag(const char* ptr) {
|
||||
if (tag < 128) {
|
||||
return *ptr == tag;
|
||||
} else {
|
||||
static_assert(tag < 128 * 128, "We only expect tags for 1 or 2 bytes");
|
||||
char buf[2] = {static_cast<char>(tag | 0x80), static_cast<char>(tag >> 7)};
|
||||
return std::memcmp(ptr, buf, 2) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <int>
|
||||
struct EndianHelper;
|
||||
|
||||
template <>
|
||||
struct EndianHelper<1> {
|
||||
static uint8 Load(const void* p) { return *static_cast<const uint8*>(p); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct EndianHelper<2> {
|
||||
static uint16 Load(const void* p) {
|
||||
uint16 tmp;
|
||||
std::memcpy(&tmp, p, 2);
|
||||
#ifndef PROTOBUF_LITTLE_ENDIAN
|
||||
tmp = bswap_16(tmp);
|
||||
#endif
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct EndianHelper<4> {
|
||||
static uint32 Load(const void* p) {
|
||||
uint32 tmp;
|
||||
std::memcpy(&tmp, p, 4);
|
||||
#ifndef PROTOBUF_LITTLE_ENDIAN
|
||||
tmp = bswap_32(tmp);
|
||||
#endif
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct EndianHelper<8> {
|
||||
static uint64 Load(const void* p) {
|
||||
uint64 tmp;
|
||||
std::memcpy(&tmp, p, 8);
|
||||
#ifndef PROTOBUF_LITTLE_ENDIAN
|
||||
tmp = bswap_64(tmp);
|
||||
#endif
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T UnalignedLoad(const char* p) {
|
||||
auto tmp = EndianHelper<sizeof(T)>::Load(p);
|
||||
T res;
|
||||
memcpy(&res, &tmp, sizeof(T));
|
||||
return res;
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT
|
||||
std::pair<const char*, uint32> VarintParseSlow32(const char* p, uint32 res);
|
||||
PROTOBUF_EXPORT
|
||||
std::pair<const char*, uint64> VarintParseSlow64(const char* p, uint32 res);
|
||||
|
||||
inline const char* VarintParseSlow(const char* p, uint32 res, uint32* out) {
|
||||
auto tmp = VarintParseSlow32(p, res);
|
||||
*out = tmp.second;
|
||||
return tmp.first;
|
||||
}
|
||||
|
||||
inline const char* VarintParseSlow(const char* p, uint32 res, uint64* out) {
|
||||
auto tmp = VarintParseSlow64(p, res);
|
||||
*out = tmp.second;
|
||||
return tmp.first;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* VarintParse(const char* p, T* out) {
|
||||
auto ptr = reinterpret_cast<const uint8*>(p);
|
||||
uint32 res = ptr[0];
|
||||
if (!(res & 0x80)) {
|
||||
*out = res;
|
||||
return p + 1;
|
||||
}
|
||||
uint32 byte = ptr[1];
|
||||
res += (byte - 1) << 7;
|
||||
if (!(byte & 0x80)) {
|
||||
*out = res;
|
||||
return p + 2;
|
||||
}
|
||||
return VarintParseSlow(p, res, out);
|
||||
}
|
||||
|
||||
// Used for tags, could read up to 5 bytes which must be available.
|
||||
// Caller must ensure its safe to call.
|
||||
|
||||
PROTOBUF_EXPORT
|
||||
std::pair<const char*, uint32> ReadTagFallback(const char* p, uint32 res);
|
||||
|
||||
// Same as ParseVarint but only accept 5 bytes at most.
|
||||
inline const char* ReadTag(const char* p, uint32* out, uint32 /*max_tag*/ = 0) {
|
||||
uint32 res = static_cast<uint8>(p[0]);
|
||||
if (res < 128) {
|
||||
*out = res;
|
||||
return p + 1;
|
||||
}
|
||||
uint32 second = static_cast<uint8>(p[1]);
|
||||
res += (second - 1) << 7;
|
||||
if (second < 128) {
|
||||
*out = res;
|
||||
return p + 2;
|
||||
}
|
||||
auto tmp = ReadTagFallback(p, res);
|
||||
*out = tmp.second;
|
||||
return tmp.first;
|
||||
}
|
||||
|
||||
// Decode 2 consecutive bytes of a varint and returns the value, shifted left
|
||||
// by 1. It simultaneous updates *ptr to *ptr + 1 or *ptr + 2 depending if the
|
||||
// first byte's continuation bit is set.
|
||||
// If bit 15 of return value is set (equivalent to the continuation bits of both
|
||||
// bytes being set) the varint continues, otherwise the parse is done. On x86
|
||||
// movsx eax, dil
|
||||
// add edi, eax
|
||||
// adc [rsi], 1
|
||||
// add eax, eax
|
||||
// and eax, edi
|
||||
inline uint32 DecodeTwoBytes(const char** ptr) {
|
||||
uint32 value = UnalignedLoad<uint16>(*ptr);
|
||||
// Sign extend the low byte continuation bit
|
||||
uint32_t x = static_cast<int8_t>(value);
|
||||
// This add is an amazing operation, it cancels the low byte continuation bit
|
||||
// from y transferring it to the carry. Simultaneously it also shifts the 7
|
||||
// LSB left by one tightly against high byte varint bits. Hence value now
|
||||
// contains the unpacked value shifted left by 1.
|
||||
value += x;
|
||||
// Use the carry to update the ptr appropriately.
|
||||
*ptr += value < x ? 2 : 1;
|
||||
return value & (x + x); // Mask out the high byte iff no continuation
|
||||
}
|
||||
|
||||
// More efficient varint parsing for big varints
|
||||
inline const char* ParseBigVarint(const char* p, uint64* out) {
|
||||
auto pnew = p;
|
||||
auto tmp = DecodeTwoBytes(&pnew);
|
||||
uint64 res = tmp >> 1;
|
||||
if (PROTOBUF_PREDICT_TRUE(std::int16_t(tmp) >= 0)) {
|
||||
*out = res;
|
||||
return pnew;
|
||||
}
|
||||
for (std::uint32_t i = 1; i < 5; i++) {
|
||||
pnew = p + 2 * i;
|
||||
tmp = DecodeTwoBytes(&pnew);
|
||||
res += (static_cast<std::uint64_t>(tmp) - 2) << (14 * i - 1);
|
||||
if (PROTOBUF_PREDICT_TRUE(std::int16_t(tmp) >= 0)) {
|
||||
*out = res;
|
||||
return pnew;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT
|
||||
std::pair<const char*, int32> ReadSizeFallback(const char* p, uint32 first);
|
||||
// Used for tags, could read up to 5 bytes which must be available. Additionally
|
||||
// it makes sure the unsigned value fits a int32, otherwise returns nullptr.
|
||||
// Caller must ensure its safe to call.
|
||||
inline uint32 ReadSize(const char** pp) {
|
||||
auto p = *pp;
|
||||
uint32 res = static_cast<uint8>(p[0]);
|
||||
if (res < 128) {
|
||||
*pp = p + 1;
|
||||
return res;
|
||||
}
|
||||
auto x = ReadSizeFallback(p, res);
|
||||
*pp = x.first;
|
||||
return x.second;
|
||||
}
|
||||
|
||||
// Some convenience functions to simplify the generated parse loop code.
|
||||
// Returning the value and updating the buffer pointer allows for nicer
|
||||
// function composition. We rely on the compiler to inline this.
|
||||
// Also in debug compiles having local scoped variables tend to generated
|
||||
// stack frames that scale as O(num fields).
|
||||
inline uint64 ReadVarint64(const char** p) {
|
||||
uint64 tmp;
|
||||
*p = VarintParse(*p, &tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline uint32 ReadVarint32(const char** p) {
|
||||
uint32 tmp;
|
||||
*p = VarintParse(*p, &tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int64 ReadVarintZigZag64(const char** p) {
|
||||
uint64 tmp;
|
||||
*p = VarintParse(*p, &tmp);
|
||||
return WireFormatLite::ZigZagDecode64(tmp);
|
||||
}
|
||||
|
||||
inline int32 ReadVarintZigZag32(const char** p) {
|
||||
uint64 tmp;
|
||||
*p = VarintParse(*p, &tmp);
|
||||
return WireFormatLite::ZigZagDecode32(static_cast<uint32>(tmp));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* ParseContext::ParseMessage(
|
||||
T* msg, const char* ptr) {
|
||||
int size = ReadSize(&ptr);
|
||||
if (!ptr) return nullptr;
|
||||
auto old = PushLimit(ptr, size);
|
||||
if (--depth_ < 0) return nullptr;
|
||||
ptr = msg->_InternalParse(ptr, this);
|
||||
if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) return nullptr;
|
||||
depth_++;
|
||||
if (!PopLimit(old)) return nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename Add>
|
||||
const char* EpsCopyInputStream::ReadPackedVarint(const char* ptr, Add add) {
|
||||
int size = ReadSize(&ptr);
|
||||
if (ptr == nullptr) return nullptr;
|
||||
auto old = PushLimit(ptr, size);
|
||||
if (old < 0) return nullptr;
|
||||
while (!DoneWithCheck(&ptr, -1)) {
|
||||
uint64 varint;
|
||||
ptr = VarintParse(ptr, &varint);
|
||||
if (!ptr) return nullptr;
|
||||
add(varint);
|
||||
}
|
||||
if (!PopLimit(old)) return nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Helper for verification of utf8
|
||||
PROTOBUF_EXPORT
|
||||
bool VerifyUTF8(StringPiece s, const char* field_name);
|
||||
|
||||
inline bool VerifyUTF8(const std::string* s, const char* field_name) {
|
||||
return VerifyUTF8(*s, field_name);
|
||||
}
|
||||
|
||||
// All the string parsers with or without UTF checking and for all CTypes.
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* InlineGreedyStringParser(
|
||||
std::string* s, const char* ptr, ParseContext* ctx);
|
||||
|
||||
|
||||
// Add any of the following lines to debug which parse function is failing.
|
||||
|
||||
#define GOOGLE_PROTOBUF_ASSERT_RETURN(predicate, ret) \
|
||||
if (!(predicate)) { \
|
||||
/* ::raise(SIGINT); */ \
|
||||
/* GOOGLE_LOG(ERROR) << "Parse failure"; */ \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define GOOGLE_PROTOBUF_PARSER_ASSERT(predicate) \
|
||||
GOOGLE_PROTOBUF_ASSERT_RETURN(predicate, nullptr)
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* FieldParser(uint64 tag, T& field_parser,
|
||||
const char* ptr,
|
||||
ParseContext* ctx) {
|
||||
uint32 number = tag >> 3;
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(number != 0);
|
||||
using WireType = internal::WireFormatLite::WireType;
|
||||
switch (tag & 7) {
|
||||
case WireType::WIRETYPE_VARINT: {
|
||||
uint64 value;
|
||||
ptr = VarintParse(ptr, &value);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
field_parser.AddVarint(number, value);
|
||||
break;
|
||||
}
|
||||
case WireType::WIRETYPE_FIXED64: {
|
||||
uint64 value = UnalignedLoad<uint64>(ptr);
|
||||
ptr += 8;
|
||||
field_parser.AddFixed64(number, value);
|
||||
break;
|
||||
}
|
||||
case WireType::WIRETYPE_LENGTH_DELIMITED: {
|
||||
ptr = field_parser.ParseLengthDelimited(number, ptr, ctx);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
break;
|
||||
}
|
||||
case WireType::WIRETYPE_START_GROUP: {
|
||||
ptr = field_parser.ParseGroup(number, ptr, ctx);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
|
||||
break;
|
||||
}
|
||||
case WireType::WIRETYPE_END_GROUP: {
|
||||
GOOGLE_LOG(FATAL) << "Can't happen";
|
||||
break;
|
||||
}
|
||||
case WireType::WIRETYPE_FIXED32: {
|
||||
uint32 value = UnalignedLoad<uint32>(ptr);
|
||||
ptr += 4;
|
||||
field_parser.AddFixed32(number, value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_MUST_USE_RESULT const char* WireFormatParser(T& field_parser,
|
||||
const char* ptr,
|
||||
ParseContext* ctx) {
|
||||
while (!ctx->Done(&ptr)) {
|
||||
uint32 tag;
|
||||
ptr = ReadTag(ptr, &tag);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr != nullptr);
|
||||
if (tag == 0 || (tag & 7) == 4) {
|
||||
ctx->SetLastTag(tag);
|
||||
return ptr;
|
||||
}
|
||||
ptr = FieldParser(tag, field_parser, ptr, ctx);
|
||||
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr != nullptr);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// The packed parsers parse repeated numeric primitives directly into the
|
||||
// corresponding field
|
||||
|
||||
// These are packed varints
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedInt32Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedUInt32Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedInt64Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedUInt64Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedSInt32Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedSInt64Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
PROTOBUF_MUST_USE_RESULT const
|
||||
char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx,
|
||||
bool (*is_valid)(int), InternalMetadata* metadata,
|
||||
int field_num) {
|
||||
return ctx->ReadPackedVarint(
|
||||
ptr, [object, is_valid, metadata, field_num](uint64 val) {
|
||||
if (is_valid(val)) {
|
||||
static_cast<RepeatedField<int>*>(object)->Add(val);
|
||||
} else {
|
||||
WriteVarint(field_num, val, metadata->mutable_unknown_fields<T>());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
PROTOBUF_MUST_USE_RESULT const
|
||||
char* PackedEnumParserArg(void* object, const char* ptr, ParseContext* ctx,
|
||||
bool (*is_valid)(const void*, int),
|
||||
const void* data, InternalMetadata* metadata,
|
||||
int field_num) {
|
||||
return ctx->ReadPackedVarint(
|
||||
ptr, [object, is_valid, data, metadata, field_num](uint64 val) {
|
||||
if (is_valid(data, val)) {
|
||||
static_cast<RepeatedField<int>*>(object)->Add(val);
|
||||
} else {
|
||||
WriteVarint(field_num, val, metadata->mutable_unknown_fields<T>());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedBoolParser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedFixed32Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedSFixed32Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedFixed64Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedSFixed64Parser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedFloatParser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedDoubleParser(
|
||||
void* object, const char* ptr, ParseContext* ctx);
|
||||
|
||||
// This is the only recursive parser.
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* UnknownGroupLiteParse(
|
||||
std::string* unknown, const char* ptr, ParseContext* ctx);
|
||||
// This is a helper to for the UnknownGroupLiteParse but is actually also
|
||||
// useful in the generated code. It uses overload on std::string* vs
|
||||
// UnknownFieldSet* to make the generated code isomorphic between full and lite.
|
||||
PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* UnknownFieldParse(
|
||||
uint32 tag, std::string* unknown, const char* ptr, ParseContext* ctx);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_PARSE_CONTEXT_H__
|
43
include/google/protobuf/port.h
Normal file
43
include/google/protobuf/port.h
Normal file
@ -0,0 +1,43 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// A common header that is included across all protobuf headers. We do our best
|
||||
// to avoid #defining any macros here; instead we generally put macros in
|
||||
// port_def.inc and port_undef.inc so they are not visible from outside of
|
||||
// protobuf.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_PORT_H__
|
||||
#define GOOGLE_PROTOBUF_PORT_H__
|
||||
|
||||
|
||||
#include <google/protobuf/stubs/port.h>
|
||||
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_PORT_H__
|
486
include/google/protobuf/port_def.inc
Normal file
486
include/google/protobuf/port_def.inc
Normal file
@ -0,0 +1,486 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file defines common macros that are used in protobuf.
|
||||
//
|
||||
// To hide these definitions from the outside world (and to prevent collisions
|
||||
// if more than one version of protobuf is #included in the same project) you
|
||||
// must follow this pattern when #including port_def.inc in a header file:
|
||||
//
|
||||
// #include "other_header.h"
|
||||
// #include "message.h"
|
||||
// // etc.
|
||||
//
|
||||
// #include "port_def.inc" // MUST be last header included
|
||||
//
|
||||
// // Definitions for this header.
|
||||
//
|
||||
// #include "port_undef.inc"
|
||||
//
|
||||
// This is a textual header with no include guard, because we want to
|
||||
// detect/prohibit anytime it is #included twice without a corresponding
|
||||
// #undef.
|
||||
|
||||
// These macros are private and should always be
|
||||
// ::util::RetrieveErrorSpace(*this) headers. If any of these errors fire, you
|
||||
// should either properly #include port_undef.h at the end of your header that
|
||||
// #includes port.h, or don't #include port.h twice in a .cc file.
|
||||
#ifdef PROTOBUF_NAMESPACE
|
||||
#error PROTOBUF_NAMESPACE was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_NAMESPACE_ID
|
||||
#error PROTOBUF_NAMESPACE_ID was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_ALWAYS_INLINE
|
||||
#error PROTOBUF_ALWAYS_INLINE was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_COLD
|
||||
#error PROTOBUF_COLD was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_NOINLINE
|
||||
#error PROTOBUF_NOINLINE was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_SECTION_VARIABLE
|
||||
#error PROTOBUF_SECTION_VARIABLE was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_DEPRECATED
|
||||
#error PROTOBUF_DEPRECATED was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_DEPRECATED_MSG
|
||||
#error PROTOBUF_DEPRECATED_MSG was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_FUNC_ALIGN
|
||||
#error PROTOBUF_FUNC_ALIGN was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_RETURNS_NONNULL
|
||||
#error PROTOBUF_RETURNS_NONNULL was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_ATTRIBUTE_REINITIALIZES
|
||||
#error PROTOBUF_ATTRIBUTE_REINITIALIZES was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_RTTI
|
||||
#error PROTOBUF_RTTI was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_VERSION
|
||||
#error PROTOBUF_VERSION was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_VERSION_SUFFIX
|
||||
#error PROTOBUF_VERSION_SUFFIX was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC
|
||||
#error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error PROTOBUF_MIN_PROTOC_VERSION was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_PREDICT_TRUE
|
||||
#error PROTOBUF_PREDICT_TRUE was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_PREDICT_FALSE
|
||||
#error PROTOBUF_PREDICT_FALSE was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_FIELD_OFFSET
|
||||
#error PROTOBUF_FIELD_OFFSET was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_LL_FORMAT
|
||||
#error PROTOBUF_LL_FORMAT was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_GUARDED_BY
|
||||
#error PROTOBUF_GUARDED_BY was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_LONGLONG
|
||||
#error PROTOBUF_LONGLONG was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_ULONGLONG
|
||||
#error PROTOBUF_ULONGLONG was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_FALLTHROUGH_INTENDED
|
||||
#error PROTOBUF_FALLTHROUGH_INTENDED was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_EXPORT
|
||||
#error PROTOBUF_EXPORT was previously defined
|
||||
#endif
|
||||
#ifdef PROTOC_EXPORT
|
||||
#error PROTOC_EXPORT was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_MUST_USE_RESULT
|
||||
#error PROTOBUF_MUST_USE_RESULT was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_UNUSED
|
||||
#error PROTOBUF_UNUSED was previously defined
|
||||
#endif
|
||||
#ifdef PROTOBUF_FINAL
|
||||
#error PROTOBUF_FINAL was previously defined
|
||||
#endif
|
||||
|
||||
|
||||
#define PROTOBUF_NAMESPACE "google::protobuf"
|
||||
#define PROTOBUF_NAMESPACE_ID google::protobuf
|
||||
#define PROTOBUF_NAMESPACE_OPEN \
|
||||
namespace google { \
|
||||
namespace protobuf {
|
||||
#define PROTOBUF_NAMESPACE_CLOSE \
|
||||
} /* namespace protobuf */ \
|
||||
} /* namespace google */
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define PROTOBUF_DEPRECATED __attribute__((deprecated))
|
||||
#define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated))
|
||||
#define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define PROTOBUF_DEPRECATED __declspec(deprecated)
|
||||
#define PROTOBUF_DEPRECATED_ENUM
|
||||
#define PROTOBUF_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
|
||||
#endif
|
||||
|
||||
#define PROTOBUF_SECTION_VARIABLE(x)
|
||||
#define PROTOBUF_MUST_USE_RESULT
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Annotations: Some parts of the code have been annotated in ways that might
|
||||
// be useful to some compilers or tools, but are not supported universally.
|
||||
// You can #define these annotations yourself if the default implementation
|
||||
// is not right for you.
|
||||
|
||||
#ifdef GOOGLE_ATTRIBUTE_ALWAYS_INLINE
|
||||
#define PROTOBUF_ALWAYS_INLINE GOOGLE_ATTRIBUTE_ALWAYS_INLINE
|
||||
#else
|
||||
#if defined(__GNUC__) && \
|
||||
(__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
|
||||
// For functions we want to force inline.
|
||||
// Introduced in gcc 3.1.
|
||||
#define PROTOBUF_ALWAYS_INLINE __attribute__((always_inline))
|
||||
#else
|
||||
// Other compilers will have to figure it out for themselves.
|
||||
#define PROTOBUF_ALWAYS_INLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GOOGLE_ATTRIBUTE_NOINLINE
|
||||
#define PROTOBUF_NOINLINE GOOGLE_ATTRIBUTE_NOINLINE
|
||||
#else
|
||||
#if defined(__GNUC__) && \
|
||||
(__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
|
||||
// For functions we want to force not inline.
|
||||
// Introduced in gcc 3.1.
|
||||
#define PROTOBUF_NOINLINE __attribute__((noinline))
|
||||
#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
// Seems to have been around since at least Visual Studio 2005
|
||||
#define PROTOBUF_NOINLINE __declspec(noinline)
|
||||
#else
|
||||
// Other compilers will have to figure it out for themselves.
|
||||
#define PROTOBUF_NOINLINE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GOOGLE_ATTRIBUTE_FUNC_ALIGN
|
||||
#define PROTOBUF_FUNC_ALIGN GOOGLE_ATTRIBUTE_FUNC_ALIGN
|
||||
#else
|
||||
#if defined(__clang__) || \
|
||||
defined(__GNUC__) && \
|
||||
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
|
||||
// Function alignment attribute introduced in gcc 4.3
|
||||
#define PROTOBUF_FUNC_ALIGN(bytes) __attribute__((aligned(bytes)))
|
||||
#else
|
||||
#define PROTOBUF_FUNC_ALIGN(bytes)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GOOGLE_PREDICT_TRUE
|
||||
#define PROTOBUF_PREDICT_TRUE GOOGLE_PREDICT_TRUE
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
// Provided at least since GCC 3.0.
|
||||
#define PROTOBUF_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
|
||||
#else
|
||||
#define PROTOBUF_PREDICT_TRUE(x) (x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GOOGLE_PREDICT_FALSE
|
||||
#define PROTOBUF_PREDICT_FALSE GOOGLE_PREDICT_FALSE
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
// Provided at least since GCC 3.0.
|
||||
#define PROTOBUF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
|
||||
#else
|
||||
#define PROTOBUF_PREDICT_FALSE(x) (x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GOOGLE_PROTOBUF_ATTRIBUTE_RETURNS_NONNULL
|
||||
#define PROTOBUF_RETURNS_NONNULL GOOGLE_PROTOBUF_ATTRIBUTE_RETURNS_NONNULL
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#define PROTOBUF_RETURNS_NONNULL __attribute__((returns_nonnull))
|
||||
#else
|
||||
#define PROTOBUF_RETURNS_NONNULL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(clang::reinitializes)
|
||||
#define PROTOBUF_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PROTOBUF_ATTRIBUTE_REINITIALIZES
|
||||
#define PROTOBUF_ATTRIBUTE_REINITIALIZES
|
||||
#endif
|
||||
|
||||
#define PROTOBUF_GUARDED_BY(x)
|
||||
#define PROTOBUF_COLD
|
||||
|
||||
// Copied from ABSL.
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
|
||||
#define PROTOBUF_FALLTHROUGH_INTENDED [[clang::fallthrough]]
|
||||
#endif
|
||||
#elif defined(__GNUC__) && __GNUC__ >= 7
|
||||
#define PROTOBUF_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
|
||||
#endif
|
||||
|
||||
#ifndef PROTOBUF_FALLTHROUGH_INTENDED
|
||||
#define PROTOBUF_FALLTHROUGH_INTENDED
|
||||
#endif
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#define HAS_ATTRIBUTE(attr) __has_cpp_attribute(attr)
|
||||
#else
|
||||
#define HAS_ATTRIBUTE(attr) 0
|
||||
#endif
|
||||
|
||||
#if HAS_ATTRIBUTE(unused) || (defined(__GNUC__) && !defined(__clang__))
|
||||
#define PROTOBUF_UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define PROTOBUF_UNUSED
|
||||
#endif
|
||||
|
||||
#undef HAS_ATTRIBUTE
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define PROTOBUF_LONGLONG(x) x##I64
|
||||
#define PROTOBUF_ULONGLONG(x) x##UI64
|
||||
#define PROTOBUF_LL_FORMAT "I64" // As in printf("%I64d", ...)
|
||||
#else
|
||||
// By long long, we actually mean int64.
|
||||
#define PROTOBUF_LONGLONG(x) x##LL
|
||||
#define PROTOBUF_ULONGLONG(x) x##ULL
|
||||
// Used to format real long long integers.
|
||||
#define PROTOBUF_LL_FORMAT \
|
||||
"ll" // As in "%lld". Note that "q" is poor form also.
|
||||
#endif
|
||||
|
||||
|
||||
// Shared google3/opensource definitions. //////////////////////////////////////
|
||||
|
||||
#define PROTOBUF_VERSION 3012004
|
||||
#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 3012000
|
||||
#define PROTOBUF_MIN_PROTOC_VERSION 3012000
|
||||
#define PROTOBUF_VERSION_SUFFIX ""
|
||||
|
||||
// The minimum library version which works with the current version of the
|
||||
// headers.
|
||||
#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3012000
|
||||
|
||||
#if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI
|
||||
#define PROTOBUF_RTTI 0
|
||||
#elif defined(__has_feature)
|
||||
// https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
|
||||
#define PROTOBUF_RTTI __has_feature(cxx_rtti)
|
||||
#elif !defined(__cxx_rtti)
|
||||
// https://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros#C.2B.2B98
|
||||
#define PROTOBUF_RTTI 0
|
||||
#elif defined(__GNUC__) && !defined(__GXX_RTTI)
|
||||
#https: // gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
|
||||
#define PROTOBUF_RTTI 0
|
||||
#else
|
||||
#define PROTOBUF_RTTI 1
|
||||
#endif
|
||||
|
||||
// Returns the offset of the given field within the given aggregate type.
|
||||
// This is equivalent to the ANSI C offsetof() macro. However, according
|
||||
// to the C++ standard, offsetof() only works on POD types, and GCC
|
||||
// enforces this requirement with a warning. In practice, this rule is
|
||||
// unnecessarily strict; there is probably no compiler or platform on
|
||||
// which the offsets of the direct fields of a class are non-constant.
|
||||
// Fields inherited from superclasses *can* have non-constant offsets,
|
||||
// but that's not what this macro will be used for.
|
||||
#if defined(__clang__)
|
||||
// For Clang we use __builtin_offsetof() and suppress the warning,
|
||||
// to avoid Control Flow Integrity and UBSan vptr sanitizers from
|
||||
// crashing while trying to validate the invalid reinterpet_casts.
|
||||
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
|
||||
__builtin_offsetof(TYPE, FIELD) \
|
||||
_Pragma("clang diagnostic pop")
|
||||
#elif defined(__GNUC__) && \
|
||||
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
|
||||
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD)
|
||||
#else // defined(__clang__)
|
||||
// Note that we calculate relative to the pointer value 16 here since if we
|
||||
// just use zero, GCC complains about dereferencing a NULL pointer. We
|
||||
// choose 16 rather than some other number just in case the compiler would
|
||||
// be confused by an unaligned pointer.
|
||||
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
|
||||
static_cast< ::google::protobuf::uint32>(reinterpret_cast<const char*>( \
|
||||
&reinterpret_cast<const TYPE*>(16)->FIELD) - \
|
||||
reinterpret_cast<const char*>(16))
|
||||
#endif
|
||||
|
||||
#if defined(PROTOBUF_USE_DLLS)
|
||||
#if defined(_MSC_VER)
|
||||
#ifdef LIBPROTOBUF_EXPORTS
|
||||
#define PROTOBUF_EXPORT __declspec(dllexport)
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
|
||||
#else
|
||||
#define PROTOBUF_EXPORT __declspec(dllimport)
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
|
||||
#endif
|
||||
#ifdef LIBPROTOC_EXPORTS
|
||||
#define PROTOC_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define PROTOC_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else // defined(_MSC_VER)
|
||||
#ifdef LIBPROTOBUF_EXPORTS
|
||||
#define PROTOBUF_EXPORT __attribute__((visibility("default")))
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
#else
|
||||
#define PROTOBUF_EXPORT
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
#endif
|
||||
#ifdef LIBPROTOC_EXPORTS
|
||||
#define PROTOC_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PROTOC_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#else // defined(PROTOBUF_USE_DLLS)
|
||||
#define PROTOBUF_EXPORT
|
||||
#define PROTOC_EXPORT
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
|
||||
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
#endif
|
||||
|
||||
// Windows declares several inconvenient macro names. We #undef them and then
|
||||
// restore them in port_undef.inc.
|
||||
#ifdef _MSC_VER
|
||||
#pragma push_macro("ERROR")
|
||||
#undef ERROR
|
||||
#pragma push_macro("GetMessage")
|
||||
#undef GetMessage
|
||||
#pragma push_macro("IGNORE")
|
||||
#undef IGNORE
|
||||
#pragma push_macro("IN")
|
||||
#undef IN
|
||||
#pragma push_macro("OUT")
|
||||
#undef OUT
|
||||
#pragma push_macro("OPTIONAL")
|
||||
#undef OPTIONAL
|
||||
#pragma push_macro("min")
|
||||
#undef min
|
||||
#pragma push_macro("max")
|
||||
#undef max
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||
// Don't let the YES/NO Objective-C Macros interfere with proto identifiers with
|
||||
// the same name.
|
||||
#pragma push_macro("YES")
|
||||
#undef YES
|
||||
#pragma push_macro("NO")
|
||||
#undef NO
|
||||
#endif // defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
// TODO(gerbens) ideally we cleanup the code. But a cursory try shows many
|
||||
// violations. So let's ignore for now.
|
||||
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
||||
#elif defined(__GNUC__)
|
||||
// GCC does not allow disabling diagnostics within an expression:
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one
|
||||
// globally even though it's only used for PROTOBUF_FIELD_OFFSET.
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||
#endif
|
||||
|
||||
// PROTOBUF_ASSUME(pred) tells the compiler that it can assume pred is true. To
|
||||
// be safe, we also validate the assumption with a GOOGLE_DCHECK in unoptimized
|
||||
// builds. The macro does not do anything useful if the compiler does not
|
||||
// support __builtin_assume.
|
||||
#ifdef __has_builtin
|
||||
#if __has_builtin(__builtin_assume)
|
||||
#define PROTOBUF_ASSUME(pred) \
|
||||
GOOGLE_DCHECK(pred); \
|
||||
__builtin_assume(pred)
|
||||
#else
|
||||
#define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred)
|
||||
#endif
|
||||
#else
|
||||
#define PROTOBUF_ASSUME(pred) GOOGLE_DCHECK(pred)
|
||||
#endif
|
||||
|
||||
// Specify memory alignment for structs, classes, etc.
|
||||
// Use like:
|
||||
// class PROTOBUF_ALIGNAS(16) MyClass { ... }
|
||||
// PROTOBUF_ALIGNAS(16) int array[4];
|
||||
//
|
||||
// In most places you can use the C++11 keyword "alignas", which is preferred.
|
||||
//
|
||||
// But compilers have trouble mixing __attribute__((...)) syntax with
|
||||
// alignas(...) syntax.
|
||||
//
|
||||
// Doesn't work in clang or gcc:
|
||||
// struct alignas(16) __attribute__((packed)) S { char c; };
|
||||
// Works in clang but not gcc:
|
||||
// struct __attribute__((packed)) alignas(16) S2 { char c; };
|
||||
// Works in clang and gcc:
|
||||
// struct alignas(16) S3 { char c; } __attribute__((packed));
|
||||
//
|
||||
// There are also some attributes that must be specified *before* a class
|
||||
// definition: visibility (used for exporting functions/classes) is one of
|
||||
// these attributes. This means that it is not possible to use alignas() with a
|
||||
// class that is marked as exported.
|
||||
#if defined(_MSC_VER)
|
||||
#define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
|
||||
#elif defined(__GNUC__)
|
||||
#define PROTOBUF_ALIGNAS(byte_alignment) \
|
||||
__attribute__((aligned(byte_alignment)))
|
||||
#else
|
||||
#define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment)
|
||||
#endif
|
||||
|
||||
#define PROTOBUF_FINAL final
|
95
include/google/protobuf/port_undef.inc
Normal file
95
include/google/protobuf/port_undef.inc
Normal file
@ -0,0 +1,95 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// #undefs all macros defined in port_def.inc. See comments in port_def.inc
|
||||
// for more info.
|
||||
|
||||
#ifndef PROTOBUF_NAMESPACE
|
||||
#error "port_undef.inc must be included after port_def.inc"
|
||||
#endif
|
||||
#undef PROTOBUF_NAMESPACE
|
||||
#undef PROTOBUF_NAMESPACE_ID
|
||||
#undef PROTOBUF_ALWAYS_INLINE
|
||||
#undef PROTOBUF_COLD
|
||||
#undef PROTOBUF_NOINLINE
|
||||
#undef PROTOBUF_SECTION_VARIABLE
|
||||
#undef PROTOBUF_DEPRECATED
|
||||
#undef PROTOBUF_DEPRECATED_ENUM
|
||||
#undef PROTOBUF_DEPRECATED_MSG
|
||||
#undef PROTOBUF_FUNC_ALIGN
|
||||
#undef PROTOBUF_RETURNS_NONNULL
|
||||
#undef PROTOBUF_ATTRIBUTE_REINITIALIZES
|
||||
#undef PROTOBUF_RTTI
|
||||
#undef PROTOBUF_VERSION
|
||||
#undef PROTOBUF_VERSION_SUFFIX
|
||||
#undef PROTOBUF_FIELD_OFFSET
|
||||
#undef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC
|
||||
#undef PROTOBUF_MIN_PROTOC_VERSION
|
||||
#undef PROTOBUF_PREDICT_TRUE
|
||||
#undef PROTOBUF_PREDICT_FALSE
|
||||
#undef PROTOBUF_LONGLONG
|
||||
#undef PROTOBUF_ULONGLONG
|
||||
#undef PROTOBUF_LL_FORMAT
|
||||
#undef PROTOBUF_GUARDED_BY
|
||||
#undef PROTOBUF_FALLTHROUGH_INTENDED
|
||||
#undef PROTOBUF_EXPORT
|
||||
#undef PROTOC_EXPORT
|
||||
#undef PROTOBUF_MUST_USE_RESULT
|
||||
#undef PROTOBUF_NAMESPACE_OPEN
|
||||
#undef PROTOBUF_NAMESPACE_CLOSE
|
||||
#undef PROTOBUF_UNUSED
|
||||
#undef PROTOBUF_ASSUME
|
||||
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE
|
||||
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
#undef PROTOBUF_ALIGNAS
|
||||
#undef PROTOBUF_FINAL
|
||||
|
||||
// Restore macro that may have been #undef'd in port_def.inc.
|
||||
#ifdef _MSC_VER
|
||||
#pragma pop_macro("ERROR")
|
||||
#pragma pop_macro("GetMessage")
|
||||
#pragma pop_macro("IGNORE")
|
||||
#pragma pop_macro("IN")
|
||||
#pragma pop_macro("OUT")
|
||||
#pragma pop_macro("OPTIONAL")
|
||||
#pragma pop_macro("min")
|
||||
#pragma pop_macro("max")
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||
#pragma pop_macro("YES")
|
||||
#pragma pop_macro("NO")
|
||||
#endif // defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
563
include/google/protobuf/reflection.h
Normal file
563
include/google/protobuf/reflection.h
Normal file
@ -0,0 +1,563 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This header defines the RepeatedFieldRef class template used to access
|
||||
// repeated fields with protobuf reflection API.
|
||||
#ifndef GOOGLE_PROTOBUF_REFLECTION_H__
|
||||
#define GOOGLE_PROTOBUF_REFLECTION_H__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/generated_enum_util.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
template <typename T, typename Enable = void>
|
||||
struct RefTypeTraits;
|
||||
} // namespace internal
|
||||
|
||||
template <typename T>
|
||||
RepeatedFieldRef<T> Reflection::GetRepeatedFieldRef(
|
||||
const Message& message, const FieldDescriptor* field) const {
|
||||
return RepeatedFieldRef<T>(message, field);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MutableRepeatedFieldRef<T> Reflection::GetMutableRepeatedFieldRef(
|
||||
Message* message, const FieldDescriptor* field) const {
|
||||
return MutableRepeatedFieldRef<T>(message, field);
|
||||
}
|
||||
|
||||
// RepeatedFieldRef definition for non-message types.
|
||||
template <typename T>
|
||||
class RepeatedFieldRef<
|
||||
T, typename std::enable_if<!std::is_base_of<Message, T>::value>::type> {
|
||||
typedef typename internal::RefTypeTraits<T>::iterator IteratorType;
|
||||
typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
|
||||
|
||||
public:
|
||||
bool empty() const { return accessor_->IsEmpty(data_); }
|
||||
int size() const { return accessor_->Size(data_); }
|
||||
T Get(int index) const { return accessor_->template Get<T>(data_, index); }
|
||||
|
||||
typedef IteratorType iterator;
|
||||
typedef IteratorType const_iterator;
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef int size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
iterator begin() const { return iterator(data_, accessor_, true); }
|
||||
iterator end() const { return iterator(data_, accessor_, false); }
|
||||
|
||||
private:
|
||||
friend class Reflection;
|
||||
RepeatedFieldRef(const Message& message, const FieldDescriptor* field) {
|
||||
const Reflection* reflection = message.GetReflection();
|
||||
data_ = reflection->RepeatedFieldData(const_cast<Message*>(&message), field,
|
||||
internal::RefTypeTraits<T>::cpp_type,
|
||||
NULL);
|
||||
accessor_ = reflection->RepeatedFieldAccessor(field);
|
||||
}
|
||||
|
||||
const void* data_;
|
||||
const AccessorType* accessor_;
|
||||
};
|
||||
|
||||
// MutableRepeatedFieldRef definition for non-message types.
|
||||
template <typename T>
|
||||
class MutableRepeatedFieldRef<
|
||||
T, typename std::enable_if<!std::is_base_of<Message, T>::value>::type> {
|
||||
typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
|
||||
|
||||
public:
|
||||
bool empty() const { return accessor_->IsEmpty(data_); }
|
||||
int size() const { return accessor_->Size(data_); }
|
||||
T Get(int index) const { return accessor_->template Get<T>(data_, index); }
|
||||
|
||||
void Set(int index, const T& value) const {
|
||||
accessor_->template Set<T>(data_, index, value);
|
||||
}
|
||||
void Add(const T& value) const { accessor_->template Add<T>(data_, value); }
|
||||
void RemoveLast() const { accessor_->RemoveLast(data_); }
|
||||
void SwapElements(int index1, int index2) const {
|
||||
accessor_->SwapElements(data_, index1, index2);
|
||||
}
|
||||
void Clear() const { accessor_->Clear(data_); }
|
||||
|
||||
void Swap(const MutableRepeatedFieldRef& other) const {
|
||||
accessor_->Swap(data_, other.accessor_, other.data_);
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void MergeFrom(const Container& container) const {
|
||||
typedef typename Container::const_iterator Iterator;
|
||||
for (Iterator it = container.begin(); it != container.end(); ++it) {
|
||||
Add(*it);
|
||||
}
|
||||
}
|
||||
template <typename Container>
|
||||
void CopyFrom(const Container& container) const {
|
||||
Clear();
|
||||
MergeFrom(container);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Reflection;
|
||||
MutableRepeatedFieldRef(Message* message, const FieldDescriptor* field) {
|
||||
const Reflection* reflection = message->GetReflection();
|
||||
data_ = reflection->RepeatedFieldData(
|
||||
message, field, internal::RefTypeTraits<T>::cpp_type, NULL);
|
||||
accessor_ = reflection->RepeatedFieldAccessor(field);
|
||||
}
|
||||
|
||||
void* data_;
|
||||
const AccessorType* accessor_;
|
||||
};
|
||||
|
||||
// RepeatedFieldRef definition for message types.
|
||||
template <typename T>
|
||||
class RepeatedFieldRef<
|
||||
T, typename std::enable_if<std::is_base_of<Message, T>::value>::type> {
|
||||
typedef typename internal::RefTypeTraits<T>::iterator IteratorType;
|
||||
typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
|
||||
|
||||
public:
|
||||
bool empty() const { return accessor_->IsEmpty(data_); }
|
||||
int size() const { return accessor_->Size(data_); }
|
||||
// This method returns a reference to the underlying message object if it
|
||||
// exists. If a message object doesn't exist (e.g., data stored in serialized
|
||||
// form), scratch_space will be filled with the data and a reference to it
|
||||
// will be returned.
|
||||
//
|
||||
// Example:
|
||||
// RepeatedFieldRef<Message> h = ...
|
||||
// unique_ptr<Message> scratch_space(h.NewMessage());
|
||||
// const Message& item = h.Get(index, scratch_space.get());
|
||||
const T& Get(int index, T* scratch_space) const {
|
||||
return *static_cast<const T*>(accessor_->Get(data_, index, scratch_space));
|
||||
}
|
||||
// Create a new message of the same type as the messages stored in this
|
||||
// repeated field. Caller takes ownership of the returned object.
|
||||
T* NewMessage() const { return static_cast<T*>(default_instance_->New()); }
|
||||
|
||||
typedef IteratorType iterator;
|
||||
typedef IteratorType const_iterator;
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef int size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
iterator begin() const {
|
||||
return iterator(data_, accessor_, true, NewMessage());
|
||||
}
|
||||
iterator end() const {
|
||||
// The end iterator must not be dereferenced, no need for scratch space.
|
||||
return iterator(data_, accessor_, false, nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Reflection;
|
||||
RepeatedFieldRef(const Message& message, const FieldDescriptor* field) {
|
||||
const Reflection* reflection = message.GetReflection();
|
||||
data_ = reflection->RepeatedFieldData(
|
||||
const_cast<Message*>(&message), field,
|
||||
internal::RefTypeTraits<T>::cpp_type,
|
||||
internal::RefTypeTraits<T>::GetMessageFieldDescriptor());
|
||||
accessor_ = reflection->RepeatedFieldAccessor(field);
|
||||
default_instance_ =
|
||||
reflection->GetMessageFactory()->GetPrototype(field->message_type());
|
||||
}
|
||||
|
||||
const void* data_;
|
||||
const AccessorType* accessor_;
|
||||
const Message* default_instance_;
|
||||
};
|
||||
|
||||
// MutableRepeatedFieldRef definition for message types.
|
||||
template <typename T>
|
||||
class MutableRepeatedFieldRef<
|
||||
T, typename std::enable_if<std::is_base_of<Message, T>::value>::type> {
|
||||
typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
|
||||
|
||||
public:
|
||||
bool empty() const { return accessor_->IsEmpty(data_); }
|
||||
int size() const { return accessor_->Size(data_); }
|
||||
// See comments for RepeatedFieldRef<Message>::Get()
|
||||
const T& Get(int index, T* scratch_space) const {
|
||||
return *static_cast<const T*>(accessor_->Get(data_, index, scratch_space));
|
||||
}
|
||||
// Create a new message of the same type as the messages stored in this
|
||||
// repeated field. Caller takes ownership of the returned object.
|
||||
T* NewMessage() const { return static_cast<T*>(default_instance_->New()); }
|
||||
|
||||
void Set(int index, const T& value) const {
|
||||
accessor_->Set(data_, index, &value);
|
||||
}
|
||||
void Add(const T& value) const { accessor_->Add(data_, &value); }
|
||||
void RemoveLast() const { accessor_->RemoveLast(data_); }
|
||||
void SwapElements(int index1, int index2) const {
|
||||
accessor_->SwapElements(data_, index1, index2);
|
||||
}
|
||||
void Clear() const { accessor_->Clear(data_); }
|
||||
|
||||
void Swap(const MutableRepeatedFieldRef& other) const {
|
||||
accessor_->Swap(data_, other.accessor_, other.data_);
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void MergeFrom(const Container& container) const {
|
||||
typedef typename Container::const_iterator Iterator;
|
||||
for (Iterator it = container.begin(); it != container.end(); ++it) {
|
||||
Add(*it);
|
||||
}
|
||||
}
|
||||
template <typename Container>
|
||||
void CopyFrom(const Container& container) const {
|
||||
Clear();
|
||||
MergeFrom(container);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Reflection;
|
||||
MutableRepeatedFieldRef(Message* message, const FieldDescriptor* field) {
|
||||
const Reflection* reflection = message->GetReflection();
|
||||
data_ = reflection->RepeatedFieldData(
|
||||
message, field, internal::RefTypeTraits<T>::cpp_type,
|
||||
internal::RefTypeTraits<T>::GetMessageFieldDescriptor());
|
||||
accessor_ = reflection->RepeatedFieldAccessor(field);
|
||||
default_instance_ =
|
||||
reflection->GetMessageFactory()->GetPrototype(field->message_type());
|
||||
}
|
||||
|
||||
void* data_;
|
||||
const AccessorType* accessor_;
|
||||
const Message* default_instance_;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
// Interfaces used to implement reflection RepeatedFieldRef API.
|
||||
// Reflection::GetRepeatedAccessor() should return a pointer to an singleton
|
||||
// object that implements the below interface.
|
||||
//
|
||||
// This interface passes/returns values using void pointers. The actual type
|
||||
// of the value depends on the field's cpp_type. Following is a mapping from
|
||||
// cpp_type to the type that should be used in this interface:
|
||||
//
|
||||
// field->cpp_type() T Actual type of void*
|
||||
// CPPTYPE_INT32 int32 int32
|
||||
// CPPTYPE_UINT32 uint32 uint32
|
||||
// CPPTYPE_INT64 int64 int64
|
||||
// CPPTYPE_UINT64 uint64 uint64
|
||||
// CPPTYPE_DOUBLE double double
|
||||
// CPPTYPE_FLOAT float float
|
||||
// CPPTYPE_BOOL bool bool
|
||||
// CPPTYPE_ENUM generated enum type int32
|
||||
// CPPTYPE_STRING string std::string
|
||||
// CPPTYPE_MESSAGE generated message type google::protobuf::Message
|
||||
// or google::protobuf::Message
|
||||
//
|
||||
// Note that for enums we use int32 in the interface.
|
||||
//
|
||||
// You can map from T to the actual type using RefTypeTraits:
|
||||
// typedef RefTypeTraits<T>::AccessorValueType ActualType;
|
||||
class PROTOBUF_EXPORT RepeatedFieldAccessor {
|
||||
public:
|
||||
// Typedefs for clarity.
|
||||
typedef void Field;
|
||||
typedef void Value;
|
||||
typedef void Iterator;
|
||||
|
||||
virtual bool IsEmpty(const Field* data) const = 0;
|
||||
virtual int Size(const Field* data) const = 0;
|
||||
// Depends on the underlying representation of the repeated field, this
|
||||
// method can return a pointer to the underlying object if such an object
|
||||
// exists, or fill the data into scratch_space and return scratch_space.
|
||||
// Callers of this method must ensure scratch_space is a valid pointer
|
||||
// to a mutable object of the correct type.
|
||||
virtual const Value* Get(const Field* data, int index,
|
||||
Value* scratch_space) const = 0;
|
||||
|
||||
virtual void Clear(Field* data) const = 0;
|
||||
virtual void Set(Field* data, int index, const Value* value) const = 0;
|
||||
virtual void Add(Field* data, const Value* value) const = 0;
|
||||
virtual void RemoveLast(Field* data) const = 0;
|
||||
virtual void SwapElements(Field* data, int index1, int index2) const = 0;
|
||||
virtual void Swap(Field* data, const RepeatedFieldAccessor* other_mutator,
|
||||
Field* other_data) const = 0;
|
||||
|
||||
// Create an iterator that points at the beginning of the repeated field.
|
||||
virtual Iterator* BeginIterator(const Field* data) const = 0;
|
||||
// Create an iterator that points at the end of the repeated field.
|
||||
virtual Iterator* EndIterator(const Field* data) const = 0;
|
||||
// Make a copy of an iterator and return the new copy.
|
||||
virtual Iterator* CopyIterator(const Field* data,
|
||||
const Iterator* iterator) const = 0;
|
||||
// Move an iterator to point to the next element.
|
||||
virtual Iterator* AdvanceIterator(const Field* data,
|
||||
Iterator* iterator) const = 0;
|
||||
// Compare whether two iterators point to the same element.
|
||||
virtual bool EqualsIterator(const Field* data, const Iterator* a,
|
||||
const Iterator* b) const = 0;
|
||||
// Delete an iterator created by BeginIterator(), EndIterator() and
|
||||
// CopyIterator().
|
||||
virtual void DeleteIterator(const Field* data, Iterator* iterator) const = 0;
|
||||
// Like Get() but for iterators.
|
||||
virtual const Value* GetIteratorValue(const Field* data,
|
||||
const Iterator* iterator,
|
||||
Value* scratch_space) const = 0;
|
||||
|
||||
// Templated methods that make using this interface easier for non-message
|
||||
// types.
|
||||
template <typename T>
|
||||
T Get(const Field* data, int index) const {
|
||||
typedef typename RefTypeTraits<T>::AccessorValueType ActualType;
|
||||
ActualType scratch_space;
|
||||
return static_cast<T>(*reinterpret_cast<const ActualType*>(
|
||||
Get(data, index, static_cast<Value*>(&scratch_space))));
|
||||
}
|
||||
|
||||
template <typename T, typename ValueType>
|
||||
void Set(Field* data, int index, const ValueType& value) const {
|
||||
typedef typename RefTypeTraits<T>::AccessorValueType ActualType;
|
||||
// In this RepeatedFieldAccessor interface we pass/return data using
|
||||
// raw pointers. Type of the data these raw pointers point to should
|
||||
// be ActualType. Here we have a ValueType object and want a ActualType
|
||||
// pointer. We can't cast a ValueType pointer to an ActualType pointer
|
||||
// directly because their type might be different (for enums ValueType
|
||||
// may be a generated enum type while ActualType is int32). To be safe
|
||||
// we make a copy to get a temporary ActualType object and use it.
|
||||
ActualType tmp = static_cast<ActualType>(value);
|
||||
Set(data, index, static_cast<const Value*>(&tmp));
|
||||
}
|
||||
|
||||
template <typename T, typename ValueType>
|
||||
void Add(Field* data, const ValueType& value) const {
|
||||
typedef typename RefTypeTraits<T>::AccessorValueType ActualType;
|
||||
// In this RepeatedFieldAccessor interface we pass/return data using
|
||||
// raw pointers. Type of the data these raw pointers point to should
|
||||
// be ActualType. Here we have a ValueType object and want a ActualType
|
||||
// pointer. We can't cast a ValueType pointer to an ActualType pointer
|
||||
// directly because their type might be different (for enums ValueType
|
||||
// may be a generated enum type while ActualType is int32). To be safe
|
||||
// we make a copy to get a temporary ActualType object and use it.
|
||||
ActualType tmp = static_cast<ActualType>(value);
|
||||
Add(data, static_cast<const Value*>(&tmp));
|
||||
}
|
||||
|
||||
protected:
|
||||
// We want the destructor to be completely trivial as to allow it to be
|
||||
// a function local static. Hence we make it non-virtual and protected,
|
||||
// this class only live as part of a global singleton and should not be
|
||||
// deleted.
|
||||
~RepeatedFieldAccessor() = default;
|
||||
};
|
||||
|
||||
// Implement (Mutable)RepeatedFieldRef::iterator
|
||||
template <typename T>
|
||||
class RepeatedFieldRefIterator
|
||||
: public std::iterator<std::forward_iterator_tag, T> {
|
||||
typedef typename RefTypeTraits<T>::AccessorValueType AccessorValueType;
|
||||
typedef typename RefTypeTraits<T>::IteratorValueType IteratorValueType;
|
||||
typedef typename RefTypeTraits<T>::IteratorPointerType IteratorPointerType;
|
||||
|
||||
public:
|
||||
// Constructor for non-message fields.
|
||||
RepeatedFieldRefIterator(const void* data,
|
||||
const RepeatedFieldAccessor* accessor, bool begin)
|
||||
: data_(data),
|
||||
accessor_(accessor),
|
||||
iterator_(begin ? accessor->BeginIterator(data)
|
||||
: accessor->EndIterator(data)),
|
||||
// The end iterator must not be dereferenced, no need for scratch space.
|
||||
scratch_space_(begin ? new AccessorValueType : nullptr) {}
|
||||
// Constructor for message fields.
|
||||
RepeatedFieldRefIterator(const void* data,
|
||||
const RepeatedFieldAccessor* accessor, bool begin,
|
||||
AccessorValueType* scratch_space)
|
||||
: data_(data),
|
||||
accessor_(accessor),
|
||||
iterator_(begin ? accessor->BeginIterator(data)
|
||||
: accessor->EndIterator(data)),
|
||||
scratch_space_(scratch_space) {}
|
||||
~RepeatedFieldRefIterator() { accessor_->DeleteIterator(data_, iterator_); }
|
||||
RepeatedFieldRefIterator operator++(int) {
|
||||
RepeatedFieldRefIterator tmp(*this);
|
||||
iterator_ = accessor_->AdvanceIterator(data_, iterator_);
|
||||
return tmp;
|
||||
}
|
||||
RepeatedFieldRefIterator& operator++() {
|
||||
iterator_ = accessor_->AdvanceIterator(data_, iterator_);
|
||||
return *this;
|
||||
}
|
||||
IteratorValueType operator*() const {
|
||||
return static_cast<IteratorValueType>(
|
||||
*static_cast<const AccessorValueType*>(accessor_->GetIteratorValue(
|
||||
data_, iterator_, scratch_space_.get())));
|
||||
}
|
||||
IteratorPointerType operator->() const {
|
||||
return static_cast<IteratorPointerType>(
|
||||
accessor_->GetIteratorValue(data_, iterator_, scratch_space_.get()));
|
||||
}
|
||||
bool operator!=(const RepeatedFieldRefIterator& other) const {
|
||||
assert(data_ == other.data_);
|
||||
assert(accessor_ == other.accessor_);
|
||||
return !accessor_->EqualsIterator(data_, iterator_, other.iterator_);
|
||||
}
|
||||
bool operator==(const RepeatedFieldRefIterator& other) const {
|
||||
return !this->operator!=(other);
|
||||
}
|
||||
|
||||
RepeatedFieldRefIterator(const RepeatedFieldRefIterator& other)
|
||||
: data_(other.data_),
|
||||
accessor_(other.accessor_),
|
||||
iterator_(accessor_->CopyIterator(data_, other.iterator_)) {}
|
||||
RepeatedFieldRefIterator& operator=(const RepeatedFieldRefIterator& other) {
|
||||
if (this != &other) {
|
||||
accessor_->DeleteIterator(data_, iterator_);
|
||||
data_ = other.data_;
|
||||
accessor_ = other.accessor_;
|
||||
iterator_ = accessor_->CopyIterator(data_, other.iterator_);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
const void* data_;
|
||||
const RepeatedFieldAccessor* accessor_;
|
||||
void* iterator_;
|
||||
std::unique_ptr<AccessorValueType> scratch_space_;
|
||||
};
|
||||
|
||||
// TypeTraits that maps the type parameter T of RepeatedFieldRef or
|
||||
// MutableRepeatedFieldRef to corresponding iterator type,
|
||||
// RepeatedFieldAccessor type, etc.
|
||||
template <typename T>
|
||||
struct PrimitiveTraits {
|
||||
static constexpr bool is_primitive = false;
|
||||
};
|
||||
#define DEFINE_PRIMITIVE(TYPE, type) \
|
||||
template <> \
|
||||
struct PrimitiveTraits<type> { \
|
||||
static const bool is_primitive = true; \
|
||||
static const FieldDescriptor::CppType cpp_type = \
|
||||
FieldDescriptor::CPPTYPE_##TYPE; \
|
||||
};
|
||||
DEFINE_PRIMITIVE(INT32, int32)
|
||||
DEFINE_PRIMITIVE(UINT32, uint32)
|
||||
DEFINE_PRIMITIVE(INT64, int64)
|
||||
DEFINE_PRIMITIVE(UINT64, uint64)
|
||||
DEFINE_PRIMITIVE(FLOAT, float)
|
||||
DEFINE_PRIMITIVE(DOUBLE, double)
|
||||
DEFINE_PRIMITIVE(BOOL, bool)
|
||||
#undef DEFINE_PRIMITIVE
|
||||
|
||||
template <typename T>
|
||||
struct RefTypeTraits<
|
||||
T, typename std::enable_if<PrimitiveTraits<T>::is_primitive>::type> {
|
||||
typedef RepeatedFieldRefIterator<T> iterator;
|
||||
typedef RepeatedFieldAccessor AccessorType;
|
||||
typedef T AccessorValueType;
|
||||
typedef T IteratorValueType;
|
||||
typedef T* IteratorPointerType;
|
||||
static constexpr FieldDescriptor::CppType cpp_type =
|
||||
PrimitiveTraits<T>::cpp_type;
|
||||
static const Descriptor* GetMessageFieldDescriptor() { return NULL; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct RefTypeTraits<
|
||||
T, typename std::enable_if<is_proto_enum<T>::value>::type> {
|
||||
typedef RepeatedFieldRefIterator<T> iterator;
|
||||
typedef RepeatedFieldAccessor AccessorType;
|
||||
// We use int32 for repeated enums in RepeatedFieldAccessor.
|
||||
typedef int32 AccessorValueType;
|
||||
typedef T IteratorValueType;
|
||||
typedef int32* IteratorPointerType;
|
||||
static constexpr FieldDescriptor::CppType cpp_type =
|
||||
FieldDescriptor::CPPTYPE_ENUM;
|
||||
static const Descriptor* GetMessageFieldDescriptor() { return NULL; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct RefTypeTraits<
|
||||
T, typename std::enable_if<std::is_same<std::string, T>::value>::type> {
|
||||
typedef RepeatedFieldRefIterator<T> iterator;
|
||||
typedef RepeatedFieldAccessor AccessorType;
|
||||
typedef std::string AccessorValueType;
|
||||
typedef const std::string IteratorValueType;
|
||||
typedef const std::string* IteratorPointerType;
|
||||
static constexpr FieldDescriptor::CppType cpp_type =
|
||||
FieldDescriptor::CPPTYPE_STRING;
|
||||
static const Descriptor* GetMessageFieldDescriptor() { return NULL; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MessageDescriptorGetter {
|
||||
static const Descriptor* get() {
|
||||
return T::default_instance().GetDescriptor();
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct MessageDescriptorGetter<Message> {
|
||||
static const Descriptor* get() { return NULL; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct RefTypeTraits<
|
||||
T, typename std::enable_if<std::is_base_of<Message, T>::value>::type> {
|
||||
typedef RepeatedFieldRefIterator<T> iterator;
|
||||
typedef RepeatedFieldAccessor AccessorType;
|
||||
typedef Message AccessorValueType;
|
||||
typedef const T& IteratorValueType;
|
||||
typedef const T* IteratorPointerType;
|
||||
static constexpr FieldDescriptor::CppType cpp_type =
|
||||
FieldDescriptor::CPPTYPE_MESSAGE;
|
||||
static const Descriptor* GetMessageFieldDescriptor() {
|
||||
return MessageDescriptorGetter<T>::get();
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_REFLECTION_H__
|
89
include/google/protobuf/reflection_ops.h
Normal file
89
include/google/protobuf/reflection_ops.h
Normal file
@ -0,0 +1,89 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// This header is logically internal, but is made public because it is used
|
||||
// from protocol-compiler-generated code, which may reside in other components.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__
|
||||
#define GOOGLE_PROTOBUF_REFLECTION_OPS_H__
|
||||
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
#include <google/protobuf/message.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
|
||||
// Basic operations that can be performed using reflection.
|
||||
// These can be used as a cheap way to implement the corresponding
|
||||
// methods of the Message interface, though they are likely to be
|
||||
// slower than implementations tailored for the specific message type.
|
||||
//
|
||||
// This class should stay limited to operations needed to implement
|
||||
// the Message interface.
|
||||
//
|
||||
// This class is really a namespace that contains only static methods.
|
||||
class PROTOBUF_EXPORT ReflectionOps {
|
||||
public:
|
||||
static void Copy(const Message& from, Message* to);
|
||||
static void Merge(const Message& from, Message* to);
|
||||
static void Clear(Message* message);
|
||||
static bool IsInitialized(const Message& message);
|
||||
static void DiscardUnknownFields(Message* message);
|
||||
|
||||
// Finds all unset required fields in the message and adds their full
|
||||
// paths (e.g. "foo.bar[5].baz") to *names. "prefix" will be attached to
|
||||
// the front of each name.
|
||||
static void FindInitializationErrors(const Message& message,
|
||||
const std::string& prefix,
|
||||
std::vector<std::string>* errors);
|
||||
|
||||
private:
|
||||
// All methods are static. No need to construct.
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionOps);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__
|
2834
include/google/protobuf/repeated_field.h
Normal file
2834
include/google/protobuf/repeated_field.h
Normal file
File diff suppressed because it is too large
Load Diff
293
include/google/protobuf/service.h
Normal file
293
include/google/protobuf/service.h
Normal file
@ -0,0 +1,293 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
//
|
||||
// DEPRECATED: This module declares the abstract interfaces underlying proto2
|
||||
// RPC services. These are intended to be independent of any particular RPC
|
||||
// implementation, so that proto2 services can be used on top of a variety
|
||||
// of implementations. Starting with version 2.3.0, RPC implementations should
|
||||
// not try to build on these, but should instead provide code generator plugins
|
||||
// which generate code specific to the particular RPC implementation. This way
|
||||
// the generated code can be more appropriate for the implementation in use
|
||||
// and can avoid unnecessary layers of indirection.
|
||||
//
|
||||
//
|
||||
// When you use the protocol compiler to compile a service definition, it
|
||||
// generates two classes: An abstract interface for the service (with
|
||||
// methods matching the service definition) and a "stub" implementation.
|
||||
// A stub is just a type-safe wrapper around an RpcChannel which emulates a
|
||||
// local implementation of the service.
|
||||
//
|
||||
// For example, the service definition:
|
||||
// service MyService {
|
||||
// rpc Foo(MyRequest) returns(MyResponse);
|
||||
// }
|
||||
// will generate abstract interface "MyService" and class "MyService::Stub".
|
||||
// You could implement a MyService as follows:
|
||||
// class MyServiceImpl : public MyService {
|
||||
// public:
|
||||
// MyServiceImpl() {}
|
||||
// ~MyServiceImpl() {}
|
||||
//
|
||||
// // implements MyService ---------------------------------------
|
||||
//
|
||||
// void Foo(google::protobuf::RpcController* controller,
|
||||
// const MyRequest* request,
|
||||
// MyResponse* response,
|
||||
// Closure* done) {
|
||||
// // ... read request and fill in response ...
|
||||
// done->Run();
|
||||
// }
|
||||
// };
|
||||
// You would then register an instance of MyServiceImpl with your RPC server
|
||||
// implementation. (How to do that depends on the implementation.)
|
||||
//
|
||||
// To call a remote MyServiceImpl, first you need an RpcChannel connected to it.
|
||||
// How to construct a channel depends, again, on your RPC implementation.
|
||||
// Here we use a hypothetical "MyRpcChannel" as an example:
|
||||
// MyRpcChannel channel("rpc:hostname:1234/myservice");
|
||||
// MyRpcController controller;
|
||||
// MyServiceImpl::Stub stub(&channel);
|
||||
// FooRequest request;
|
||||
// FooResponse response;
|
||||
//
|
||||
// // ... fill in request ...
|
||||
//
|
||||
// stub.Foo(&controller, request, &response, NewCallback(HandleResponse));
|
||||
//
|
||||
// On Thread-Safety:
|
||||
//
|
||||
// Different RPC implementations may make different guarantees about what
|
||||
// threads they may run callbacks on, and what threads the application is
|
||||
// allowed to use to call the RPC system. Portable software should be ready
|
||||
// for callbacks to be called on any thread, but should not try to call the
|
||||
// RPC system from any thread except for the ones on which it received the
|
||||
// callbacks. Realistically, though, simple software will probably want to
|
||||
// use a single-threaded RPC system while high-end software will want to
|
||||
// use multiple threads. RPC implementations should provide multiple
|
||||
// choices.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_SERVICE_H__
|
||||
#define GOOGLE_PROTOBUF_SERVICE_H__
|
||||
|
||||
#include <string>
|
||||
#include <google/protobuf/stubs/callback.h>
|
||||
#include <google/protobuf/stubs/common.h>
|
||||
|
||||
#ifdef SWIG
|
||||
#error "You cannot SWIG proto headers"
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
// Defined in this file.
|
||||
class Service;
|
||||
class RpcController;
|
||||
class RpcChannel;
|
||||
|
||||
// Defined in other files.
|
||||
class Descriptor; // descriptor.h
|
||||
class ServiceDescriptor; // descriptor.h
|
||||
class MethodDescriptor; // descriptor.h
|
||||
class Message; // message.h
|
||||
|
||||
// Abstract base interface for protocol-buffer-based RPC services. Services
|
||||
// themselves are abstract interfaces (implemented either by servers or as
|
||||
// stubs), but they subclass this base interface. The methods of this
|
||||
// interface can be used to call the methods of the Service without knowing
|
||||
// its exact type at compile time (analogous to Reflection).
|
||||
class PROTOBUF_EXPORT Service {
|
||||
public:
|
||||
inline Service() {}
|
||||
virtual ~Service();
|
||||
|
||||
// When constructing a stub, you may pass STUB_OWNS_CHANNEL as the second
|
||||
// parameter to the constructor to tell it to delete its RpcChannel when
|
||||
// destroyed.
|
||||
enum ChannelOwnership { STUB_OWNS_CHANNEL, STUB_DOESNT_OWN_CHANNEL };
|
||||
|
||||
// Get the ServiceDescriptor describing this service and its methods.
|
||||
virtual const ServiceDescriptor* GetDescriptor() = 0;
|
||||
|
||||
// Call a method of the service specified by MethodDescriptor. This is
|
||||
// normally implemented as a simple switch() that calls the standard
|
||||
// definitions of the service's methods.
|
||||
//
|
||||
// Preconditions:
|
||||
// * method->service() == GetDescriptor()
|
||||
// * request and response are of the exact same classes as the objects
|
||||
// returned by GetRequestPrototype(method) and
|
||||
// GetResponsePrototype(method).
|
||||
// * After the call has started, the request must not be modified and the
|
||||
// response must not be accessed at all until "done" is called.
|
||||
// * "controller" is of the correct type for the RPC implementation being
|
||||
// used by this Service. For stubs, the "correct type" depends on the
|
||||
// RpcChannel which the stub is using. Server-side Service
|
||||
// implementations are expected to accept whatever type of RpcController
|
||||
// the server-side RPC implementation uses.
|
||||
//
|
||||
// Postconditions:
|
||||
// * "done" will be called when the method is complete. This may be
|
||||
// before CallMethod() returns or it may be at some point in the future.
|
||||
// * If the RPC succeeded, "response" contains the response returned by
|
||||
// the server.
|
||||
// * If the RPC failed, "response"'s contents are undefined. The
|
||||
// RpcController can be queried to determine if an error occurred and
|
||||
// possibly to get more information about the error.
|
||||
virtual void CallMethod(const MethodDescriptor* method,
|
||||
RpcController* controller, const Message* request,
|
||||
Message* response, Closure* done) = 0;
|
||||
|
||||
// CallMethod() requires that the request and response passed in are of a
|
||||
// particular subclass of Message. GetRequestPrototype() and
|
||||
// GetResponsePrototype() get the default instances of these required types.
|
||||
// You can then call Message::New() on these instances to construct mutable
|
||||
// objects which you can then pass to CallMethod().
|
||||
//
|
||||
// Example:
|
||||
// const MethodDescriptor* method =
|
||||
// service->GetDescriptor()->FindMethodByName("Foo");
|
||||
// Message* request = stub->GetRequestPrototype (method)->New();
|
||||
// Message* response = stub->GetResponsePrototype(method)->New();
|
||||
// request->ParseFromString(input);
|
||||
// service->CallMethod(method, *request, response, callback);
|
||||
virtual const Message& GetRequestPrototype(
|
||||
const MethodDescriptor* method) const = 0;
|
||||
virtual const Message& GetResponsePrototype(
|
||||
const MethodDescriptor* method) const = 0;
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Service);
|
||||
};
|
||||
|
||||
// An RpcController mediates a single method call. The primary purpose of
|
||||
// the controller is to provide a way to manipulate settings specific to the
|
||||
// RPC implementation and to find out about RPC-level errors.
|
||||
//
|
||||
// The methods provided by the RpcController interface are intended to be a
|
||||
// "least common denominator" set of features which we expect all
|
||||
// implementations to support. Specific implementations may provide more
|
||||
// advanced features (e.g. deadline propagation).
|
||||
class PROTOBUF_EXPORT RpcController {
|
||||
public:
|
||||
inline RpcController() {}
|
||||
virtual ~RpcController();
|
||||
|
||||
// Client-side methods ---------------------------------------------
|
||||
// These calls may be made from the client side only. Their results
|
||||
// are undefined on the server side (may crash).
|
||||
|
||||
// Resets the RpcController to its initial state so that it may be reused in
|
||||
// a new call. Must not be called while an RPC is in progress.
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// After a call has finished, returns true if the call failed. The possible
|
||||
// reasons for failure depend on the RPC implementation. Failed() must not
|
||||
// be called before a call has finished. If Failed() returns true, the
|
||||
// contents of the response message are undefined.
|
||||
virtual bool Failed() const = 0;
|
||||
|
||||
// If Failed() is true, returns a human-readable description of the error.
|
||||
virtual std::string ErrorText() const = 0;
|
||||
|
||||
// Advises the RPC system that the caller desires that the RPC call be
|
||||
// canceled. The RPC system may cancel it immediately, may wait awhile and
|
||||
// then cancel it, or may not even cancel the call at all. If the call is
|
||||
// canceled, the "done" callback will still be called and the RpcController
|
||||
// will indicate that the call failed at that time.
|
||||
virtual void StartCancel() = 0;
|
||||
|
||||
// Server-side methods ---------------------------------------------
|
||||
// These calls may be made from the server side only. Their results
|
||||
// are undefined on the client side (may crash).
|
||||
|
||||
// Causes Failed() to return true on the client side. "reason" will be
|
||||
// incorporated into the message returned by ErrorText(). If you find
|
||||
// you need to return machine-readable information about failures, you
|
||||
// should incorporate it into your response protocol buffer and should
|
||||
// NOT call SetFailed().
|
||||
virtual void SetFailed(const std::string& reason) = 0;
|
||||
|
||||
// If true, indicates that the client canceled the RPC, so the server may
|
||||
// as well give up on replying to it. The server should still call the
|
||||
// final "done" callback.
|
||||
virtual bool IsCanceled() const = 0;
|
||||
|
||||
// Asks that the given callback be called when the RPC is canceled. The
|
||||
// callback will always be called exactly once. If the RPC completes without
|
||||
// being canceled, the callback will be called after completion. If the RPC
|
||||
// has already been canceled when NotifyOnCancel() is called, the callback
|
||||
// will be called immediately.
|
||||
//
|
||||
// NotifyOnCancel() must be called no more than once per request.
|
||||
virtual void NotifyOnCancel(Closure* callback) = 0;
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcController);
|
||||
};
|
||||
|
||||
// Abstract interface for an RPC channel. An RpcChannel represents a
|
||||
// communication line to a Service which can be used to call that Service's
|
||||
// methods. The Service may be running on another machine. Normally, you
|
||||
// should not call an RpcChannel directly, but instead construct a stub Service
|
||||
// wrapping it. Example:
|
||||
// RpcChannel* channel = new MyRpcChannel("remotehost.example.com:1234");
|
||||
// MyService* service = new MyService::Stub(channel);
|
||||
// service->MyMethod(request, &response, callback);
|
||||
class PROTOBUF_EXPORT RpcChannel {
|
||||
public:
|
||||
inline RpcChannel() {}
|
||||
virtual ~RpcChannel();
|
||||
|
||||
// Call the given method of the remote service. The signature of this
|
||||
// procedure looks the same as Service::CallMethod(), but the requirements
|
||||
// are less strict in one important way: the request and response objects
|
||||
// need not be of any specific class as long as their descriptors are
|
||||
// method->input_type() and method->output_type().
|
||||
virtual void CallMethod(const MethodDescriptor* method,
|
||||
RpcController* controller, const Message* request,
|
||||
Message* response, Closure* done) = 0;
|
||||
|
||||
private:
|
||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel);
|
||||
};
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_SERVICE_H__
|
323
include/google/protobuf/source_context.pb.h
Normal file
323
include/google/protobuf/source_context.pb.h
Normal file
@ -0,0 +1,323 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: google/protobuf/source_context.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#if PROTOBUF_VERSION < 3012000
|
||||
#error This file was generated by a newer version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please update
|
||||
#error your headers.
|
||||
#endif
|
||||
#if 3012004 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error This file was generated by an older version of protoc which is
|
||||
#error incompatible with your Protocol Buffer headers. Please
|
||||
#error regenerate this file with a newer version of protoc.
|
||||
#endif
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/arena.h>
|
||||
#include <google/protobuf/arenastring.h>
|
||||
#include <google/protobuf/generated_message_table_driven.h>
|
||||
#include <google/protobuf/generated_message_util.h>
|
||||
#include <google/protobuf/inlined_string_field.h>
|
||||
#include <google/protobuf/metadata_lite.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
|
||||
#include <google/protobuf/extension_set.h> // IWYU pragma: export
|
||||
#include <google/protobuf/unknown_field_set.h>
|
||||
// @@protoc_insertion_point(includes)
|
||||
#include <google/protobuf/port_def.inc>
|
||||
#define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fsource_5fcontext_2eproto PROTOBUF_EXPORT
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto {
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1]
|
||||
PROTOBUF_SECTION_VARIABLE(protodesc_cold);
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[];
|
||||
static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[];
|
||||
};
|
||||
extern PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto;
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
class SourceContext;
|
||||
class SourceContextDefaultTypeInternal;
|
||||
PROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_;
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
template<> PROTOBUF_EXPORT PROTOBUF_NAMESPACE_ID::SourceContext* Arena::CreateMaybeMessage<PROTOBUF_NAMESPACE_ID::SourceContext>(Arena*);
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
PROTOBUF_NAMESPACE_OPEN
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class PROTOBUF_EXPORT SourceContext PROTOBUF_FINAL :
|
||||
public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceContext) */ {
|
||||
public:
|
||||
inline SourceContext() : SourceContext(nullptr) {};
|
||||
virtual ~SourceContext();
|
||||
|
||||
SourceContext(const SourceContext& from);
|
||||
SourceContext(SourceContext&& from) noexcept
|
||||
: SourceContext() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline SourceContext& operator=(const SourceContext& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline SourceContext& operator=(SourceContext&& from) noexcept {
|
||||
if (GetArena() == from.GetArena()) {
|
||||
if (this != &from) InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() {
|
||||
return GetMetadataStatic().descriptor;
|
||||
}
|
||||
static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() {
|
||||
return GetMetadataStatic().reflection;
|
||||
}
|
||||
static const SourceContext& default_instance();
|
||||
|
||||
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
|
||||
static inline const SourceContext* internal_default_instance() {
|
||||
return reinterpret_cast<const SourceContext*>(
|
||||
&_SourceContext_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(SourceContext& a, SourceContext& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(SourceContext* other) {
|
||||
if (other == this) return;
|
||||
if (GetArena() == other->GetArena()) {
|
||||
InternalSwap(other);
|
||||
} else {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(SourceContext* other) {
|
||||
if (other == this) return;
|
||||
GOOGLE_DCHECK(GetArena() == other->GetArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
inline SourceContext* New() const final {
|
||||
return CreateMaybeMessage<SourceContext>(nullptr);
|
||||
}
|
||||
|
||||
SourceContext* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final {
|
||||
return CreateMaybeMessage<SourceContext>(arena);
|
||||
}
|
||||
void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final;
|
||||
void CopyFrom(const SourceContext& from);
|
||||
void MergeFrom(const SourceContext& from);
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize(
|
||||
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
inline void SharedCtor();
|
||||
inline void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(SourceContext* other);
|
||||
friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;
|
||||
static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {
|
||||
return "google.protobuf.SourceContext";
|
||||
}
|
||||
protected:
|
||||
explicit SourceContext(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
private:
|
||||
static void ArenaDtor(void* object);
|
||||
inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);
|
||||
public:
|
||||
|
||||
::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;
|
||||
private:
|
||||
static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() {
|
||||
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto);
|
||||
return ::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto.file_level_metadata[kIndexInFileMessages];
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kFileNameFieldNumber = 1,
|
||||
};
|
||||
// string file_name = 1;
|
||||
void clear_file_name();
|
||||
const std::string& file_name() const;
|
||||
void set_file_name(const std::string& value);
|
||||
void set_file_name(std::string&& value);
|
||||
void set_file_name(const char* value);
|
||||
void set_file_name(const char* value, size_t size);
|
||||
std::string* mutable_file_name();
|
||||
std::string* release_file_name();
|
||||
void set_allocated_file_name(std::string* file_name);
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
std::string* unsafe_arena_release_file_name();
|
||||
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
|
||||
" string fields are deprecated and will be removed in a"
|
||||
" future release.")
|
||||
void unsafe_arena_set_allocated_file_name(
|
||||
std::string* file_name);
|
||||
private:
|
||||
const std::string& _internal_file_name() const;
|
||||
void _internal_set_file_name(const std::string& value);
|
||||
std::string* _internal_mutable_file_name();
|
||||
public:
|
||||
|
||||
// @@protoc_insertion_point(class_scope:google.protobuf.SourceContext)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr file_name_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
friend struct ::TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto;
|
||||
};
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// SourceContext
|
||||
|
||||
// string file_name = 1;
|
||||
inline void SourceContext::clear_file_name() {
|
||||
file_name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline const std::string& SourceContext::file_name() const {
|
||||
// @@protoc_insertion_point(field_get:google.protobuf.SourceContext.file_name)
|
||||
return _internal_file_name();
|
||||
}
|
||||
inline void SourceContext::set_file_name(const std::string& value) {
|
||||
_internal_set_file_name(value);
|
||||
// @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name)
|
||||
}
|
||||
inline std::string* SourceContext::mutable_file_name() {
|
||||
// @@protoc_insertion_point(field_mutable:google.protobuf.SourceContext.file_name)
|
||||
return _internal_mutable_file_name();
|
||||
}
|
||||
inline const std::string& SourceContext::_internal_file_name() const {
|
||||
return file_name_.Get();
|
||||
}
|
||||
inline void SourceContext::_internal_set_file_name(const std::string& value) {
|
||||
|
||||
file_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena());
|
||||
}
|
||||
inline void SourceContext::set_file_name(std::string&& value) {
|
||||
|
||||
file_name_.Set(
|
||||
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena());
|
||||
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceContext.file_name)
|
||||
}
|
||||
inline void SourceContext::set_file_name(const char* value) {
|
||||
GOOGLE_DCHECK(value != nullptr);
|
||||
|
||||
file_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name)
|
||||
}
|
||||
inline void SourceContext::set_file_name(const char* value,
|
||||
size_t size) {
|
||||
|
||||
file_name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(
|
||||
reinterpret_cast<const char*>(value), size), GetArena());
|
||||
// @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceContext.file_name)
|
||||
}
|
||||
inline std::string* SourceContext::_internal_mutable_file_name() {
|
||||
|
||||
return file_name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline std::string* SourceContext::release_file_name() {
|
||||
// @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name)
|
||||
return file_name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
|
||||
}
|
||||
inline void SourceContext::set_allocated_file_name(std::string* file_name) {
|
||||
if (file_name != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
file_name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), file_name,
|
||||
GetArena());
|
||||
// @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name)
|
||||
}
|
||||
inline std::string* SourceContext::unsafe_arena_release_file_name() {
|
||||
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.SourceContext.file_name)
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
|
||||
return file_name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
GetArena());
|
||||
}
|
||||
inline void SourceContext::unsafe_arena_set_allocated_file_name(
|
||||
std::string* file_name) {
|
||||
GOOGLE_DCHECK(GetArena() != nullptr);
|
||||
if (file_name != nullptr) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
file_name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
|
||||
file_name, GetArena());
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.SourceContext.file_name)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
|
||||
PROTOBUF_NAMESPACE_CLOSE
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include <google/protobuf/port_undef.inc>
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto
|
48
include/google/protobuf/source_context.proto
Normal file
48
include/google/protobuf/source_context.proto
Normal file
@ -0,0 +1,48 @@
|
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.protobuf;
|
||||
|
||||
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||
option java_package = "com.google.protobuf";
|
||||
option java_outer_classname = "SourceContextProto";
|
||||
option java_multiple_files = true;
|
||||
option objc_class_prefix = "GPB";
|
||||
option go_package = "google.golang.org/genproto/protobuf/source_context;source_context";
|
||||
|
||||
// `SourceContext` represents information about the source of a
|
||||
// protobuf element, like the file in which it is defined.
|
||||
message SourceContext {
|
||||
// The path-qualified name of the .proto file that contained the associated
|
||||
// protobuf element. For example: `"google/protobuf/source_context.proto"`.
|
||||
string file_name = 1;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user