1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-25 05:13:04 +04:00

Compare commits

...

565 Commits

Author SHA1 Message Date
Alexander Alekhin 3b15f3e3b9 avoid calling of setNumThreads() to respect user settings 2018-03-29 13:48:37 +03:00
Maksim Shabunin 265f335dae Add install component for 3rdparty libraries licenses 2018-03-06 16:55:08 +03:00
Maksim Shabunin e283a75a19 Minor refactoring in several C++ samples:
- bgfg_segm
- peopledetect
- opencv_version
- dnn/colorization
- tapi/opencl_custom_kernel
- tapi/dense_optical_flow (renamed tvl1_optical_flow)
2018-03-06 16:51:03 +03:00
Alexander Alekhin ed96279920 ocl: update getOpenCLErrorString() code 2018-03-01 14:01:44 +03:00
Alexander Alekhin e79be78ef4 dnn(workaround): switch to CPU target if compiled without OpenCL 2018-03-01 12:18:40 +03:00
Alexander Alekhin 4a6d582f2e dnn: make OpenCL DNN code optional 2018-03-01 12:18:39 +03:00
Alexander Alekhin e969f184e1 3rdparty: fix protobuf version in README file 2018-03-01 12:18:32 +03:00
Alexander Alekhin ca9af20179 OpenCV version '-cvsdk' 2018-02-26 13:27:49 +03:00
Maksim Shabunin 0f1e193193 Fixed two issues found by static analysis 2018-02-26 13:27:49 +03:00
Alexander Alekhin 6ffc48769a OpenCV version++
OpenCV 3.4.1
2018-02-23 11:38:33 +03:00
Alexander Alekhin 4a74408eee experimental version++ 2018-02-23 11:38:33 +03:00
Alexander Alekhin c729fbd652 Merge pull request #10925 from pengli:dnn 2018-02-23 08:38:03 +00:00
Li Peng 608968aa83 Deconvolution ocl fix
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-23 18:31:30 +08:00
Li, Peng 5caf6244a3 Merge pull request #10922 from pengli:dnn
* ave pooling ocl fix

support the padded area control in ave pooling

Signed-off-by: Li Peng <peng.li@intel.com>

* warning fix: ununitialized field
2018-02-22 21:01:12 +03:00
Maksim Shabunin eaaba6462e Merge pull request #10919 from mshabunin:fix-static-9 2018-02-22 15:05:25 +00:00
Maksim Shabunin 92e9d4ec3a Fixed several issues detected by static analysis 2018-02-22 17:11:33 +03:00
Maksim Shabunin fbb2cabe77 Use fixed size types in AVIContainer structs 2018-02-22 17:11:25 +03:00
Maksim Shabunin 3fd2384b81 Fixed mingw compilation on Windows 2018-02-22 17:11:18 +03:00
Alexander Alekhin e851a41d78 Merge pull request #10909 from alalek:ffmpeg_update 2018-02-22 14:05:37 +00:00
Vadim Pisarevsky 5e0f95b948 Merge pull request #9708 from dkurt:tf_face_detector 2018-02-22 12:04:26 +00:00
Alexander Alekhin f7aa2e0d44 ffmpeg: update wrapper
FFmpeg: 3.3.4 -> 3.4.2
LibVPX: 1.6.1 -> 1.7.0
OpenH264: 1.6.0 -> 1.7.0
2018-02-22 15:04:06 +03:00
Vadim Pisarevsky a11b7a8293 Merge pull request #10916 from alalek:videoio_sample_aspect_ratio 2018-02-22 12:03:39 +00:00
Alexander Alekhin e6062532fa Merge pull request #10918 from pengli:dnn 2018-02-22 10:30:00 +00:00
Li Peng e7d35d51fa Fix for opencv face detector ocl test
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-22 23:37:54 +08:00
Li Peng c524f669c7 Fallback for "SAME" padMode in ocl convolution and pooling
It fixes tensorflow ocl testcase of MobileNetSSD and Inception_v2_SSD

Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-22 21:17:59 +08:00
Alexander Alekhin 203ac0f818 Merge pull request #10914 from alalek:issue_10815 2018-02-21 18:26:15 +00:00
Dmitry Kurtaev eab556e1e0 OpenCV face detection network in TensorFlow 2018-02-21 19:58:24 +03:00
Alexander Alekhin 9819ebc095 videoio: add missing CAP_PROP_SAR_NUM/DEN propepties into .hpp file
reuse av_guess_sample_aspect_ratio() if available in ffmpeg
2018-02-21 19:14:04 +03:00
Alexander Alekhin fb6db3dcfc Merge pull request #10915 from alalek:issue_10910 2018-02-21 15:55:03 +00:00
Alexander Alekhin 7601c21612 Merge pull request #10912 from alalek:fix_imgcodecs_hang 2018-02-21 13:39:35 +00:00
Alexander Alekhin cb9b08eca1 createsamples: fix ROI in icvGetBackgroundImage() 2018-02-21 14:40:35 +03:00
Alexander Alekhin 48b8aa51cd core: eliminate redundant cv::format() declarations
Existed includes sequence:
- utility.hpp -> core.hpp -> operations.hpp
2018-02-21 14:22:16 +03:00
Alexander Alekhin 6e8241b78d imgcodecs: fix RBaseStream hang on truncated inputs 2018-02-21 13:17:18 +03:00
Vadim Pisarevsky f61076a5d8 Merge pull request #10367 from savuor:multiwrite_tiff_renew 2018-02-20 23:13:55 +00:00
Alexander Alekhin 5f5fcef962 Merge pull request #10907 from alalek:cmake_ninja_fix 2018-02-20 18:54:43 +00:00
Namgoo Lee 12ce6b5c15 Merge pull request #10906 from nglee:dev_cudaFastMultiStreamSafety
cuda_fast : multi stream safety (#10906)

* CUDA_Features2D/FAST Asynchronous test

* cuda_fast : multi stream safety

* Use parallel_for instead of OpenMP
2018-02-20 20:55:57 +03:00
Rostislav Vasilikhin 27b1f8f446 imwrite for multipage images implemented 2018-02-20 19:08:45 +03:00
Vadim Pisarevsky c6e1e3acdc Merge pull request #10892 from alalek:android_sdk_build_gradle 2018-02-20 14:59:32 +00:00
Vadim Pisarevsky 53661d55ae Merge pull request #10406 from seiko2plus:coreUnvintrinCopy 2018-02-20 14:50:17 +00:00
Vadim Pisarevsky 120b7a61c3 Merge pull request #10745 from terfendail:tiff_fix 2018-02-20 14:47:13 +00:00
PalkoNazar 470d34ddbb make tmpRow proper size before copyTo to avoid reallocated tmpCol (#10860)
* make tmpRow proper size before copyTo to avoid reallocated tmpCol

* do the transposition without creating temporary array; replace TAB with spaces.

* revert the previous commit
2018-02-20 16:55:25 +03:00
Vadim Pisarevsky a0c2718adb Merge pull request #10902 from alalek:port_10695 2018-02-20 13:26:59 +00:00
Vadim Pisarevsky a836892edb Merge pull request #10903 from alalek:ml_ann_test 2018-02-20 13:25:58 +00:00
Vadim Pisarevsky 25518a12f1 Merge pull request #10908 from alalek:fix_ffmpeg_uchar 2018-02-20 12:22:09 +00:00
Alexander Alekhin 2aa15ab3ff ffmpeg: fix 'uchar' error
> cap_ffmpeg_impl.hpp:1710:11: error: 'uchar' does not name a type
2018-02-20 13:15:41 +03:00
Alexander Alekhin 807ec00b85 cmake: fix Ninja warning
about BYPRODUCTS bin/opencv-340.jar
2018-02-20 13:13:31 +03:00
Alexander Alekhin 53305d4a7e Merge pull request #10891 from pengli:dnn 2018-02-20 08:59:07 +00:00
Li Peng 2863f950d6 ReLU6 layer ocl support
include relu6 ocl kernel and layer fusion support

Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-20 15:11:09 +08:00
Alexander Alekhin 12d2bd4adb ml: refactor ML_ANN test 2018-02-19 21:35:48 +03:00
Vitaly Tuzov 24ee7b5080 Fix for vertically flipped tiff files reading 2018-02-19 18:49:19 +03:00
mworchel aab390c51d Add mask support to SimpleBlobDetector 2018-02-19 17:54:27 +03:00
Dmitry Kurtaev 8b4871a28d Use only absolute prior boxes explicit sizes. Remove scales attributes. (#10874)
* Use only absolute prior boxes explicit sizes. Remove scales attributes.

* Simplified PriorBox layer forward pass
2018-02-19 17:25:18 +03:00
Alexander Alekhin cf31243c74 android: add build.grade into Android SDK
For using 'OpenCV for Android SDK' with Android Studio projects.
2018-02-19 17:19:26 +03:00
Vadim Pisarevsky 88b689bcf1 Merge pull request #10876 from alalek:android_static_libs 2018-02-19 14:16:06 +00:00
Vadim Pisarevsky f589237e23 Merge pull request #10880 from StevenPuttemans:fix_10594 2018-02-19 14:13:43 +00:00
Vadim Pisarevsky 7da6e9086c Merge pull request #10893 from alalek:fix_cpu_disable_flags 2018-02-19 14:11:11 +00:00
Vadim Pisarevsky 68043f4de9 Merge pull request #10896 from dkurt:tensorflow_tests_generator 2018-02-19 14:08:58 +00:00
Alexander Alekhin c0eaff3608 Merge pull request #10900 from tomoaki0705:fixPerfVideoioGstreamer 2018-02-19 13:59:20 +00:00
Tomoaki Teshima bcce25900b read in gray scale mode when writing a gray scale video 2018-02-19 18:33:05 +09:00
Dmitry Kurtaev 34ba32ff27 Fix DNN flatten test 2018-02-18 12:45:43 +03:00
Alexander Alekhin 857007372d Merge pull request #10895 from tomoaki0705:fixBuildVS2013sprintf 2018-02-18 07:45:01 +00:00
Tomoaki Teshima 6a661e1e28 fix test error on VS2013 2018-02-18 09:29:38 +09:00
Alexander Alekhin cc5a6f3b86 core: remove '-' from separators list of disabled CPU flags
To allow runtime disabling of AVX512-SKX via 'OPENCV_CPU_DISABLE' parameter
2018-02-18 00:03:04 +00:00
Maksim Shabunin aa7a964139 Merge pull request #10868 from mshabunin:sample-bgsegm
* Samples: reworked bgfg_bgsegm

* fixup! Samples: reworked bgfg_bgsegm
2018-02-17 15:04:14 +03:00
Alexander Alekhin 73a8369631 Merge pull request #10890 from Reputeless:patch-1 2018-02-17 12:02:48 +00:00
Florian Echtler 6a8f57e5d7 Merge pull request #10081 from floe:java-camera2-view
* add (untested) JavaCamera2View class

* initial fixes

* minor cleanup

* exclude JavaCamera2View from build for older SDK version

* fix method name typo

* add asserts + sanity checks

* fix preview format checks

* fix the memory leak

* export cvtTwoPlaneYUVtoBGR for Java usage

* add handling for two-plane YUV frames (C wrapper still missing)

* add two-plane cvtColor helper function

* fix warnings

* actually use the new cvtColorTwoPlane helper func

* fix wrong output matrix size

* fix wrong conversion type

* simplify method signature, add error condition

* minor fixes to Mat types

* remove leftover semaphore from camera api 1

* android: JavaCamera2View minor refactoring

- re-apply Java code style
- imports cleanup
- dump exceptions information

* android: JavaCamera2View: pause/resume fixes

* android: JavaCamera2View: fix mScale
2018-02-17 15:01:24 +03:00
Alexander Alekhin eb94dfb442 Merge pull request #10885 from alalek:issue_10881 2018-02-17 11:58:51 +00:00
Patrik Huber 7be0c78533 Merge pull request #10589 from patrikhuber:patch-1
* Make <array> #ifdef true for MSVC

I think MSVC had `std::array` for quite a while (possibly going back as far as VS 2012, but it's definitely there in 2015 and 2017. So I think `_MSC_VER` `1900` is a safe bet. Probably `1800` and maybe even `1700` could work as well but I can't test that locally.

* fix test
2018-02-17 14:53:30 +03:00
Ryo Suzuki 97d9ea00fe Fix typo in core/base.hpp 2018-02-17 19:35:25 +09:00
Alexander Alekhin 491502a349 core: fix parallel_for data race 2018-02-16 21:13:48 +03:00
Alexander Alekhin 0e4eed0ba1 Merge pull request #10867 from dkurt:dnn_fix_ave_pooling_area 2018-02-16 11:17:32 +00:00
Alexander Alekhin 8ffcc76011 Merge pull request #10883 from alalek:portable_stdint 2018-02-16 10:29:39 +00:00
Alexander Alekhin c020a7bb67 build: portable integer types 2018-02-15 23:43:02 +03:00
Alexander Alekhin e268fdc0ed Merge pull request #10793 from denmatfoton:master 2018-02-15 15:52:52 +00:00
Alexander Alekhin bb925fe488 Merge pull request #10879 from StevenPuttemans:fix_10650 2018-02-15 15:48:12 +00:00
Alexander Alekhin 1dbdb1cfc9 Merge pull request #10727 from alalek:cmake_hook_system 2018-02-15 15:46:12 +00:00
Alexander Alekhin 30b33a4413 Merge pull request #10145 from allnes:vedeoio_avi_container 2018-02-15 15:14:03 +00:00
Steven 945ad277ea add missing DNN header to opencv2/opencv.hpp 2018-02-15 15:59:14 +01:00
Steven 6f4e35cc0e fix tutorial on real time pose estimation 2018-02-15 15:48:52 +01:00
Alexander Nesterov df8f61877e Added avi-container with tests 2018-02-15 17:34:49 +03:00
Alexander Alekhin ddb482b14a android: move .a files into 'staticlibs' directory
to reduce overhead of gradle builds
2018-02-15 16:31:49 +03:00
Alexander Alekhin f378f1d585 calib3d: add regression test for stereoCalibrate 2018-02-15 15:24:09 +03:00
Alexander Alekhin 36f11a54e1 cmake: customize OpenCV build via CMake script hooks 2018-02-15 14:03:38 +03:00
Dmitry Kurtaev f8d0d6365e Add a flag to manage average pooling with padding 2018-02-14 16:56:31 +03:00
Alexander Alekhin cff79609c8 Merge pull request #10854 from pengli:dnn 2018-02-14 12:49:53 +00:00
Alexander Alekhin c434198ee5 Merge pull request #10864 from alalek:cmake_update_debug_info 2018-02-14 12:47:43 +00:00
Vadim Pisarevsky ef70b0baa4 Merge pull request #10865 from dkurt:dnn_inf_engine_getInputsInfo 2018-02-14 12:25:18 +00:00
Vadim Pisarevsky b4ddf3d8c5 Merge pull request #10678 from terfendail:OutputArray_recreate 2018-02-14 11:36:51 +00:00
Vadim Pisarevsky 42b25d747b Merge pull request #10856 from tomoaki0705:fixVisualStudioFixedWidthInt 2018-02-14 11:33:15 +00:00
Dmitry Kurtaev a66b5e2c13 Add const getInputsInfo 2018-02-14 14:17:44 +03:00
Vadim Pisarevsky 8f0b72be9e Merge pull request #10861 from nglee:dev_cudaDftAlgorithmTest 2018-02-14 10:50:05 +00:00
Vadim Pisarevsky 15dc6f70dc Merge pull request #10863 from mshabunin:fix-viz-samples-build 2018-02-14 10:49:05 +00:00
Alexander Alekhin 95014f311d cmake: debug info 2018-02-14 13:44:10 +03:00
Vadim Pisarevsky 6dfd7e3da2 Merge pull request #10850 from dkurt:dnn_tf_deconv_tests 2018-02-14 10:35:14 +00:00
Alexander Alekhin cfe84b953c Merge pull request #10859 from luzpaz:misc-modules-typos-cont-2 2018-02-14 09:56:11 +00:00
Maksim Shabunin f78b9468dd Samples: fixed samples build in case the viz module is disabled 2018-02-14 12:45:10 +03:00
Namgoo Lee 034dc3b0dd Fix for CUDA_Arithm/Dft.Algorithm/0 test 2018-02-14 09:54:13 +09:00
Li Peng 80d1f2ddfa re-enable tensor flow mobilenet ssd ocl test
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-14 01:04:58 +08:00
luz.paz d05714995c Misc. modules/ cont. pt2
Found via `codespell`
2018-02-13 11:28:11 -05:00
Alexander Alekhin 252e871a8b Merge pull request #10846 from luzpaz:misc-modules-typos-cont 2018-02-13 16:12:28 +00:00
Alexander Alekhin 59b91d6c31 Merge pull request #10821 from dkurt:dnn_layers_fusion 2018-02-13 16:08:48 +00:00
Li Peng 5992c46606 add fallback case for ocl convolution
The ocl convolution doesn't support tensorflow padMode well.
Add fallback check if we meet this situation, it could fix the
tensorflow MobileNet SSD failure.

Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-14 00:04:38 +08:00
Li Peng 00d2f34888 ocl fix for detection_output and prior_box layer
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-13 23:09:14 +08:00
Alexander Alekhin a91a11e533 Merge pull request #10818 from mshabunin:install-samples-src 2018-02-13 14:37:38 +00:00
Alexander Alekhin 2423cddb00 Merge pull request #10852 from alalek:fix_cpuid 2018-02-13 13:56:22 +00:00
Alexander Alekhin eb54e5c55c core: generalize and fix x86 'cpuid' calls 2018-02-13 15:35:04 +03:00
Dmitry Kurtaev 514e6df460 Refactored deep learning layers fusion 2018-02-13 14:35:58 +03:00
Tomoaki Teshima 94253e8b83 fix build error on Visual Studio 2013 and earlier 2018-02-13 18:30:02 +09:00
Dmitry Kurtaev a6baedd02c Fix deconvolution layer. Add batch norm layer with mean-variance normalization from TensorFlow. 2018-02-13 11:00:27 +03:00
Maksim Shabunin c63092781a Samples: fixed viz tutorials building with enabled opencv_world 2018-02-12 18:42:36 +03:00
Maksim Shabunin 2d1350a9d6 Added group targets for samples (opencv_samples, opencv_samples_<group>), install samples/data inseparate component 'samples_data' 2018-02-12 18:42:36 +03:00
Maksim Shabunin 2200e13c71 cmake: refactored scripts with samples building:
- allow installing samples sources on all platforms
  even if BUILD_EXAMPLES is disabled,  fixed minor
  issues in sources installation process
- use 'example_<group>_<name>' scheme for target and binary file naming
- use single function for sample executable creation
2018-02-12 18:42:36 +03:00
Maksim Shabunin 633b0e56a5 Fixed compilation warnings in samples:
- use per-module includes instead of "opencv.hpp"
- unused function warnings
- undefined macro warning
2018-02-12 18:42:36 +03:00
Maksim Shabunin 8393d755f6 Fixed OpenGL-specific compilation warning (unused function) 2018-02-12 18:42:36 +03:00
Alexander Alekhin 7474ad81d9 Merge pull request #10845 from alalek:cpu_dispatch_fix_file_generation 2018-02-12 15:39:24 +00:00
luz.paz e805a55a5b Misc. modules/ typos (cont.)
Found via `codespell`
2018-02-12 10:15:36 -05:00
Alexander Alekhin 14032c6653 cmake: reset __content variable if file doesn't exist
Resolves CMake error after relaunch with updated source code:
Cannot find source file:
    modules/dnn/layers/layers_common.avx512_skx.cpp
2018-02-12 17:30:53 +03:00
Alexander Alekhin 17233c687e Merge pull request #10797 from mshabunin:split-convert 2018-02-12 13:49:53 +00:00
Alexander Alekhin 57cbde3393 Merge pull request #10798 from mshabunin:split-stat 2018-02-12 13:49:41 +00:00
Alexander Alekhin 579781e35e Merge pull request #10822 from alalek:ocl_fix_imgproc_amd 2018-02-12 13:48:06 +00:00
Alexander Alekhin 66f3c1ae79 Merge pull request #10843 from luzpaz:misc-modules-typos 2018-02-12 13:47:12 +00:00
Sui Libin 1ad814a191 fix faster_rcnn sample crashed at PoolingInvoker on Windows7(x64). (#10724)
* fix faster_rcnn sample crashed at PoolingInvoker operator() of pooling_layer.

* find_odj onmouse bug about find matched point status.

* reverted AutoBuffer back to std::vector
2018-02-12 16:07:56 +03:00
Maksim Shabunin 221342fb25 Split convert.cpp into smaller pieces 2018-02-12 15:17:19 +03:00
luz.paz 5718d09e39 Misc. modules/ typos
Found via `codespell`
2018-02-12 07:09:43 -05:00
Rémi Ratajczak b67523550f dnn : Added an imagesFromBlob method to the dnn module (#10607)
* Added the imagesFromBlob method to the dnn module.

* Rewritten imagesFromBlob based on first dkurt comments

* Updated code with getPlane()

* Modify comment of imagesFromBlob() in dnn module

* modified comments, removed useless assertions & added OutputArrayOfArray

* replaced tabs with whitespaces & put vectorOfChannels instantiation outside the loop

* Changed pre-commit.sample to pre-commit in .git/hooks/

* Added a test for imagesFromBlob in test_misc.cpp (dnn)

* Changed nbOfImages, robustified test with cv::randu, modified assertion
2018-02-12 14:51:07 +03:00
Alexander Alekhin 5a791e6e06 cmake: update reporting of excluded dispatching files (#10711)
* cmake: add ocv_get_smart_file_name() macro

* cmake: avoid adding files for unavailable dispatch modes
2018-02-12 14:48:20 +03:00
Namgoo Lee 61e76e767d Update BufferReader documentation with some example code (#10803)
* Update BufferReader documentation with some example code

* Add warning to BufferPool doc regarding deallocation of StackAllocator

* Added a sample code that satisfies LIFO rule for StackAllocator
2018-02-12 14:41:23 +03:00
Vadim Pisarevsky 51b5fdba25 Merge pull request #10805 from dkurt:dnn_inf_engine_tf_ssd 2018-02-12 11:40:00 +00:00
yuki takehara 379ea15d16 Add new Mat constructor (#10808)
* Add new Mat constructor

* Fix build error

* Fix build error

* Fixed the code about 4 comments

* Fixed three comments

* delete previous local declaration

* fix build error
2018-02-12 14:36:54 +03:00
Maksim Shabunin 4437e0c3b9 Split stat.cpp into smaller pieces 2018-02-12 14:14:08 +03:00
Alexander Alekhin fad3a6bf15 ocl: disable Laplacian5 and sepFilter2D_SinglePass kernels for AMD OpenCL 2018-02-12 14:06:57 +03:00
Alexander Alekhin ab0f0f26a1 Merge pull request #10839 from csukuangfj:fix-9486 2018-02-12 09:24:29 +00:00
Alexander Alekhin b7ad95beaa Merge pull request #10836 from csukuangfj:fix-10826 2018-02-12 09:23:55 +00:00
Alexander Alekhin 2c8da29f3a Merge pull request #10835 from csukuangfj:fix-10827 2018-02-12 09:19:52 +00:00
Alexander Alekhin efd3fafa25 Merge pull request #10834 from csukuangfj:fix-issue-9387 2018-02-12 09:19:25 +00:00
Alexander Alekhin d61528b2d5 Merge pull request #10833 from csukuangfj:improve-viz3d 2018-02-12 09:12:39 +00:00
Fangjun Kuang e8b2c5682e fix issue #9387 and #9575. 2018-02-11 21:04:20 +08:00
Fangjun Kuang ce2a65db85 fix issue #9486. 2018-02-11 20:08:53 +08:00
Fangjun Kuang 2f3d4df2f2 improve the doc for the viz module. 2018-02-11 16:14:09 +08:00
Fangjun Kuang 6205981235 Fix issue 10826. 2018-02-11 16:01:21 +08:00
Fangjun Kuang 28a78003f0 Fix issue 10827. 2018-02-11 15:54:36 +08:00
Alexander Alekhin e2a99d24ec Merge pull request #10813 from alalek:cmake_cxx_flags 2018-02-10 12:27:00 +00:00
Alexander Alekhin 601e3aaf98 Merge pull request #10820 from alalek:python_isystem 2018-02-09 15:32:50 +00:00
Alexander Alekhin dd2fd39c05 Merge pull request #10819 from alalek:ocl_fix_dgpu_locks 2018-02-09 15:24:33 +00:00
Alexander Alekhin 84887d3011 cmake: use -isystem for Python/numpy include directories 2018-02-09 17:10:02 +03:00
Alexander Alekhin 9e298ea1bb build: eliminate c++17 Python build warning 2018-02-09 17:09:36 +03:00
Alexander Alekhin 65ba2e0adf cmake: update adding of extra compiler flags
Read flags from 'cache' instead of resetting them
2018-02-09 17:09:35 +03:00
Alexander Alekhin 42e1fe301c ocl: allow recursive UMatData lock() calls with the same objects
OpenCLAllocator::copy() may call upload()/download() methods
2018-02-09 14:19:10 +03:00
Dmitry Kurtaev 7fe97376c2 MobileNet-SSD from TensorFlow 1.3 and Inception-V2-SSD using Inference Engine backend 2018-02-09 13:45:45 +03:00
take1014 03407a9da0 Merge pull request #10646 from take1014:master
* Add a new interface for hough transform

* Fixed warning code

* Fix HoughLinesUsingSetOfPoints based on HoughLinesStandard

* Delete memset

* Rename HoughLinesUsingSetOfPoints and add common function

* Fix test error

* Change static function name

* Change using CV_Assert instead of if-block and add integer test case

* I solve the conflict and delete 'std :: tr1' and changed it to use 'tuple'

* I deleted std::tr1::get and changed int to use 'get'

* Fixed sample code

* revert test_main.cpp

* Delete sample code in comment and add snippets

* Change file name

* Delete static function

* Fixed build error
2018-02-08 22:54:43 +03:00
Alexander Alekhin d56b2b56fb Merge pull request #10814 from luzpaz:opencv-misc-apps-docs-platforms-typos 2018-02-08 19:14:30 +00:00
luz.paz d47b1f3b70 Misc. ./apps ./doc ./platoforms typos
Found via `codespell -q 3 --skip="./3rdparty" -I ../opencv-whitelist.txt`
2018-02-08 13:04:34 -05:00
Alexander Alekhin 090ee46f4a Merge pull request #10812 from luzpaz:opencv-misc-samples-dir-typos 2018-02-08 12:07:14 +00:00
luz.paz dbb57cd0ae Misc. ./samples typos
Found via `codespell -q 3 --skip="./3rdparty" -I ../opencv-whitelist.txt`
2018-02-08 05:52:08 -05:00
Vadim Pisarevsky 0c07836fba Merge pull request #10807 from luzpaz:misc-typos 2018-02-07 13:43:10 +00:00
Vadim Pisarevsky 835acd3f31 Merge pull request #10799 from dkurt:dnn_inference_engine_face_detection 2018-02-07 13:42:08 +00:00
Vadim Pisarevsky f8b03d4a4b Merge pull request #10806 from alalek:build_cxx17 2018-02-07 13:28:22 +00:00
luz.paz 413fba14ab Some mist. typo fixes
Found via `codespell -i 3 -w --skip="./3rdparty" -I ../opencv-whitelist.txt`
2018-02-07 06:59:15 -05:00
Alexander Alekhin 44d7435a48 build: eliminate calls of removed functionality from C++17
Most part is deprecated since C++11
2018-02-07 12:00:33 +03:00
Alexander Alekhin f77f2876ff Merge pull request #10800 from alalek:parallel_for_update 2018-02-06 17:56:33 +00:00
Alexander Alekhin 914f57f28d core(parallel_for): fix data race 2018-02-06 18:19:50 +03:00
Dmitry Kurtaev ed94136548 OpenCV face detection network using Inference Engine backend 2018-02-06 17:53:24 +03:00
Alexander Alekhin c973aaabc5 Merge pull request #10787 from dkurt:dnn_tutorial_face_detection 2018-02-06 14:37:09 +00:00
Vitaly Tuzov 3267fb90c6 Updated check on OutputArray to allow recreation of fixed_size for 1-d sizes array 2018-02-06 17:07:36 +03:00
Alexander Alekhin b10fedde56 core(parallel_for): cleanup
remove 'dont_wait' (can be replaced with has_wake_signal)
2018-02-06 16:10:41 +03:00
Dmitry Kurtaev 8817907647 Test for FP16 version of OpenCV face detection network 2018-02-06 13:16:07 +03:00
Alexander Alekhin 398ebbac98 Merge pull request #10795 from pengli:dnn 2018-02-06 10:04:29 +00:00
Li Peng c43498c6ad check vector emptiness before access it
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-06 22:59:51 +08:00
Li Peng 389fa5d38e slice layer ocl update
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-06 22:59:47 +08:00
Alexander Alekhin 2a1f46c42d Merge pull request #9770 from alalek:refactor_test_files 2018-02-06 09:33:58 +00:00
Maksim Shabunin e225850cc6 Split persistence.cpp into smaller pieces (#10788)
* Extracted base64 persistence functionality

* Extracted YML persistence functionality

* Extracted JSON persistence functionality

* Extracted XML persistence functionality

* Extracted public C and C++ interfaces implementation in persistence

* Persistence: cleanup and fixes

* fixup! Persistence: cleanup and fixes
2018-02-06 11:59:32 +03:00
Dmitry Kurtaev 10e1de74d2 Intel Inference Engine deep learning backend (#10608)
* Intel Inference Engine deep learning backend.

* OpenFace network using Inference Engine backend
2018-02-06 11:57:35 +03:00
Vadim Pisarevsky 292dfc2d72 Merge pull request #10789 from mshabunin:split-matrix 2018-02-06 08:54:16 +00:00
denmatfoton b085158d59 Fix unstable work of stereoRectify function. Issue description: https://github.com/opencv/opencv/issues/10791 2018-02-05 15:30:26 -05:00
Maksim Shabunin 904640c9ae Split matrix.cpp into smaller pieces 2018-02-05 19:16:33 +03:00
Alexander Alekhin 06455fc0cd Merge pull request #10764 from sturkmen72:update_cmake 2018-02-05 14:07:40 +00:00
Suleyman TURKMEN 3b191bf2dd update CMakeList.txt 2018-02-05 16:23:52 +03:00
berak 56bcdfd7d9 Merge pull request #10777 from berak:dnn_colorize_cpp
* dnn: add colorization.cpp

* Update arguments of dnn/colorization.py
2018-02-05 15:07:40 +03:00
Vadim Pisarevsky 14089b1e7c Merge pull request #10782 from csukuangfj:patch-1 2018-02-05 10:10:16 +00:00
Dmitry Kurtaev 5f6077bc62 Tool to generate text graphs for SSD models from TensorFlow (#10723)
* Added tool to generate text graph for SSD models from TensorFlow

* Update tf_text_graph_ssd.py
2018-02-05 13:00:43 +03:00
Alexander Alekhin 19a914be16 Merge pull request #10759 from mshabunin:fix-msvc-lto-debug 2018-02-05 09:33:03 +00:00
csukuangfj f1c91a8d34 Fix issue #10781
Fix issue #10781.
2018-02-05 11:26:25 +08:00
Alexander Alekhin 5a71f4a0ca Merge pull request #10775 from alalek:update_valgrind_suppression 2018-02-04 13:52:09 +00:00
Alexander Alekhin a449731a57 valgrind: update suppression rules 2018-02-03 22:59:45 +00:00
Alexander Alekhin e801e336ed Merge pull request #10769 from mshabunin:add-tbb-cmake-support 2018-02-03 19:48:19 +00:00
Alexander Alekhin 0d01b97b75 cuda: don't use std::numeric_limits
CUDA code uses own implementation in cuda/limits.hpp
2018-02-03 19:43:05 +00:00
Alexander Alekhin 7fedfa0380 cudev(test): avoid namespace check 2018-02-03 19:39:47 +00:00
Alexander Alekhin 4a297a2443 ts: refactor OpenCV tests
- removed tr1 usage (dropped in C++17)
- moved includes of vector/map/iostream/limits into ts.hpp
- require opencv_test + anonymous namespace (added compile check)
- fixed norm() usage (must be from cvtest::norm for checks) and other conflict functions
- added missing license headers
2018-02-03 19:39:47 +00:00
Maksim Shabunin 108d07c655 TBB: added workaround for linking issue with conflicting system and custom libraries 2018-02-03 14:27:46 +03:00
Maksim Shabunin 34a9ce6eb3 cmake: support searching for TBB via cmake package mechanism 2018-02-03 13:51:54 +03:00
Alexander Alekhin f1e50ecab3 ts: fix missing std::tr1 (C++17) 2018-02-02 20:02:45 +00:00
Alexander Alekhin a0ce12f8ba Merge pull request #10767 from alalek:fix_cmake 2018-02-02 19:26:49 +00:00
Alexander Alekhin 3d6659112f cmake: fix includes processing 2018-02-02 21:52:54 +03:00
Rostislav Vasilikhin 1055f9d208 Merge pull request #10757 from savuor:test_hist_renew
* old types removed

* QueryHist tests: new types

* ThreshHist tests: new types

* CalcHist tests: new types

* CalcBackProject tests: new types

* CalcBackProjectPatch tests: new types

* const ref added
2018-02-02 21:35:44 +03:00
Alexander Alekhin 403c3c3d03 Merge pull request #10766 from mshabunin:fix-world-interface-include 2018-02-02 16:25:17 +00:00
Alexander Alekhin 877b175565 Merge pull request #10758 from mshabunin:allow-many-contrib 2018-02-02 16:07:48 +00:00
Alexander Alekhin 82f889d9b8 Merge pull request #10765 from BelBES:sb/findContours_fix 2018-02-02 16:03:15 +00:00
Maksim Shabunin 7eb37bd1dd Fixed components INTERFACE_INCLUDE_DIRECTORY property in "world" builds 2018-02-02 18:14:25 +03:00
Harshal Nishar 384fa95680 Fix in Canny when Sobel apertureSize is 7 (#10743)
* Fixing a bug in Canny implemetation when Sobel aperture size is 7.

* Fixing the bug in Canny accross variants and in test_canny.cpp

* Replacing a tab with white space
2018-02-02 17:00:11 +03:00
sergeybe 2266a8c85f fix FindContours default offset for CV_LINK_RUNS method 2018-02-02 16:46:05 +03:00
Vadim Pisarevsky 83761d5f8e Merge pull request #10761 from seiko2plus:issue10753 2018-02-02 11:27:26 +00:00
Alexander Alekhin ecbd5b0574 Merge pull request #10751 from nglee:dev 2018-02-02 10:48:50 +00:00
Ya-Chiu Wu c8d8b1fbcd Merge pull request #10553 from GlueCrow:bgfg_knn_opencl
Add ocl version BackgroundSubtractorKNN (#10553)

* Add ocl version bgfg_knn

* Add ocl KNN perf test

* ocl KNN: Avoid unnecessary initializing when non-UMat parameters are used

* video: turn off OpenCL for color KNN on Intel devices

due performance degradation

* video: turn off KNN OpenCL on Apple devices with Intel iGPU

due process freeze during clBuildProgram() call
2018-02-02 13:20:46 +03:00
Alexander Alekhin 92fb3fb33f Merge pull request #10763 from alalek:issue_10760 2018-02-02 12:34:59 +03:00
Alexander Alekhin 02bc17be6f js: filterout OpenCL headers 2018-02-02 12:26:22 +03:00
Sayed Adel 534dcbe017 core:ppc Fix compile issue with Eigen 2018-02-02 03:31:25 +00:00
Alexander Alekhin 12cd3b55ec Merge pull request #10756 from terfendail:orb_firstlevel 2018-02-01 18:34:57 +00:00
Alexander Alekhin bbfa239036 Merge pull request #10706 from alalek:exception_opencv_version 2018-02-01 18:32:13 +00:00
Alexander Alekhin c96630c9f0 Merge pull request #10705 from alalek:opencv_version_update 2018-02-01 18:31:52 +00:00
Maksim Shabunin 60f1c9dcdf Do not enable LTO flags for MSVC debug configuration 2018-02-01 19:22:48 +03:00
Maksim Shabunin 82aff110b7 cmake: allow providing list of extra modules paths 2018-02-01 19:02:02 +03:00
Vitaly Tuzov 26321795f7 Fixed assertion in ORB::setFirstLevel() 2018-02-01 16:58:35 +03:00
Vadim Pisarevsky f780ee12a0 Merge pull request #10690 from terfendail:orb_firstlevel 2018-02-01 13:41:29 +00:00
Maksim Shabunin e56d6054aa Do not build protobuf without dnn (#10689)
* Do not build protobuf if dnn is disabled

* Added BUILD_LIST cmake option to the cache

* Moved protobuf to the top level

* Fixed static build

* Fixed world build

* fixup! Fixed world build
2018-02-01 16:30:23 +03:00
Vadim Pisarevsky 36222c9eed Merge pull request #10730 from dkurt:dnn_faster_rcnn_rfcn_tests 2018-02-01 13:28:10 +00:00
Vadim Pisarevsky 8436dac090 Merge pull request #10742 from alalek:fix_winrt_fs_build 2018-02-01 13:23:49 +00:00
Vadim Pisarevsky 713ec7be45 Merge pull request #10746 from dkurt:dnn_batch_norm_from_nvidia_caffe 2018-02-01 13:22:09 +00:00
Alexander Alekhin 42569cfd61 Merge pull request #10748 from dkurt:fix_dnn_slice_layer 2018-02-01 13:21:17 +00:00
Alexander Alekhin 7c8a3da0ac Merge pull request #10709 from alalek:cleanup_2018 2018-02-01 13:08:36 +00:00
Alexander Alekhin 9d25bd583f Merge pull request #10754 from dkurt:dnn_ocl_gemv_min_globalsize 2018-02-01 12:39:27 +00:00
Vadim Pisarevsky 85af8735ab Merge pull request #10749 from alalek:issue_10736 2018-02-01 12:26:50 +00:00
Aditya Rohan ccea0a831a Merge pull request #10732 from Riyuzakii:10598
* Introduces error throw for line drawn with THICKNESS=0
2018-02-01 15:21:00 +03:00
Dmitry Kurtaev 65a6674c6e ocl4dnnGEMV in case of row_size < 4 2018-02-01 14:06:47 +03:00
Alexander Alekhin 9698b93d10 Merge pull request #10717 from pengli:dnn 2018-02-01 10:49:54 +00:00
Alexander Alekhin 78ce5b815d Merge pull request #10733 from alalek:issue_10654 2018-02-01 10:31:48 +00:00
Li Peng 6aec71d7ee mvn layer ocl update
it fuse ocl kernels to reduce kernel enqueue

Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-01 17:48:12 +08:00
Li Peng 83b16ab7b7 fix extra spaces in build option
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-01 17:46:11 +08:00
Li Peng 54c81cbde4 eltwise layer SUM op update
Signed-off-by: Li Peng <peng.li@intel.com>
2018-02-01 17:46:06 +08:00
Namgoo Lee 3cf535926a cuda_stream: do not allocate GPU memory by default (fixes #8725) 2018-02-01 03:55:52 +09:00
Alexander Alekhin 35738bcadd samples: remove orphan documentation snippet: SBM_Sample.cpp 2018-01-31 18:54:08 +00:00
Dmitry Kurtaev 184862582c Fix slice layer from TensorFlow 2018-01-31 19:12:37 +03:00
Alexander Alekhin c4f9ff0285 cmake: avoid using of pkg-config in cross-compilation mode unconditionally
- specify PKG_CONFIG_LIBDIR environment variable to new target SYSROOT
2018-01-31 16:56:24 +03:00
Arjan van de Ven a75840d19c Merge pull request #10468 from fenrus75:avx512-2
* Add a 512 bit codepath to the AVX512 fastConv function

this patch adds a 512 wide codepath to the fastConv() function for
AVX512 use.
The basic idea is to process the first N * 16 elements of the vector
with avx512, and then run the rest of the vector using the traditional
AVX2 codepath.

* dnn: use unaligned AVX512 load (OpenCV aligns data on 32-byte boundary)

* dnn: change "vecsize" condition for AVX512

* dnn: fix indentation
2018-01-31 16:34:12 +03:00
Alexander Alekhin f06c44f1f1 Merge pull request #10701 from dkurt:tf_ave_pooling 2018-01-31 13:28:09 +00:00
Dmitry Kurtaev 844f1d0281 Fix Batch Normalization layer imported from NVIDIA Caffe. 2018-01-31 16:25:45 +03:00
Dmitry Kurtaev a2e9bfbaf4 Fix padding for average pooling from TensorFlow 2018-01-31 15:54:30 +03:00
Alexander Alekhin 2e45095e8d winrt: fix build 2018-01-31 15:00:45 +03:00
Alexander Alekhin 027da35c33 Merge pull request #10738 from tomoaki0705:fixBuildVisualStudio 2018-01-31 09:57:29 +00:00
Alexander Alekhin 2c1161a6f9 Merge pull request #10735 from seiko2plus:coreYieldPPC 2018-01-31 09:41:37 +00:00
Tomoaki Teshima 5f4b48da34 fix build error on Visual Studio 2013 and earlier 2018-01-31 18:22:09 +09:00
Sayed Adel 4e1d396ce1 core:ppc Add yield support 2018-01-31 04:03:35 +00:00
Alexander Alekhin 98bd0a06dc cmake: fix gnu.toolchain
- CMAKE_FIND_ROOT_PATH_MODE_PROGRAM: ONLY => NEVER
- update handling of CMAKE_FIND_ROOT_PATH_MODE_* variables
2018-01-30 18:29:18 +00:00
Alexander Alekhin f57630d92b Merge pull request #10691 from alalek:parallel_for_2018 2018-01-30 14:13:29 +00:00
Dmitry Kurtaev ae2e4af4a1 Faster-RCNN and RFCN tests
https://github.com/rbgirshick/py-faster-rcnn
https://github.com/YuwenXiong/py-R-FCN
2018-01-30 13:17:35 +03:00
Vadim Pisarevsky cb66f82c1d Merge pull request #10707 from alalek:update_reports 2018-01-30 09:22:46 +00:00
Vadim Pisarevsky 1389fd67ab Merge pull request #10721 from alalek:ocl_force_clBuildProgram 2018-01-30 09:20:58 +00:00
Li Peng 7a4c5e9421 slice layer ocl support
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-29 22:34:32 +08:00
Alexander Alekhin cf1ba0c4e1 Merge pull request #10719 from alisentas:master
Fix cv::CommandLineParser::check() documentation
2018-01-29 16:24:59 +03:00
Alexander Alekhin ebdb0eb0c1 ocl: force clBuildProgram() call after clCreateProgramWithBinary() 2018-01-29 15:51:07 +03:00
Ali Sentas 4d80419f29 Fix cv::CommandLineParser::check() documentation 2018-01-29 15:14:21 +03:00
Alexander Alekhin 32d71cf85f Merge pull request #10713 from alalek:issue_10710 2018-01-29 09:03:36 +00:00
Alexander Alekhin 2876670de3 dnn(ocl): fix build options for Apple OpenCL 2018-01-28 01:54:25 +00:00
Alexander Alekhin 36d4c29b11 cleanup unused/outdated files/scripts/links 2018-01-27 23:22:44 +00:00
Alexander Alekhin c8930cc279 opencv_version: dump detected HW features 2018-01-27 17:08:29 +00:00
Alexander Alekhin 01f4a173ab opencv_version: dump OpenCL information via opencv_version
fix missing "opencv2/core/opencl" headers from core module (updated install list)
2018-01-27 17:08:28 +00:00
Alexander Alekhin daf3368d2e perf reports: remove units from table cells
- moved to table title
- can be restored via '--show_units' option
- fix microseconds: mks -> us
2018-01-27 14:38:40 +00:00
Alexander Alekhin f6fd3abd31 core: add OpenCV version information into Exception messages 2018-01-27 13:51:16 +00:00
Woody Chow f1c52e426b Merge pull request #10697 from woodychow:tbb_task_arena
* Use Intel TBB's task arena if possible
2018-01-27 08:46:54 +03:00
Pavel Rojtberg 203dc3bb48 Merge pull request #10667 from paroj:stereo_calib_ex
calib3d: add stereoCalibrateExtended (#10667)

* cvCalibrateCamera2Internal: simplify per view error computation

* calib3d: add stereoCalibrateExtended

- allow CALIB_USE_EXTRINSIC_GUESS
- returns per view errors

* calib3d: add stereoCalibrateExtended test
2018-01-26 22:05:13 +03:00
Alexander Alekhin 7b8ab4e5c6 Merge pull request #10688 from LaurentBerger:calcback 2018-01-26 19:01:48 +00:00
Alexander Alekhin 73891d619a Merge pull request #10700 from alalek:cpu_dispatch_axv512
* cmake: enable CPU dispatching for AVX512 (SKX)

* cmake: update handling of unsupported flags/modes
2018-01-26 21:59:47 +03:00
Alexander Alekhin fe4fbc2c3b Merge pull request #10693 from travbid:IntrinsicParams_fix 2018-01-26 16:22:38 +00:00
LaurentBerger 2ebf4e084a solve issue #10687 2018-01-26 17:01:02 +01:00
Alexander Alekhin df22bafe6d Merge pull request #10681 from hmaarrfk:python_stitching_scans 2018-01-26 10:04:41 +00:00
Alexander Alekhin c49d5d5252 core: fix pthreads performance
OpenCV pthreads-based implementation changes:
- rework worker threads pool, allow to execute job by the main thread too
- rework synchronization scheme (wait for job completion, threads 'pong' answer is not required)
- allow "active wait" (spin) by worker threads and by the main thread
- use _mm_pause() during active wait (support for Hyper-Threading technology)
- use sched_yield() to avoid preemption of still working other workers
- don't use getTickCount()
- optional builtin thread pool profiler (disabled by compilation flag)
2018-01-26 04:09:11 +00:00
Alexander Alekhin 104502c5be Merge pull request #10676 from dkurt:dnn_for_newer_mobilenet_ssd 2018-01-26 04:02:21 +00:00
Travers 7d6cf66303 IntrinsicParams operator+ fix 2018-01-26 14:04:45 +13:00
Maksim Shabunin d1b08486ae Merge pull request #10619 from mshabunin:fix-run-py-without-java 2018-01-25 13:47:47 +00:00
Vitaly Tuzov 205022ceee Fixed issue in ORB detection if firstLevel property is set above 0 2018-01-25 16:14:16 +03:00
Alexander Alekhin 47998c03f8 perf: update message 2018-01-25 13:18:47 +03:00
Alexander Alekhin 27cddfb8e9 Merge pull request #10661 from alalek:parallel_kmeans 2018-01-25 10:18:37 +00:00
Maksim Shabunin 3f116468c6 Merge pull request #10679 from mshabunin:vs-defense-flags 2018-01-25 09:57:43 +00:00
Alexander Alekhin 8c2563be41 Merge pull request #10672 from pengli:dnn 2018-01-25 07:18:25 +00:00
Li Peng 2493083935 mvn, batch_norm and relu layer fusion
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-25 18:57:05 +08:00
Li Peng e15928b49e convolution and tanh layer fusion
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-25 17:45:33 +08:00
Mark Harfouche df434298b8 Exported a high level stitcher the DLL
allows Stitcher to be used for scans from within python.
I had to use very strange notation because I couldn't export the `enum`
`Mode` making the Cpython generated code unable to compile.

```c++
class Stitcher {
public:
enum Mode
    {
        PANORAMA = 0,
        SCANS = 1,
    };
...
```

Also removed duplicate code from the `createStitcher` function making
use of the `Stitcher::create` function
2018-01-24 12:43:00 -08:00
Alexander Alekhin c401168bea Merge pull request #10675 from LaurentBerger:tutopy_arithm 2018-01-24 17:49:20 +00:00
Alexander Alekhin 0b1f626efd Merge pull request #10677 from alalek:issue_10668 2018-01-24 17:48:11 +00:00
Maksim Shabunin 74367093c8 VS with hardening: added guard flag, moved dynamicbase and safeseh to linker flags 2018-01-24 17:59:10 +03:00
Jozef Mlich 7a472d85ef Merge pull request #10663 from jmlich:master
* hogsvm compatibility with python3
2018-01-24 17:03:23 +03:00
Alexander Alekhin 81c5fae56f core(lapack): fix build issues related to 'extern "C"' 2018-01-24 14:53:04 +03:00
Dmitry Kurtaev 9e9926a2f0 PriorBox layer with explicit normalized sizes 2018-01-24 14:01:42 +03:00
LaurentBerger 6e5da9dbe3 bad image file 2018-01-24 09:09:49 +01:00
Elena Gvozdeva b97b650ab3 add HAL for FAST (#10362)
* add HAL for FAST

* add new interface
2018-01-24 01:48:06 +03:00
Vadim Pisarevsky a1d2258ac3 Merge pull request #10635 from csukuangfj:doc-checkVector 2018-01-23 10:42:05 +00:00
Vadim Pisarevsky 8f04c8b16c Merge pull request #10644 from csukuangfj:doc-fundamental-matrix 2018-01-23 10:38:14 +00:00
Pavel Rojtberg 2d674fc151 persistence: replace arbitrary limit of cn to 4 by CV_CN_MAX (#10636)
* persistence: replace arbitrary limit of cn to 4 by CV_CN_MAX

* python: added persistence test, remove temp files

* fixup! python: added persistence test, remove temp files

* fixup! python: added persistence test, remove temp files
2018-01-23 13:36:30 +03:00
Alexander Alekhin 479179638e Merge pull request #10655 from dkurt:dnn_tests 2018-01-23 10:16:55 +00:00
Dmitry Kurtaev a3d74704e5 OpenCV face detection network test 2018-01-23 09:27:58 +03:00
Alexander Alekhin 90aac764dd core: kmeans refactoring
- reduce scope of i,k,j variables
- use cv::AutoBuffer
- template<bool onlyDistance> class KMeansDistanceComputer
- eliminate manual unrolling: CV_ENABLE_UNROLLED
2018-01-22 14:26:41 +03:00
Alexander Alekhin 46470d92a0 core: fix kmeans multi-threaded performance 2018-01-22 14:26:41 +03:00
Alexander Alekhin a5cd62f7bf core(perf): refactor kmeans test
- don't use RNG for "task size" parameters (N, K, dims)
- add "good" kmeans test data (without singularities: K > unique points)
2018-01-22 14:25:29 +03:00
Vitaly Tuzov 12ea8477a3 bitexact gaussianblur implementation (#10345)
* Bit-exact implementation of GaussianBlur smoothing

* Added universal intrinsics based implementation for bit-exact CV_8U GaussianBlur smoothing.

* Added parallel_for to evaluation of bit-exact GaussianBlur

* Added custom implementations for 3x3 and 5x5 bit-exact GaussianBlur
2018-01-22 13:26:32 +03:00
Alexander Alekhin 87db636c61 Merge pull request #10657 from GlueCrow:mog2_init_fix 2018-01-21 17:25:37 +00:00
Glue Crow c5c620bab0 ocl: Avoid unnecessary initializing when non-UMat parameters are used 2018-01-21 23:02:05 +08:00
Gregory Morse d84c7e5143 Merge pull request #10649 from GregoryMorse:patch-3
* Fix for QT image window rectangle

* Update window_QT.h

* Update window_QT.cpp

* trailing whitespace

* highgui: fix QT getWindowImageRect()
2018-01-21 09:26:48 +03:00
Maksim Shabunin 8ba88892d7 run.py: simplified scripts, fixed most of PEP8 warnings 2018-01-19 17:05:40 +03:00
Fangjun Kuang eb2901bd69 Improve the doc for fundamental matrix. 2018-01-19 13:41:47 +01:00
Vadim Pisarevsky c89ae6e537 Merge pull request #10629 from GlueCrow:ocl_mog2_test_fix 2018-01-19 11:12:19 +00:00
Namgoo Lee 25c36fb05f cv::cuda::cvtColor bug fix (#10640)
* cuda::cvtColor bug fix

Fixed bug in conversion formula between RGB space and LUV space.
Testing with opencv_test_cudaimgproc.exe, this commit reduces the number
of failed tests from 191 to 95. (96 more tests pass)

* Rename variables
2018-01-19 14:06:05 +03:00
Vadim Pisarevsky 71ba54b2f4 Merge pull request #10637 from catree:fix_perf_build_cuda_9 2018-01-19 11:02:14 +00:00
Alexander Alekhin 18ce529256 Merge pull request #10633 from csukuangfj:doc-estimateAffine 2018-01-19 10:11:56 +00:00
Alexander Alekhin 26e0f408f0 Merge pull request #10639 from pengli:dnn 2018-01-19 10:01:41 +00:00
Li Peng fe494297e4 more update on MVN layer ocl implementation
cut one ocl kernel if normVariance is disabled,
also use native_powr for performance reason.

Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-19 22:54:04 +08:00
Alexander Alekhin c3569211d5 Merge pull request #10591 from drkoller:master 2018-01-19 09:44:21 +00:00
catree dcc5a2cb22 Fix perf build with CUDA 9. 2018-01-19 00:23:02 +01:00
Fangjun Kuang 67842df9e2 Improve the documentation for affine transform estimation. 2018-01-18 19:54:18 +01:00
Alexander Alekhin 8226bd25c4 Merge pull request #10625 from pengli:dnn 2018-01-18 18:26:30 +00:00
Fangjun Kuang 8efe7bafaa Improve the doc for cv::Mat::checkVector. 2018-01-18 16:48:59 +01:00
Li Peng 2124361ff7 ocl support for Deconvolution layer
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-18 23:40:22 +08:00
Vadim Pisarevsky 42459cad02 Merge pull request #10634 from sturkmen72:update_samples 2018-01-18 13:46:27 +00:00
Alexander Alekhin 0def2dbb73 Merge pull request #10605 from alalek:ocl_fix_deadlock 2018-01-18 13:39:36 +00:00
Maksim Shabunin 1b0ff57562 Merge pull request #10621 from mshabunin:disable-docs
Documentation generation refactoring (#10621)

* Documentation build updates:

- disable documentation by default, do not add to ALL target
- combine Doxygen and Javadoc
- optimize Doxygen html

* javadoc: fix path in build directory

* cmake: fix "Documentation" status line
2018-01-18 16:37:19 +03:00
Glue Crow 95ce21d407 Fix #10525 2018-01-18 18:49:29 +08:00
Gregory Morse ec353dbdda Merge pull request #10412 from GregoryMorse:patch-2
Update to add window position and size retrieval to HighGUI (#10412)

* Update highgui.hpp

Add read only property retrieval for enhanced rendering capabilities and more sophisticated research tools

* Update window.cpp

* Update window_w32.cpp

* Update window_QT.cpp

* Update window_QT.h

* Update window_QT.h

* Update window_gtk.cpp

* Update precomp.hpp

* Update highgui_c.h

* Update highgui_c.h

* Update window_w32.cpp

* Update precomp.hpp

* Update window_QT.cpp

* Update window_QT.h

* Update window_gtk.cpp

* Update window_gtk.cpp

* Update window_w32.cpp

* Update window_QT.cpp

* Update window_carbon.cpp

* Update window_cocoa.mm

* Update precomp.hpp

* Update window_cocoa.mm

* Update window_w32.cpp

* Update window_gtk.cpp

* Update window_QT.cpp

* Update window_gtk.cpp

* Update window_QT.cpp

* Update window_cocoa.mm

* Update window_carbon.cpp

* Update window_w32.cpp

* Update window_cocoa.mm

* Update window_gtk.cpp

* Update window_cocoa.mm

* Update window_gtk.cpp

* Update window_cocoa.mm

* Update window_cocoa.mm

* Update window.cpp

* Update test_gui.cpp

* Update test_gui.cpp

* Update test_gui.cpp

* Update highgui_c.h

* Update highgui.hpp

* Update window.cpp

* Update highgui_c.h

* Update test_gui.cpp

* Update highgui.hpp

* Update window.cpp

* Update window.cpp

* Update window.cpp

* Update window.cpp

* Update window.cpp
2018-01-18 07:49:47 +03:00
Alexander Alekhin f056e713c3 Merge pull request #10512 from sturkmen72:update_documentation 2018-01-18 04:44:59 +00:00
Suleyman TURKMEN 4046d9f850 Update samples 2018-01-18 07:04:42 +03:00
Alexander Alekhin aa55cdb735 Merge pull request #10622 from alalek:fix_build_js
Re-apply protobuf fix for JavaScript builds
2018-01-17 23:52:26 +03:00
Dmitry Kurtaev ec8d39d059 Re-apply protobuf fix for JavaScript builds
original commit: f503515082
JavaScript bindings for dnn module
2018-01-17 20:20:00 +00:00
David Koller d1a3b530be Make DNN Crop layer match Caffe default offset behavior
and add parametric unit test for crop layer.
2018-01-17 10:52:36 -05:00
Alexander Alekhin a55aed5f42 Merge pull request #10593 from alalek:android_build_sdk_configuration 2018-01-17 11:34:03 +00:00
Alexander Alekhin b067e0ca5d Merge pull request #10613 from csukuangfj:fix-10612 2018-01-17 09:58:34 +00:00
Alexander Alekhin 85e133a051 Merge pull request #10604 from aimotive:master 2018-01-17 09:40:42 +00:00
Alexander Alekhin 4a086cf517 Merge pull request #10609 from csukuangfj:patch-1 2018-01-17 09:02:50 +00:00
razerhell fb22028be3 Merge pull request #10574 from razerhell:patch-1
* Newton's method can be more efficient

when we get the result of function distortPoint with a point (0, 0) and then undistortPoint with  the result, we get the point not (0, 0). and then we discovered that the old method is not convergence sometimes. finally we have gotten the right values by Newton's method.

* modify by advice  Newton's method...#10574

* calib3d(fisheye): fix codestyle, update theta before exit EPS check
2018-01-17 12:05:13 +03:00
Alexander Alekhin 6728b40ad3 Merge pull request #10602 from pengli:dnn 2018-01-17 08:58:25 +00:00
Li Peng e77af4ae33 MVN layer ocl implementation
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-17 17:11:32 +08:00
Li Peng 7bc017601f Power, Tanh and Channels ReLU layer ocl support
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-17 17:11:27 +08:00
csukuangfj decf6cab5e Improve the documentation for cv::completeSymm and cv::RANSACUpdateNumIters. 2018-01-17 08:05:39 +01:00
Fangjun Kuang 2b635edce6 fix issue #10612. 2018-01-16 23:47:15 +01:00
Csaba Keszegh 2aa18ca3e9 fix: use CXX_STANDARD when extracting compiler flags for PCH with GNUCXX
When compiling with cmake using -DCMAKE_CXX_STANDARD=11 use `-std=gnu++11`
for PCH compiler flags, otherwise it triggers an error:

   opencv_core_Release.gch: not used because `__cplusplus' defined as ` 201103L' not ` 199711L' [-Winvalid-pch]

Use CXX_EXTENSIONS property to select `gnu++11` or `c++11`.
Trying to mimic cmake logic here: https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmLocalGenerator.cxx#L1527-1557
2018-01-16 20:32:21 +01:00
Alexander Alekhin 4dc788ff84 Merge pull request #10606 from alalek:update_copyright_2018 2018-01-16 17:47:30 +00:00
Alexander Alekhin cec700525c core(ocl): fix deadlock in UMatDataAutoLock
UMatData locks are not mapped on real locks (they are mapped to some "pre-initialized" pool).

Concurrent execution of these statements may lead to deadlock:
- a.copyTo(b) from thread 1
- c.copyTo(d) from thread 2
where:
- 'a' and 'd' are mapped to single lock "A".
- 'b' and 'c' are mapped to single lock "B".

Workaround is to process locks with strict order.
2018-01-16 17:33:06 +03:00
Woody Chow 20b3261204 Propagate calculated Gaussian kernel size(ref). Otherwise, ipp_GaussianBlur will fail if user doesn't specify a kernel size. (#10579) 2018-01-16 17:15:23 +03:00
Alexander Alekhin ab8cf31ae9 Merge pull request #10581 from mshabunin:minor-issues-fixes 2018-01-16 13:19:32 +00:00
Maksim Shabunin c0ae812aa2 Add ThinLTO support for clang 2018-01-16 15:26:28 +03:00
Maksim Shabunin 8b87c4b96a Fixed several warnings produced by clang 6 and static analyzers 2018-01-16 15:26:28 +03:00
Alexander Alekhin cbb21f3cf2 Merge pull request #10595 from oqtvs:updateProtobuf 2018-01-16 12:18:18 +00:00
Li Peng 4189214d04 batch_norm layer ocl update
use a batch_norm ocl kernel to do the work

Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-16 19:01:58 +08:00
Alexander Alekhin e6ed853905 copyright: 2018 2018-01-16 13:55:42 +03:00
Vadim Pisarevsky 59915a3fc9 Merge pull request #10575 from ioxp:getFontScale 2018-01-16 10:51:04 +00:00
Alexander Alekhin 22816a4c43 protobuf: drop unused files 2018-01-15 21:15:23 +00:00
Alexander Alekhin 4d84999452 dnn: protobuf build warnings 2018-01-15 21:15:23 +00:00
oqtvs 6d4b778303 dnn: Updated protobuf files (3.5.1) 2018-01-15 15:51:38 +00:00
oqtvs df0b83332d Updated protobuf version to 3.5.1 2018-01-15 13:51:37 -02:00
Alexander Alekhin be1207e5e4 Merge pull request #10580 from woodychow:parallel_initUndistortRectifyMap 2018-01-15 15:05:32 +00:00
Alexander Alekhin 1255bd8d4b Merge pull request #10585 from dkurt:dnn_weightless_scale 2018-01-15 06:07:50 +00:00
woody.chow f5d9a2a9c1 Parallelize initUndistortRectifyMap 2018-01-15 09:20:35 +09:00
Alexander Alekhin edcbbee979 android: update build_sdk.py
- configuration files for ABIs configuration
- use builtin Android NDK's toolchain by default (force flag to use OpenCV's toolchain)
- default values for 'work_dir' and 'opencv_dir'
2018-01-14 16:05:48 +00:00
Alexander Alekhin 70ff4af4fa Merge pull request #10588 from dkurt:dnn_blobFromImage_ext 2018-01-14 08:12:29 +00:00
Dmitry Kurtaev 6a395d88ff dnn::blobFromImage with OutputArray 2018-01-13 18:20:24 +03:00
Dmitry Kurtaev 1f4fdfd599 Untrainable version of Scale layer from Caffe 2018-01-13 10:35:29 +03:00
Alexander Alekhin 0c00652f6b Merge pull request #10495 from alalek:cmake_java 2018-01-13 04:31:10 +00:00
Alexander Alekhin 91e10a3105 cmake: ocv_target_include_directories() handle SYSTEM directories 2018-01-13 02:12:39 +00:00
Alexander Alekhin 08086178bd android: fix SDK build
- fix Javadoc:
  - generate Javadoc after gather step to process all Java files (including Android 21)
  - generate into 'OpenCV-android-sdk' directly without additional copy step
- use smart copy/move utility functions ('shutil' doesn't well with existed destination)
- by default move files to reduce pressure on storage I/O (> 800Mb)
2018-01-13 02:12:39 +00:00
Alexander Alekhin 839cffdefe java: fix MacOS Java problem 2018-01-13 02:12:39 +00:00
Alexander Alekhin a362fd80df java: fix bindings generator
- fix imports override.
  Problem is observed with BoostDesc.

- add Ptr<> handling (constructor is protected from other packages).
  Observed in ximgproc:
      Ptr<StereoMatcher> createRightMatcher(Ptr<StereoMatcher> matcher_left)"
  where, "StereoMather" is from another package (calib3d)
2018-01-13 02:12:39 +00:00
Alexander Alekhin 1237faef80 java: disable highgui wrapped code 2018-01-13 02:12:39 +00:00
Alexander Alekhin a0d9d6db5b fixes for old CMake (2.8.12.2) 2018-01-13 02:12:39 +00:00
Alexander Alekhin 8533b45ce9 cmake: Java/Android SDK refactoring 2018-01-13 02:12:39 +00:00
Suleyman TURKMEN dcd4f8f5db Update documentation 2018-01-12 22:21:14 +03:00
Alexander Alekhin 0cad2d2a83 java: files rename
intermediate commit (to simplify code review)
2018-01-12 19:14:00 +00:00
Alexander Alekhin 73316e10a0 java(test): fix test names 2018-01-12 19:14:00 +00:00
Alexander Alekhin 69cd9cc1a6 Merge pull request #10582 from mshabunin:fix-ocl-concurrent-cache-name 2018-01-12 18:43:08 +00:00
Maksim Shabunin 594a93316c Fixed concurrent OpenCL cache folder name generation 2018-01-12 19:03:16 +03:00
SarenT c6d9ce8fd3 Merge pull request #10489 from SarenT:offset-mat_put
Adding capability to parse subsections of a byte array in Java bindings (#10489)

* Adding capability to parse subsections of a byte array in Java bindings. (Because Java lacks pointers. Therefore, reading images within a subsection of a byte array is impossible by Java's nature and limitations. Because of this, many IO functions in Java require additional parameters offset and length to define, which section of an array to be read.)

* Corrected according to the review. Previous interfaces were restored, instead internal interfaces were modified to provide subsampling of java byte arrays.

* Adding tests and test related files.

* Adding missing files for the test.

* Simplified the test

* Check was corrected according to discussion. An OutOfRangeException will be thrown instead of returning.

* java: update MatOfByte implementation checks / tests
2018-01-12 18:00:58 +03:00
Alexander Alekhin 9deaddcdff Merge pull request #10490 from alalek:cmake_android_refactor_copy_project_files 2018-01-12 12:23:37 +00:00
Alexander Alekhin 98b6e1d5fe Merge pull request #10515 from alalek:android_ndk16 2018-01-12 12:22:40 +00:00
Alexander Alekhin 57dc28fe99 Merge pull request #10504 from opentrack:fork 2018-01-11 18:47:27 +00:00
Stanislaw Halik c8794c89c7 modules/videoio: fix PS3Eye camera property window
v2: fix stray trailing whitespace

v3: only allow for up to one property window at the time

Opening multiple windows in the same process will just confuse
the camera filter or outright crash.

Suggested-by: @alalek

Also return whether a dialog was opened at the time.
2018-01-11 16:37:02 +01:00
Alexander Alekhin 18edd917e3 Merge pull request #10391 from ElenaGvozdeva:HAL_minMaxIdx 2018-01-11 14:15:40 +00:00
Philipp Hasper 6032d86e23 Added getFontScaleFromHeight() 2018-01-11 14:00:27 +01:00
Dmitry Kurtaev 64a9e92390 Merge pull request #10466 from dkurt:reduce_umat_try_2
* UMat blobs are wrapped

* Replace getUMat and getMat at OpenCLBackendWrapper
2018-01-10 21:50:54 +03:00
Alexander Alekhin b6075e11b8 Merge pull request #10549 from Sahloul:bug_fix/FLANN 2018-01-10 11:39:47 +00:00
Alexander Alekhin c19764e557 Merge pull request #10568 from alalek:fix_10565 2018-01-10 11:35:25 +00:00
Alexander Alekhin 71768de939 Merge pull request #10567 from terfendail:createsample_fix 2018-01-10 10:22:19 +00:00
Alexander Alekhin f943261847 Merge pull request #10566 from alalek:jasper_checks 2018-01-10 10:15:41 +00:00
Alexander Alekhin 7763b58a60 Merge pull request #10563 from alalek:issue_10540 2018-01-10 10:15:10 +00:00
Aaron Bray 6f8be3f693 Merge pull request #10497 from aaron-bray:msvc2017-findcuda
* Update to properly find the compiler tools for MSVC 2017

* FindCUDA: Fix the MSVC 2017 compiler tool locations
2018-01-10 12:32:34 +03:00
Alexander Alekhin 6113dc1b99 core: fix unresolved symbols from utils::fs 2018-01-09 19:29:50 +00:00
Alexander Alekhin 4d4f291553 Merge pull request #10513 from pengli:dnn 2018-01-09 19:24:28 +00:00
Vitaly Tuzov 29faf164b9 Fixed exception when ROI for generated sample is evaluated out of image borders 2018-01-09 20:30:39 +03:00
Alexander Alekhin 435a3e337b imgcodecs: add more Jasper checks for supported and tested cases 2018-01-09 19:06:03 +03:00
Alexander Alekhin f92e880d3d Merge pull request #10544 from alalek:issue_10535 2018-01-09 15:32:42 +00:00
Alexander Alekhin 8a76fadaa3 imgcodecs: add overflow checks 2018-01-09 18:05:24 +03:00
Alexander Alekhin be5247921d imgcodecs: remove assert() usage 2018-01-09 17:49:38 +03:00
Li Peng e3b42bf93b batch_norm and blank layer ocl implementation
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-09 21:58:46 +08:00
tobycollins f34a0a874a Merge pull request #10522 from tobycollins:issue10519 2018-01-09 15:54:36 +03:00
Alessandro de Oliveira Faria (A.K.A.CABELO) c71dc78cd4 Merge pull request #10502 from cabelo/save-dnn-yolo
Save video file (#10502)
2018-01-08 22:30:28 +03:00
Alexander Alekhin f3dde79ed6 cmake: allow BUILD_FAT_JAVA_LIB for non-Android targets too 2018-01-08 19:24:39 +00:00
Alexander Alekhin da0904df2d Merge pull request #10550 from dkurt:replace_psroi_pooling_tag 2018-01-08 19:19:00 +00:00
Alexander Alekhin c08a0edea1 Merge pull request #10545 from alalek:dnn_blob_manager_runtime_option 2018-01-08 13:22:44 +00:00
Dmitry Kurtaev 27b55ea761 Replace Caffe's psroi_pooling_param tag from 10001 to 10002 2018-01-08 13:29:20 +03:00
Hamdi Sahloul 8943441115 resolves #10548 - FLANN::knnSearch garbage bug (when kNN is larger than the dataset size) 2018-01-08 18:58:55 +09:00
Alexander Alekhin 6674a024fc dnn: add OPENCV_DNN_DISABLE_MEMORY_OPTIMIZATIONS runtime option
replaces REUSE_DNN_MEMORY compile-time option
2018-01-07 18:38:14 +00:00
Alexander Alekhin ee35263e48 Merge pull request #10537 from pnemonic78:master_false 2018-01-07 12:53:22 +00:00
Moshe 84596bff09 Bitwise "and false"
Bitwise "and false" is always false.
2018-01-07 10:12:53 +02:00
Alexander Alekhin e3a6d74945 Merge pull request #10536 from Sahloul:bug_fix/BLOB 2018-01-07 06:50:49 +00:00
Alexander Alekhin dd3c1d3b8c Merge pull request #10534 from ericrwx:videoio-psnr-typo-fix 2018-01-07 06:48:05 +00:00
Alexander Alekhin 3a5cd12dee Merge pull request #10527 from csukuangfj:local 2018-01-07 06:46:45 +00:00
Hamdi Sahloul 2d2499f610 BLOB - Support RGBA 2018-01-07 14:30:40 +09:00
Eric Wang c11895f529 Fix typo in video_input_psnr_ssim 2018-01-06 16:15:43 -08:00
LaurentBerger 004a1cd64a Merge pull request #10529 from LaurentBerger:ExampleGoogleNet
* Add a parameter labels to command line

* default value

* samples: caffe_googlenet.cpp minor refactoring
2018-01-06 23:44:47 +03:00
Alexander Alekhin d0b2e60edc Merge pull request #10514 from alalek:build_warnings 2018-01-05 20:54:01 +00:00
Alexander Alekhin 8e1f31f543 Merge pull request #10521 from DabatoIsCool:master 2018-01-05 23:56:07 +03:00
Fangjun Kuang a2869109f0 Improve the documentation for cv::Affine3. 2018-01-05 19:35:38 +01:00
Alexander Alekhin 431b3b4323 cmake(android): refactor copying of Android samples project files 2018-01-05 17:32:27 +00:00
Alexander Alekhin 9966903ae1 cmake(android): fix non-idempotent INSTALL scripts 2018-01-05 17:19:37 +00:00
Arthur Williams 8a67858068 Fixed missing #include "../precomp.hpp" 2018-01-05 15:10:39 +00:00
Alexander Alekhin f5862dacb6 Merge pull request #10432 from GlueCrow:bgfg_knn_fix 2018-01-05 14:16:17 +00:00
Li Peng 67f9406cbe add normalize_bbox layer ocl implementation
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-05 19:38:36 +08:00
Li Peng f99a135eda add eltwise layer ocl implementation
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-05 19:38:30 +08:00
Alexander Alekhin e1ec45c948 Merge pull request #10517 from alalek:perf_video_bgfg 2018-01-05 10:27:24 +00:00
Alexander Alekhin 8acd05f12a Merge pull request #10421 from cezheng:patch-1 2018-01-05 09:24:33 +00:00
Alexander Alekhin be01ea734d video(perf): add Mog2/KNN tests, fixed bug in prepareData()
prepareData() bug feeds the same image (the latest)
OCL perf test doesn't pass accuracy(!) check now, so this check is disabled.
2018-01-05 08:50:38 +00:00
Alexander Alekhin d01a2038ae cmake(android): update CMAKE_FIND_ROOT_PATH_MODE_* handling
Avoids this error message with CMake 3.10:
CMake Error: CMake was unable to find a build program corresponding to "Ninja".
CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.

Related changes is that pkg-config tool is found (/usr/bin/pkg-config).
2018-01-05 05:59:08 +00:00
Alexander Alekhin 0e6dd32858 cmake(android): update zlib alias condition
To use 'z' in Android.mk instead of absolute path from the build machine.
2018-01-05 04:52:17 +00:00
Alexander Alekhin bc7923e382 cmake(android): fix ccache detection (native Android toolchain with NDK_CCACHE)
To prevent this result:
    /usr/bin/ccache ccache <android-ndk-r16.1>/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc ...
with:
    ccache: error: Recursive invocation (the name of the ccache binary must be "ccache")
2018-01-05 04:52:17 +00:00
Alexander Alekhin c608c232a2 3rdparty(libtiff): fix build with Android NDK 16
Compiler message:
tif_unix.c:170:12: error: call to 'mmap' declared with attribute error:
mmap is not available with _FILE_OFFSET_BITS=64 when using GCC until android-21.
Either raise your minSdkVersion, disable _FILE_OFFSET_BITS=64, or switch to Clang.
2018-01-05 04:52:17 +00:00
Alexander Alekhin 5f9bb6249e android: IPPICV static libraries workarounds for NDK 16 2018-01-05 04:52:17 +00:00
Alexander Alekhin b76a691bcf 3rdparty(protobuf): fix build with Android NDK 16 2018-01-05 04:52:17 +00:00
Alexander Alekhin bc6a355370 android(toolchain): fix find_path() behavior (zlib search problem) 2018-01-05 04:52:17 +00:00
Erik Man 37911e60d8 Allow compilation with unified include directory
This makes it possible to compile OpenCV with for instance ndk-r16
2018-01-05 04:52:17 +00:00
Alexander Alekhin c92aa95726 android(toolchain): detailed error message 2018-01-05 04:52:17 +00:00
Alexander Alekhin 59c6661db0 cmake: eliminate ninja generator warning (CMake 3.10), refactor code 2018-01-05 04:42:24 +00:00
Alexander Alekhin f0453bd853 build: eliminate warning
warning: 'layout.channel_layout::gchan' may be used uninitialized in this function [-Wmaybe-uninitialized]
2018-01-05 04:33:30 +00:00
Alexander Alekhin 116c8d0ddf build: eliminate warnings
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
2018-01-05 04:30:08 +00:00
Coralie RACHEX 16821b877c Merge pull request #10493 from RachexCoralie:tiff32FC1Codec
* Load and save tiff images in CV_32FC1 format (1 channel of floats).

* Add test

* Fix error handling and resources leak. Improve test.
2018-01-04 15:51:58 +03:00
Alexander Alekhin 45c5f0a549 Merge pull request #10488 from alalek:cmake_simplify_configure_macro 2018-01-04 08:22:27 +00:00
Alexander Alekhin f46eff4eb0 Merge pull request #10492 from pengli:dnn 2018-01-04 04:40:02 +00:00
Li Peng 1073175c77 add opencl option for resnet_ssd_face sample
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-04 18:40:56 +08:00
Li Peng 34bfd7ef51 add ocl implementation of proposal layer
Signed-off-by: Li Peng <peng.li@intel.com>
2018-01-04 18:40:51 +08:00
Alexander Alekhin 94b236872c cmake: avoid unnecessary files creation in ocv_cmake_configure() 2018-01-02 19:16:51 +00:00
Alessandro de Oliveira Faria (A.K.A.CABELO) 7abaae39ec Merge pull request #10446 from cabelo:style-dnn-yolo
* add style draw in yolo

* fix sintaxe whitespace

* fix conversion from float to int

* sample refactoring

- minor code style fixes
- avoid confusing "bottom" names
- use cv::format
- always draw object detection/roi
2018-01-02 17:26:29 +03:00
Alexander Alekhin 940a90130d Merge pull request #10477 from berak:fix_bg_sub_tutorial 2018-01-02 03:21:16 +00:00
Alexander Alekhin a42ca2eeb3 Merge pull request #10483 from dkurt:fix_dnn_ssd_cpp_sample 2018-01-02 03:18:39 +00:00
Alexander Alekhin bf80c94125 Merge pull request #10481 from alalek:fix_10474 2018-01-02 03:17:59 +00:00
Dmitry Kurtaev d0580df339 Update C++ MobileNet-SSD object detection sample 2018-01-01 23:01:23 +03:00
Alexander Alekhin ea5a3e557f python: filter modules headers (from <module>/include directory) 2018-01-01 15:56:14 +00:00
Alexander Alekhin 22576f4dfe Merge pull request #10480 from alalek:fix_10479 2018-01-01 15:40:12 +00:00
Alexander Alekhin 4ca89db22d imgproc(hdr): fix bounds check in HdrDecoder::checkSignature() 2018-01-01 13:12:21 +00:00
berak dc88a2bcf2 video: clean up bg subtraction tutorial 2017-12-31 12:23:02 +01:00
Alexander Alekhin 71f4281080 Merge pull request #10473 from alalek:cmake_version_string_timestamp 2017-12-31 10:47:33 +00:00
Alexander Alekhin 4bd1e3dcbd cmake: avoid timestamp change of version_string.inc file 2017-12-30 20:26:15 +00:00
Alexander Alekhin 30373d2566 Merge pull request #10470 from victor-ludorum:caliper 2017-12-30 18:19:39 +00:00
victor-ludorum 914d9662d3 Merge pull request #10469 from victor-ludorum:stichingbranch
Updating stiching.cpp to resolve new line issue #10461 (#10469)
2017-12-30 21:22:02 +03:00
victor-ludorum ad23c10600 Updating rotcalipers.cpp to resolve issue #10096
Updating the documentation of the rotcalipers.cpp to resolve issue #10096
2017-12-30 10:21:46 +05:30
Alexander Alekhin a50a355e63 Merge pull request #10463 from alalek:avx512skx 2017-12-29 15:57:57 +00:00
Alexander Alekhin 7d67d60fb1 cmake(opt): AVX512_SKX 2017-12-29 07:18:11 +00:00
Alexander Alekhin fc1d85bf59 Merge pull request #10329 from jasjuang:master 2017-12-28 16:45:16 +00:00
Alexander Alekhin 125f9f0be1 Merge pull request #10410 from GlueCrow:master 2017-12-28 16:43:17 +00:00
Alexander Alekhin 8e7af7f089 Merge pull request #10456 from dkurt:dnn_allocate_mem_for_optimized_concat 2017-12-28 16:04:51 +00:00
Alexander Alekhin a65b5df5da Merge pull request #10416 from fenrus75:avx512 2017-12-28 15:56:56 +00:00
Alexander Alekhin 2370c8a058 Merge pull request #10429 from wxzs5:fix-documentation 2017-12-28 18:30:43 +03:00
Alexander Alekhin 2b3c140f04 Merge pull request #10436 from alalek:test_threads 2017-12-28 18:29:30 +03:00
Alexander Alekhin ec32022bdf Merge pull request #10444 from alalek:fix_asan_imgcodecs 2017-12-28 18:28:29 +03:00
Alexander Alekhin 898ca38257 cmake: AVX512 -> AVX_512F 2017-12-28 15:20:27 +00:00
Vinay Sharma 5aac909046 Merge pull request #10352 from vinay0410:write_pbm
* added write as pbm

* add tests for pbm

* imgcodecs: PBM support

- drop additional PBM parameters
- write: fix P1/P4 mode (no maxval 255 value after width/height)
- write: invert values for P1/P4
- write: P1: compact ASCII mode (no spaces)
- simplify pbm test
- drop .pxm extension (http://netpbm.sourceforge.net/doc/ doesn't know such extension)
2017-12-28 17:28:34 +03:00
Tom Becker 592f8d8c1b Merge pull request #10232 from TomBecker-BD:hough-many-circles
Hough many circles (#10232)

* Add Hui's optimization. Merge with latest changes in OpenCV.

* Use conditional compilation instead of a runtime flag.

* Whitespace.

* Create the sequence for the nonzero edge pixels only if using that approach.

* Improve performance for finding very large numbers of circles

* Return the circles with the larger accumulator values first, as per API documentation.
Use a separate step to check distance between circles. Allows circles to be sorted by strength first. Avoids locking in EstimateRadius which was slowing it down.
Return centers only if maxRadius == 0 as per API documentation.

* Sort the circles so results are deterministic. Otherwise the order of circles with the same strength depends on parallel processing completion order.

* Add test for HoughCircles.

* Add beads test.

* Wrap the non-zero points structure in a common interface so the code can use either a vector or a matrix.

* Remove the special case for skipping the radius search if maxRadius==0.

* Add performance tests.

* Use NULL instead of nullptr.
OpenCV should compile with C++98 compiler.

* Put test suite name first.
Use different test suite names for each test to avoid an error from the test runner.

* Address build bot errors and warnings.

* Skip radius search if maxRadius < 0.

* Dynamically switch to NZPointList when it will be faster than NZPointSet.

* Fix compile error: missing 'typename' prior to dependent type name.

* Fix compile error: missing 'typename' prior to dependent type name.
This time fix it the non C++ 11 way.

* Fix compile error: no type named 'const_reference' in 'class cv::NZPointList'

* Disable ManySmallCircles tests. Failing on Mac.

* Change beads image to JPEG for smaller file size.
Try enabling the ManySmallCircles tests again.

* Remove ManySmallCircles tests. They are failing on the Mac build.

* Fix expectations to check all circles.

* Changing case on a case-insensitive file system
Step 1: remove the old file names

* Changing case on a case-insensitive file system
Step 2: add them back with the new names

* Fix cmpAccum function to be strictly weak ordered.

* Add tests for many small circles.

* imgproc(perf): fix HoughCircles tests

* imgproc(houghCircles): refactor code

- simplify NZPointList
- drop broken (de-synchronization of 'current'/'mi' fields) NZPointSet iterator
- NZPointSet iterator is replaced to direct area scan
- use SIMD intrinsics
- avoid std exceptions (build for embedded systems)
2017-12-28 17:23:11 +03:00
Dmitry Kurtaev a9807d8f54 Allocate new memory for optimized concat to prevent collisions.
Add a flag to disable memory reusing in dnn module.
2017-12-28 16:45:53 +03:00
Alexander Alekhin d9c0231475 Merge pull request #10452 from mshabunin:mediasdk-device 2017-12-28 12:48:26 +00:00
Maksim Shabunin f0b606ff77 Changed VA device in MediaSDK session initialization 2017-12-28 14:10:36 +03:00
Alexander Alekhin 3542c98d45 Merge pull request #10445 from pengli:dnn 2017-12-28 04:43:41 +00:00
Li Peng 00f03c5739 Add ocl version FasterRCNN accuracy test
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-28 19:15:15 +08:00
Alexander Alekhin 4f6c493b87 imgcodecs(png): resolve ASAN issue with vars scope and setjmp() call 2017-12-28 02:43:07 +00:00
Alexander Alekhin 73c2a12449 Merge pull request #10435 from DabatoIsCool:master 2017-12-28 05:30:59 +03:00
Alexander Alekhin 99a9c10b57 Merge pull request #10424 from dkurt:fix_concat_optim 2017-12-28 01:26:14 +00:00
Alexander Alekhin 9b131b5f7e dnn(test): avoid calling of cv::setNumThreads() in tests directly
It is not necessary by default.
Also it breaks test system command-line parameters: --perf_threads / --test_threads
2017-12-27 15:16:41 +00:00
Alexander Alekhin 5232ea1ee6 ts(feature): add "--test_threads=<N>" command-line option 2017-12-27 15:16:41 +00:00
Arthur Williams d8d4ea857a Fixed #10433 2017-12-27 14:09:25 +00:00
Alexander Alekhin f3880c60a6 Merge pull request #10428 from pengli:dnn 2017-12-27 13:18:10 +00:00
Glue Crow 6045608330 Parallelization of BackgroundSubtractorKNN 2017-12-27 19:28:09 +08:00
wxzs5 0a4b1b8d68 Use class' method to set attribute value 2017-12-27 11:57:58 +08:00
wxzs5 25c17b107e Fix functions‘ class attribution error 2017-12-27 11:57:17 +08:00
Arjan van de Ven 2938860b3f Provide a few AVX512 optimized functions for the DNN module
This patch adds AVX512 optimized fastConv as well as the hookups
needed to get these called in the convolution_layer.

AVX512 fastConv is code-identical on a C level to the AVX2 one,
but is measurably faster due to AVX512 having more registers available
to cache results in.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
2017-12-26 16:00:17 +00:00
Alexander Alekhin 2e33844f0d Merge pull request #10419 from shortcipher3:master 2017-12-26 17:26:58 +03:00
Alexander Alekhin 1e4395a8e1 Merge pull request #10418 from mypopydev:master 2017-12-26 14:21:59 +00:00
Dmitry Kurtaev 70c605a03d Limit Concat layer optimization 2017-12-26 16:49:33 +03:00
Li Peng 84e2fa79a0 dnn(ocl4dnn): update pre-tuned kernel config
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-26 20:14:41 +08:00
Alexander Alekhin a8844de7b5 Merge pull request #10404 from alalek:build_fix_msvs2010 2017-12-26 05:51:16 +00:00
Jun Zhao 0369431ebd opencl/cvtclr_dx: fix not compile-time constants issue.
fix the "initializing global variables with values that are not
compile-time constants" issue in Intel SDK for OpenCL. The root cause
is when initializing global variables with value, the variable need is
compile-time constants.

Thanks Zheng, Yang <yang.zheng@intel.com>,
Chodor, Jaroslaw <jaroslaw.chodor@intel.com> give a help.

Signed-off-by: Liu,Kaixuan <kaixuan.liu@intel.com>
Signed-off-by: Jun Zhao <jun.zhao@intel.com>
2017-12-26 13:44:37 +08:00
Chris Hall 50e8f91064 JS examples - FFT didn't work for non-square images because rows/cols were switched, Histogram example misspelled point 2017-12-25 22:01:48 -07:00
Sayed Adel fd0ac962fb core: replace raw intrinsics with universal intrinsics in copy.cpp
- use universal intrinsic instead of raw intrinsic
- add performance check for Mat::copyTo/setTo with mask
2017-12-26 05:30:32 +02:00
Arjan van de Ven fc8e848a54 Add basic plumbing for AVX512 support
The opencv infrastructure mostly has the basics for supporting avx512 math functions,
but it wasn't hooked up (likely due to lack of users)

In order to compile the DNN functions for AVX512, a few things need to be hooked up
and this patch does that

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
2017-12-25 21:06:52 +00:00
GlueCrow 26d288bd11 Optimize OpenCL BackgroundSubstractionMOG2 2017-12-23 21:57:17 +08:00
Alexander Alekhin adf43e7d2a build: fix MSVS2010 build error 2017-12-23 00:06:34 +00:00
Alexander Alekhin 047764f476 Merge tag '3.4.0' 2017-12-22 23:22:50 +00:00
Alexander Alekhin 6d4f66472e OpenCV version++
3.4.0
2017-12-22 19:46:21 +00:00
Alexander Alekhin eba176c299 Merge pull request #10398 from alalek:ml_simplify_simulated_annealing 2017-12-22 22:43:59 +03:00
Alexander Alekhin 00e43a9022 ml(ANN_MLP): ensure that train() call is always successful 2017-12-22 18:50:04 +00:00
Alexander Alekhin 9148a37624 Merge pull request #10401 from terfendail:resize_linear_revert 2017-12-22 16:18:50 +00:00
Alexander Alekhin 019b7c5a66 Merge pull request #10402 from dkurt:dnn_tf_quantized 2017-12-22 15:58:56 +00:00
Alexander Alekhin 59e825ee02 Merge pull request #10385 from pengli:dnn 2017-12-22 15:48:40 +00:00
Dmitry Kurtaev bcc669f3f7 TensorFlow weights dequantization 2017-12-22 17:25:10 +03:00
Vitaly Tuzov e5313246a7 Reverted calls to linear resize back to generic version for floating point matrices 2017-12-22 17:10:03 +03:00
Alexander Alekhin 97af608030 Merge pull request #10397 from mshabunin:fix-incorrect-assert 2017-12-22 14:07:02 +00:00
Li Peng 181b448c4d add one more convolution kernel tuning candidate
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-22 21:37:00 +08:00
Alexander Alekhin 289a8da39e ml: simplify interfaces of SimulatedAnnealingSolver 2017-12-22 16:35:48 +03:00
Vadim Pisarevsky b85c77283b Merge pull request #10396 from berak:fix_superres_sample 2017-12-22 13:35:36 +00:00
Vadim Pisarevsky 0742e12f0b Merge pull request #10265 from dkurt:nms_for_region_layer 2017-12-22 13:29:37 +00:00
Vadim Pisarevsky 9b659736da Merge pull request #10394 from alalek:cmake_fix_pch_pic_pie 2017-12-22 13:26:32 +00:00
Vadim Pisarevsky 69a6765bf7 Merge pull request #10387 from terfendail:resize23_perftest 2017-12-22 13:26:05 +00:00
Vadim Pisarevsky 3f68d6d8a7 Merge pull request #10392 from terfendail:bitexact_fallback 2017-12-22 13:23:55 +00:00
Alexander Alekhin 83b8cd0152 Merge pull request #10375 from tomoaki0705:buildWarningMSVC 2017-12-22 13:17:12 +00:00
Alexander Alekhin 4e542a65a3 Merge pull request #10390 from alalek:ocl_option_buffer_rect 2017-12-22 12:52:56 +00:00
Maksim Shabunin aa46e31c6d Replaced incorrect CV_Assert calls with CV_Error 2017-12-22 15:20:13 +03:00
berak ddbd074678 samples: check for valid input in gpu/super_resolution.cpp 2017-12-22 12:34:25 +01:00
Vitaly Tuzov 5fdb42a7c9 Added fallback to generic linear resize in case bit-exact resize of provided matrix isn't supported 2017-12-22 14:29:50 +03:00
Alexander Alekhin 6c252d8cdc cmake: fix -fPIC/-fPIE handling in precompiled headers (PCH) 2017-12-22 13:57:06 +03:00
Vadim Pisarevsky 636b7ec0c4 Merge pull request #10386 from terfendail:resizeexact_c3 2017-12-22 10:54:49 +00:00
Alexander Alekhin 534645a12f ocl: workaround option to disable usage of buffer "Rect" operations 2017-12-22 13:05:03 +03:00
Alexander Alekhin 09c84a0164 Merge pull request #10389 from wxzs5:yangli 2017-12-22 10:04:05 +00:00
elenagvo cd1c8693d8 HAL for minMaxIdx 2017-12-22 12:56:52 +03:00
Vadim Pisarevsky 325cbd7c84 Merge pull request #10364 from dkurt:dnn_smooth_tf_data_layout 2017-12-22 09:56:45 +00:00
wxzs5 b19cd93738 Remove redundant return variable 2017-12-22 17:13:57 +08:00
Ce Zheng 602b08d9c7 Update resize inline comments
Reading through the implementation, I feel this line of comment is not consistent with the actually code, so this is for correcting it.
2017-12-22 16:03:12 +08:00
Vitaly Tuzov 019162486c Disabled universal intrinsic based implementation for bit-exact resize of 3-channel images 2017-12-22 10:08:30 +03:00
Tomoaki Teshima fe7b3f1228 clean up the code
* disable the warning in CMake, not int the code using pragma
2017-12-22 08:42:21 +09:00
Alexander Alekhin 1bc1f3d311 Merge pull request #10374 from tomoaki0705:removeGstreamerTest 2017-12-21 19:02:13 +00:00
Vadim Pisarevsky a8a51db42b Merge pull request #10316 from terfendail:bitexact_c234 2017-12-21 18:56:54 +00:00
Vadim Pisarevsky 70d49446e9 Merge pull request #10369 from alalek:issue_10351 2017-12-21 18:48:38 +00:00
Alexander Alekhin a2620f72c7 Merge pull request #10370 from pengli:dnn 2017-12-21 15:36:23 +00:00
Tomoaki Teshima 50d44e06e3 avoid the test which is too strict
* confirmed test failure on Jetson TX1 and TX2
  * show the performance but not bit exact result
2017-12-22 00:14:10 +09:00
Li Peng c5fc8e03ff cleanup unnecessary macros in convolution ocl kernel
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-21 20:32:36 +08:00
Li Peng 0aa5e43a14 refactor candidate generation of convolution auto-tuning
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-21 23:05:54 +08:00
jasjuang 235889ddbb handle legacy VTK functions 2017-12-21 01:33:25 -08:00
Dmitry Kurtaev c67e75b68f Refactor NMS procedure at RegionLayer 2017-12-21 12:21:45 +03:00
Vadim Pisarevsky 047ad4ff71 Merge pull request #10366 from alalek:ocl_fix_cvtcolor_read 2017-12-21 08:33:59 +00:00
Vadim Pisarevsky ae8bb718cd Merge pull request #10340 from alalek:log_level_option 2017-12-21 08:33:18 +00:00
Alexander Alekhin 7bbe1a53cf imgcodecs(pxm): fix memcpy size 2017-12-21 01:10:24 +00:00
Vitaly Tuzov b6fe4cc807 Added performance tests for linear resize of 2 and 3-channel images 2017-12-20 18:11:21 +03:00
Vadim Pisarevsky eecb64a973 Merge pull request #10331 from arrybn:python_dnn_net 2017-12-20 14:30:27 +00:00
Vadim Pisarevsky e72a053cca Merge pull request #10354 from catree:add_python_sample_show_extrinsics 2017-12-20 14:23:01 +00:00
LaurentBerger e43997dbb5 Calcerror uses now weighted samples (#10346)
* Calcerror uses now sample weights

* catree comment in #10319
2017-12-20 17:24:46 +03:00
Alexander Alekhin 813ff37967 imgproc(ocl): fix RGB2RGBA kernel out of range access 2017-12-20 14:19:46 +00:00
Vadim Pisarevsky b8a24b36ce Merge pull request #10356 from dkurt:dnn_rfcn 2017-12-20 14:19:46 +00:00
Vadim Pisarevsky d2f13a8259 Merge pull request #10360 from sturkmen72:update_links 2017-12-20 14:19:17 +00:00
Vadim Pisarevsky 94d84c5fad Merge pull request #10358 from catree:add_tutorial_homography_panorama_stitching 2017-12-20 14:18:41 +00:00
Vitaly Tuzov 1eb2fa9efb Added universal intrinsics based implementations for CV_8UC2, CV_8UC3, CV_8UC4 bit-exact resizes. 2017-12-20 17:17:10 +03:00
Dmitry Kurtaev 7e48fa58eb Manage TensorFlow's NHWC data layout is smoother 2017-12-20 14:13:40 +03:00
catree 59ec224009 Update left_intrinsics.yml file with chessboard square_size=0.025 and with extrinsic parameters. Add camera_calibration_show_extrinsics.py, a Python sample that allows to display the extrinsics saved during the camera calibration process (cpp-example-calibration). 2017-12-20 12:06:08 +01:00
Dmitry Kurtaev 0ed2cbc931 R-FCN models support 2017-12-20 10:43:22 +03:00
Suleyman TURKMEN 1ff33e6e4d Update links 2017-12-20 02:55:29 +03:00
Alexander Alekhin b450811e4b core(logger): add log level configuration option 2017-12-19 22:57:07 +00:00
catree 87160cb297 Add Demo 5: Basic panorama stitching from a rotating camera in the homography tutorial. 2017-12-19 22:45:35 +01:00
Alexander Alekhin dcdd6af5a8 Merge pull request #10341 from pengli:dnn 2017-12-19 14:04:55 +00:00
Alexander Alekhin badc3bd312 Merge pull request #10348 from ElenaGvozdeva:Canny_HAL 2017-12-19 13:07:59 +00:00
Vadim Pisarevsky b1ed8bc0d1 Merge pull request #10347 from dkurt:dnn_remove_deprecated_importer 2017-12-19 11:03:06 +00:00
Li Peng 3b84acfc48 add ocl accuracy test for tf mobilenet ssd
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-19 18:38:55 +08:00
Li Peng 436d7e4eaf add depthwise convolution kernel
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-19 17:59:13 +08:00
Li Peng 910d7dab1f prior box layer ocl implementation
Signed-off-by: Li Peng <peng.li@intel.com>
2017-12-19 17:44:10 +08:00
elenagvo b0e9d76ced HAL for canny 2017-12-19 11:03:10 +03:00
Alexander Alekhin 05b259fe2e Merge pull request #10344 from tomoaki0705:fixBuildLibtiff 2017-12-18 17:00:45 +00:00
Dmitry Kurtaev 6aabd6cc7a Remove cv::dnn::Importer 2017-12-18 18:08:28 +03:00
Alexander Rybnikov 19c914db51 Changed wrapping mode for cv::dnn::Net::forward 2017-12-18 15:56:09 +03:00
Tomoaki Teshima c057d29192 fix compilation error on Visual Studio 2013 and earlier
- fix compilation error about "inline"
  - fix linker error about "_TIFF_snprintf_f"
2017-12-18 21:51:33 +09:00
Vadim Pisarevsky e29de5dd2b Merge pull request #10343 from tomoaki0705:suppressWarningEncoding 2017-12-18 10:53:24 +00:00
Suleyman TURKMEN 1654dfe3a9 Update samples (#10333)
* Update samples

* Update calib3d.hpp

* Update calib3d.hpp

* Update calib3d.hpp

* Update calib3d.hpp
2017-12-18 13:44:11 +03:00
Vadim Pisarevsky d3a124c820 Merge pull request #10339 from catree:add_doc_solvepnp_figure_desc 2017-12-18 09:13:06 +00:00
Vadim Pisarevsky 86cc4f3aa4 Merge pull request #10337 from dkurt:fix_pooling_layer 2017-12-18 09:11:54 +00:00
Alexander Alekhin 9de87d96cc Merge pull request #10338 from hrnr:fix-build 2017-12-18 06:52:08 +00:00
Tomoaki Teshima 65f502bc99 suppress warning on Visual Studio
* remove non ASCII character from the comment
2017-12-18 15:32:06 +09:00
catree fcb537bacd Add a figure and some formulas to illustrate the PnP pose estimation principle. 2017-12-17 21:38:22 +01:00
Jiri Horner 3dbf392d48 fix build with intrinsics enabled
* since #10231 opencv with instrumentation does not build
2017-12-17 20:23:15 +01:00
Dmitry Kurtaev 2b43d4f477 Fix default pooling layer type 2017-12-17 16:46:40 +03:00
1354 changed files with 132667 additions and 134752 deletions
-2
View File
@@ -1,2 +0,0 @@
[tgit]
icon = doc/opencv.ico
+2
View File
@@ -31,3 +31,5 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${OPENCV_CPUFEATURES_TARGET_NAME} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(cpufeatures LICENSE README.md)
+6 -6
View File
@@ -1,9 +1,9 @@
# Binary branch name: ffmpeg/master_20171009
# Binaries were created for OpenCV: 8ac2c5d620b467d3f22802e96c88ddde6da707af
set(FFMPEG_BINARIES_COMMIT "66b1fed06cf3510235f367f96aa26da5cb234a15")
set(FFMPEG_FILE_HASH_BIN32 "3ae76b105113d944984b2351c61e21c6")
set(FFMPEG_FILE_HASH_BIN64 "cf3bb5bc9d393b022ea7a42eb63e794d")
set(FFMPEG_FILE_HASH_CMAKE "ec59008da403fb18ab3c1ed66aed583b")
# Binaries branch name: ffmpeg/master_20180220
# Binaries were created for OpenCV: 9819ebc0954c2df62943ebbd5936d325e5dc89e1
ocv_update(FFMPEG_BINARIES_COMMIT "0a0e88972a7ea97708378d0488a65f83e7cc5e69")
ocv_update(FFMPEG_FILE_HASH_BIN32 "b8120c07962d591e2e9071a1bf566fd0")
ocv_update(FFMPEG_FILE_HASH_BIN64 "dc9c50e7b05482acc25d6ce0ac61bf1d")
ocv_update(FFMPEG_FILE_HASH_CMAKE "3b90f67f4b429e77d3da36698cef700c")
function(download_win_ffmpeg script_var)
set(${script_var} "" PARENT_SCOPE)
+25
View File
@@ -0,0 +1,25 @@
Copyright (c) 2008-2015 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Materials.
MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
https://www.khronos.org/registry/
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+2
View File
@@ -60,3 +60,5 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${ITT_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(ittnotify src/ittnotify/LICENSE.BSD src/ittnotify/LICENSE.GPL)
+2
View File
@@ -47,3 +47,5 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(jasper LICENSE README copyright)
+2
View File
@@ -51,3 +51,5 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(libjpeg README)
+3 -1
View File
@@ -48,7 +48,7 @@ if(PPC64LE OR PPC64)
list(APPEND lib_srcs powerpc/powerpc_init.c powerpc/filter_vsx_intrinsics.c)
add_definitions(-DPNG_POWERPC_VSX_OPT=2)
else()
add_definitions(-DPNG_POWERPC_VSX_OPT=0)
add_definitions(-DPNG_POWERPC_VSX_OPT=0)
endif()
endif()
@@ -80,3 +80,5 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(libpng LICENSE README opencv-libpng.patch)
+31 -28
View File
@@ -35,31 +35,27 @@ if(NOT MSVC)
check_include_file(unistd.h HAVE_UNISTD_H)
endif()
if(MSVC)
set(INLINE_KEYWORD "inline")
else()
# Inspired from /usr/share/autoconf/autoconf/c.m4
foreach(inline_keyword "inline" "__inline__" "__inline")
if(NOT DEFINED C_INLINE)
set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
"-Dinline=${inline_keyword}")
check_c_source_compiles("
typedef int foo_t;
static inline foo_t static_foo() {return 0;}
foo_t foo(){return 0;}
int main(int argc, char *argv[]) {return 0;}"
C_HAS_${inline_keyword})
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
if(C_HAS_${inline_keyword})
set(C_INLINE TRUE)
set(INLINE_KEYWORD "${inline_keyword}")
endif()
endif()
endforeach()
# Inspired from /usr/share/autoconf/autoconf/c.m4
foreach(inline_keyword "inline" "__inline__" "__inline")
if(NOT DEFINED C_INLINE)
set(INLINE_KEYWORD)
endif()
set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
"-Dinline=${inline_keyword}")
check_c_source_compiles("
typedef int foo_t;
static inline foo_t static_foo() {return 0;}
foo_t foo(){return 0;}
int main(int argc, char *argv[]) {return 0;}"
C_HAS_${inline_keyword})
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
if(C_HAS_${inline_keyword})
set(C_INLINE TRUE)
set(INLINE_KEYWORD "${inline_keyword}")
endif()
endif()
endforeach()
if(NOT DEFINED C_INLINE)
set(INLINE_KEYWORD)
endif()
@@ -248,10 +244,14 @@ mark_as_advanced(HAVE_IEEEFP)
# Large file support
if(UNIX OR MINGW)
# This might not catch every possibility catered for by
# AC_SYS_LARGEFILE.
add_definitions(-D_FILE_OFFSET_BITS=64)
set(FILE_OFFSET_BITS 64)
if(ANDROID AND (ANDROID_NATIVE_API_LEVEL LESS 21) AND (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES Clang))
# Android NDK build problem: 'mmap' issue with GCC and API<21
else()
# This might not catch every possibility catered for by
# AC_SYS_LARGEFILE.
add_definitions(-D_FILE_OFFSET_BITS=64)
set(FILE_OFFSET_BITS 64)
endif()
endif()
# Documentation install directory (default to cmake project docdir)
@@ -414,6 +414,7 @@ set(lib_srcs
tif_write.c
tif_zip.c
tif_stream.cxx
snprintf.c
t4.h
tif_dir.h
tif_fax3.h
@@ -469,3 +470,5 @@ endif()
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(libtiff COPYRIGHT)
+38
View File
@@ -0,0 +1,38 @@
/**
* Workaround for lack of snprintf(3) in Visual Studio. See
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996
* It's a trivial wrapper around the builtin _vsnprintf_s and
* _vscprintf functions.
*/
#ifdef _MSC_VER
#include <stdio.h>
#include <stdarg.h>
int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = vsnprintf(str, size, format, ap);
va_end(ap);
return count;
}
#endif // _MSC_VER
-3
View File
@@ -245,9 +245,6 @@
# endif
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS @FILE_OFFSET_BITS@
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
+1 -1
View File
@@ -605,7 +605,7 @@ static void HistogramCombineEntropyBin(VP8LHistogramSet* const image_histo,
}
// Implement a Lehmer random number generator with a multiplicative constant of
// 48271 and a modulo constant of 2^31 1.
// 48271 and a modulo constant of 2^31 - 1.
static uint32_t MyRand(uint32_t* const seed) {
*seed = (uint32_t)(((uint64_t)(*seed) * 48271u) % 2147483647u);
assert(*seed > 0);
+2
View File
@@ -76,5 +76,7 @@ if(NOT BUILD_SHARED_LIBS)
ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(openexr LICENSE AUTHORS.ilmbase AUTHORS.openexr fix_msvc2013_errors.patch)
set(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATHS} PARENT_SCOPE)
set(OPENEXR_VERSION "1.7.1" PARENT_SCOPE)
+15 -4
View File
@@ -1,5 +1,4 @@
project(libprotobuf)
include(CheckIncludeFiles)
if(HAVE_PTHREAD)
@@ -11,12 +10,16 @@ if(MSVC)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
/wd4305 /wd4127 /wd4100 /wd4512 /wd4125 /wd4389 /wd4510 /wd4610
/wd4702 /wd4456 /wd4457 /wd4065 /wd4310 /wd4661 /wd4506
/wd4701 /wd4703 # potentially uninitialized local/pointer variable 'value' used
/wd4505 # unreferenced local function has been removed
)
else()
#NOTE: -Wno-invalid-offsetof was used as solution for invalid offset warning on protobuf #3450
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
-Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo
-Wundef -Wtautological-undefined-compare -Wignored-qualifiers -Wextra
-Wunused-function -Wunused-const-variable -Wshorten-64-to-32
-Wunused-function -Wunused-const-variable -Wshorten-64-to-32 -Wno-invalid-offsetof
-Wenum-compare-switch
)
endif()
if(CV_ICC)
@@ -52,6 +55,7 @@ append_if_exist(Protobuf_SRCS
${PROTOBUF_ROOT}/src/google/protobuf/arena.cc
${PROTOBUF_ROOT}/src/google/protobuf/arenastring.cc
${PROTOBUF_ROOT}/src/google/protobuf/extension_set.cc
${PROTOBUF_ROOT}/src/google/protobuf/generated_message_table_driven_lite.cc
${PROTOBUF_ROOT}/src/google/protobuf/generated_message_util.cc
${PROTOBUF_ROOT}/src/google/protobuf/io/coded_stream.cc
${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream.cc
@@ -62,6 +66,7 @@ append_if_exist(Protobuf_SRCS
${PROTOBUF_ROOT}/src/google/protobuf/stubs/bytestream.cc
${PROTOBUF_ROOT}/src/google/protobuf/stubs/common.cc
${PROTOBUF_ROOT}/src/google/protobuf/stubs/int128.cc
${PROTOBUF_ROOT}/src/google/protobuf/stubs/io_win32.cc
${PROTOBUF_ROOT}/src/google/protobuf/stubs/once.cc
${PROTOBUF_ROOT}/src/google/protobuf/stubs/status.cc
${PROTOBUF_ROOT}/src/google/protobuf/stubs/statusor.cc
@@ -86,6 +91,7 @@ append_if_exist(Protobuf_SRCS
${PROTOBUF_ROOT}/src/google/protobuf/extension_set_heavy.cc
${PROTOBUF_ROOT}/src/google/protobuf/field_mask.pb.cc
${PROTOBUF_ROOT}/src/google/protobuf/generated_message_reflection.cc
${PROTOBUF_ROOT}/src/google/protobuf/generated_message_table_driven.cc
${PROTOBUF_ROOT}/src/google/protobuf/io/gzip_stream.cc
${PROTOBUF_ROOT}/src/google/protobuf/io/printer.cc
${PROTOBUF_ROOT}/src/google/protobuf/io/strtod.cc
@@ -103,6 +109,7 @@ append_if_exist(Protobuf_SRCS
${PROTOBUF_ROOT}/src/google/protobuf/timestamp.pb.cc
${PROTOBUF_ROOT}/src/google/protobuf/type.pb.cc
${PROTOBUF_ROOT}/src/google/protobuf/unknown_field_set.cc
${PROTOBUF_ROOT}/src/google/protobuf/util/delimited_message_util.cc
${PROTOBUF_ROOT}/src/google/protobuf/util/field_comparator.cc
${PROTOBUF_ROOT}/src/google/protobuf/util/field_mask_util.cc
${PROTOBUF_ROOT}/src/google/protobuf/util/internal/datapiece.cc
@@ -128,8 +135,7 @@ append_if_exist(Protobuf_SRCS
)
add_library(libprotobuf STATIC ${Protobuf_SRCS})
ocv_include_directories(${PROTOBUF_ROOT}/src)
target_include_directories(libprotobuf SYSTEM PUBLIC $<BUILD_INTERFACE:${PROTOBUF_ROOT}/src>)
set_target_properties(libprotobuf
PROPERTIES
FOLDER "3rdparty"
@@ -138,6 +144,11 @@ set_target_properties(libprotobuf
ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
)
get_protobuf_version(Protobuf_VERSION "${PROTOBUF_ROOT}/src")
set(Protobuf_VERSION ${Protobuf_VERSION} CACHE INTERNAL "" FORCE)
if(NOT BUILD_SHARED_LIBS)
ocv_install_target(libprotobuf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endif()
ocv_install_3rdparty_licenses(protobuf LICENSE README.md)
+1 -1
View File
@@ -1,3 +1,3 @@
Project: Protocol Buffers - Google's data interchange format
Source code: https://github.com/google/protobuf
Version: 3.1.0
Version: 3.5.1
+4 -4
View File
@@ -30,6 +30,8 @@
#include <google/protobuf/any.h>
#include <google/protobuf/generated_message_util.h>
namespace google {
namespace protobuf {
namespace internal {
@@ -70,13 +72,11 @@ bool AnyMetadata::UnpackTo(Message* message) const {
if (!InternalIs(message->GetDescriptor())) {
return false;
}
return message->ParseFromString(
value_->GetNoArena(&::google::protobuf::internal::GetEmptyString()));
return message->ParseFromString(value_->GetNoArena());
}
bool AnyMetadata::InternalIs(const Descriptor* descriptor) const {
const string type_url = type_url_->GetNoArena(
&::google::protobuf::internal::GetEmptyString());
const string type_url = type_url_->GetNoArena();
string full_name;
if (!ParseAnyTypeUrl(type_url, &full_name)) {
return false;
+3 -3
View File
@@ -63,7 +63,7 @@ class LIBPROTOBUF_EXPORT AnyMetadata {
// 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 actaul
// name after the last "/" of the type URL doesn't match the message's actual
// full name) or parsing the payload has failed.
bool UnpackTo(Message* message) const;
@@ -90,8 +90,8 @@ extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/".
// 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 type_url does not start with
// "type.googleapis.com" or "type.googleprod.com".
// *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 string& type_url, string* full_type_name);
// See if message is of type google.protobuf.Any, if so, return the descriptors
+173 -256
View File
@@ -1,7 +1,6 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/any.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <google/protobuf/any.pb.h>
#include <algorithm>
@@ -15,119 +14,114 @@
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// This is a temporary google only hack
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
#include "third_party/protobuf/version.h"
#endif
// @@protoc_insertion_point(includes)
namespace google {
namespace protobuf {
class AnyDefaultTypeInternal {
public:
::google::protobuf::internal::ExplicitlyConstructed<Any>
_instance;
} _Any_default_instance_;
} // namespace protobuf
} // namespace google
namespace protobuf_google_2fprotobuf_2fany_2eproto {
void InitDefaultsAnyImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
::google::protobuf::internal::InitProtobufDefaultsForceUnique();
#else
::google::protobuf::internal::InitProtobufDefaults();
#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
{
void* ptr = &::google::protobuf::_Any_default_instance_;
new (ptr) ::google::protobuf::Any();
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
}
::google::protobuf::Any::InitAsDefaultInstance();
}
void InitDefaultsAny() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &InitDefaultsAnyImpl);
}
::google::protobuf::Metadata file_level_metadata[1];
const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
~0u, // no _has_bits_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Any, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Any, type_url_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Any, value_),
};
static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, sizeof(::google::protobuf::Any)},
};
static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Any_default_instance_),
};
void protobuf_AssignDescriptors() {
AddDescriptors();
::google::protobuf::MessageFactory* factory = NULL;
AssignDescriptors(
"google/protobuf/any.proto", schemas, file_default_instances, TableStruct::offsets, factory,
file_level_metadata, NULL, NULL);
}
void protobuf_AssignDescriptorsOnce() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\031google/protobuf/any.proto\022\017google.prot"
"obuf\"&\n\003Any\022\020\n\010type_url\030\001 \001(\t\022\r\n\005value\030\002"
" \001(\014Bo\n\023com.google.protobufB\010AnyProtoP\001Z"
"%github.com/golang/protobuf/ptypes/any\242\002"
"\003GPB\252\002\036Google.Protobuf.WellKnownTypesb\006p"
"roto3"
};
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
descriptor, 205);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/any.proto", &protobuf_RegisterTypes);
}
void AddDescriptors() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
}
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
}
} static_descriptor_initializer;
} // namespace protobuf_google_2fprotobuf_2fany_2eproto
namespace google {
namespace protobuf {
namespace {
const ::google::protobuf::Descriptor* Any_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
Any_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"google/protobuf/any.proto");
GOOGLE_CHECK(file != NULL);
Any_descriptor_ = file->message_type(0);
static const int Any_offsets_[2] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, type_url_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, value_),
};
Any_reflection_ =
::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
Any_descriptor_,
Any::internal_default_instance(),
Any_offsets_,
-1,
-1,
-1,
sizeof(Any),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _internal_metadata_));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
Any_descriptor_, Any::internal_default_instance());
}
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto() {
Any_default_instance_.Shutdown();
delete Any_reflection_;
}
void protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::internal::GetEmptyString();
Any_default_instance_.DefaultConstruct();
Any_default_instance_.get_mutable()->InitAsDefaultInstance();
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_once_);
void protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_once_,
&protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl);
}
void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto();
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\031google/protobuf/any.proto\022\017google.prot"
"obuf\"&\n\003Any\022\020\n\010type_url\030\001 \001(\t\022\r\n\005value\030\002"
" \001(\014Bo\n\023com.google.protobufB\010AnyProtoP\001Z"
"%github.com/golang/protobuf/ptypes/any\242\002"
"\003GPB\252\002\036Google.Protobuf.WellKnownTypesb\006p"
"roto3", 205);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/any.proto", &protobuf_RegisterTypes);
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_once_);
void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_once_,
&protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto {
StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
}
} static_descriptor_initializer_google_2fprotobuf_2fany_2eproto_;
namespace {
static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN;
static void MergeFromFail(int line) {
::google::protobuf::internal::MergeFromFail(__FILE__, line);
}
} // namespace
// ===================================================================
void Any::InitAsDefaultInstance() {
}
void Any::PackFrom(const ::google::protobuf::Message& message) {
_any_metadata_.PackFrom(message);
}
@@ -148,20 +142,26 @@ const int Any::kValueFieldNumber;
Any::Any()
: ::google::protobuf::Message(), _internal_metadata_(NULL), _any_metadata_(&type_url_, &value_) {
if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto();
if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
::protobuf_google_2fprotobuf_2fany_2eproto::InitDefaultsAny();
}
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Any)
}
void Any::InitAsDefaultInstance() {
}
Any::Any(const Any& from)
: ::google::protobuf::Message(),
_internal_metadata_(NULL),
_any_metadata_(&type_url_, &value_) {
SharedCtor();
UnsafeMergeFrom(from);
_internal_metadata_(NULL),
_cached_size_(0),
_any_metadata_(&type_url_, &value_) {
_internal_metadata_.MergeFrom(from._internal_metadata_);
type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (from.type_url().size() > 0) {
type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_);
}
value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (from.value().size() > 0) {
value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.value_);
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
}
@@ -187,17 +187,15 @@ void Any::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Any::descriptor() {
protobuf_AssignDescriptorsOnce();
return Any_descriptor_;
::protobuf_google_2fprotobuf_2fany_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
}
const Any& Any::default_instance() {
protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto();
::protobuf_google_2fprotobuf_2fany_2eproto::InitDefaultsAny();
return *internal_default_instance();
}
::google::protobuf::internal::ExplicitlyConstructed<Any> Any_default_instance_;
Any* Any::New(::google::protobuf::Arena* arena) const {
Any* n = new Any;
if (arena != NULL) {
@@ -208,8 +206,13 @@ Any* Any::New(::google::protobuf::Arena* arena) const {
void Any::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Any)
::google::protobuf::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
_internal_metadata_.Clear();
}
bool Any::MergePartialFromCodedStream(
@@ -218,47 +221,45 @@ bool Any::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Any)
for (;;) {
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string type_url = 1;
// string type_url = 1;
case 1: {
if (tag == 10) {
if (static_cast< ::google::protobuf::uint8>(tag) ==
static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_type_url()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
this->type_url().data(), static_cast<int>(this->type_url().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.Any.type_url"));
} else {
goto handle_unusual;
}
if (input->ExpectTag(18)) goto parse_value;
break;
}
// optional bytes value = 2;
// bytes value = 2;
case 2: {
if (tag == 18) {
parse_value:
if (static_cast< ::google::protobuf::uint8>(tag) ==
static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_value()));
} else {
goto handle_unusual;
}
if (input->ExpectAtEnd()) goto success;
break;
}
default: {
handle_unusual:
if (tag == 0 ||
::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -275,22 +276,29 @@ failure:
void Any::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Any)
// optional string type_url = 1;
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// string type_url = 1;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
this->type_url().data(), static_cast<int>(this->type_url().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Any.type_url");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
1, this->type_url(), output);
}
// optional bytes value = 2;
// bytes value = 2;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(
2, this->value(), output);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.Any)
}
@@ -298,10 +306,13 @@ void Any::SerializeWithCachedSizes(
bool deterministic, ::google::protobuf::uint8* target) const {
(void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any)
// optional string type_url = 1;
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// string type_url = 1;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
this->type_url().data(), static_cast<int>(this->type_url().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.Any.type_url");
target =
@@ -309,13 +320,17 @@ void Any::SerializeWithCachedSizes(
1, this->type_url(), target);
}
// optional bytes value = 2;
// bytes value = 2;
if (this->value().size() > 0) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
2, this->value(), target);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Any)
return target;
}
@@ -324,14 +339,19 @@ size_t Any::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Any)
size_t total_size = 0;
// optional string type_url = 1;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()));
}
// string type_url = 1;
if (this->type_url().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->type_url());
}
// optional bytes value = 2;
// bytes value = 2;
if (this->value().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
@@ -347,7 +367,7 @@ size_t Any::ByteSizeLong() const {
void Any::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Any)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
GOOGLE_DCHECK_NE(&from, this);
const Any* source =
::google::protobuf::internal::DynamicCastToGenerated<const Any>(
&from);
@@ -356,21 +376,17 @@ void Any::MergeFrom(const ::google::protobuf::Message& from) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
// @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Any)
UnsafeMergeFrom(*source);
MergeFrom(*source);
}
}
void Any::MergeFrom(const Any& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any)
if (GOOGLE_PREDICT_TRUE(&from != this)) {
UnsafeMergeFrom(from);
} else {
MergeFromFail(__LINE__);
}
}
GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_);
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
void Any::UnsafeMergeFrom(const Any& from) {
GOOGLE_DCHECK(&from != this);
if (from.type_url().size() > 0) {
type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_);
@@ -392,11 +408,10 @@ void Any::CopyFrom(const Any& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Any)
if (&from == this) return;
Clear();
UnsafeMergeFrom(from);
MergeFrom(from);
}
bool Any::IsInitialized() const {
return true;
}
@@ -405,118 +420,20 @@ void Any::Swap(Any* other) {
InternalSwap(other);
}
void Any::InternalSwap(Any* other) {
using std::swap;
type_url_.Swap(&other->type_url_);
value_.Swap(&other->value_);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Any::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = Any_descriptor_;
metadata.reflection = Any_reflection_;
return metadata;
protobuf_google_2fprotobuf_2fany_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[kIndexInFileMessages];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Any
// optional string type_url = 1;
void Any::clear_type_url() {
type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
const ::std::string& Any::type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
return type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void Any::set_type_url(const ::std::string& value) {
type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
}
void Any::set_type_url(const char* value) {
type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url)
}
void Any::set_type_url(const char* value, size_t size) {
type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
::std::string(reinterpret_cast<const char*>(value), size));
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url)
}
::std::string* Any::mutable_type_url() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Any.type_url)
return type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* Any::release_type_url() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.type_url)
return type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void Any::set_allocated_type_url(::std::string* type_url) {
if (type_url != NULL) {
} else {
}
type_url_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type_url);
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
// optional bytes value = 2;
void Any::clear_value() {
value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
const ::std::string& Any::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
return value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void Any::set_value(const ::std::string& value) {
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
}
void Any::set_value(const char* value) {
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.value)
}
void Any::set_value(const void* value, size_t size) {
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
::std::string(reinterpret_cast<const char*>(value), size));
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value)
}
::std::string* Any::mutable_value() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Any.value)
return value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* Any::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Any.value)
return value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void Any::set_allocated_value(::std::string* value) {
if (value != NULL) {
} else {
}
value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
}
inline const Any* Any::internal_default_instance() {
return &Any_default_instance_.get();
}
#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// @@protoc_insertion_point(namespace_scope)
} // namespace protobuf
} // namespace google
+107 -50
View File
@@ -8,38 +8,56 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.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>
#include <google/protobuf/any.h>
// @@protoc_insertion_point(includes)
namespace protobuf_google_2fprotobuf_2fany_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[1];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsAnyImpl();
void LIBPROTOBUF_EXPORT InitDefaultsAny();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsAny();
}
} // namespace protobuf_google_2fprotobuf_2fany_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto();
class Any;
class AnyDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
// ===================================================================
@@ -54,11 +72,31 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Any(Any&& from) noexcept
: Any() {
*this = ::std::move(from);
}
inline Any& operator=(Any&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
static const ::google::protobuf::Descriptor* descriptor();
static const Any& default_instance();
static const Any* internal_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 PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
0;
// implements Any -----------------------------------------------
@@ -71,67 +109,72 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in
}
void Swap(Any* other);
friend void swap(Any& a, Any& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Any* New() const { return New(NULL); }
inline Any* New() const PROTOBUF_FINAL { return New(NULL); }
Any* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Any* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Any& from);
void MergeFrom(const Any& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Any* other);
void UnsafeMergeFrom(const Any& from);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
return NULL;
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
return NULL;
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional string type_url = 1;
// string type_url = 1;
void clear_type_url();
static const int kTypeUrlFieldNumber = 1;
const ::std::string& type_url() const;
void set_type_url(const ::std::string& value);
#if LANG_CXX11
void set_type_url(::std::string&& value);
#endif
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);
// optional bytes value = 2;
// bytes value = 2;
void clear_value();
static const int kValueFieldNumber = 2;
const ::std::string& value() const;
void set_value(const ::std::string& value);
#if LANG_CXX11
void set_value(::std::string&& value);
#endif
void set_value(const char* value);
void set_value(const void* value, size_t size);
::std::string* mutable_value();
@@ -146,37 +189,43 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in
::google::protobuf::internal::ArenaStringPtr value_;
mutable int _cached_size_;
::google::protobuf::internal::AnyMetadata _any_metadata_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fany_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fany_2eproto::InitDefaultsAnyImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Any> Any_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// Any
// optional string type_url = 1;
// string type_url = 1;
inline void Any::clear_type_url() {
type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Any::type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.type_url)
return type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return type_url_.GetNoArena();
}
inline void Any::set_type_url(const ::std::string& value) {
type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Any.type_url)
}
#if LANG_CXX11
inline void Any::set_type_url(::std::string&& value) {
type_url_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
}
#endif
inline void Any::set_type_url(const char* value) {
GOOGLE_DCHECK(value != NULL);
type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url)
@@ -207,20 +256,29 @@ inline void Any::set_allocated_type_url(::std::string* type_url) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
// optional bytes value = 2;
// bytes value = 2;
inline void Any::clear_value() {
value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Any::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
return value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return value_.GetNoArena();
}
inline void Any::set_value(const ::std::string& value) {
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
}
#if LANG_CXX11
inline void Any::set_value(::std::string&& value) {
value_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
}
#endif
inline void Any::set_value(const char* value) {
GOOGLE_DCHECK(value != NULL);
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Any.value)
@@ -251,10 +309,9 @@ inline void Any::set_allocated_value(::std::string* value) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
}
inline const Any* Any::internal_default_instance() {
return &Any_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// @@protoc_insertion_point(namespace_scope)
File diff suppressed because it is too large Load Diff
+372 -226
View File
@@ -8,41 +8,69 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.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>
#include <google/protobuf/source_context.pb.h>
#include <google/protobuf/type.pb.h>
// @@protoc_insertion_point(includes)
namespace protobuf_google_2fprotobuf_2fapi_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[3];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsApiImpl();
void LIBPROTOBUF_EXPORT InitDefaultsApi();
void LIBPROTOBUF_EXPORT InitDefaultsMethodImpl();
void LIBPROTOBUF_EXPORT InitDefaultsMethod();
void LIBPROTOBUF_EXPORT InitDefaultsMixinImpl();
void LIBPROTOBUF_EXPORT InitDefaultsMixin();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsApi();
InitDefaultsMethod();
InitDefaultsMixin();
}
} // namespace protobuf_google_2fprotobuf_2fapi_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
class Api;
class ApiDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern ApiDefaultTypeInternal _Api_default_instance_;
class Method;
class MethodDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern MethodDefaultTypeInternal _Method_default_instance_;
class Mixin;
class MixinDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern MixinDefaultTypeInternal _Mixin_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
// ===================================================================
@@ -57,69 +85,77 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Api(Api&& from) noexcept
: Api() {
*this = ::std::move(from);
}
inline Api& operator=(Api&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
static const ::google::protobuf::Descriptor* descriptor();
static const Api& default_instance();
static const Api* internal_default_instance();
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
static inline const Api* internal_default_instance() {
return reinterpret_cast<const Api*>(
&_Api_default_instance_);
}
static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
0;
void Swap(Api* other);
friend void swap(Api& a, Api& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Api* New() const { return New(NULL); }
inline Api* New() const PROTOBUF_FINAL { return New(NULL); }
Api* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Api* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Api& from);
void MergeFrom(const Api& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Api* other);
void UnsafeMergeFrom(const Api& from);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
return NULL;
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
return NULL;
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
// repeated .google.protobuf.Method methods = 2;
int methods_size() const;
void clear_methods();
@@ -144,26 +180,6 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
options() const;
// optional string version = 4;
void clear_version();
static const int kVersionFieldNumber = 4;
const ::std::string& version() const;
void set_version(const ::std::string& value);
void set_version(const char* value);
void set_version(const char* value, size_t size);
::std::string* mutable_version();
::std::string* release_version();
void set_allocated_version(::std::string* version);
// optional .google.protobuf.SourceContext source_context = 5;
bool has_source_context() const;
void clear_source_context();
static const int kSourceContextFieldNumber = 5;
const ::google::protobuf::SourceContext& source_context() const;
::google::protobuf::SourceContext* mutable_source_context();
::google::protobuf::SourceContext* release_source_context();
void set_allocated_source_context(::google::protobuf::SourceContext* source_context);
// repeated .google.protobuf.Mixin mixins = 6;
int mixins_size() const;
void clear_mixins();
@@ -176,7 +192,44 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >&
mixins() const;
// optional .google.protobuf.Syntax syntax = 7;
// string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
#if LANG_CXX11
void set_name(::std::string&& value);
#endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
// string version = 4;
void clear_version();
static const int kVersionFieldNumber = 4;
const ::std::string& version() const;
void set_version(const ::std::string& value);
#if LANG_CXX11
void set_version(::std::string&& value);
#endif
void set_version(const char* value);
void set_version(const char* value, size_t size);
::std::string* mutable_version();
::std::string* release_version();
void set_allocated_version(::std::string* version);
// .google.protobuf.SourceContext source_context = 5;
bool has_source_context() const;
void clear_source_context();
static const int kSourceContextFieldNumber = 5;
const ::google::protobuf::SourceContext& source_context() const;
::google::protobuf::SourceContext* release_source_context();
::google::protobuf::SourceContext* mutable_source_context();
void set_allocated_source_context(::google::protobuf::SourceContext* source_context);
// .google.protobuf.Syntax syntax = 7;
void clear_syntax();
static const int kSyntaxFieldNumber = 7;
::google::protobuf::Syntax syntax() const;
@@ -194,15 +247,9 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in
::google::protobuf::SourceContext* source_context_;
int syntax_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaultsApiImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Api> Api_default_instance_;
// -------------------------------------------------------------------
class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ {
@@ -216,103 +263,77 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Method(Method&& from) noexcept
: Method() {
*this = ::std::move(from);
}
inline Method& operator=(Method&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
static const ::google::protobuf::Descriptor* descriptor();
static const Method& default_instance();
static const Method* internal_default_instance();
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
static inline const Method* internal_default_instance() {
return reinterpret_cast<const Method*>(
&_Method_default_instance_);
}
static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
1;
void Swap(Method* other);
friend void swap(Method& a, Method& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Method* New() const { return New(NULL); }
inline Method* New() const PROTOBUF_FINAL { return New(NULL); }
Method* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Method* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Method& from);
void MergeFrom(const Method& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Method* other);
void UnsafeMergeFrom(const Method& from);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
return NULL;
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
return NULL;
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
// optional string request_type_url = 2;
void clear_request_type_url();
static const int kRequestTypeUrlFieldNumber = 2;
const ::std::string& request_type_url() const;
void set_request_type_url(const ::std::string& value);
void set_request_type_url(const char* value);
void set_request_type_url(const char* value, size_t size);
::std::string* mutable_request_type_url();
::std::string* release_request_type_url();
void set_allocated_request_type_url(::std::string* request_type_url);
// optional bool request_streaming = 3;
void clear_request_streaming();
static const int kRequestStreamingFieldNumber = 3;
bool request_streaming() const;
void set_request_streaming(bool value);
// optional string response_type_url = 4;
void clear_response_type_url();
static const int kResponseTypeUrlFieldNumber = 4;
const ::std::string& response_type_url() const;
void set_response_type_url(const ::std::string& value);
void set_response_type_url(const char* value);
void set_response_type_url(const char* value, size_t size);
::std::string* mutable_response_type_url();
::std::string* release_response_type_url();
void set_allocated_response_type_url(::std::string* response_type_url);
// optional bool response_streaming = 5;
void clear_response_streaming();
static const int kResponseStreamingFieldNumber = 5;
bool response_streaming() const;
void set_response_streaming(bool value);
// repeated .google.protobuf.Option options = 6;
int options_size() const;
void clear_options();
@@ -325,7 +346,61 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
options() const;
// optional .google.protobuf.Syntax syntax = 7;
// string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
#if LANG_CXX11
void set_name(::std::string&& value);
#endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
// string request_type_url = 2;
void clear_request_type_url();
static const int kRequestTypeUrlFieldNumber = 2;
const ::std::string& request_type_url() const;
void set_request_type_url(const ::std::string& value);
#if LANG_CXX11
void set_request_type_url(::std::string&& value);
#endif
void set_request_type_url(const char* value);
void set_request_type_url(const char* value, size_t size);
::std::string* mutable_request_type_url();
::std::string* release_request_type_url();
void set_allocated_request_type_url(::std::string* request_type_url);
// string response_type_url = 4;
void clear_response_type_url();
static const int kResponseTypeUrlFieldNumber = 4;
const ::std::string& response_type_url() const;
void set_response_type_url(const ::std::string& value);
#if LANG_CXX11
void set_response_type_url(::std::string&& value);
#endif
void set_response_type_url(const char* value);
void set_response_type_url(const char* value, size_t size);
::std::string* mutable_response_type_url();
::std::string* release_response_type_url();
void set_allocated_response_type_url(::std::string* response_type_url);
// bool request_streaming = 3;
void clear_request_streaming();
static const int kRequestStreamingFieldNumber = 3;
bool request_streaming() const;
void set_request_streaming(bool value);
// bool response_streaming = 5;
void clear_response_streaming();
static const int kResponseStreamingFieldNumber = 5;
bool response_streaming() const;
void set_response_streaming(bool value);
// .google.protobuf.Syntax syntax = 7;
void clear_syntax();
static const int kSyntaxFieldNumber = 7;
::google::protobuf::Syntax syntax() const;
@@ -343,15 +418,9 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc
bool response_streaming_;
int syntax_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaultsMethodImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Method> Method_default_instance_;
// -------------------------------------------------------------------
class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ {
@@ -365,74 +434,99 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Mixin(Mixin&& from) noexcept
: Mixin() {
*this = ::std::move(from);
}
inline Mixin& operator=(Mixin&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
static const ::google::protobuf::Descriptor* descriptor();
static const Mixin& default_instance();
static const Mixin* internal_default_instance();
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
static inline const Mixin* internal_default_instance() {
return reinterpret_cast<const Mixin*>(
&_Mixin_default_instance_);
}
static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
2;
void Swap(Mixin* other);
friend void swap(Mixin& a, Mixin& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Mixin* New() const { return New(NULL); }
inline Mixin* New() const PROTOBUF_FINAL { return New(NULL); }
Mixin* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Mixin* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Mixin& from);
void MergeFrom(const Mixin& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Mixin* other);
void UnsafeMergeFrom(const Mixin& from);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
return NULL;
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
return NULL;
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional string name = 1;
// string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
#if LANG_CXX11
void set_name(::std::string&& value);
#endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
// optional string root = 2;
// string root = 2;
void clear_root();
static const int kRootFieldNumber = 2;
const ::std::string& root() const;
void set_root(const ::std::string& value);
#if LANG_CXX11
void set_root(::std::string&& value);
#endif
void set_root(const char* value);
void set_root(const char* value, size_t size);
::std::string* mutable_root();
@@ -446,37 +540,43 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_
::google::protobuf::internal::ArenaStringPtr name_;
::google::protobuf::internal::ArenaStringPtr root_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaultsMixinImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Mixin> Mixin_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// Api
// optional string name = 1;
// string name = 1;
inline void Api::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Api::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.name)
return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return name_.GetNoArena();
}
inline void Api::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Api.name)
}
#if LANG_CXX11
inline void Api::set_name(::std::string&& value) {
name_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name)
}
#endif
inline void Api::set_name(const char* value) {
GOOGLE_DCHECK(value != NULL);
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.name)
@@ -541,9 +641,6 @@ Api::methods() const {
inline int Api::options_size() const {
return options_.size();
}
inline void Api::clear_options() {
options_.Clear();
}
inline const ::google::protobuf::Option& Api::options(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.options)
return options_.Get(index);
@@ -567,20 +664,29 @@ Api::options() const {
return options_;
}
// optional string version = 4;
// string version = 4;
inline void Api::clear_version() {
version_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Api::version() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.version)
return version_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return version_.GetNoArena();
}
inline void Api::set_version(const ::std::string& value) {
version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Api.version)
}
#if LANG_CXX11
inline void Api::set_version(::std::string&& value) {
version_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version)
}
#endif
inline void Api::set_version(const char* value) {
GOOGLE_DCHECK(value != NULL);
version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Api.version)
@@ -611,18 +717,22 @@ inline void Api::set_allocated_version(::std::string* version) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
}
// optional .google.protobuf.SourceContext source_context = 5;
// .google.protobuf.SourceContext source_context = 5;
inline bool Api::has_source_context() const {
return this != internal_default_instance() && source_context_ != NULL;
}
inline void Api::clear_source_context() {
if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_;
source_context_ = NULL;
}
inline const ::google::protobuf::SourceContext& Api::source_context() const {
const ::google::protobuf::SourceContext* p = source_context_;
// @@protoc_insertion_point(field_get:google.protobuf.Api.source_context)
return source_context_ != NULL ? *source_context_
: *::google::protobuf::SourceContext::internal_default_instance();
return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>(
&::google::protobuf::_SourceContext_default_instance_);
}
inline ::google::protobuf::SourceContext* Api::release_source_context() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.source_context)
::google::protobuf::SourceContext* temp = source_context_;
source_context_ = NULL;
return temp;
}
inline ::google::protobuf::SourceContext* Api::mutable_source_context() {
@@ -632,21 +742,22 @@ inline ::google::protobuf::SourceContext* Api::mutable_source_context() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Api.source_context)
return source_context_;
}
inline ::google::protobuf::SourceContext* Api::release_source_context() {
// @@protoc_insertion_point(field_release:google.protobuf.Api.source_context)
::google::protobuf::SourceContext* temp = source_context_;
source_context_ = NULL;
return temp;
}
inline void Api::set_allocated_source_context(::google::protobuf::SourceContext* source_context) {
delete source_context_;
source_context_ = source_context;
::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
if (message_arena == NULL) {
delete reinterpret_cast< ::google::protobuf::MessageLite*>(source_context_);
}
if (source_context) {
::google::protobuf::Arena* submessage_arena = NULL;
if (message_arena != submessage_arena) {
source_context = ::google::protobuf::internal::GetOwnedMessage(
message_arena, source_context, submessage_arena);
}
} else {
}
source_context_ = source_context;
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context)
}
@@ -680,7 +791,7 @@ Api::mixins() const {
return mixins_;
}
// optional .google.protobuf.Syntax syntax = 7;
// .google.protobuf.Syntax syntax = 7;
inline void Api::clear_syntax() {
syntax_ = 0;
}
@@ -694,27 +805,33 @@ inline void Api::set_syntax(::google::protobuf::Syntax value) {
// @@protoc_insertion_point(field_set:google.protobuf.Api.syntax)
}
inline const Api* Api::internal_default_instance() {
return &Api_default_instance_.get();
}
// -------------------------------------------------------------------
// Method
// optional string name = 1;
// string name = 1;
inline void Method::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Method::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.name)
return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return name_.GetNoArena();
}
inline void Method::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Method.name)
}
#if LANG_CXX11
inline void Method::set_name(::std::string&& value) {
name_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name)
}
#endif
inline void Method::set_name(const char* value) {
GOOGLE_DCHECK(value != NULL);
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.name)
@@ -745,20 +862,29 @@ inline void Method::set_allocated_name(::std::string* name) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
}
// optional string request_type_url = 2;
// string request_type_url = 2;
inline void Method::clear_request_type_url() {
request_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Method::request_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url)
return request_type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return request_type_url_.GetNoArena();
}
inline void Method::set_request_type_url(const ::std::string& value) {
request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url)
}
#if LANG_CXX11
inline void Method::set_request_type_url(::std::string&& value) {
request_type_url_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url)
}
#endif
inline void Method::set_request_type_url(const char* value) {
GOOGLE_DCHECK(value != NULL);
request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url)
@@ -789,7 +915,7 @@ inline void Method::set_allocated_request_type_url(::std::string* request_type_u
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
}
// optional bool request_streaming = 3;
// bool request_streaming = 3;
inline void Method::clear_request_streaming() {
request_streaming_ = false;
}
@@ -803,20 +929,29 @@ inline void Method::set_request_streaming(bool value) {
// @@protoc_insertion_point(field_set:google.protobuf.Method.request_streaming)
}
// optional string response_type_url = 4;
// string response_type_url = 4;
inline void Method::clear_response_type_url() {
response_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Method::response_type_url() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url)
return response_type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return response_type_url_.GetNoArena();
}
inline void Method::set_response_type_url(const ::std::string& value) {
response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url)
}
#if LANG_CXX11
inline void Method::set_response_type_url(::std::string&& value) {
response_type_url_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url)
}
#endif
inline void Method::set_response_type_url(const char* value) {
GOOGLE_DCHECK(value != NULL);
response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url)
@@ -847,7 +982,7 @@ inline void Method::set_allocated_response_type_url(::std::string* response_type
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
}
// optional bool response_streaming = 5;
// bool response_streaming = 5;
inline void Method::clear_response_streaming() {
response_streaming_ = false;
}
@@ -865,9 +1000,6 @@ inline void Method::set_response_streaming(bool value) {
inline int Method::options_size() const {
return options_.size();
}
inline void Method::clear_options() {
options_.Clear();
}
inline const ::google::protobuf::Option& Method::options(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.options)
return options_.Get(index);
@@ -891,7 +1023,7 @@ Method::options() const {
return options_;
}
// optional .google.protobuf.Syntax syntax = 7;
// .google.protobuf.Syntax syntax = 7;
inline void Method::clear_syntax() {
syntax_ = 0;
}
@@ -905,27 +1037,33 @@ inline void Method::set_syntax(::google::protobuf::Syntax value) {
// @@protoc_insertion_point(field_set:google.protobuf.Method.syntax)
}
inline const Method* Method::internal_default_instance() {
return &Method_default_instance_.get();
}
// -------------------------------------------------------------------
// Mixin
// optional string name = 1;
// string name = 1;
inline void Mixin::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Mixin::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.name)
return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return name_.GetNoArena();
}
inline void Mixin::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.name)
}
#if LANG_CXX11
inline void Mixin::set_name(::std::string&& value) {
name_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name)
}
#endif
inline void Mixin::set_name(const char* value) {
GOOGLE_DCHECK(value != NULL);
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name)
@@ -956,20 +1094,29 @@ inline void Mixin::set_allocated_name(::std::string* name) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
}
// optional string root = 2;
// string root = 2;
inline void Mixin::clear_root() {
root_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Mixin::root() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.root)
return root_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return root_.GetNoArena();
}
inline void Mixin::set_root(const ::std::string& value) {
root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.root)
}
#if LANG_CXX11
inline void Mixin::set_root(::std::string&& value) {
root_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root)
}
#endif
inline void Mixin::set_root(const char* value) {
GOOGLE_DCHECK(value != NULL);
root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root)
@@ -1000,10 +1147,9 @@ inline void Mixin::set_allocated_root(::std::string* root) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)
}
inline const Mixin* Mixin::internal_default_instance() {
return &Mixin_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// -------------------------------------------------------------------
// -------------------------------------------------------------------
Vendored Regular → Executable
+245 -176
View File
@@ -36,280 +36,349 @@
#ifdef ADDRESS_SANITIZER
#include <sanitizer/asan_interface.h>
#endif
#endif // ADDRESS_SANITIZER
#include <google/protobuf/stubs/port.h>
namespace google {
static const size_t kMinCleanupListElements = 8;
static const size_t kMaxCleanupListElements = 64; // 1kB on 64-bit.
namespace protobuf {
namespace internal {
google::protobuf::internal::SequenceNumber Arena::lifecycle_id_generator_;
google::protobuf::internal::SequenceNumber ArenaImpl::lifecycle_id_generator_;
#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
Arena::ThreadCache& Arena::thread_cache() {
ArenaImpl::ThreadCache& ArenaImpl::thread_cache() {
static internal::ThreadLocalStorage<ThreadCache>* thread_cache_ =
new internal::ThreadLocalStorage<ThreadCache>();
return *thread_cache_->Get();
}
#elif defined(PROTOBUF_USE_DLLS)
Arena::ThreadCache& Arena::thread_cache() {
ArenaImpl::ThreadCache& ArenaImpl::thread_cache() {
static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_ = { -1, NULL };
return thread_cache_;
}
#else
GOOGLE_THREAD_LOCAL Arena::ThreadCache Arena::thread_cache_ = { -1, NULL };
GOOGLE_THREAD_LOCAL ArenaImpl::ThreadCache ArenaImpl::thread_cache_ = {-1, NULL};
#endif
void Arena::Init() {
void ArenaImpl::Init() {
lifecycle_id_ = lifecycle_id_generator_.GetNext();
blocks_ = 0;
hint_ = 0;
owns_first_block_ = true;
cleanup_list_ = 0;
google::protobuf::internal::NoBarrier_Store(&hint_, 0);
google::protobuf::internal::NoBarrier_Store(&threads_, 0);
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.";
// Add first unowned block to list.
Block* first_block = reinterpret_cast<Block*>(options_.initial_block);
first_block->size = options_.initial_block_size;
first_block->pos = kHeaderSize;
first_block->next = NULL;
if (initial_block_) {
// Thread which calls Init() owns the first block. This allows the
// single-threaded case to allocate on the first block without taking any
// locks.
first_block->owner = &thread_cache();
SetThreadCacheBlock(first_block);
AddBlockInternal(first_block);
owns_first_block_ = false;
}
// Call the initialization hook
if (options_.on_arena_init != NULL) {
hooks_cookie_ = options_.on_arena_init(this);
// single-threaded case to allocate on the first block without having to
// perform atomic operations.
InitBlock(initial_block_, &thread_cache(), options_.initial_block_size);
ThreadInfo* info = NewThreadInfo(initial_block_);
info->next = NULL;
google::protobuf::internal::NoBarrier_Store(&threads_,
reinterpret_cast<google::protobuf::internal::AtomicWord>(info));
google::protobuf::internal::NoBarrier_Store(&space_allocated_,
options_.initial_block_size);
CacheBlock(initial_block_);
} else {
hooks_cookie_ = NULL;
google::protobuf::internal::NoBarrier_Store(&space_allocated_, 0);
}
}
Arena::~Arena() {
uint64 space_allocated = ResetInternal();
// Call the destruction hook
if (options_.on_arena_destruction != NULL) {
options_.on_arena_destruction(this, hooks_cookie_, space_allocated);
}
ArenaImpl::~ArenaImpl() {
// Have to do this in a first pass, because some of the destructors might
// refer to memory in other blocks.
CleanupList();
FreeBlocks();
}
uint64 Arena::Reset() {
// Invalidate any ThreadCaches pointing to any blocks we just destroyed.
lifecycle_id_ = lifecycle_id_generator_.GetNext();
return ResetInternal();
}
uint64 Arena::ResetInternal() {
uint64 ArenaImpl::Reset() {
// Have to do this in a first pass, because some of the destructors might
// refer to memory in other blocks.
CleanupList();
uint64 space_allocated = FreeBlocks();
// Call the reset hook
if (options_.on_arena_reset != NULL) {
options_.on_arena_reset(this, hooks_cookie_, space_allocated);
}
Init();
return space_allocated;
}
Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n,
size_t start_block_size, size_t max_block_size) {
ArenaImpl::Block* ArenaImpl::NewBlock(void* me, Block* my_last_block,
size_t min_bytes) {
size_t size;
if (my_last_block != NULL) {
// Double the current block size, up to a limit.
size = 2 * (my_last_block->size);
if (size > max_block_size) size = max_block_size;
size = std::min(2 * my_last_block->size, options_.max_block_size);
} else {
size = start_block_size;
size = options_.start_block_size;
}
// Verify that n + kHeaderSize won't overflow.
GOOGLE_CHECK_LE(n, std::numeric_limits<size_t>::max() - kHeaderSize);
size = std::max(size, kHeaderSize + n);
// Verify that min_bytes + kHeaderSize won't overflow.
GOOGLE_CHECK_LE(min_bytes, std::numeric_limits<size_t>::max() - kHeaderSize);
size = std::max(size, kHeaderSize + min_bytes);
Block* b = reinterpret_cast<Block*>(options_.block_alloc(size));
b->pos = kHeaderSize + n;
InitBlock(b, me, size);
google::protobuf::internal::NoBarrier_AtomicIncrement(&space_allocated_, size);
return b;
}
void ArenaImpl::InitBlock(Block* b, void *me, size_t size) {
b->pos = kHeaderSize;
b->size = size;
b->owner = me;
b->next = NULL;
#ifdef ADDRESS_SANITIZER
// Poison the rest of the block for ASAN. It was unpoisoned by the underlying
// malloc but it's not yet usable until we return it as part of an allocation.
ASAN_POISON_MEMORY_REGION(
reinterpret_cast<char*>(b) + b->pos, b->size - b->pos);
#endif
return b;
#endif // ADDRESS_SANITIZER
}
void Arena::AddBlock(Block* b) {
MutexLock l(&blocks_lock_);
AddBlockInternal(b);
}
void Arena::AddBlockInternal(Block* b) {
b->next = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
google::protobuf::internal::Release_Store(&blocks_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b));
if (b->avail() != 0) {
// Direct future allocations to this block.
google::protobuf::internal::Release_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b));
ArenaImpl::CleanupChunk* ArenaImpl::ExpandCleanupList(CleanupChunk* cleanup,
Block* b) {
size_t size = cleanup ? cleanup->size * 2 : kMinCleanupListElements;
size = std::min(size, kMaxCleanupListElements);
size_t bytes = internal::AlignUpTo8(CleanupChunk::SizeOf(size));
if (b->avail() < bytes) {
b = GetBlock(bytes);
}
CleanupChunk* list =
reinterpret_cast<CleanupChunk*>(AllocFromBlock(b, bytes));
list->next = b->thread_info->cleanup;
list->size = size;
list->len = 0;
b->thread_info->cleanup = list;
return list;
}
void Arena::AddListNode(void* elem, void (*cleanup)(void*)) {
Node* node = reinterpret_cast<Node*>(AllocateAligned(sizeof(Node)));
inline GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
void ArenaImpl::AddCleanupInBlock(
Block* b, void* elem, void (*func)(void*)) {
CleanupChunk* cleanup = b->thread_info->cleanup;
if (cleanup == NULL || cleanup->len == cleanup->size) {
cleanup = ExpandCleanupList(cleanup, b);
}
CleanupNode* node = &cleanup->nodes[cleanup->len++];
node->elem = elem;
node->cleanup = cleanup;
node->next = reinterpret_cast<Node*>(
google::protobuf::internal::NoBarrier_AtomicExchange(&cleanup_list_,
reinterpret_cast<google::protobuf::internal::AtomicWord>(node)));
node->cleanup = func;
}
void* Arena::AllocateAligned(const std::type_info* allocated, size_t n) {
// Align n to next multiple of 8 (from Hacker's Delight, Chapter 3.)
n = (n + 7) & -8;
void ArenaImpl::AddCleanup(void* elem, void (*cleanup)(void*)) {
return AddCleanupInBlock(GetBlock(0), elem, cleanup);
}
// Monitor allocation if needed.
if (GOOGLE_PREDICT_FALSE(hooks_cookie_ != NULL) &&
options_.on_arena_allocation != NULL) {
options_.on_arena_allocation(allocated, n, hooks_cookie_);
}
void* ArenaImpl::AllocateAligned(size_t n) {
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned.
return AllocFromBlock(GetBlock(n), n);
}
void* ArenaImpl::AllocateAlignedAndAddCleanup(size_t n,
void (*cleanup)(void*)) {
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned.
Block* b = GetBlock(n);
void* mem = AllocFromBlock(b, n);
AddCleanupInBlock(b, mem, cleanup);
return mem;
}
inline GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
ArenaImpl::Block* ArenaImpl::GetBlock(size_t n) {
Block* my_block = NULL;
// 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.
if (thread_cache().last_lifecycle_id_seen == lifecycle_id_ &&
thread_cache().last_block_used_ != NULL) {
if (thread_cache().last_block_used_->avail() < n) {
return SlowAlloc(n);
ThreadCache* tc = &thread_cache();
if (tc->last_lifecycle_id_seen == lifecycle_id_) {
my_block = tc->last_block_used_;
if (my_block->avail() >= n) {
return my_block;
}
return AllocFromBlock(thread_cache().last_block_used_, n);
}
// Check whether we own the last accessed block on this arena.
// This fast path optimizes the case where a single thread uses multiple
// arenas.
void* me = &thread_cache();
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&hint_));
if (!b || b->owner != me || b->avail() < n) {
return SlowAlloc(n);
if (b != NULL && b->owner == tc) {
my_block = b;
if (my_block->avail() >= n) {
return my_block;
}
}
return AllocFromBlock(b, n);
return GetBlockSlow(tc, my_block, n);
}
void* Arena::AllocFromBlock(Block* b, size_t n) {
inline GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
void* ArenaImpl::AllocFromBlock(Block* b, size_t n) {
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(b->pos), b->pos); // Must be already aligned.
GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned.
GOOGLE_DCHECK_GE(b->avail(), n);
size_t p = b->pos;
b->pos = p + n;
#ifdef ADDRESS_SANITIZER
ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b) + p, n);
#endif
#endif // ADDRESS_SANITIZER
return reinterpret_cast<char*>(b) + p;
}
void* Arena::SlowAlloc(size_t n) {
void* me = &thread_cache();
Block* b = FindBlock(me); // Find block owned by me.
// See if allocation fits in my latest block.
if (b != NULL && b->avail() >= n) {
SetThreadCacheBlock(b);
google::protobuf::internal::NoBarrier_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b));
return AllocFromBlock(b, n);
ArenaImpl::Block* ArenaImpl::GetBlockSlow(void* me, Block* my_full_block,
size_t n) {
ThreadInfo* info =
my_full_block ? my_full_block->thread_info : GetThreadInfo(me, n);
GOOGLE_DCHECK(info != NULL);
Block* b = info->head;
if (b->avail() < n) {
Block* new_b = NewBlock(me, b, n);
new_b->thread_info = info;
new_b->next = b;
info->head = new_b;
b = new_b;
}
b = NewBlock(me, b, n, options_.start_block_size, options_.max_block_size);
AddBlock(b);
SetThreadCacheBlock(b);
return reinterpret_cast<char*>(b) + kHeaderSize;
CacheBlock(b);
return b;
}
uint64 Arena::SpaceAllocated() const {
uint64 space_allocated = 0;
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
while (b != NULL) {
space_allocated += (b->size);
b = b->next;
}
return space_allocated;
uint64 ArenaImpl::SpaceAllocated() const {
return google::protobuf::internal::NoBarrier_Load(&space_allocated_);
}
uint64 Arena::SpaceUsed() const {
uint64 ArenaImpl::SpaceUsed() const {
ThreadInfo* info =
reinterpret_cast<ThreadInfo*>(google::protobuf::internal::Acquire_Load(&threads_));
uint64 space_used = 0;
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
while (b != NULL) {
space_used += (b->pos - kHeaderSize);
b = b->next;
for ( ; info; info = info->next) {
// Remove the overhead of the ThreadInfo itself.
space_used -= sizeof(ThreadInfo);
for (Block* b = info->head; b; b = b->next) {
space_used += (b->pos - kHeaderSize);
}
}
return space_used;
}
pair<uint64, uint64> Arena::SpaceAllocatedAndUsed() const {
uint64 allocated = 0;
uint64 used = 0;
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
while (b != NULL) {
allocated += b->size;
used += (b->pos - kHeaderSize);
b = b->next;
}
return std::make_pair(allocated, used);
}
uint64 Arena::FreeBlocks() {
uint64 ArenaImpl::FreeBlocks() {
uint64 space_allocated = 0;
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
Block* first_block = NULL;
while (b != NULL) {
space_allocated += (b->size);
Block* next = b->next;
if (next != NULL) {
options_.block_dealloc(b, b->size);
} else {
if (owns_first_block_) {
// By omitting an Acquire barrier we ensure that any user code that doesn't
// properly synchronize Reset() or the destructor will throw a TSAN warning.
ThreadInfo* info =
reinterpret_cast<ThreadInfo*>(google::protobuf::internal::NoBarrier_Load(&threads_));
while (info) {
// This is inside the block we are freeing, so we need to read it now.
ThreadInfo* next_info = info->next;
for (Block* b = info->head; b; ) {
// This is inside the block we are freeing, so we need to read it now.
Block* next_block = b->next;
space_allocated += (b->size);
#ifdef ADDRESS_SANITIZER
// This memory was provided by the underlying allocator as unpoisoned, so
// return it in an unpoisoned state.
ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b), b->size);
#endif // ADDRESS_SANITIZER
if (b != initial_block_) {
options_.block_dealloc(b, b->size);
} else {
// User passed in the first block, skip free'ing the memory.
first_block = b;
}
b = next_block;
}
b = next;
}
blocks_ = 0;
hint_ = 0;
if (!owns_first_block_) {
// Make the first block that was passed in through ArenaOptions
// available for reuse.
first_block->pos = kHeaderSize;
// Thread which calls Reset() owns the first block. This allows the
// single-threaded case to allocate on the first block without taking any
// locks.
first_block->owner = &thread_cache();
SetThreadCacheBlock(first_block);
AddBlockInternal(first_block);
info = next_info;
}
return space_allocated;
}
void Arena::CleanupList() {
Node* head =
reinterpret_cast<Node*>(google::protobuf::internal::NoBarrier_Load(&cleanup_list_));
while (head != NULL) {
head->cleanup(head->elem);
head = head->next;
void ArenaImpl::CleanupList() {
// By omitting an Acquire barrier we ensure that any user code that doesn't
// properly synchronize Reset() or the destructor will throw a TSAN warning.
ThreadInfo* info =
reinterpret_cast<ThreadInfo*>(google::protobuf::internal::NoBarrier_Load(&threads_));
for ( ; info; info = info->next) {
CleanupChunk* list = info->cleanup;
while (list) {
size_t n = list->len;
CleanupNode* node = &list->nodes[list->len - 1];
for (size_t i = 0; i < n; i++, node--) {
node->cleanup(node->elem);
}
list = list->next;
}
}
cleanup_list_ = 0;
}
Arena::Block* Arena::FindBlock(void* me) {
// TODO(sanjay): We might want to keep a separate list with one
// entry per thread.
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&blocks_));
while (b != NULL && b->owner != me) {
b = b->next;
ArenaImpl::ThreadInfo* ArenaImpl::NewThreadInfo(Block* b) {
GOOGLE_DCHECK(FindThreadInfo(b->owner) == NULL);
ThreadInfo* info =
reinterpret_cast<ThreadInfo*>(AllocFromBlock(b, sizeof(ThreadInfo)));
b->thread_info = info;
info->owner = b->owner;
info->head = b;
info->cleanup = NULL;
return info;
}
ArenaImpl::ThreadInfo* ArenaImpl::FindThreadInfo(void* me) {
ThreadInfo* info =
reinterpret_cast<ThreadInfo*>(google::protobuf::internal::Acquire_Load(&threads_));
for ( ; info; info = info->next) {
if (info->owner == me) {
return info;
}
}
return NULL;
}
ArenaImpl::ThreadInfo* ArenaImpl::GetThreadInfo(void* me, size_t n) {
ThreadInfo* info = FindThreadInfo(me);
if (!info) {
// This thread doesn't have any ThreadInfo, which also means it doesn't have
// any blocks yet. So we'll allocate its first block now.
Block* b = NewBlock(me, NULL, sizeof(ThreadInfo) + n);
info = NewThreadInfo(b);
google::protobuf::internal::AtomicWord head;
do {
head = google::protobuf::internal::NoBarrier_Load(&threads_);
info->next = reinterpret_cast<ThreadInfo*>(head);
} while (google::protobuf::internal::Release_CompareAndSwap(
&threads_, head, reinterpret_cast<google::protobuf::internal::AtomicWord>(info)) != head);
}
return info;
}
} // namespace internal
void Arena::CallDestructorHooks() {
uint64 space_allocated = impl_.SpaceAllocated();
// Call the reset hook
if (on_arena_reset_ != NULL) {
on_arena_reset_(this, hooks_cookie_, space_allocated);
}
// Call the destruction hook
if (on_arena_destruction_ != NULL) {
on_arena_destruction_(this, hooks_cookie_, space_allocated);
}
}
void Arena::OnArenaAllocation(const std::type_info* allocated_type,
size_t n) const {
if (on_arena_allocation_ != NULL) {
on_arena_allocation_(allocated_type, n, hooks_cookie_);
}
return b;
}
} // namespace protobuf
File diff suppressed because it is too large Load Diff
+242
View File
@@ -0,0 +1,242 @@
// 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 <limits>
#include <google/protobuf/stubs/atomic_sequence_num.h>
#include <google/protobuf/stubs/atomicops.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/mutex.h>
#include <google/protobuf/stubs/type_traits.h>
#include <google/protobuf/stubs/port.h>
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) & -8;
}
// 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 LIBPROTOBUF_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);
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:
// 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 len; // Number of elements currently present.
size_t size; // Total elements in the list.
CleanupChunk* next; // Next node in the list.
CleanupNode nodes[1]; // True length is |size|.
};
struct Block;
// Tracks per-thread info. ThreadInfos are kept in a linked list.
struct ThreadInfo {
void *owner; // &ThreadCache of this thread;
Block* head; // Head of linked list of blocks.
CleanupChunk* cleanup; // Head of cleanup list.
ThreadInfo* next; // Next ThreadInfo in this linked list.
};
// Blocks are variable length malloc-ed objects. The following structure
// describes the common header for all blocks.
struct Block {
void* owner; // &ThreadCache of thread that owns this block.
ThreadInfo* thread_info; // ThreadInfo of thread that owns this block.
Block* next; // Next block in arena (may have different owner)
// ((char*) &block) + pos is next available byte. It is always
// aligned at a multiple of 8 bytes.
size_t pos;
size_t size; // total size of the block.
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
size_t avail() const { return size - pos; }
// 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_block_used_(NULL) {}
#endif
// The ThreadCache is considered valid as long as this matches the
// lifecycle_id of the arena being used.
int64 last_lifecycle_id_seen;
Block* last_block_used_;
};
static google::protobuf::internal::SequenceNumber 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();
void AddCleanupInBlock(Block* b, void* elem, void (*func)(void*));
CleanupChunk* ExpandCleanupList(CleanupChunk* cleanup, Block* b);
// Delete or Destruct all objects owned by the arena.
void CleanupList();
inline void CacheBlock(Block* block) {
thread_cache().last_block_used_ = block;
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.
google::protobuf::internal::Release_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(block));
}
google::protobuf::internal::AtomicWord threads_; // Pointer to a linked list of ThreadInfo.
google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access
google::protobuf::internal::AtomicWord space_allocated_; // Sum of sizes of all allocated blocks.
Block *initial_block_; // If non-NULL, points to the block that came from
// user data.
// Returns a block owned by this thread.
Block* GetBlock(size_t n);
Block* GetBlockSlow(void* me, Block* my_full_block, size_t n);
Block* NewBlock(void* me, Block* my_last_block, size_t min_bytes);
void InitBlock(Block* b, void *me, size_t size);
static void* AllocFromBlock(Block* b, size_t n);
ThreadInfo* NewThreadInfo(Block* b);
ThreadInfo* FindThreadInfo(void* me);
ThreadInfo* GetThreadInfo(void* me, size_t n);
int64 lifecycle_id_; // Unique for each arena. Changes on Reset().
Options options_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArenaImpl);
public:
// kHeaderSize 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 kHeaderSize = (sizeof(Block) + 7) & -8;
#if LANG_CXX11
static_assert(kHeaderSize % 8 == 0, "kHeaderSize must be a multiple of 8.");
#endif
};
} // namespace internal
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_ARENA_IMPL_H__
-10
View File
@@ -38,16 +38,6 @@ namespace protobuf {
namespace internal {
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(default_value));
}
}
} // namespace internal
} // namespace protobuf
} // namespace google
+55 -31
View File
@@ -33,13 +33,11 @@
#include <string>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/fastmem.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/port.h>
// This is the implementation of arena string fields written for the open-source
// release. The ArenaStringPtr struct below is an internal implementation class
@@ -63,11 +61,15 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
}
}
// Basic accessors.
inline const ::std::string& Get(const ::std::string* /* default_value */) const {
return *ptr_;
inline void SetLite(const ::std::string* default_value,
const ::std::string& value,
::google::protobuf::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,
::google::protobuf::Arena* arena) {
if (ptr_ == default_value) {
@@ -87,8 +89,9 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
}
::std::string* released = NULL;
if (arena != NULL) {
// ptr_ is owned by the arena -- we need to return a copy.
released = new ::std::string(*ptr_);
// ptr_ is owned by the arena.
released = new ::std::string;
released->swap(*ptr_);
} else {
released = ptr_;
}
@@ -146,17 +149,16 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
// 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.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(ArenaStringPtr* other) {
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE void Swap(ArenaStringPtr* other) {
std::swap(ptr_, other->ptr_);
}
// Frees storage (if not on an arena) and sets field to default value.
// Frees storage (if not on an arena).
inline void Destroy(const ::std::string* default_value,
::google::protobuf::Arena* arena) {
if (arena == NULL && ptr_ != default_value) {
delete ptr_;
}
ptr_ = const_cast< ::std::string* >(default_value);
}
// Clears content, but keeps allocated string if arena != NULL, to avoid the
@@ -214,11 +216,19 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
}
}
#if LANG_CXX11
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);
}
}
#endif
void AssignWithDefault(const ::std::string* default_value, ArenaStringPtr value);
inline const ::std::string& GetNoArena(const ::std::string* /* default_value */) const {
return *ptr_;
}
inline const ::std::string& GetNoArena() const { return *ptr_; }
inline ::std::string* MutableNoArena(const ::std::string* default_value) {
if (ptr_ == default_value) {
@@ -253,7 +263,6 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
if (ptr_ != default_value) {
delete ptr_;
}
ptr_ = NULL;
}
inline void ClearToEmptyNoArena(const ::std::string* default_value) {
@@ -281,27 +290,26 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
return &ptr_;
}
inline bool IsDefault(const ::std::string* default_value) const {
return ptr_ == default_value;
}
private:
::std::string* ptr_;
GOOGLE_ATTRIBUTE_NOINLINE void CreateInstance(::google::protobuf::Arena* arena,
const ::std::string* initial_value) {
// Assumes ptr_ is not NULL.
if (initial_value != NULL) {
ptr_ = new ::std::string(*initial_value);
} else {
ptr_ = new ::std::string();
}
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
void CreateInstance(::google::protobuf::Arena* arena,
const ::std::string* initial_value) {
GOOGLE_DCHECK(initial_value != NULL);
ptr_ = new ::std::string(*initial_value);
if (arena != NULL) {
arena->Own(ptr_);
}
}
GOOGLE_ATTRIBUTE_NOINLINE void CreateInstanceNoArena(const ::std::string* initial_value) {
if (initial_value != NULL) {
ptr_ = new ::std::string(*initial_value);
} else {
ptr_ = new ::std::string();
}
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
void CreateInstanceNoArena(const ::std::string* initial_value) {
GOOGLE_DCHECK(initial_value != NULL);
ptr_ = new ::std::string(*initial_value);
}
};
@@ -310,5 +318,21 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
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
#endif // GOOGLE_PROTOBUF_ARENASTRING_H__
File diff suppressed because it is too large Load Diff
+265 -52
View File
@@ -62,6 +62,8 @@
#include <string>
#include <vector>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/mutex.h>
#include <google/protobuf/stubs/once.h>
// TYPE_BOOL is defined in the MacOS's ConditionalMacros.h.
#ifdef TYPE_BOOL
@@ -97,6 +99,7 @@ class FieldOptions;
class OneofOptions;
class EnumOptions;
class EnumValueOptions;
class ExtensionRangeOptions;
class ServiceOptions;
class MethodOptions;
class FileOptions;
@@ -109,6 +112,7 @@ class Message;
// Defined in descriptor.cc
class DescriptorBuilder;
class FileDescriptorTables;
struct Symbol;
// Defined in unknown_field_set.h.
class UnknownField;
@@ -164,6 +168,55 @@ struct DebugStringOptions {
elide_oneof_body(false) {}
};
// A class to handle the simplest cases of a lazily linked descriptor
// for a message type that isn't built at the time of cross linking,
// which is needed when a pool has lazily_build_dependencies_ set.
// Must be instantiated as mutable in a descriptor.
namespace internal {
class LIBPROTOBUF_EXPORT LazyDescriptor {
public:
// Init function to be called at init time of a descriptor containing
// a LazyDescriptor.
void Init() {
descriptor_ = NULL;
name_ = NULL;
once_ = NULL;
file_ = NULL;
}
// Sets the value of the descriptor if it is known during the descriptor
// building process. Not thread safe, should only be called during the
// descriptor build process. Should not be called after SetLazy has been
// called.
void Set(const Descriptor* descriptor);
// Sets the information needed to lazily cross link the descriptor at a later
// time, SetLazy is not thread safe, should be called only once at descriptor
// build time if the symbol wasn't found and building of the file containing
// that type is delayed because lazily_build_dependencies_ is set on the pool.
// Should not be called after Set() has been called.
void SetLazy(const string& name, const FileDescriptor* file);
// Returns the current value of the descriptor, thread-safe. If SetLazy(...)
// has been called, will do a one-time cross link of the type specified,
// building the descriptor file that contains the type if necessary.
inline const Descriptor* Get() {
Once();
return descriptor_;
}
private:
static void OnceStatic(LazyDescriptor* lazy);
void OnceInternal();
void Once();
const Descriptor* descriptor_;
const string* name_;
GoogleOnceDynamic* once_;
const FileDescriptor* file_;
};
} // namespace internal
// Describes a type of protocol message, or a particular group within a
// message. To obtain the Descriptor for a given message object, call
// Message::GetDescriptor(). Generated message classes also have a
@@ -285,8 +338,12 @@ class LIBPROTOBUF_EXPORT Descriptor {
// A range of field numbers which are designated for third-party
// extensions.
struct ExtensionRange {
typedef ExtensionRangeOptions OptionsType;
int start; // inclusive
int end; // exclusive
const ExtensionRangeOptions* options_;
};
// The number of extension ranges in this message type.
@@ -388,27 +445,30 @@ class LIBPROTOBUF_EXPORT Descriptor {
const Descriptor* containing_type_;
const MessageOptions* options_;
// These arrays are separated from their sizes to minimize padding on 64-bit.
FieldDescriptor* fields_;
OneofDescriptor* oneof_decls_;
Descriptor* nested_types_;
EnumDescriptor* enum_types_;
ExtensionRange* extension_ranges_;
FieldDescriptor* extensions_;
ReservedRange* reserved_ranges_;
const string** reserved_names_;
int field_count_;
int oneof_decl_count_;
int nested_type_count_;
int enum_type_count_;
int extension_range_count_;
int extension_count_;
int reserved_range_count_;
int reserved_name_count_;
// True if this is a placeholder for an unknown type.
bool is_placeholder_;
// True if this is a placeholder and the type name wasn't fully-qualified.
bool is_unqualified_placeholder_;
int field_count_;
FieldDescriptor* fields_;
int oneof_decl_count_;
OneofDescriptor* oneof_decls_;
int nested_type_count_;
Descriptor* nested_types_;
int enum_type_count_;
EnumDescriptor* enum_types_;
int extension_range_count_;
ExtensionRange* extension_ranges_;
int extension_count_;
FieldDescriptor* extensions_;
int reserved_range_count_;
ReservedRange* reserved_ranges_;
int reserved_name_count_;
const string** reserved_names_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<Descriptor>() and AllocateArray<Descriptor>() in descriptor.cc
// and update them to initialize the field.
@@ -416,6 +476,7 @@ class LIBPROTOBUF_EXPORT Descriptor {
// Must be constructed using DescriptorPool.
Descriptor() {}
friend class DescriptorBuilder;
friend class DescriptorPool;
friend class EnumDescriptor;
friend class FieldDescriptor;
friend class OneofDescriptor;
@@ -424,6 +485,7 @@ class LIBPROTOBUF_EXPORT Descriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor);
};
// Describes a single field of a message. To get the descriptor for a given
// field, first get the Descriptor for the message in which it is defined,
// then call Descriptor::FindFieldByName(). To get a FieldDescriptor for
@@ -679,33 +741,41 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
// to this descriptor from the file root.
void GetLocationPath(std::vector<int>* output) const;
// Returns true if this is a map message type.
bool is_map_message_type() const;
const string* name_;
const string* full_name_;
const string* lowercase_name_;
const string* camelcase_name_;
// Whether the user has specified the json_name field option in the .proto
// file.
bool has_json_name_;
// If has_json_name_ is true, it's the value specified by the user.
// Otherwise, it has the same value as camelcase_name_.
const string* json_name_;
const FileDescriptor* file_;
int number_;
Type type_;
GoogleOnceDynamic* type_once_;
static void TypeOnceInit(const FieldDescriptor* to_init);
void InternalTypeOnceInit() const;
mutable Type type_;
Label label_;
bool has_default_value_;
// Whether the user has specified the json_name field option in the .proto
// file.
bool has_json_name_;
bool is_extension_;
int number_;
int index_in_oneof_;
const Descriptor* containing_type_;
const OneofDescriptor* containing_oneof_;
const Descriptor* extension_scope_;
const Descriptor* message_type_;
const EnumDescriptor* enum_type_;
mutable const Descriptor* message_type_;
mutable const EnumDescriptor* enum_type_;
const FieldOptions* options_;
const string* type_name_;
const string* default_value_enum_name_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<FieldDescriptor>() and AllocateArray<FieldDescriptor>() in
// descriptor.cc and update them to initialize the field.
bool has_default_value_;
union {
int32 default_value_int32_;
int64 default_value_int64_;
@@ -715,7 +785,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
double default_value_double_;
bool default_value_bool_;
const EnumValueDescriptor* default_value_enum_;
mutable const EnumValueDescriptor* default_value_enum_;
const string* default_value_string_;
};
@@ -736,6 +806,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor);
};
// Describes a oneof defined in a message type.
class LIBPROTOBUF_EXPORT OneofDescriptor {
public:
@@ -745,6 +816,8 @@ class LIBPROTOBUF_EXPORT OneofDescriptor {
// Index of this oneof within the message's oneof array.
int index() const;
// The .proto file in which this oneof was defined. Never NULL.
const FileDescriptor* file() const;
// The Descriptor for the message containing this oneof.
const Descriptor* containing_type() const;
@@ -854,12 +927,42 @@ class LIBPROTOBUF_EXPORT EnumDescriptor {
// See Descriptor::DebugStringWithOptions().
string DebugStringWithOptions(const DebugStringOptions& options) const;
// Returns true if this is a placeholder for an unknown enum. This will
// only be the case if this descriptor comes from a DescriptorPool
// with AllowUnknownDependencies() set.
bool is_placeholder() const;
// Reserved fields -------------------------------------------------
// A range of reserved field numbers.
struct ReservedRange {
int start; // inclusive
int end; // inclusive
};
// The number of reserved ranges in this message type.
int reserved_range_count() const;
// Gets an reserved range by index, where 0 <= index <
// reserved_range_count(). These are returned in the order they were defined
// in the .proto file.
const EnumDescriptor::ReservedRange* reserved_range(int index) const;
// Returns true if the number is in one of the reserved ranges.
bool IsReservedNumber(int number) const;
// Returns NULL if no reserved range contains the given number.
const EnumDescriptor::ReservedRange*
FindReservedRangeContainingNumber(int number) const;
// The number of reserved field names in this message type.
int reserved_name_count() const;
// Gets a reserved name by index, where 0 <= index < reserved_name_count().
const string& reserved_name(int index) const;
// Returns true if the field name is reserved.
bool IsReservedName(const string& name) const;
// Source Location ---------------------------------------------------
// Updates |*out_location| to the source location of the complete
@@ -906,6 +1009,12 @@ class LIBPROTOBUF_EXPORT EnumDescriptor {
int value_count_;
EnumValueDescriptor* values_;
int reserved_range_count_;
int reserved_name_count_;
EnumDescriptor::ReservedRange* reserved_ranges_;
const string** reserved_names_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<EnumDescriptor>() and AllocateArray<EnumDescriptor>() in
// descriptor.cc and update them to initialize the field.
@@ -917,6 +1026,7 @@ class LIBPROTOBUF_EXPORT EnumDescriptor {
friend class FieldDescriptor;
friend class EnumValueDescriptor;
friend class FileDescriptor;
friend class DescriptorPool;
friend class internal::GeneratedMessageReflection;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor);
};
@@ -939,6 +1049,8 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor {
// with C++ scoping rules for enums.
const string& full_name() const;
// The .proto file in which this value was defined. Never NULL.
const FileDescriptor* file() const;
// The type of this value. Never NULL.
const EnumDescriptor* type() const;
@@ -993,6 +1105,7 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor {
EnumValueDescriptor() {}
friend class DescriptorBuilder;
friend class EnumDescriptor;
friend class DescriptorPool;
friend class FileDescriptorTables;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor);
};
@@ -1062,8 +1175,8 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor {
const string* full_name_;
const FileDescriptor* file_;
const ServiceOptions* options_;
int method_count_;
MethodDescriptor* methods_;
int method_count_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<ServiceDescriptor>() and AllocateArray<ServiceDescriptor>() in
// descriptor.cc and update them to initialize the field.
@@ -1076,6 +1189,7 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor);
};
// Describes an individual service method. To obtain a MethodDescriptor given
// a service, first get its ServiceDescriptor, then call
// ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your
@@ -1089,6 +1203,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptor {
// Index within the service's Descriptor.
int index() const;
// The .proto file in which this method was defined. Never NULL.
const FileDescriptor* file() const;
// Gets the service to which this method belongs. Never NULL.
const ServiceDescriptor* service() const;
@@ -1143,8 +1259,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptor {
const string* name_;
const string* full_name_;
const ServiceDescriptor* service_;
const Descriptor* input_type_;
const Descriptor* output_type_;
mutable internal::LazyDescriptor input_type_;
mutable internal::LazyDescriptor output_type_;
const MethodOptions* options_;
bool client_streaming_;
bool server_streaming_;
@@ -1300,34 +1416,49 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
const string* name_;
const string* package_;
const DescriptorPool* pool_;
GoogleOnceDynamic* dependencies_once_;
static void DependenciesOnceInit(const FileDescriptor* to_init);
void InternalDependenciesOnceInit() const;
// These are arranged to minimze padding on 64-bit.
int dependency_count_;
const FileDescriptor** dependencies_;
int public_dependency_count_;
int* public_dependencies_;
int weak_dependency_count_;
int* weak_dependencies_;
int message_type_count_;
Descriptor* message_types_;
int enum_type_count_;
EnumDescriptor* enum_types_;
int service_count_;
ServiceDescriptor* services_;
int extension_count_;
Syntax syntax_;
bool is_placeholder_;
// Indicates the FileDescriptor is completed building. Used to verify
// that type accessor functions that can possibly build a dependent file
// aren't called during the process of building the file.
bool finished_building_;
mutable const FileDescriptor** dependencies_;
const string** dependencies_names_;
int* public_dependencies_;
int* weak_dependencies_;
Descriptor* message_types_;
EnumDescriptor* enum_types_;
ServiceDescriptor* services_;
FieldDescriptor* extensions_;
const FileOptions* options_;
const FileDescriptorTables* tables_;
const SourceCodeInfo* source_code_info_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<FileDescriptor>() and AllocateArray<FileDescriptor>() in
// descriptor.cc and update them to initialize the field.
FileDescriptor() {}
friend class DescriptorBuilder;
friend class DescriptorPool;
friend class Descriptor;
friend class FieldDescriptor;
friend class internal::LazyDescriptor;
friend class OneofDescriptor;
friend class EnumDescriptor;
friend class EnumValueDescriptor;
@@ -1336,6 +1467,7 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor);
};
// ===================================================================
// Used to construct descriptors.
@@ -1558,6 +1690,9 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
static void InternalAddGeneratedFile(
const void* encoded_file_descriptor, int size);
// Disallow [enforce_utf8 = false] in .proto files.
void DisallowEnforceUtf8() { disallow_enforce_utf8_ = true; }
// For internal use only: Gets a non-const pointer to the generated pool.
// This is called at static-initialization time only, so thread-safety is
@@ -1570,6 +1705,21 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
// which it did not officially declare as dependencies.
void InternalDontEnforceDependencies();
// For internal use only: Enables lazy building of dependencies of a file.
// Delay the building of dependencies of a file descriptor until absolutely
// necessary, like when message_type() is called on a field that is defined
// in that dependency's file. This will cause functional issues if a proto
// or one of it's dependencies has errors. Should only be enabled for the
// generated_pool_ (because no descriptor build errors are guaranteed by
// the compilation generation process), testing, or if a lack of descriptor
// build errors can be guaranteed for a pool.
void InternalSetLazilyBuildDependencies() {
lazily_build_dependencies_ = true;
// This needs to be set when lazily building dependencies, as it breaks
// dependency checking.
InternalDontEnforceDependencies();
}
// For internal use only.
void internal_set_underlay(const DescriptorPool* underlay) {
underlay_ = underlay;
@@ -1588,10 +1738,13 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
private:
friend class Descriptor;
friend class internal::LazyDescriptor;
friend class FieldDescriptor;
friend class EnumDescriptor;
friend class ServiceDescriptor;
friend class MethodDescriptor;
friend class FileDescriptor;
friend class StreamDescriptor;
friend class DescriptorBuilder;
friend class FileDescriptorTables;
@@ -1615,6 +1768,28 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
const FileDescriptor* BuildFileFromDatabase(
const FileDescriptorProto& proto) const;
// Helper for when lazily_build_dependencies_ is set, can look up a symbol
// after the file's descriptor is built, and can build the file where that
// symbol is defined if necessary. Will create a placeholder if the type
// doesn't exist in the fallback database, or the file doesn't build
// successfully.
Symbol CrossLinkOnDemandHelper(const string& name, bool expecting_enum) const;
// Create a placeholder FileDescriptor of the specified name
FileDescriptor* NewPlaceholderFile(const string& name) const;
FileDescriptor* NewPlaceholderFileWithMutexHeld(const string& name) const;
enum PlaceholderType {
PLACEHOLDER_MESSAGE,
PLACEHOLDER_ENUM,
PLACEHOLDER_EXTENDABLE_MESSAGE
};
// Create a placeholder Descriptor of the specified name
Symbol NewPlaceholder(const string& name,
PlaceholderType placeholder_type) const;
Symbol NewPlaceholderWithMutexHeld(const string& name,
PlaceholderType placeholder_type) const;
// If fallback_database_ is NULL, this is NULL. Otherwise, this is a mutex
// which must be locked while accessing tables_.
Mutex* mutex_;
@@ -1630,13 +1805,16 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
google::protobuf::scoped_ptr<Tables> tables_;
bool enforce_dependencies_;
bool lazily_build_dependencies_;
bool allow_unknown_;
bool enforce_weak_;
bool disallow_enforce_utf8_;
std::set<string> unused_import_track_files_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool);
};
// inline methods ====================================================
// These macros makes this repetitive code more readable.
@@ -1692,15 +1870,12 @@ PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, camelcase_name)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, type, FieldDescriptor::Type)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_oneof,
const OneofDescriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*)
PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool)
@@ -1711,8 +1886,6 @@ PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float )
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool )
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum,
const EnumValueDescriptor*)
PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string)
PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, name)
@@ -1730,6 +1903,10 @@ PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value,
const EnumValueDescriptor*)
PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions)
PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, is_placeholder, bool)
PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_range_count, int)
PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, reserved_range,
const EnumDescriptor::ReservedRange*)
PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_name_count, int)
PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, name)
PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, full_name)
@@ -1748,8 +1925,6 @@ PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions)
PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, name)
PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, full_name)
PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*)
PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, input_type, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, output_type, const Descriptor*)
PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions)
PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, client_streaming, bool)
PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, server_streaming, bool)
@@ -1803,6 +1978,32 @@ inline const string& Descriptor::reserved_name(int index) const {
return *reserved_names_[index];
}
inline bool EnumDescriptor::IsReservedNumber(int number) const {
return FindReservedRangeContainingNumber(number) != NULL;
}
inline bool EnumDescriptor::IsReservedName(const string& name) const {
for (int i = 0; i < reserved_name_count(); i++) {
if (name == reserved_name(i)) {
return true;
}
}
return false;
}
// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because reserved_names_ is actually
// an array of pointers rather than the usual array of objects.
inline const string& EnumDescriptor::reserved_name(int index) const {
return *reserved_names_[index];
}
inline FieldDescriptor::Type FieldDescriptor::type() const {
if (type_once_) {
type_once_->Init(&FieldDescriptor::TypeOnceInit, this);
}
return type_;
}
inline bool FieldDescriptor::is_required() const {
return label() == LABEL_REQUIRED;
}
@@ -1819,11 +2020,15 @@ inline bool FieldDescriptor::is_packable() const {
return is_repeated() && IsTypePackable(type());
}
inline bool FieldDescriptor::is_map() const {
return type() == TYPE_MESSAGE && is_map_message_type();
}
// To save space, index() is computed by looking at the descriptor's position
// in the parent's array of children.
inline int FieldDescriptor::index() const {
if (!is_extension_) {
return static_cast<int>(this - containing_type_->fields_);
return static_cast<int>(this - containing_type()->fields_);
} else if (extension_scope_ != NULL) {
return static_cast<int>(this - extension_scope_->extensions_);
} else {
@@ -1839,6 +2044,10 @@ inline int Descriptor::index() const {
}
}
inline const FileDescriptor* OneofDescriptor::file() const {
return containing_type()->file();
}
inline int OneofDescriptor::index() const {
return static_cast<int>(this - containing_type_->oneof_decls_);
}
@@ -1851,6 +2060,10 @@ inline int EnumDescriptor::index() const {
}
}
inline const FileDescriptor* EnumValueDescriptor::file() const {
return type()->file();
}
inline int EnumValueDescriptor::index() const {
return static_cast<int>(this - type_->values_);
}
@@ -1859,20 +2072,24 @@ inline int ServiceDescriptor::index() const {
return static_cast<int>(this - file_->services_);
}
inline const FileDescriptor* MethodDescriptor::file() const {
return service()->file();
}
inline int MethodDescriptor::index() const {
return static_cast<int>(this - service_->methods_);
}
inline const char* FieldDescriptor::type_name() const {
return kTypeToName[type_];
return kTypeToName[type()];
}
inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const {
return kTypeToCppTypeMap[type_];
return kTypeToCppTypeMap[type()];
}
inline const char* FieldDescriptor::cpp_type_name() const {
return kCppTypeToName[kTypeToCppTypeMap[type_]];
return kCppTypeToName[kTypeToCppTypeMap[type()]];
}
inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) {
@@ -1894,18 +2111,14 @@ inline bool FieldDescriptor::IsTypePackable(Type field_type) {
field_type != FieldDescriptor::TYPE_BYTES);
}
inline const FileDescriptor* FileDescriptor::dependency(int index) const {
return dependencies_[index];
}
inline const FileDescriptor* FileDescriptor::public_dependency(
int index) const {
return dependencies_[public_dependencies_[index]];
return dependency(public_dependencies_[index]);
}
inline const FileDescriptor* FileDescriptor::weak_dependency(
int index) const {
return dependencies_[weak_dependencies_[index]];
return dependency(weak_dependencies_[index]);
}
inline FileDescriptor::Syntax FileDescriptor::syntax() const {
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+29 -25
View File
@@ -39,8 +39,9 @@
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/stl_util.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/stl_util.h>
namespace google {
namespace protobuf {
@@ -97,11 +98,12 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddSymbol(
// Try to look up the symbol to make sure a super-symbol doesn't already
// exist.
typename map<string, Value>::iterator iter = FindLastLessOrEqual(name);
typename std::map<string, Value>::iterator iter = FindLastLessOrEqual(name);
if (iter == by_symbol_.end()) {
// Apparently the map is currently empty. Just insert and be done with it.
by_symbol_.insert(typename map<string, Value>::value_type(name, value));
by_symbol_.insert(
typename std::map<string, Value>::value_type(name, value));
return true;
}
@@ -128,7 +130,8 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddSymbol(
// Insert the new symbol using the iterator as a hint, the new entry will
// appear immediately before the one the iterator is pointing at.
by_symbol_.insert(iter, typename map<string, Value>::value_type(name, value));
by_symbol_.insert(iter,
typename std::map<string, Value>::value_type(name, value));
return true;
}
@@ -179,7 +182,7 @@ Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindFile(
template <typename Value>
Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindSymbol(
const string& name) {
typename map<string, Value>::iterator iter = FindLastLessOrEqual(name);
typename std::map<string, Value>::iterator iter = FindLastLessOrEqual(name);
return (iter != by_symbol_.end() && IsSubSymbol(iter->first, name)) ?
iter->second : Value();
@@ -196,8 +199,8 @@ Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindExtension(
template <typename Value>
bool SimpleDescriptorDatabase::DescriptorIndex<Value>::FindAllExtensionNumbers(
const string& containing_type,
vector<int>* output) {
typename map<pair<string, int>, Value>::const_iterator it =
std::vector<int>* output) {
typename std::map<std::pair<string, int>, Value>::const_iterator it =
by_extension_.lower_bound(std::make_pair(containing_type, 0));
bool success = false;
@@ -211,13 +214,14 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::FindAllExtensionNumbers(
}
template <typename Value>
typename map<string, Value>::iterator
typename std::map<string, Value>::iterator
SimpleDescriptorDatabase::DescriptorIndex<Value>::FindLastLessOrEqual(
const string& name) {
// Find the last key in the map which sorts less than or equal to the
// symbol name. Since upper_bound() returns the *first* key that sorts
// *greater* than the input, we want the element immediately before that.
typename map<string, Value>::iterator iter = by_symbol_.upper_bound(name);
typename std::map<string, Value>::iterator iter =
by_symbol_.upper_bound(name);
if (iter != by_symbol_.begin()) --iter;
return iter;
}
@@ -227,7 +231,7 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::IsSubSymbol(
const string& sub_symbol, const string& super_symbol) {
return sub_symbol == super_symbol ||
(HasPrefixString(super_symbol, sub_symbol) &&
super_symbol[sub_symbol.size()] == '.');
super_symbol[sub_symbol.size()] == '.');
}
template <typename Value>
@@ -284,7 +288,7 @@ bool SimpleDescriptorDatabase::FindFileContainingExtension(
bool SimpleDescriptorDatabase::FindAllExtensionNumbers(
const string& extendee_type,
vector<int>* output) {
std::vector<int>* output) {
return index_.FindAllExtensionNumbers(extendee_type, output);
}
@@ -340,7 +344,7 @@ bool EncodedDescriptorDatabase::FindFileContainingSymbol(
bool EncodedDescriptorDatabase::FindNameOfFileContainingSymbol(
const string& symbol_name,
string* output) {
pair<const void*, int> encoded_file = index_.FindSymbol(symbol_name);
std::pair<const void*, int> encoded_file = index_.FindSymbol(symbol_name);
if (encoded_file.first == NULL) return false;
// Optimization: The name should be the first field in the encoded message.
@@ -352,7 +356,7 @@ bool EncodedDescriptorDatabase::FindNameOfFileContainingSymbol(
FileDescriptorProto::kNameFieldNumber,
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
if (input.ReadTag() == kNameTag) {
if (input.ReadTagNoLastTag() == kNameTag) {
// Success!
return internal::WireFormatLite::ReadString(&input, output);
} else {
@@ -376,12 +380,12 @@ bool EncodedDescriptorDatabase::FindFileContainingExtension(
bool EncodedDescriptorDatabase::FindAllExtensionNumbers(
const string& extendee_type,
vector<int>* output) {
std::vector<int>* output) {
return index_.FindAllExtensionNumbers(extendee_type, output);
}
bool EncodedDescriptorDatabase::MaybeParse(
pair<const void*, int> encoded_file,
std::pair<const void*, int> encoded_file,
FileDescriptorProto* output) {
if (encoded_file.first == NULL) return false;
return output->ParseFromArray(encoded_file.first, encoded_file.second);
@@ -431,11 +435,11 @@ bool DescriptorPoolDatabase::FindFileContainingExtension(
bool DescriptorPoolDatabase::FindAllExtensionNumbers(
const string& extendee_type,
vector<int>* output) {
std::vector<int>* output) {
const Descriptor* extendee = pool_.FindMessageTypeByName(extendee_type);
if (extendee == NULL) return false;
vector<const FieldDescriptor*> extensions;
std::vector<const FieldDescriptor*> extensions;
pool_.FindAllExtensions(extendee, &extensions);
for (int i = 0; i < extensions.size(); ++i) {
@@ -454,7 +458,7 @@ MergedDescriptorDatabase::MergedDescriptorDatabase(
sources_.push_back(source2);
}
MergedDescriptorDatabase::MergedDescriptorDatabase(
const vector<DescriptorDatabase*>& sources)
const std::vector<DescriptorDatabase*>& sources)
: sources_(sources) {}
MergedDescriptorDatabase::~MergedDescriptorDatabase() {}
@@ -517,23 +521,23 @@ bool MergedDescriptorDatabase::FindFileContainingExtension(
bool MergedDescriptorDatabase::FindAllExtensionNumbers(
const string& extendee_type,
vector<int>* output) {
set<int> merged_results;
vector<int> results;
std::vector<int>* output) {
std::set<int> merged_results;
std::vector<int> results;
bool success = false;
for (int i = 0; i < sources_.size(); i++) {
if (sources_[i]->FindAllExtensionNumbers(extendee_type, &results)) {
std::copy(
results.begin(), results.end(),
insert_iterator<set<int> >(merged_results, merged_results.begin()));
std::copy(results.begin(), results.end(),
std::insert_iterator<std::set<int> >(merged_results,
merged_results.begin()));
success = true;
}
results.clear();
}
std::copy(merged_results.begin(), merged_results.end(),
insert_iterator<vector<int> >(*output, output->end()));
std::insert_iterator<std::vector<int> >(*output, output->end()));
return success;
}
+30 -16
View File
@@ -97,11 +97,23 @@ class LIBPROTOBUF_EXPORT DescriptorDatabase {
// This method has a default implementation that always returns
// false.
virtual bool FindAllExtensionNumbers(const string& /* extendee_type */,
vector<int>* /* output */) {
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<string>* output) {
return false;
}
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase);
};
@@ -150,7 +162,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
int field_number,
FileDescriptorProto* output);
bool FindAllExtensionNumbers(const string& extendee_type,
vector<int>* output);
std::vector<int>* output);
private:
// So that it can use DescriptorIndex.
@@ -175,12 +187,12 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
Value FindSymbol(const string& name);
Value FindExtension(const string& containing_type, int field_number);
bool FindAllExtensionNumbers(const string& containing_type,
vector<int>* output);
std::vector<int>* output);
private:
map<string, Value> by_name_;
map<string, Value> by_symbol_;
map<pair<string, int>, Value> by_extension_;
std::map<string, Value> by_name_;
std::map<string, Value> by_symbol_;
std::map<std::pair<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
@@ -235,7 +247,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
// Find the last entry in the by_symbol_ map whose key is less than or
// equal to the given name.
typename map<string, Value>::iterator FindLastLessOrEqual(
typename std::map<string, Value>::iterator FindLastLessOrEqual(
const string& name);
// True if either the arguments are equal or super_symbol identifies a
@@ -250,7 +262,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
DescriptorIndex<const FileDescriptorProto*> index_;
vector<const FileDescriptorProto*> files_to_delete_;
std::vector<const FileDescriptorProto*> files_to_delete_;
// If file is non-NULL, copy it into *output and return true, otherwise
// return false.
@@ -295,15 +307,16 @@ class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase {
int field_number,
FileDescriptorProto* output);
bool FindAllExtensionNumbers(const string& extendee_type,
vector<int>* output);
std::vector<int>* output);
private:
SimpleDescriptorDatabase::DescriptorIndex<pair<const void*, int> > index_;
vector<void*> files_to_delete_;
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(pair<const void*, int> encoded_file,
bool MaybeParse(std::pair<const void*, int> encoded_file,
FileDescriptorProto* output);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase);
@@ -324,7 +337,7 @@ class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase {
int field_number,
FileDescriptorProto* output);
bool FindAllExtensionNumbers(const string& extendee_type,
vector<int>* output);
std::vector<int>* output);
private:
const DescriptorPool& pool_;
@@ -341,7 +354,8 @@ class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
// 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 vector<DescriptorDatabase*>& sources);
explicit MergedDescriptorDatabase(
const std::vector<DescriptorDatabase*>& sources);
~MergedDescriptorDatabase();
// implements DescriptorDatabase -----------------------------------
@@ -355,11 +369,11 @@ class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
// Merges the results of calling all databases. Returns true iff any
// of the databases returned true.
bool FindAllExtensionNumbers(const string& extendee_type,
vector<int>* output);
std::vector<int>* output);
private:
vector<DescriptorDatabase*> sources_;
std::vector<DescriptorDatabase*> sources_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase);
};
+180 -227
View File
@@ -1,7 +1,6 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/duration.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <google/protobuf/duration.pb.h>
#include <algorithm>
@@ -15,118 +14,114 @@
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// This is a temporary google only hack
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
#include "third_party/protobuf/version.h"
#endif
// @@protoc_insertion_point(includes)
namespace google {
namespace protobuf {
class DurationDefaultTypeInternal {
public:
::google::protobuf::internal::ExplicitlyConstructed<Duration>
_instance;
} _Duration_default_instance_;
} // namespace protobuf
} // namespace google
namespace protobuf_google_2fprotobuf_2fduration_2eproto {
void InitDefaultsDurationImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
::google::protobuf::internal::InitProtobufDefaultsForceUnique();
#else
::google::protobuf::internal::InitProtobufDefaults();
#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
{
void* ptr = &::google::protobuf::_Duration_default_instance_;
new (ptr) ::google::protobuf::Duration();
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
}
::google::protobuf::Duration::InitAsDefaultInstance();
}
void InitDefaultsDuration() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &InitDefaultsDurationImpl);
}
::google::protobuf::Metadata file_level_metadata[1];
const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
~0u, // no _has_bits_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Duration, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Duration, seconds_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Duration, nanos_),
};
static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, sizeof(::google::protobuf::Duration)},
};
static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Duration_default_instance_),
};
void protobuf_AssignDescriptors() {
AddDescriptors();
::google::protobuf::MessageFactory* factory = NULL;
AssignDescriptors(
"google/protobuf/duration.proto", schemas, file_default_instances, TableStruct::offsets, factory,
file_level_metadata, NULL, NULL);
}
void protobuf_AssignDescriptorsOnce() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\036google/protobuf/duration.proto\022\017google"
".protobuf\"*\n\010Duration\022\017\n\007seconds\030\001 \001(\003\022\r"
"\n\005nanos\030\002 \001(\005B|\n\023com.google.protobufB\rDu"
"rationProtoP\001Z*github.com/golang/protobu"
"f/ptypes/duration\370\001\001\242\002\003GPB\252\002\036Google.Prot"
"obuf.WellKnownTypesb\006proto3"
};
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
descriptor, 227);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/duration.proto", &protobuf_RegisterTypes);
}
void AddDescriptors() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
}
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
}
} static_descriptor_initializer;
} // namespace protobuf_google_2fprotobuf_2fduration_2eproto
namespace google {
namespace protobuf {
namespace {
const ::google::protobuf::Descriptor* Duration_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
Duration_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"google/protobuf/duration.proto");
GOOGLE_CHECK(file != NULL);
Duration_descriptor_ = file->message_type(0);
static const int Duration_offsets_[2] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, seconds_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, nanos_),
};
Duration_reflection_ =
::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
Duration_descriptor_,
Duration::internal_default_instance(),
Duration_offsets_,
-1,
-1,
-1,
sizeof(Duration),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _internal_metadata_));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
Duration_descriptor_, Duration::internal_default_instance());
}
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto() {
Duration_default_instance_.Shutdown();
delete Duration_reflection_;
}
void protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
Duration_default_instance_.DefaultConstruct();
Duration_default_instance_.get_mutable()->InitAsDefaultInstance();
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_once_);
void protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_once_,
&protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl);
}
void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto();
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\036google/protobuf/duration.proto\022\017google"
".protobuf\"*\n\010Duration\022\017\n\007seconds\030\001 \001(\003\022\r"
"\n\005nanos\030\002 \001(\005B|\n\023com.google.protobufB\rDu"
"rationProtoP\001Z*github.com/golang/protobu"
"f/ptypes/duration\370\001\001\242\002\003GPB\252\002\036Google.Prot"
"obuf.WellKnownTypesb\006proto3", 227);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/duration.proto", &protobuf_RegisterTypes);
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_once_);
void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_once_,
&protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto {
StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
}
} static_descriptor_initializer_google_2fprotobuf_2fduration_2eproto_;
namespace {
static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN;
static void MergeFromFail(int line) {
::google::protobuf::internal::MergeFromFail(__FILE__, line);
}
} // namespace
// ===================================================================
void Duration::InitAsDefaultInstance() {
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Duration::kSecondsFieldNumber;
const int Duration::kNanosFieldNumber;
@@ -134,35 +129,35 @@ const int Duration::kNanosFieldNumber;
Duration::Duration()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto();
if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
::protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaultsDuration();
}
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Duration)
}
Duration::Duration(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto();
#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
::protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaultsDuration();
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Duration)
}
void Duration::InitAsDefaultInstance() {
}
Duration::Duration(const Duration& from)
: ::google::protobuf::Message(),
_internal_metadata_(NULL) {
SharedCtor();
UnsafeMergeFrom(from);
_internal_metadata_(NULL),
_cached_size_(0) {
_internal_metadata_.MergeFrom(from._internal_metadata_);
::memcpy(&seconds_, &from.seconds_,
static_cast<size_t>(reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_)) + sizeof(nanos_));
// @@protoc_insertion_point(copy_constructor:google.protobuf.Duration)
}
void Duration::SharedCtor() {
::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
::memset(&seconds_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_)) + sizeof(nanos_));
_cached_size_ = 0;
}
@@ -172,11 +167,7 @@ Duration::~Duration() {
}
void Duration::SharedDtor() {
::google::protobuf::Arena* arena = GetArenaNoVirtual();
if (arena != NULL) {
return;
}
GOOGLE_DCHECK(GetArenaNoVirtual() == NULL);
}
void Duration::ArenaDtor(void* object) {
@@ -191,44 +182,29 @@ void Duration::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Duration::descriptor() {
protobuf_AssignDescriptorsOnce();
return Duration_descriptor_;
::protobuf_google_2fprotobuf_2fduration_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
}
const Duration& Duration::default_instance() {
protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto();
::protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaultsDuration();
return *internal_default_instance();
}
::google::protobuf::internal::ExplicitlyConstructed<Duration> Duration_default_instance_;
Duration* Duration::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<Duration>(arena);
}
void Duration::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Duration)
#if defined(__clang__)
#define ZR_HELPER_(f) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
__builtin_offsetof(Duration, f) \
_Pragma("clang diagnostic pop")
#else
#define ZR_HELPER_(f) reinterpret_cast<char*>(\
&reinterpret_cast<Duration*>(16)->f)
#endif
#define ZR_(first, last) do {\
::memset(&(first), 0,\
ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
} while (0)
ZR_(seconds_, nanos_);
#undef ZR_HELPER_
#undef ZR_
::google::protobuf::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
::memset(&seconds_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&nanos_) -
reinterpret_cast<char*>(&seconds_)) + sizeof(nanos_));
_internal_metadata_.Clear();
}
bool Duration::MergePartialFromCodedStream(
@@ -237,13 +213,14 @@ bool Duration::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Duration)
for (;;) {
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional int64 seconds = 1;
// int64 seconds = 1;
case 1: {
if (tag == 8) {
if (static_cast< ::google::protobuf::uint8>(tag) ==
static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>(
@@ -251,14 +228,13 @@ bool Duration::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
if (input->ExpectTag(16)) goto parse_nanos;
break;
}
// optional int32 nanos = 2;
// int32 nanos = 2;
case 2: {
if (tag == 16) {
parse_nanos:
if (static_cast< ::google::protobuf::uint8>(tag) ==
static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
@@ -266,18 +242,16 @@ bool Duration::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
if (input->ExpectAtEnd()) goto success;
break;
}
default: {
handle_unusual:
if (tag == 0 ||
::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -294,16 +268,23 @@ failure:
void Duration::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Duration)
// optional int64 seconds = 1;
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// int64 seconds = 1;
if (this->seconds() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->seconds(), output);
}
// optional int32 nanos = 2;
// int32 nanos = 2;
if (this->nanos() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->nanos(), output);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.Duration)
}
@@ -311,16 +292,23 @@ void Duration::SerializeWithCachedSizes(
bool deterministic, ::google::protobuf::uint8* target) const {
(void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration)
// optional int64 seconds = 1;
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// int64 seconds = 1;
if (this->seconds() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->seconds(), target);
}
// optional int32 nanos = 2;
// int32 nanos = 2;
if (this->nanos() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->nanos(), target);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Duration)
return target;
}
@@ -329,14 +317,19 @@ size_t Duration::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Duration)
size_t total_size = 0;
// optional int64 seconds = 1;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()));
}
// int64 seconds = 1;
if (this->seconds() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int64Size(
this->seconds());
}
// optional int32 nanos = 2;
// int32 nanos = 2;
if (this->nanos() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
@@ -352,7 +345,7 @@ size_t Duration::ByteSizeLong() const {
void Duration::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Duration)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
GOOGLE_DCHECK_NE(&from, this);
const Duration* source =
::google::protobuf::internal::DynamicCastToGenerated<const Duration>(
&from);
@@ -361,21 +354,17 @@ void Duration::MergeFrom(const ::google::protobuf::Message& from) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
// @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Duration)
UnsafeMergeFrom(*source);
MergeFrom(*source);
}
}
void Duration::MergeFrom(const Duration& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration)
if (GOOGLE_PREDICT_TRUE(&from != this)) {
UnsafeMergeFrom(from);
} else {
MergeFromFail(__LINE__);
}
}
GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_);
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
void Duration::UnsafeMergeFrom(const Duration& from) {
GOOGLE_DCHECK(&from != this);
if (from.seconds() != 0) {
set_seconds(from.seconds());
}
@@ -395,11 +384,10 @@ void Duration::CopyFrom(const Duration& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Duration)
if (&from == this) return;
Clear();
UnsafeMergeFrom(from);
MergeFrom(from);
}
bool Duration::IsInitialized() const {
return true;
}
@@ -408,10 +396,13 @@ void Duration::Swap(Duration* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
Duration temp;
temp.UnsafeMergeFrom(*this);
CopyFrom(*other);
other->CopyFrom(temp);
Duration* temp = New(GetArenaNoVirtual());
temp->MergeFrom(*other);
other->CopyFrom(*this);
InternalSwap(temp);
if (GetArenaNoVirtual() == NULL) {
delete temp;
}
}
}
void Duration::UnsafeArenaSwap(Duration* other) {
@@ -420,58 +411,20 @@ void Duration::UnsafeArenaSwap(Duration* other) {
InternalSwap(other);
}
void Duration::InternalSwap(Duration* other) {
std::swap(seconds_, other->seconds_);
std::swap(nanos_, other->nanos_);
using std::swap;
swap(seconds_, other->seconds_);
swap(nanos_, other->nanos_);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Duration::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = Duration_descriptor_;
metadata.reflection = Duration_reflection_;
return metadata;
protobuf_google_2fprotobuf_2fduration_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[kIndexInFileMessages];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Duration
// optional int64 seconds = 1;
void Duration::clear_seconds() {
seconds_ = GOOGLE_LONGLONG(0);
}
::google::protobuf::int64 Duration::seconds() const {
// @@protoc_insertion_point(field_get:google.protobuf.Duration.seconds)
return seconds_;
}
void Duration::set_seconds(::google::protobuf::int64 value) {
seconds_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds)
}
// optional int32 nanos = 2;
void Duration::clear_nanos() {
nanos_ = 0;
}
::google::protobuf::int32 Duration::nanos() const {
// @@protoc_insertion_point(field_get:google.protobuf.Duration.nanos)
return nanos_;
}
void Duration::set_nanos(::google::protobuf::int32 value) {
nanos_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos)
}
inline const Duration* Duration::internal_default_instance() {
return &Duration_default_instance_.get();
}
#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// @@protoc_insertion_point(namespace_scope)
} // namespace protobuf
} // namespace google
+84 -49
View File
@@ -8,37 +8,55 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.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)
namespace protobuf_google_2fprotobuf_2fduration_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[1];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsDurationImpl();
void LIBPROTOBUF_EXPORT InitDefaultsDuration();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsDuration();
}
} // namespace protobuf_google_2fprotobuf_2fduration_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto();
class Duration;
class DurationDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern DurationDefaultTypeInternal _Duration_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
// ===================================================================
@@ -53,48 +71,69 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Duration(Duration&& from) noexcept
: Duration() {
*this = ::std::move(from);
}
inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
inline void* GetMaybeArenaPointer() const {
inline Duration& operator=(Duration&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
return GetArenaNoVirtual();
}
inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Duration& default_instance();
static const Duration* internal_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 PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
0;
void UnsafeArenaSwap(Duration* other);
void Swap(Duration* other);
friend void swap(Duration& a, Duration& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Duration* New() const { return New(NULL); }
inline Duration* New() const PROTOBUF_FINAL { return New(NULL); }
Duration* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Duration* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Duration& from);
void MergeFrom(const Duration& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Duration* other);
void UnsafeMergeFrom(const Duration& from);
protected:
explicit Duration(::google::protobuf::Arena* arena);
private:
@@ -109,19 +148,19 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional int64 seconds = 1;
// int64 seconds = 1;
void clear_seconds();
static const int kSecondsFieldNumber = 1;
::google::protobuf::int64 seconds() const;
void set_seconds(::google::protobuf::int64 value);
// optional int32 nanos = 2;
// int32 nanos = 2;
void clear_nanos();
static const int kNanosFieldNumber = 2;
::google::protobuf::int32 nanos() const;
@@ -131,30 +170,27 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
friend class ::google::protobuf::Arena;
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::google::protobuf::int64 seconds_;
::google::protobuf::int32 nanos_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fduration_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaultsDurationImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Duration> Duration_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// Duration
// optional int64 seconds = 1;
// int64 seconds = 1;
inline void Duration::clear_seconds() {
seconds_ = GOOGLE_LONGLONG(0);
}
@@ -168,7 +204,7 @@ inline void Duration::set_seconds(::google::protobuf::int64 value) {
// @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds)
}
// optional int32 nanos = 2;
// int32 nanos = 2;
inline void Duration::clear_nanos() {
nanos_ = 0;
}
@@ -182,10 +218,9 @@ inline void Duration::set_nanos(::google::protobuf::int32 value) {
// @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos)
}
inline const Duration* Duration::internal_default_instance() {
return &Duration_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// @@protoc_insertion_point(namespace_scope)
+116 -79
View File
@@ -77,22 +77,23 @@
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/map_field.h>
#include <google/protobuf/map_field_inl.h>
#include <google/protobuf/map_type_handler.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/map_type_handler.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/map_field.h>
namespace google {
namespace protobuf {
using internal::WireFormat;
using internal::DynamicMapField;
using internal::ExtensionSet;
using internal::GeneratedMessageReflection;
using internal::InternalMetadataWithArena;
using internal::MapField;
using internal::DynamicMapField;
using internal::ArenaStringPtr;
@@ -221,7 +222,7 @@ class DynamicMessage : public Message {
int size;
int has_bits_offset;
int oneof_case_offset;
int unknown_fields_offset;
int internal_metadata_offset;
int extensions_offset;
// Not owned by the TypeInfo.
@@ -231,24 +232,28 @@ class DynamicMessage : public Message {
// Warning: The order in which the following pointers are defined is
// important (the prototype must be deleted *before* the offsets).
google::protobuf::scoped_array<int> offsets;
google::protobuf::scoped_array<uint32> offsets;
google::protobuf::scoped_array<uint32> has_bits_indices;
google::protobuf::scoped_ptr<const GeneratedMessageReflection> reflection;
// Don't use a scoped_ptr to hold the prototype: the destructor for
// DynamicMessage needs to know whether it is the prototype, and does so by
// looking back at this field. This would assume details about the
// implementation of scoped_ptr.
const DynamicMessage* prototype;
void* default_oneof_instance;
int weak_field_map_offset; // The offset for the weak_field_map;
TypeInfo() : prototype(NULL), default_oneof_instance(NULL) {}
TypeInfo() : prototype(NULL) {}
~TypeInfo() {
delete prototype;
operator delete(default_oneof_instance);
}
};
DynamicMessage(const TypeInfo* type_info);
// This should only be used by GetPrototypeNoLock() to avoid dead lock.
DynamicMessage(const TypeInfo* type_info, bool lock_factory);
~DynamicMessage();
// Called on the prototype after construction to initialize message fields.
@@ -279,7 +284,8 @@ class DynamicMessage : public Message {
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessage);
DynamicMessage(const TypeInfo* type_info, ::google::protobuf::Arena* arena);
void SharedCtor();
void SharedCtor(bool lock_factory);
inline bool is_prototype() const {
return type_info_->prototype == this ||
@@ -303,17 +309,22 @@ class DynamicMessage : public Message {
DynamicMessage::DynamicMessage(const TypeInfo* type_info)
: type_info_(type_info),
cached_byte_size_(0) {
SharedCtor();
SharedCtor(true);
}
DynamicMessage::DynamicMessage(const TypeInfo* type_info,
::google::protobuf::Arena* arena)
: type_info_(type_info),
cached_byte_size_(0) {
SharedCtor();
SharedCtor(true);
}
void DynamicMessage::SharedCtor() {
DynamicMessage::DynamicMessage(const TypeInfo* type_info, bool lock_factory)
: type_info_(type_info), cached_byte_size_(0) {
SharedCtor(lock_factory);
}
void DynamicMessage::SharedCtor(bool lock_factory) {
// We need to call constructors for various fields manually and set
// default values where appropriate. We use placement new to call
// constructors. If you haven't heard of placement new, I suggest Googling
@@ -324,19 +335,18 @@ void DynamicMessage::SharedCtor() {
// constructor.)
const Descriptor* descriptor = type_info_->type;
// Initialize oneof cases.
for (int i = 0 ; i < descriptor->oneof_decl_count(); ++i) {
new(OffsetToPointer(type_info_->oneof_case_offset + sizeof(uint32) * i))
new (OffsetToPointer(type_info_->oneof_case_offset + sizeof(uint32) * i))
uint32(0);
}
new(OffsetToPointer(type_info_->unknown_fields_offset)) UnknownFieldSet;
new (OffsetToPointer(type_info_->internal_metadata_offset))
InternalMetadataWithArena;
if (type_info_->extensions_offset != -1) {
new(OffsetToPointer(type_info_->extensions_offset)) ExtensionSet;
new (OffsetToPointer(type_info_->extensions_offset)) ExtensionSet;
}
for (int i = 0; i < descriptor->field_count(); i++) {
const FieldDescriptor* field = descriptor->field(i);
void* field_ptr = OffsetToPointer(type_info_->offsets[i]);
@@ -379,10 +389,10 @@ void DynamicMessage::SharedCtor() {
if (is_prototype()) {
default_value = &field->default_value_string();
} else {
default_value =
&(reinterpret_cast<const ArenaStringPtr*>(
type_info_->prototype->OffsetToPointer(
type_info_->offsets[i]))->Get(NULL));
default_value = &(reinterpret_cast<const ArenaStringPtr*>(
type_info_->prototype->OffsetToPointer(
type_info_->offsets[i]))
->Get());
}
ArenaStringPtr* asp = new(field_ptr) ArenaStringPtr();
asp->UnsafeSetDefault(default_value);
@@ -398,8 +408,17 @@ void DynamicMessage::SharedCtor() {
new(field_ptr) Message*(NULL);
} else {
if (IsMapFieldInApi(field)) {
new (field_ptr) DynamicMapField(
type_info_->factory->GetPrototypeNoLock(field->message_type()));
// We need to lock in most cases to avoid data racing. Only not lock
// when the constructor is called inside GetPrototype(), in which
// case we have already locked the factory.
if (lock_factory) {
new (field_ptr) DynamicMapField(
type_info_->factory->GetPrototype(field->message_type()));
} else {
new (field_ptr)
DynamicMapField(type_info_->factory->GetPrototypeNoLock(
field->message_type()));
}
} else {
new (field_ptr) RepeatedPtrField<Message>();
}
@@ -413,8 +432,9 @@ void DynamicMessage::SharedCtor() {
DynamicMessage::~DynamicMessage() {
const Descriptor* descriptor = type_info_->type;
reinterpret_cast<UnknownFieldSet*>(
OffsetToPointer(type_info_->unknown_fields_offset))->~UnknownFieldSet();
reinterpret_cast<InternalMetadataWithArena*>(
OffsetToPointer(type_info_->internal_metadata_offset))
->~InternalMetadataWithArena();
if (type_info_->extensions_offset != -1) {
reinterpret_cast<ExtensionSet*>(
@@ -445,10 +465,10 @@ DynamicMessage::~DynamicMessage() {
case FieldOptions::STRING: {
const ::std::string* default_value =
&(reinterpret_cast<const ArenaStringPtr*>(
reinterpret_cast<uint8*>(
type_info_->default_oneof_instance)
+ type_info_->offsets[i])
->Get(NULL));
reinterpret_cast<const uint8*>(
type_info_->prototype) +
type_info_->offsets[i])
->Get());
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, NULL);
break;
@@ -506,8 +526,9 @@ DynamicMessage::~DynamicMessage() {
case FieldOptions::STRING: {
const ::std::string* default_value =
&(reinterpret_cast<const ArenaStringPtr*>(
type_info_->prototype->OffsetToPointer(
type_info_->offsets[i]))->Get(NULL));
type_info_->prototype->OffsetToPointer(
type_info_->offsets[i]))
->Get());
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, NULL);
break;
@@ -535,11 +556,6 @@ void DynamicMessage::CrossLinkPrototypes() {
for (int i = 0; i < descriptor->field_count(); i++) {
const FieldDescriptor* field = descriptor->field(i);
void* field_ptr = OffsetToPointer(type_info_->offsets[i]);
if (field->containing_oneof()) {
field_ptr = reinterpret_cast<uint8*>(
type_info_->default_oneof_instance) + type_info_->offsets[i];
}
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
!field->is_repeated()) {
// For fields with message types, we need to cross-link with the
@@ -610,7 +626,7 @@ DynamicMessageFactory::~DynamicMessageFactory() {
iter != prototypes_->map_.end(); ++iter) {
DeleteDefaultOneofInstance(iter->second->type,
iter->second->offsets.get(),
iter->second->default_oneof_instance);
iter->second->prototype);
delete iter->second;
}
}
@@ -649,7 +665,8 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
// or not that field is set.
// Compute size and offsets.
int* offsets = new int[type->field_count() + type->oneof_decl_count()];
uint32* offsets =
new uint32[type->field_count() + type->oneof_decl_count()];
type_info->offsets.reset(offsets);
// Decide all field offsets by packing in order.
@@ -667,6 +684,12 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
DivideRoundingUp(type->field_count(), bitsizeof(uint32));
size += has_bits_array_size * sizeof(uint32);
size = AlignOffset(size);
uint32* has_bits_indices = new uint32[type->field_count()];
for (int i = 0; i < type->field_count(); i++) {
has_bits_indices[i] = i;
}
type_info->has_bits_indices.reset(has_bits_indices);
}
// The oneof_case, if any. It is an array of uint32s.
@@ -687,6 +710,9 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
}
// All the fields.
//
// TODO(b/31226269): Optimize the order of fields to minimize padding.
int num_weak_fields = 0;
for (int i = 0; i < type->field_count(); i++) {
// Make sure field is aligned to avoid bus errors.
// Oneof fields do not use any space.
@@ -705,19 +731,38 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
size += kMaxOneofUnionSize;
}
// Add the UnknownFieldSet to the end.
// Add the InternalMetadataWithArena to the end.
size = AlignOffset(size);
type_info->unknown_fields_offset = size;
size += sizeof(UnknownFieldSet);
type_info->internal_metadata_offset = size;
size += sizeof(InternalMetadataWithArena);
type_info->weak_field_map_offset = -1;
// Align the final size to make sure no clever allocators think that
// alignment is not necessary.
size = AlignOffset(size);
type_info->size = size;
// Allocate the prototype.
// Construct the reflection object.
if (type->oneof_decl_count() > 0) {
// Compute the size of default oneof instance and offsets of default
// oneof fields.
for (int i = 0; i < type->oneof_decl_count(); i++) {
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = type->oneof_decl(i)->field(j);
int field_size = OneofFieldSpaceUsed(field);
size = AlignTo(size, std::min(kSafeAlignment, field_size));
offsets[field->index()] = size;
size += field_size;
}
}
}
size = AlignOffset(size);
// Allocate the prototype + oneof fields.
void* base = operator new(size);
memset(base, 0, size);
// The prototype in type_info has to be set before creating the prototype
// instance on memory. e.g., message Foo { map<int32, Foo> a = 1; }. When
// creating prototype for Foo, prototype of the map entry will also be
@@ -725,40 +770,32 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
// map). To break the cyclic dependency, we have to assgin the address of
// prototype into type_info first.
type_info->prototype = static_cast<DynamicMessage*>(base);
DynamicMessage* prototype = new(base) DynamicMessage(type_info);
// Construct the reflection object.
if (type->oneof_decl_count() > 0) {
// Compute the size of default oneof instance and offsets of default
// oneof fields.
int oneof_size = 0;
for (int i = 0; i < type->oneof_decl_count(); i++) {
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = type->oneof_decl(i)->field(j);
int field_size = OneofFieldSpaceUsed(field);
oneof_size = AlignTo(oneof_size, std::min(kSafeAlignment, field_size));
offsets[field->index()] = oneof_size;
oneof_size += field_size;
}
}
// We have already locked the factory so we should not lock in the constructor
// of dynamic message to avoid dead lock.
DynamicMessage* prototype = new (base) DynamicMessage(type_info, false);
if (type->oneof_decl_count() > 0 || num_weak_fields > 0) {
// Construct default oneof instance.
type_info->default_oneof_instance = ::operator new(oneof_size);
ConstructDefaultOneofInstance(type_info->type,
type_info->offsets.get(),
type_info->default_oneof_instance);
type_info->reflection.reset(new GeneratedMessageReflection(
type_info->type, type_info->prototype, type_info->offsets.get(),
type_info->has_bits_offset, type_info->unknown_fields_offset,
type_info->extensions_offset, type_info->default_oneof_instance,
type_info->oneof_case_offset, type_info->pool, this, type_info->size,
-1 /* arena_offset */));
} else {
type_info->reflection.reset(new GeneratedMessageReflection(
type_info->type, type_info->prototype, type_info->offsets.get(),
type_info->has_bits_offset, type_info->unknown_fields_offset,
type_info->extensions_offset, type_info->pool, this, type_info->size,
-1 /* arena_offset */));
prototype);
}
internal::ReflectionSchema schema = {
type_info->prototype,
type_info->offsets.get(),
type_info->has_bits_indices.get(),
type_info->has_bits_offset,
type_info->internal_metadata_offset,
type_info->extensions_offset,
type_info->oneof_case_offset,
type_info->size,
type_info->weak_field_map_offset};
type_info->reflection.reset(new GeneratedMessageReflection(
type_info->type, schema, type_info->pool, this));
// Cross link prototypes.
prototype->CrossLinkPrototypes();
@@ -767,13 +804,13 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
void DynamicMessageFactory::ConstructDefaultOneofInstance(
const Descriptor* type,
const int offsets[],
void* default_oneof_instance) {
const uint32 offsets[],
void* default_oneof_or_weak_instance) {
for (int i = 0; i < type->oneof_decl_count(); i++) {
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = type->oneof_decl(i)->field(j);
void* field_ptr = reinterpret_cast<uint8*>(
default_oneof_instance) + offsets[field->index()];
default_oneof_or_weak_instance) + offsets[field->index()];
switch (field->cpp_type()) {
#define HANDLE_TYPE(CPPTYPE, TYPE) \
case FieldDescriptor::CPPTYPE_##CPPTYPE: \
@@ -813,8 +850,8 @@ void DynamicMessageFactory::ConstructDefaultOneofInstance(
void DynamicMessageFactory::DeleteDefaultOneofInstance(
const Descriptor* type,
const int offsets[],
void* default_oneof_instance) {
const uint32 offsets[],
const void* default_oneof_instance) {
for (int i = 0; i < type->oneof_decl_count(); i++) {
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = type->oneof_decl(i)->field(j);
+87 -3
View File
@@ -38,12 +38,15 @@
#ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
#define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
#include <algorithm>
#include <memory>
#ifndef _SHARED_PTR_H
#include <google/protobuf/stubs/shared_ptr.h>
#endif
#include <vector>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/mutex.h>
@@ -136,16 +139,97 @@ class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
// Construct default oneof instance for reflection usage if oneof
// is defined.
static void ConstructDefaultOneofInstance(const Descriptor* type,
const int offsets[],
const uint32 offsets[],
void* default_oneof_instance);
// Delete default oneof instance. Called by ~DynamicMessageFactory.
static void DeleteDefaultOneofInstance(const Descriptor* type,
const int offsets[],
void* default_oneof_instance);
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 LIBPROTOBUF_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(static_cast<size_t>(map_size));
const RepeatedPtrField<Message>& map_field =
reflection->GetRepeatedPtrField<Message>(message, field);
size_t i = 0;
for (RepeatedPtrField<Message>::const_pointer_iterator it =
map_field.pointer_begin(); it != map_field.pointer_end(); ) {
result[i++] = *it++;
}
GOOGLE_DCHECK_EQ(result.size(), i);
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 LIBPROTOBUF_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: {
string first = reflection->GetString(*a, field_);
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
+155 -159
View File
@@ -1,7 +1,6 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/empty.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <google/protobuf/empty.pb.h>
#include <algorithm>
@@ -15,143 +14,135 @@
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// This is a temporary google only hack
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
#include "third_party/protobuf/version.h"
#endif
// @@protoc_insertion_point(includes)
namespace google {
namespace protobuf {
class EmptyDefaultTypeInternal {
public:
::google::protobuf::internal::ExplicitlyConstructed<Empty>
_instance;
} _Empty_default_instance_;
} // namespace protobuf
} // namespace google
namespace protobuf_google_2fprotobuf_2fempty_2eproto {
void InitDefaultsEmptyImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
::google::protobuf::internal::InitProtobufDefaultsForceUnique();
#else
::google::protobuf::internal::InitProtobufDefaults();
#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
{
void* ptr = &::google::protobuf::_Empty_default_instance_;
new (ptr) ::google::protobuf::Empty();
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
}
::google::protobuf::Empty::InitAsDefaultInstance();
}
void InitDefaultsEmpty() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &InitDefaultsEmptyImpl);
}
::google::protobuf::Metadata file_level_metadata[1];
const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
~0u, // no _has_bits_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::Empty, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
};
static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, sizeof(::google::protobuf::Empty)},
};
static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Empty_default_instance_),
};
void protobuf_AssignDescriptors() {
AddDescriptors();
::google::protobuf::MessageFactory* factory = NULL;
AssignDescriptors(
"google/protobuf/empty.proto", schemas, file_default_instances, TableStruct::offsets, factory,
file_level_metadata, NULL, NULL);
}
void protobuf_AssignDescriptorsOnce() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\033google/protobuf/empty.proto\022\017google.pr"
"otobuf\"\007\n\005EmptyBv\n\023com.google.protobufB\n"
"EmptyProtoP\001Z\'github.com/golang/protobuf"
"/ptypes/empty\370\001\001\242\002\003GPB\252\002\036Google.Protobuf"
".WellKnownTypesb\006proto3"
};
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
descriptor, 183);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/empty.proto", &protobuf_RegisterTypes);
}
void AddDescriptors() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
}
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
}
} static_descriptor_initializer;
} // namespace protobuf_google_2fprotobuf_2fempty_2eproto
namespace google {
namespace protobuf {
namespace {
const ::google::protobuf::Descriptor* Empty_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
Empty_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"google/protobuf/empty.proto");
GOOGLE_CHECK(file != NULL);
Empty_descriptor_ = file->message_type(0);
static const int Empty_offsets_[1] = {
};
Empty_reflection_ =
::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
Empty_descriptor_,
Empty::internal_default_instance(),
Empty_offsets_,
-1,
-1,
-1,
sizeof(Empty),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _internal_metadata_));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
Empty_descriptor_, Empty::internal_default_instance());
}
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto() {
Empty_default_instance_.Shutdown();
delete Empty_reflection_;
}
void protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
Empty_default_instance_.DefaultConstruct();
Empty_default_instance_.get_mutable()->InitAsDefaultInstance();
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_once_);
void protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_once_,
&protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl);
}
void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto();
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n\033google/protobuf/empty.proto\022\017google.pr"
"otobuf\"\007\n\005EmptyBv\n\023com.google.protobufB\n"
"EmptyProtoP\001Z\'github.com/golang/protobuf"
"/ptypes/empty\370\001\001\242\002\003GPB\252\002\036Google.Protobuf"
".WellKnownTypesb\006proto3", 183);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/empty.proto", &protobuf_RegisterTypes);
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_once_);
void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_once_,
&protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto {
StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
}
} static_descriptor_initializer_google_2fprotobuf_2fempty_2eproto_;
namespace {
static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN;
static void MergeFromFail(int line) {
::google::protobuf::internal::MergeFromFail(__FILE__, line);
}
} // namespace
// ===================================================================
void Empty::InitAsDefaultInstance() {
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Empty::Empty()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto();
if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
::protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaultsEmpty();
}
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Empty)
}
Empty::Empty(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto();
#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
::protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaultsEmpty();
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Empty)
}
void Empty::InitAsDefaultInstance() {
}
Empty::Empty(const Empty& from)
: ::google::protobuf::Message(),
_internal_metadata_(NULL) {
SharedCtor();
UnsafeMergeFrom(from);
_internal_metadata_(NULL),
_cached_size_(0) {
_internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Empty)
}
@@ -165,11 +156,7 @@ Empty::~Empty() {
}
void Empty::SharedDtor() {
::google::protobuf::Arena* arena = GetArenaNoVirtual();
if (arena != NULL) {
return;
}
GOOGLE_DCHECK(GetArenaNoVirtual() == NULL);
}
void Empty::ArenaDtor(void* object) {
@@ -184,23 +171,26 @@ void Empty::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Empty::descriptor() {
protobuf_AssignDescriptorsOnce();
return Empty_descriptor_;
::protobuf_google_2fprotobuf_2fempty_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
}
const Empty& Empty::default_instance() {
protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto();
::protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaultsEmpty();
return *internal_default_instance();
}
::google::protobuf::internal::ExplicitlyConstructed<Empty> Empty_default_instance_;
Empty* Empty::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<Empty>(arena);
}
void Empty::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Empty)
::google::protobuf::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
_internal_metadata_.Clear();
}
bool Empty::MergePartialFromCodedStream(
@@ -209,16 +199,15 @@ bool Empty::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Empty)
for (;;) {
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
handle_unusual:
if (tag == 0 ||
::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, _internal_metadata_.mutable_unknown_fields()));
}
success:
// @@protoc_insertion_point(parse_success:google.protobuf.Empty)
@@ -232,6 +221,13 @@ failure:
void Empty::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Empty)
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.Empty)
}
@@ -239,6 +235,13 @@ void Empty::SerializeWithCachedSizes(
bool deterministic, ::google::protobuf::uint8* target) const {
(void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Empty)
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Empty)
return target;
}
@@ -247,6 +250,11 @@ size_t Empty::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Empty)
size_t total_size = 0;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()));
}
int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
_cached_size_ = cached_size;
@@ -256,7 +264,7 @@ size_t Empty::ByteSizeLong() const {
void Empty::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Empty)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
GOOGLE_DCHECK_NE(&from, this);
const Empty* source =
::google::protobuf::internal::DynamicCastToGenerated<const Empty>(
&from);
@@ -265,21 +273,17 @@ void Empty::MergeFrom(const ::google::protobuf::Message& from) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
// @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Empty)
UnsafeMergeFrom(*source);
MergeFrom(*source);
}
}
void Empty::MergeFrom(const Empty& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Empty)
if (GOOGLE_PREDICT_TRUE(&from != this)) {
UnsafeMergeFrom(from);
} else {
MergeFromFail(__LINE__);
}
}
GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_);
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
void Empty::UnsafeMergeFrom(const Empty& from) {
GOOGLE_DCHECK(&from != this);
}
void Empty::CopyFrom(const ::google::protobuf::Message& from) {
@@ -293,11 +297,10 @@ void Empty::CopyFrom(const Empty& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Empty)
if (&from == this) return;
Clear();
UnsafeMergeFrom(from);
MergeFrom(from);
}
bool Empty::IsInitialized() const {
return true;
}
@@ -306,10 +309,13 @@ void Empty::Swap(Empty* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
Empty temp;
temp.UnsafeMergeFrom(*this);
CopyFrom(*other);
other->CopyFrom(temp);
Empty* temp = New(GetArenaNoVirtual());
temp->MergeFrom(*other);
other->CopyFrom(*this);
InternalSwap(temp);
if (GetArenaNoVirtual() == NULL) {
delete temp;
}
}
}
void Empty::UnsafeArenaSwap(Empty* other) {
@@ -318,28 +324,18 @@ void Empty::UnsafeArenaSwap(Empty* other) {
InternalSwap(other);
}
void Empty::InternalSwap(Empty* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Empty::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = Empty_descriptor_;
metadata.reflection = Empty_reflection_;
return metadata;
protobuf_google_2fprotobuf_2fempty_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[kIndexInFileMessages];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Empty
inline const Empty* Empty::internal_default_instance() {
return &Empty_default_instance_.get();
}
#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// @@protoc_insertion_point(namespace_scope)
} // namespace protobuf
} // namespace google
+80 -45
View File
@@ -8,37 +8,55 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.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)
namespace protobuf_google_2fprotobuf_2fempty_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[1];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsEmptyImpl();
void LIBPROTOBUF_EXPORT InitDefaultsEmpty();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsEmpty();
}
} // namespace protobuf_google_2fprotobuf_2fempty_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto();
class Empty;
class EmptyDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern EmptyDefaultTypeInternal _Empty_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
// ===================================================================
@@ -53,48 +71,69 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Empty(Empty&& from) noexcept
: Empty() {
*this = ::std::move(from);
}
inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
inline void* GetMaybeArenaPointer() const {
inline Empty& operator=(Empty&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
return GetArenaNoVirtual();
}
inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Empty& default_instance();
static const Empty* internal_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 PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
0;
void UnsafeArenaSwap(Empty* other);
void Swap(Empty* other);
friend void swap(Empty& a, Empty& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Empty* New() const { return New(NULL); }
inline Empty* New() const PROTOBUF_FINAL { return New(NULL); }
Empty* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Empty* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Empty& from);
void MergeFrom(const Empty& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Empty* other);
void UnsafeMergeFrom(const Empty& from);
protected:
explicit Empty(::google::protobuf::Arena* arena);
private:
@@ -109,7 +148,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -119,31 +158,27 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
friend class ::google::protobuf::Arena;
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fempty_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaultsEmptyImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Empty> Empty_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// Empty
inline const Empty* Empty::internal_default_instance() {
return &Empty_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// @@protoc_insertion_point(namespace_scope)
+3 -3
View File
@@ -76,7 +76,7 @@ inline bool is_packable(WireFormatLite::WireType type) {
}
// Registry stuff.
typedef hash_map<pair<const MessageLite*, int>,
typedef hash_map<std::pair<const MessageLite*, int>,
ExtensionInfo> ExtensionRegistry;
ExtensionRegistry* registry_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_);
@@ -221,7 +221,7 @@ int ExtensionSet::NumExtensions() const {
int ExtensionSet::ExtensionSize(int number) const {
ExtensionMap::const_iterator iter = extensions_.find(number);
if (iter == extensions_.end()) return false;
if (iter == extensions_.end()) return 0;
return iter->second.GetSize();
}
@@ -1371,7 +1371,7 @@ size_t ExtensionSet::ByteSize() const {
bool ExtensionSet::MaybeNewExtension(int number,
const FieldDescriptor* descriptor,
Extension** result) {
pair<ExtensionMap::iterator, bool> insert_result =
std::pair<ExtensionMap::iterator, bool> insert_result =
extensions_.insert(std::make_pair(number, Extension()));
*result = &insert_result.first->second;
(*result)->descriptor = descriptor;
+67 -6
View File
@@ -416,7 +416,8 @@ class LIBPROTOBUF_EXPORT ExtensionSet {
uint8* target) const;
// For backward-compatibility, versions of two of the above methods that
// are never forced to serialize deterministically.
// serialize deterministically iff SetDefaultSerializationDeterministic()
// has been called.
uint8* SerializeWithCachedSizesToArray(int start_field_number,
int end_field_number,
uint8* target) const;
@@ -435,6 +436,13 @@ class LIBPROTOBUF_EXPORT ExtensionSet {
// be linked in). It's up to the protocol compiler to avoid calling this on
// such ExtensionSets (easy enough since lite messages don't implement
// SpaceUsed()).
size_t SpaceUsedExcludingSelfLong() const;
// This method just calls SpaceUsedExcludingSelfLong() but it can not be
// inlined because the definition of SpaceUsedExcludingSelfLong() is not
// included in lite runtime and when an inline method refers to it MSVC
// will complain about unresolved symbols when building the lite runtime
// as .dll.
int SpaceUsedExcludingSelf() const;
private:
@@ -457,7 +465,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet {
virtual bool IsInitialized() const = 0;
virtual int ByteSize() const = 0;
virtual int SpaceUsed() const = 0;
virtual size_t SpaceUsedLong() const = 0;
virtual void MergeFrom(const LazyMessageExtension& other) = 0;
virtual void Clear() = 0;
@@ -556,7 +564,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet {
void Clear();
int GetSize() const;
void Free();
int SpaceUsedExcludingSelf() const;
size_t SpaceUsedExcludingSelfLong() const;
};
typedef std::map<int, Extension> ExtensionMap;
@@ -620,7 +628,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet {
// class.
// Defined in extension_set_heavy.cc.
static inline int RepeatedMessage_SpaceUsedExcludingSelf(
static inline size_t RepeatedMessage_SpaceUsedExcludingSelfLong(
RepeatedPtrFieldBase* field);
// The Extension struct is small enough to be passed by value, so we use it
@@ -689,6 +697,10 @@ inline void ExtensionSet::AddString(int number, FieldType type,
// ExtensionSet* set);
// static inline void Add(int number, ConstType value, ExtensionSet* set);
// static inline MutableType Add(int number, ExtensionSet* set);
// This is used by the ExtensionIdentifier constructor to register
// the extension at dynamic initialization.
// template <typename ExtendeeT>
// static void Register(int number, FieldType type, bool is_packed);
// };
//
// Not all of these methods make sense for all field types. For example, the
@@ -720,6 +732,11 @@ class PrimitiveTypeTraits {
ConstType default_value);
static inline void Set(int number, FieldType field_type,
ConstType value, ExtensionSet* set);
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
type, false, is_packed);
}
};
template <typename Type>
@@ -743,6 +760,11 @@ class RepeatedPrimitiveTypeTraits {
bool is_packed, ExtensionSet* set);
static const RepeatedFieldType* GetDefaultRepeatedField();
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
type, true, is_packed);
}
};
LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_primitive_generic_type_traits_once_init_;
@@ -840,6 +862,11 @@ class LIBPROTOBUF_EXPORT StringTypeTraits {
ExtensionSet* set) {
return set->MutableString(number, field_type, NULL);
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
type, false, is_packed);
}
};
LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_string_type_traits_once_init_;
@@ -892,6 +919,12 @@ class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits {
return default_repeated_field_;
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
type, true, is_packed);
}
private:
static void InitializeDefaultRepeatedFields();
static void DestroyDefaultRepeatedFields();
@@ -919,6 +952,11 @@ class EnumTypeTraits {
GOOGLE_DCHECK(IsValid(value));
set->SetEnum(number, field_type, value, NULL);
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number,
type, false, is_packed, IsValid);
}
};
template <typename Type, bool IsValid(int)>
@@ -972,6 +1010,11 @@ class RepeatedEnumTypeTraits {
return reinterpret_cast<const RepeatedField<Type>*>(
RepeatedPrimitiveTypeTraits<int32>::GetDefaultRepeatedField());
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number,
type, true, is_packed, IsValid);
}
};
// -------------------------------------------------------------------
@@ -1017,6 +1060,12 @@ class MessageTypeTraits {
return static_cast<Type*>(set->UnsafeArenaReleaseMessage(
number, Type::default_instance()));
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(),
number, type, false, is_packed,
&Type::default_instance());
}
};
// forward declaration
@@ -1062,6 +1111,12 @@ class RepeatedMessageTypeTraits {
}
static const RepeatedFieldType* GetDefaultRepeatedField();
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(),
number, type, true, is_packed,
&Type::default_instance());
}
};
LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_message_generic_type_traits_once_init_;
@@ -1100,7 +1155,7 @@ template<typename Type> inline
// parameter, and thus make an instance of ExtensionIdentifier have no
// actual contents. However, if we did that, then using at extension
// identifier would not necessarily cause the compiler to output any sort
// of reference to any simple defined in the extension's .pb.o file. Some
// of reference to any symbol defined in the extension's .pb.o file. Some
// linkers will actually drop object files that are not explicitly referenced,
// but that would be bad because it would cause this extension to not be
// registered at static initialization, and therefore using it would crash.
@@ -1113,12 +1168,18 @@ class ExtensionIdentifier {
typedef ExtendeeType Extendee;
ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value)
: number_(number), default_value_(default_value) {}
: number_(number), default_value_(default_value) {
Register(number);
}
inline int number() const { return number_; }
typename TypeTraits::ConstType default_value() const {
return default_value_;
}
static void Register(int number) {
TypeTraits::template Register<ExtendeeType>(number, field_type, is_packed);
}
private:
const int number_;
typename TypeTraits::ConstType default_value_;
+43 -30
View File
@@ -35,11 +35,14 @@
// Contains methods defined in extension_set.h which cannot be part of the
// lite library because they use descriptors or reflection.
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite_inl.h>
@@ -340,31 +343,35 @@ bool ExtensionSet::ParseMessageSet(io::CodedInputStream* input,
}
int ExtensionSet::SpaceUsedExcludingSelf() const {
int total_size =
return internal::FromIntSize(SpaceUsedExcludingSelfLong());
}
size_t ExtensionSet::SpaceUsedExcludingSelfLong() const {
size_t total_size =
extensions_.size() * sizeof(ExtensionMap::value_type);
for (ExtensionMap::const_iterator iter = extensions_.begin(),
end = extensions_.end();
iter != end;
++iter) {
total_size += iter->second.SpaceUsedExcludingSelf();
total_size += iter->second.SpaceUsedExcludingSelfLong();
}
return total_size;
}
inline int ExtensionSet::RepeatedMessage_SpaceUsedExcludingSelf(
inline size_t ExtensionSet::RepeatedMessage_SpaceUsedExcludingSelfLong(
RepeatedPtrFieldBase* field) {
return field->SpaceUsedExcludingSelf<GenericTypeHandler<Message> >();
return field->SpaceUsedExcludingSelfLong<GenericTypeHandler<Message> >();
}
int ExtensionSet::Extension::SpaceUsedExcludingSelf() const {
int total_size = 0;
size_t ExtensionSet::Extension::SpaceUsedExcludingSelfLong() const {
size_t total_size = 0;
if (is_repeated) {
switch (cpp_type(type)) {
#define HANDLE_TYPE(UPPERCASE, LOWERCASE) \
case FieldDescriptor::CPPTYPE_##UPPERCASE: \
total_size += sizeof(*repeated_##LOWERCASE##_value) + \
repeated_##LOWERCASE##_value->SpaceUsedExcludingSelf();\
break
#define HANDLE_TYPE(UPPERCASE, LOWERCASE) \
case FieldDescriptor::CPPTYPE_##UPPERCASE: \
total_size += sizeof(*repeated_##LOWERCASE##_value) + \
repeated_##LOWERCASE##_value->SpaceUsedExcludingSelfLong(); \
break
HANDLE_TYPE( INT32, int32);
HANDLE_TYPE( INT64, int64);
@@ -379,24 +386,25 @@ int ExtensionSet::Extension::SpaceUsedExcludingSelf() const {
case FieldDescriptor::CPPTYPE_MESSAGE:
// repeated_message_value is actually a RepeatedPtrField<MessageLite>,
// but MessageLite has no SpaceUsed(), so we must directly call
// RepeatedPtrFieldBase::SpaceUsedExcludingSelf() with a different type
// handler.
total_size += sizeof(*repeated_message_value) +
RepeatedMessage_SpaceUsedExcludingSelf(repeated_message_value);
// but MessageLite has no SpaceUsedLong(), so we must directly call
// RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() with a different
// type handler.
total_size +=
sizeof(*repeated_message_value) +
RepeatedMessage_SpaceUsedExcludingSelfLong(repeated_message_value);
break;
}
} else {
switch (cpp_type(type)) {
case FieldDescriptor::CPPTYPE_STRING:
total_size += sizeof(*string_value) +
StringSpaceUsedExcludingSelf(*string_value);
StringSpaceUsedExcludingSelfLong(*string_value);
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
if (is_lazy) {
total_size += lazymessage_value->SpaceUsed();
total_size += lazymessage_value->SpaceUsedLong();
} else {
total_size += down_cast<Message*>(message_value)->SpaceUsed();
total_size += down_cast<Message*>(message_value)->SpaceUsedLong();
}
break;
default:
@@ -413,12 +421,16 @@ uint8* ExtensionSet::SerializeWithCachedSizesToArray(int start_field_number,
int end_field_number,
uint8* target) const {
return InternalSerializeWithCachedSizesToArray(
start_field_number, end_field_number, false, target);
start_field_number, end_field_number,
google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(),
target);
}
uint8* ExtensionSet::SerializeMessageSetWithCachedSizesToArray(
uint8* target) const {
return InternalSerializeMessageSetWithCachedSizesToArray(false, target);
return InternalSerializeMessageSetWithCachedSizesToArray(
google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(),
target);
}
uint8* ExtensionSet::InternalSerializeWithCachedSizesToArray(
@@ -479,10 +491,10 @@ uint8* ExtensionSet::Extension::InternalSerializeFieldWithCachedSizesToArray(
HANDLE_TYPE( ENUM, Enum, enum);
#undef HANDLE_TYPE
case WireFormatLite::TYPE_STRING:
case WireFormatLite::TYPE_BYTES:
case WireFormatLite::TYPE_GROUP:
case WireFormatLite::TYPE_MESSAGE:
case FieldDescriptor::TYPE_STRING:
case FieldDescriptor::TYPE_BYTES:
case FieldDescriptor::TYPE_GROUP:
case FieldDescriptor::TYPE_MESSAGE:
GOOGLE_LOG(FATAL) << "Non-primitive types can't be packed.";
break;
}
@@ -587,11 +599,12 @@ ExtensionSet::Extension::InternalSerializeMessageSetItemWithCachedSizesToArray(
WireFormatLite::kMessageSetTypeIdNumber, number, target);
// Write message.
if (is_lazy) {
target = lazymessage_value->WriteMessageToArray(
WireFormatLite::kMessageSetMessageNumber, target);
target = lazymessage_value->InternalWriteMessageToArray(
WireFormatLite::kMessageSetMessageNumber, deterministic, target);
} else {
target = WireFormatLite::WriteMessageToArray(
WireFormatLite::kMessageSetMessageNumber, *message_value, target);
target = WireFormatLite::InternalWriteMessageToArray(
WireFormatLite::kMessageSetMessageNumber, *message_value, deterministic,
target);
}
// End group.
target = io::CodedOutputStream::WriteTagToArray(
@@ -656,7 +669,7 @@ bool ExtensionSet::ParseMessageSetItem(io::CodedInputStream* input,
string message_data;
while (true) {
const uint32 tag = input->ReadTag();
const uint32 tag = input->ReadTagNoLastTag();
if (tag == 0) return false;
switch (tag) {
+159 -216
View File
@@ -1,7 +1,6 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/field_mask.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <google/protobuf/field_mask.pb.h>
#include <algorithm>
@@ -15,136 +14,131 @@
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// This is a temporary google only hack
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
#include "third_party/protobuf/version.h"
#endif
// @@protoc_insertion_point(includes)
namespace google {
namespace protobuf {
class FieldMaskDefaultTypeInternal {
public:
::google::protobuf::internal::ExplicitlyConstructed<FieldMask>
_instance;
} _FieldMask_default_instance_;
} // namespace protobuf
} // namespace google
namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto {
void InitDefaultsFieldMaskImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
::google::protobuf::internal::InitProtobufDefaultsForceUnique();
#else
::google::protobuf::internal::InitProtobufDefaults();
#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
{
void* ptr = &::google::protobuf::_FieldMask_default_instance_;
new (ptr) ::google::protobuf::FieldMask();
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
}
::google::protobuf::FieldMask::InitAsDefaultInstance();
}
void InitDefaultsFieldMask() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &InitDefaultsFieldMaskImpl);
}
::google::protobuf::Metadata file_level_metadata[1];
const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
~0u, // no _has_bits_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::FieldMask, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::FieldMask, paths_),
};
static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, sizeof(::google::protobuf::FieldMask)},
};
static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_FieldMask_default_instance_),
};
void protobuf_AssignDescriptors() {
AddDescriptors();
::google::protobuf::MessageFactory* factory = NULL;
AssignDescriptors(
"google/protobuf/field_mask.proto", schemas, file_default_instances, TableStruct::offsets, factory,
file_level_metadata, NULL, NULL);
}
void protobuf_AssignDescriptorsOnce() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n google/protobuf/field_mask.proto\022\017goog"
"le.protobuf\"\032\n\tFieldMask\022\r\n\005paths\030\001 \003(\tB"
"\211\001\n\023com.google.protobufB\016FieldMaskProtoP"
"\001Z9google.golang.org/genproto/protobuf/f"
"ield_mask;field_mask\242\002\003GPB\252\002\036Google.Prot"
"obuf.WellKnownTypesb\006proto3"
};
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
descriptor, 227);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/field_mask.proto", &protobuf_RegisterTypes);
}
void AddDescriptors() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
}
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
}
} static_descriptor_initializer;
} // namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto
namespace google {
namespace protobuf {
namespace {
const ::google::protobuf::Descriptor* FieldMask_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
FieldMask_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"google/protobuf/field_mask.proto");
GOOGLE_CHECK(file != NULL);
FieldMask_descriptor_ = file->message_type(0);
static const int FieldMask_offsets_[1] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, paths_),
};
FieldMask_reflection_ =
::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
FieldMask_descriptor_,
FieldMask::internal_default_instance(),
FieldMask_offsets_,
-1,
-1,
-1,
sizeof(FieldMask),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _internal_metadata_));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
FieldMask_descriptor_, FieldMask::internal_default_instance());
}
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto() {
FieldMask_default_instance_.Shutdown();
delete FieldMask_reflection_;
}
void protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::internal::GetEmptyString();
FieldMask_default_instance_.DefaultConstruct();
FieldMask_default_instance_.get_mutable()->InitAsDefaultInstance();
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_once_);
void protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_once_,
&protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl);
}
void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto();
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n google/protobuf/field_mask.proto\022\017goog"
"le.protobuf\"\032\n\tFieldMask\022\r\n\005paths\030\001 \003(\tB"
"N\n\023com.google.protobufB\016FieldMaskProtoP\001"
"\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypesb"
"\006proto3", 167);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/field_mask.proto", &protobuf_RegisterTypes);
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_once_);
void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_once_,
&protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto {
StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
}
} static_descriptor_initializer_google_2fprotobuf_2ffield_5fmask_2eproto_;
namespace {
static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN;
static void MergeFromFail(int line) {
::google::protobuf::internal::MergeFromFail(__FILE__, line);
}
} // namespace
// ===================================================================
void FieldMask::InitAsDefaultInstance() {
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int FieldMask::kPathsFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
FieldMask::FieldMask()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto();
if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::InitDefaultsFieldMask();
}
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.FieldMask)
}
void FieldMask::InitAsDefaultInstance() {
}
FieldMask::FieldMask(const FieldMask& from)
: ::google::protobuf::Message(),
_internal_metadata_(NULL) {
SharedCtor();
UnsafeMergeFrom(from);
_internal_metadata_(NULL),
paths_(from.paths_),
_cached_size_(0) {
_internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.FieldMask)
}
@@ -166,17 +160,15 @@ void FieldMask::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FieldMask::descriptor() {
protobuf_AssignDescriptorsOnce();
return FieldMask_descriptor_;
::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
}
const FieldMask& FieldMask::default_instance() {
protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto();
::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::InitDefaultsFieldMask();
return *internal_default_instance();
}
::google::protobuf::internal::ExplicitlyConstructed<FieldMask> FieldMask_default_instance_;
FieldMask* FieldMask::New(::google::protobuf::Arena* arena) const {
FieldMask* n = new FieldMask;
if (arena != NULL) {
@@ -187,7 +179,12 @@ FieldMask* FieldMask::New(::google::protobuf::Arena* arena) const {
void FieldMask::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.FieldMask)
::google::protobuf::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
paths_.Clear();
_internal_metadata_.Clear();
}
bool FieldMask::MergePartialFromCodedStream(
@@ -196,37 +193,34 @@ bool FieldMask::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FieldMask)
for (;;) {
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated string paths = 1;
case 1: {
if (tag == 10) {
parse_paths:
if (static_cast< ::google::protobuf::uint8>(tag) ==
static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_paths()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(this->paths_size() - 1).data(),
this->paths(this->paths_size() - 1).length(),
static_cast<int>(this->paths(this->paths_size() - 1).length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.FieldMask.paths"));
} else {
goto handle_unusual;
}
if (input->ExpectTag(10)) goto parse_paths;
if (input->ExpectAtEnd()) goto success;
break;
}
default: {
handle_unusual:
if (tag == 0 ||
::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -243,16 +237,23 @@ failure:
void FieldMask::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.FieldMask)
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// repeated string paths = 1;
for (int i = 0; i < this->paths_size(); i++) {
for (int i = 0, n = this->paths_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(i).data(), this->paths(i).length(),
this->paths(i).data(), static_cast<int>(this->paths(i).length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.FieldMask.paths");
::google::protobuf::internal::WireFormatLite::WriteString(
1, this->paths(i), output);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.FieldMask)
}
@@ -260,16 +261,23 @@ void FieldMask::SerializeWithCachedSizes(
bool deterministic, ::google::protobuf::uint8* target) const {
(void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask)
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// repeated string paths = 1;
for (int i = 0; i < this->paths_size(); i++) {
for (int i = 0, n = this->paths_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(i).data(), this->paths(i).length(),
this->paths(i).data(), static_cast<int>(this->paths(i).length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.FieldMask.paths");
target = ::google::protobuf::internal::WireFormatLite::
WriteStringToArray(1, this->paths(i), target);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FieldMask)
return target;
}
@@ -278,10 +286,15 @@ size_t FieldMask::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldMask)
size_t total_size = 0;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()));
}
// repeated string paths = 1;
total_size += 1 *
::google::protobuf::internal::FromIntSize(this->paths_size());
for (int i = 0; i < this->paths_size(); i++) {
for (int i = 0, n = this->paths_size(); i < n; i++) {
total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
this->paths(i));
}
@@ -295,7 +308,7 @@ size_t FieldMask::ByteSizeLong() const {
void FieldMask::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldMask)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
GOOGLE_DCHECK_NE(&from, this);
const FieldMask* source =
::google::protobuf::internal::DynamicCastToGenerated<const FieldMask>(
&from);
@@ -304,22 +317,18 @@ void FieldMask::MergeFrom(const ::google::protobuf::Message& from) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
// @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FieldMask)
UnsafeMergeFrom(*source);
MergeFrom(*source);
}
}
void FieldMask::MergeFrom(const FieldMask& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask)
if (GOOGLE_PREDICT_TRUE(&from != this)) {
UnsafeMergeFrom(from);
} else {
MergeFromFail(__LINE__);
}
}
GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_);
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
void FieldMask::UnsafeMergeFrom(const FieldMask& from) {
GOOGLE_DCHECK(&from != this);
paths_.UnsafeMergeFrom(from.paths_);
paths_.MergeFrom(from.paths_);
}
void FieldMask::CopyFrom(const ::google::protobuf::Message& from) {
@@ -333,11 +342,10 @@ void FieldMask::CopyFrom(const FieldMask& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FieldMask)
if (&from == this) return;
Clear();
UnsafeMergeFrom(from);
MergeFrom(from);
}
bool FieldMask::IsInitialized() const {
return true;
}
@@ -346,84 +354,19 @@ void FieldMask::Swap(FieldMask* other) {
InternalSwap(other);
}
void FieldMask::InternalSwap(FieldMask* other) {
paths_.UnsafeArenaSwap(&other->paths_);
using std::swap;
paths_.InternalSwap(&other->paths_);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata FieldMask::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = FieldMask_descriptor_;
metadata.reflection = FieldMask_reflection_;
return metadata;
protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[kIndexInFileMessages];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// FieldMask
// repeated string paths = 1;
int FieldMask::paths_size() const {
return paths_.size();
}
void FieldMask::clear_paths() {
paths_.Clear();
}
const ::std::string& FieldMask::paths(int index) const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldMask.paths)
return paths_.Get(index);
}
::std::string* FieldMask::mutable_paths(int index) {
// @@protoc_insertion_point(field_mutable:google.protobuf.FieldMask.paths)
return paths_.Mutable(index);
}
void FieldMask::set_paths(int index, const ::std::string& value) {
// @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
paths_.Mutable(index)->assign(value);
}
void FieldMask::set_paths(int index, const char* value) {
paths_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths)
}
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)
}
::std::string* FieldMask::add_paths() {
// @@protoc_insertion_point(field_add_mutable:google.protobuf.FieldMask.paths)
return paths_.Add();
}
void FieldMask::add_paths(const ::std::string& value) {
paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
}
void FieldMask::add_paths(const char* value) {
paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths)
}
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)
}
const ::google::protobuf::RepeatedPtrField< ::std::string>&
FieldMask::paths() const {
// @@protoc_insertion_point(field_list:google.protobuf.FieldMask.paths)
return paths_;
}
::google::protobuf::RepeatedPtrField< ::std::string>*
FieldMask::mutable_paths() {
// @@protoc_insertion_point(field_mutable_list:google.protobuf.FieldMask.paths)
return &paths_;
}
inline const FieldMask* FieldMask::internal_default_instance() {
return &FieldMask_default_instance_.get();
}
#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// @@protoc_insertion_point(namespace_scope)
} // namespace protobuf
} // namespace google
+97 -44
View File
@@ -8,37 +8,55 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.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)
namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[1];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsFieldMaskImpl();
void LIBPROTOBUF_EXPORT InitDefaultsFieldMask();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsFieldMask();
}
} // namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto();
class FieldMask;
class FieldMaskDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern FieldMaskDefaultTypeInternal _FieldMask_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
// ===================================================================
@@ -53,53 +71,72 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro
CopyFrom(from);
return *this;
}
#if LANG_CXX11
FieldMask(FieldMask&& from) noexcept
: FieldMask() {
*this = ::std::move(from);
}
inline FieldMask& operator=(FieldMask&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
static const ::google::protobuf::Descriptor* descriptor();
static const FieldMask& default_instance();
static const FieldMask* internal_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 PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
0;
void Swap(FieldMask* other);
friend void swap(FieldMask& a, FieldMask& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline FieldMask* New() const { return New(NULL); }
inline FieldMask* New() const PROTOBUF_FINAL { return New(NULL); }
FieldMask* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
FieldMask* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FieldMask& from);
void MergeFrom(const FieldMask& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FieldMask* other);
void UnsafeMergeFrom(const FieldMask& from);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
return NULL;
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
return NULL;
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -112,10 +149,16 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro
const ::std::string& paths(int index) const;
::std::string* mutable_paths(int index);
void set_paths(int index, const ::std::string& value);
#if LANG_CXX11
void set_paths(int index, ::std::string&& value);
#endif
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);
#if LANG_CXX11
void add_paths(::std::string&& value);
#endif
void add_paths(const char* value);
void add_paths(const char* value, size_t size);
const ::google::protobuf::RepeatedPtrField< ::std::string>& paths() const;
@@ -127,21 +170,18 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
::google::protobuf::RepeatedPtrField< ::std::string> paths_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::InitDefaultsFieldMaskImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<FieldMask> FieldMask_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// FieldMask
// repeated string paths = 1;
@@ -163,7 +203,14 @@ 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);
}
#if LANG_CXX11
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));
}
#endif
inline void FieldMask::set_paths(int index, const char* value) {
GOOGLE_DCHECK(value != NULL);
paths_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths)
}
@@ -180,7 +227,14 @@ inline void FieldMask::add_paths(const ::std::string& value) {
paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
}
#if LANG_CXX11
inline void FieldMask::add_paths(::std::string&& value) {
paths_.Add(std::move(value));
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
}
#endif
inline void FieldMask::add_paths(const char* value) {
GOOGLE_DCHECK(value != NULL);
paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths)
}
@@ -199,10 +253,9 @@ FieldMask::mutable_paths() {
return &paths_;
}
inline const FieldMask* FieldMask::internal_default_instance() {
return &FieldMask_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// @@protoc_insertion_point(namespace_scope)
File diff suppressed because it is too large Load Diff
@@ -61,7 +61,15 @@ namespace protobuf {
class DescriptorPool;
class MapKey;
class MapValueRef;
}
} // namespace protobuf
namespace protobuf {
namespace flat {
class MetadataBuilder;
} // namespace flat
} // namespace protobuf
namespace protobuf {
namespace internal {
@@ -72,6 +80,158 @@ class GeneratedMessageReflection;
// 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
// GOOGLE_PROTOBUF_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
// GOOGLE_PROTOBUF_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_); }
// 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(!field->containing_oneof());
return offsets_[field->index()];
}
// Offset of any field.
uint32 GetFieldOffset(const FieldDescriptor* field) const {
if (field->containing_oneof()) {
size_t offset =
static_cast<size_t>(field->containing_type()->field_count() +
field->containing_oneof()->index());
return offsets_[offset];
} else {
return GetFieldOffsetNonOneof(field);
}
}
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 {
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_) +
offsets_[field->index()];
}
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_;
};
// 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;
};
// THIS CLASS IS NOT INTENDED FOR DIRECT USE. It is intended for use
// by generated code. This class is just a big hack that reduces code
@@ -97,115 +257,29 @@ class ExtensionSet; // extension_set.h
// of whatever type the individual field would be. Strings and
// Messages use RepeatedPtrFields while everything else uses
// RepeatedFields.
class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL : public Reflection {
public:
// Constructs a GeneratedMessageReflection.
// Parameters:
// descriptor: The descriptor for the message type being implemented.
// 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, relative to
// the start of the message object, of each field. These can
// be computed at compile time using the
// GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined
// below.
// 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.
// schema: The description of the internal guts of the message.
// pool: DescriptorPool to search for extension definitions. Only
// used by FindKnownExtensionByName() and
// FindKnownExtensionByNumber().
// factory: MessageFactory to use to construct extension messages.
// object_size: The size of a message object of this type, as measured
// by sizeof().
GeneratedMessageReflection(const Descriptor* descriptor,
const Message* default_instance,
const int offsets[], int has_bits_offset,
int unknown_fields_offset, int extensions_offset,
const ReflectionSchema& schema,
const DescriptorPool* pool,
MessageFactory* factory, int object_size,
int arena_offset);
MessageFactory* factory);
// Similar with the construction above. Call this construction if the
// message has oneof definition.
// Parameters:
// offsets: An array of ints giving the byte offsets.
// For each oneof field, the offset is relative to the
// default_oneof_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
// GOOGLE_PROTOBUF_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].
// default_oneof_instance: The default instance of the oneofs. It is a
// struct holding the default value of all oneof fields
// for this message. It is only used to obtain pointers
// to default instances of oneof fields, which Get
// methods will return if the field is not set.
// 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.
// other parameters are the same with the construction above.
GeneratedMessageReflection(const Descriptor* descriptor,
const Message* default_instance,
const int offsets[], int has_bits_offset,
int unknown_fields_offset, int extensions_offset,
const void* default_oneof_instance,
int oneof_case_offset, const DescriptorPool* pool,
MessageFactory* factory, int object_size,
int arena_offset);
~GeneratedMessageReflection();
// Shorter-to-call helpers for the above two constructions that work if the
// pool and factory are the usual, namely, DescriptorPool::generated_pool()
// and MessageFactory::generated_factory().
static GeneratedMessageReflection* NewGeneratedMessageReflection(
const Descriptor* descriptor,
const Message* default_instance,
const int offsets[],
int has_bits_offset,
int unknown_fields_offset,
int extensions_offset,
const void* default_oneof_instance,
int oneof_case_offset,
int object_size,
int arena_offset,
int is_default_instance_offset = -1);
static GeneratedMessageReflection* NewGeneratedMessageReflection(
const Descriptor* descriptor,
const Message* default_instance,
const int offsets[],
int has_bits_offset,
int unknown_fields_offset,
int extensions_offset,
int object_size,
int arena_offset,
int is_default_instance_offset = -1);
// implements Reflection -------------------------------------------
const UnknownFieldSet& GetUnknownFields(const Message& message) const;
UnknownFieldSet* MutableUnknownFields(Message* message) const;
int SpaceUsed(const Message& message) const;
size_t SpaceUsedLong(const Message& message) const;
bool HasField(const Message& message, const FieldDescriptor* field) const;
int FieldSize(const Message& message, const FieldDescriptor* field) const;
@@ -423,37 +497,33 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
const Descriptor* message_type) const;
private:
friend class GeneratedMessage;
// To parse directly into a proto2 generated class, the class GMR_Handlers
// needs access to member offsets and hasbits.
friend class google::protobuf::flat::MetadataBuilder;
friend class upb::google_opensource::GMR_Handlers;
const Descriptor* descriptor_;
const Message* default_instance_;
const void* default_oneof_instance_;
const int* offsets_;
const Descriptor* const descriptor_;
const ReflectionSchema schema_;
const DescriptorPool* const descriptor_pool_;
MessageFactory* const message_factory_;
int has_bits_offset_;
int oneof_case_offset_;
int unknown_fields_offset_;
int extensions_offset_;
int arena_offset_;
int object_size_;
// Last non weak field index. This is an optimization when most weak fields
// are at the end of the containing message. If a message proto doesn't
// contain weak fields, then this field equals descriptor_->field_count().
int last_non_weak_field_index_;
const DescriptorPool* descriptor_pool_;
MessageFactory* message_factory_;
template <class T>
const T& GetRawNonOneof(const Message& message,
const FieldDescriptor* field) const;
template <class T>
T* MutableRawNonOneof(Message* message, const FieldDescriptor* field) const;
template <typename Type>
inline const Type& GetRaw(const Message& message,
const Type& GetRaw(const Message& message,
const FieldDescriptor* field) const;
template <typename Type>
inline Type* MutableRaw(Message* message,
const FieldDescriptor* field) const;
template <typename Type>
inline const Type& DefaultRaw(const FieldDescriptor* field) const;
template <typename Type>
inline const Type& DefaultOneofRaw(const FieldDescriptor* field) const;
inline const uint32* GetHasBits(const Message& message) const;
inline uint32* MutableHasBits(Message* message) const;
@@ -466,12 +536,12 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
inline const ExtensionSet& GetExtensionSet(const Message& message) const;
inline ExtensionSet* MutableExtensionSet(Message* message) const;
inline Arena* GetArena(Message* message) const;
inline const internal::InternalMetadataWithArena&
GetInternalMetadataWithArena(const Message& message) const;
inline internal::InternalMetadataWithArena*
MutableInternalMetadataWithArena(Message* message) const;
inline bool GetIsDefaultInstance(const Message& message) const;
inline const InternalMetadataWithArena& GetInternalMetadataWithArena(
const Message& message) const;
inline InternalMetadataWithArena*
MutableInternalMetadataWithArena(Message* message) const;
inline bool HasBit(const Message& message,
const FieldDescriptor* field) const;
@@ -559,43 +629,12 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
internal::MapFieldBase* MapData(
Message* message, const FieldDescriptor* field) const;
friend inline // inline so nobody can call this function.
void
RegisterAllTypesInternal(const Metadata* file_level_metadata, int size);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection);
};
// 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 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
__builtin_offsetof(TYPE, FIELD) \
_Pragma("clang diagnostic pop")
#else
// 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 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \
static_cast<int>( \
reinterpret_cast<const char*>( \
&reinterpret_cast<const TYPE*>(16)->FIELD) - \
reinterpret_cast<const char*>(16))
#endif
#define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \
static_cast<int>( \
reinterpret_cast<const char*>(&(ONEOF->FIELD)) \
- reinterpret_cast<const char*>(ONEOF))
// There are some places in proto2 where dynamic_cast would be useful as an
// optimization. For example, take Message::MergeFrom(const Message& other).
// For a given generated message FooMessage, we generate these two methods:
@@ -622,6 +661,8 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
template<typename To, typename From>
inline To dynamic_cast_if_available(From from) {
#if defined(GOOGLE_PROTOBUF_NO_RTTI) || (defined(_MSC_VER)&&!defined(_CPPRTTI))
// Avoid the compiler warning about unused variables.
(void)from;
return NULL;
#else
return dynamic_cast<To>(from);
@@ -664,6 +705,22 @@ T* DynamicCastToGenerated(Message* from) {
return const_cast<T*>(DynamicCastToGenerated<const T>(message_const));
}
LIBPROTOBUF_EXPORT void AssignDescriptors(
const string& filename, const MigrationSchema* schemas,
const Message* const* default_instances_, const uint32* offsets,
MessageFactory* factory,
// update the following descriptor arrays.
Metadata* file_level_metadata,
const EnumDescriptor** file_level_enum_descriptors,
const ServiceDescriptor** file_level_service_descriptors);
LIBPROTOBUF_EXPORT void RegisterAllTypes(const Metadata* file_level_metadata, int size);
// These cannot be in lite so we put them in the reflection.
LIBPROTOBUF_EXPORT void UnknownFieldSetSerializer(const uint8* base, uint32 offset, uint32 tag,
uint32 has_offset,
::google::protobuf::io::CodedOutputStream* output);
} // namespace internal
} // namespace protobuf
@@ -0,0 +1,103 @@
// 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.
#include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/stubs/type_traits.h>
#include <google/protobuf/generated_message_table_driven_lite.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
namespace protobuf {
namespace internal {
namespace {
UnknownFieldSet* MutableUnknownFields(MessageLite* msg, int64 arena_offset) {
return Raw<InternalMetadataWithArena>(msg, arena_offset)
->mutable_unknown_fields();
}
struct UnknownFieldHandler {
static bool Skip(MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input,
int tag) {
GOOGLE_DCHECK(table.unknown_field_set);
return WireFormat::SkipField(input, tag,
MutableUnknownFields(msg, table.arena_offset));
}
static void Varint(MessageLite* msg, const ParseTable& table,
int tag, int value) {
GOOGLE_DCHECK(table.unknown_field_set);
MutableUnknownFields(msg, table.arena_offset)->AddVarint(
WireFormatLite::GetTagFieldNumber(tag), value);
}
static bool ParseExtension(
MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input, int tag) {
ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
if (extensions == NULL) {
return false;
}
const Message* prototype = down_cast<const Message*>(
table.default_instance());
GOOGLE_DCHECK(prototype != NULL);
GOOGLE_DCHECK(table.unknown_field_set);
UnknownFieldSet* unknown_fields =
MutableUnknownFields(msg, table.arena_offset);
return extensions->ParseField(tag, input, prototype, unknown_fields);
}
};
} // namespace
bool MergePartialFromCodedStream(
MessageLite* msg, const ParseTable& table, io::CodedInputStream* input) {
return MergePartialFromCodedStreamImpl<UnknownFieldHandler,
InternalMetadataWithArena>(msg, table,
input);
}
} // namespace internal
} // namespace protobuf
} // namespace google
@@ -0,0 +1,219 @@
// 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>
#include <google/protobuf/wire_format_lite_inl.h>
#if LANG_CXX11
#define PROTOBUF_CONSTEXPR constexpr
// 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
#else
#define PROTOBUF_CONSTEXPR
#define PROTOBUF_CONSTEXPR_VAR
#endif
namespace google {
namespace protobuf {
namespace internal {
// Processing-type masks.
static PROTOBUF_CONSTEXPR const unsigned char kOneofMask = 0x40;
static PROTOBUF_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 PROTOBUF_CONSTEXPR const unsigned char kTypeMask = 0x1f;
// Wire type masks.
static PROTOBUF_CONSTEXPR const unsigned char kNotPackedMask = 0x10;
static PROTOBUF_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_MAP = 23,
};
#if LANG_CXX11
static_assert(TYPE_MAP < kRepeatedMask, "Invalid enum");
#endif
// 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);
}
const ParseTable* parse_table;
};
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;
#if LANG_CXX11
AuxillaryParseTableField() = default;
#else
AuxillaryParseTableField() { }
#endif
PROTOBUF_CONSTEXPR AuxillaryParseTableField(
AuxillaryParseTableField::enum_aux e) : enums(e) {}
PROTOBUF_CONSTEXPR AuxillaryParseTableField(
AuxillaryParseTableField::message_aux m) : messages(m) {}
PROTOBUF_CONSTEXPR AuxillaryParseTableField(
AuxillaryParseTableField::string_aux s) : strings(s) {}
PROTOBUF_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;
};
// TODO(jhen): Remove the __NVCC__ check when we get a version of nvcc that
// supports these checks.
#if LANG_CXX11 && !defined(__NVCC__)
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, "");
#endif
// 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 google::protobuf::Map<typename Entry::EntryKeyType,
typename Entry::EntryValueType>
MapType;
typedef typename Entry::template Parser<MapFieldType, MapType> ParserType;
ParserType parser(static_cast<MapFieldType*>(map_field));
return ::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(input,
&parser);
}
} // namespace internal
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__
@@ -0,0 +1,109 @@
// 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.
#include <google/protobuf/generated_message_table_driven_lite.h>
#include <google/protobuf/stubs/type_traits.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
namespace protobuf {
namespace internal {
namespace {
string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) {
return Raw<InternalMetadataWithArenaLite>(msg, arena_offset)
->mutable_unknown_fields();
}
struct UnknownFieldHandlerLite {
static bool Skip(MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input,
int tag) {
GOOGLE_DCHECK(!table.unknown_field_set);
::google::protobuf::io::StringOutputStream unknown_fields_string(
MutableUnknownFields(msg, table.arena_offset));
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
&unknown_fields_string, false);
return ::google::protobuf::internal::WireFormatLite::SkipField(
input, tag, &unknown_fields_stream);
}
static void Varint(MessageLite* msg, const ParseTable& table,
int tag, int value) {
GOOGLE_DCHECK(!table.unknown_field_set);
::google::protobuf::io::StringOutputStream unknown_fields_string(
MutableUnknownFields(msg, table.arena_offset));
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
&unknown_fields_string, false);
unknown_fields_stream.WriteVarint32(tag);
unknown_fields_stream.WriteVarint32(value);
}
static bool ParseExtension(
MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input, int tag) {
ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
if (extensions == NULL) {
return false;
}
const MessageLite* prototype = table.default_instance();
GOOGLE_DCHECK(!table.unknown_field_set);
::google::protobuf::io::StringOutputStream unknown_fields_string(
MutableUnknownFields(msg, table.arena_offset));
::google::protobuf::io::CodedOutputStream unknown_fields_stream(
&unknown_fields_string, false);
return extensions->ParseField(
tag, input, prototype, &unknown_fields_stream);
}
};
} // namespace
bool MergePartialFromCodedStreamLite(
MessageLite* msg, const ParseTable& table, io::CodedInputStream* input) {
return MergePartialFromCodedStreamImpl<UnknownFieldHandlerLite,
InternalMetadataWithArenaLite>(
msg, table, input);
}
} // namespace internal
} // namespace protobuf
} // namespace google
@@ -0,0 +1,823 @@
// 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_LITE_H__
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__
#include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/stubs/type_traits.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
namespace protobuf {
namespace internal {
enum StringType {
StringType_STRING = 0,
StringType_CORD = 1,
StringType_STRING_PIECE = 2
};
// Logically a superset of StringType, consisting of all field types that
// require special initialization.
enum ProcessingType {
ProcessingType_STRING = 0,
ProcessingType_CORD = 1,
ProcessingType_STRING_PIECE = 2,
ProcessingType_MESSAGE = 3
};
enum Cardinality {
Cardinality_SINGULAR = 0,
Cardinality_REPEATED = 1,
Cardinality_ONEOF = 3
};
template <typename Type>
inline Type* Raw(MessageLite* msg, int64 offset) {
return reinterpret_cast<Type*>(reinterpret_cast<uint8*>(msg) + offset);
}
template <typename Type>
inline const Type* Raw(const MessageLite* msg, int64 offset) {
return reinterpret_cast<const Type*>(reinterpret_cast<const uint8*>(msg) +
offset);
}
template <typename InternalMetadata>
inline Arena* GetArena(MessageLite* msg, int64 arena_offset) {
if (GOOGLE_PREDICT_FALSE(arena_offset == -1)) {
return NULL;
}
return Raw<InternalMetadata>(msg, arena_offset)->arena();
}
inline ExtensionSet* GetExtensionSet(MessageLite* msg, int64 extension_offset) {
if (extension_offset == -1) {
return NULL;
}
return Raw<ExtensionSet>(msg, extension_offset);
}
template <typename Type>
inline Type* AddField(MessageLite* msg, int64 offset) {
#if LANG_CXX11
static_assert(has_trivial_copy<Type>::value,
"Do not assign");
#endif
google::protobuf::RepeatedField<Type>* repeated =
Raw<google::protobuf::RepeatedField<Type> >(msg, offset);
return repeated->Add();
}
template <>
inline string* AddField<string>(MessageLite* msg, int64 offset) {
google::protobuf::RepeatedPtrField<string>* repeated =
Raw<google::protobuf::RepeatedPtrField<string> >(msg, offset);
return repeated->Add();
}
template <typename Type>
inline void AddField(MessageLite* msg, int64 offset, Type value) {
#if LANG_CXX11
static_assert(has_trivial_copy<Type>::value,
"Do not assign");
#endif
*AddField<Type>(msg, offset) = value;
}
inline void SetBit(uint32* has_bits, uint32 has_bit_index) {
GOOGLE_DCHECK(has_bits != NULL);
uint32 mask = static_cast<uint32>(1u) << (has_bit_index % 32);
has_bits[has_bit_index / 32u] |= mask;
}
template <typename Type>
inline Type* MutableField(MessageLite* msg, uint32* has_bits,
uint32 has_bit_index, int64 offset) {
SetBit(has_bits, has_bit_index);
return Raw<Type>(msg, offset);
}
template <typename Type>
inline void SetField(MessageLite* msg, uint32* has_bits, uint32 has_bit_index,
int64 offset, Type value) {
#if LANG_CXX11
static_assert(has_trivial_copy<Type>::value,
"Do not assign");
#endif
*MutableField<Type>(msg, has_bits, has_bit_index, offset) = value;
}
template <typename Type>
inline void SetOneofField(MessageLite* msg, uint32* oneof_case,
uint32 oneof_case_index, int64 offset,
int field_number, Type value) {
oneof_case[oneof_case_index] = field_number;
*Raw<Type>(msg, offset) = value;
}
// Clears a oneof field. The field argument should correspond to the particular
// field that is currently set in the oneof.
inline void ClearOneofField(const ParseTableField& field, Arena* arena,
MessageLite* msg) {
switch (field.processing_type & kTypeMask) {
case WireFormatLite::TYPE_MESSAGE:
if (arena == NULL) {
delete *Raw<MessageLite*>(msg, field.offset);
}
break;
case WireFormatLite::TYPE_STRING:
case WireFormatLite::TYPE_BYTES:
Raw<ArenaStringPtr>(msg, field.offset)
->Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
break;
default:
// No cleanup needed.
break;
}
}
// Clears and reinitializes a oneof field as necessary, in preparation for
// parsing a new value with type field_type and field number field_number.
//
// Note: the oneof_case argument should point directly to the _oneof_case_
// element corresponding to this particular oneof, not to the beginning of the
// _oneof_case_ array.
template <ProcessingType field_type>
inline void ResetOneofField(const ParseTable& table, int field_number,
Arena* arena, MessageLite* msg, uint32* oneof_case,
int64 offset, const void* default_ptr) {
if (*oneof_case == field_number) {
// The oneof is already set to the right type, so there is no need to clear
// it.
return;
}
if (*oneof_case != 0) {
ClearOneofField(table.fields[*oneof_case], arena, msg);
}
*oneof_case = field_number;
switch (field_type) {
case ProcessingType_STRING:
Raw<ArenaStringPtr>(msg, offset)
->UnsafeSetDefault(static_cast<const string*>(default_ptr));
break;
case ProcessingType_MESSAGE:
MessageLite** submessage = Raw<MessageLite*>(msg, offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
*submessage = prototype->New(arena);
break;
}
}
template <Cardinality cardinality, bool validate, StringType ctype>
static inline bool HandleString(io::CodedInputStream* input, MessageLite* msg,
Arena* arena, uint32* has_bits,
uint32 has_bit_index, int64 offset,
const void* default_ptr,
const char* field_name) {
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
const char* sdata;
size_t size;
#endif
string* value;
switch (cardinality) {
case Cardinality_SINGULAR:
// TODO(ckennelly): Is this optimal?
value =
MutableField<ArenaStringPtr>(msg, has_bits, has_bit_index, offset)
->Mutable(static_cast<const string*>(default_ptr), arena);
break;
case Cardinality_REPEATED:
value = AddField<string>(msg, offset);
break;
case Cardinality_ONEOF:
value = Raw<ArenaStringPtr>(msg, offset)
->Mutable(static_cast<const string*>(default_ptr), arena);
break;
}
GOOGLE_DCHECK(value != NULL);
if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadString(input, value))) {
return false;
}
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
sdata = value->data();
size = value->size();
#endif
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
if (validate) {
WireFormatLite::VerifyUtf8String(sdata, size, WireFormatLite::PARSE,
field_name);
}
#endif
return true;
}
template <typename UnknownFieldHandler, typename InternalMetadata,
Cardinality cardinality>
inline bool HandleEnum(const ParseTable& table, io::CodedInputStream* input,
MessageLite* msg, uint32* presence,
uint32 presence_index, int64 offset, uint32 tag,
int field_number) {
int value;
if (GOOGLE_PREDICT_FALSE(
(!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
input, &value)))) {
return false;
}
AuxillaryParseTableField::EnumValidator validator =
table.aux[field_number].enums.validator;
if (validator(value)) {
switch (cardinality) {
case Cardinality_SINGULAR:
SetField(msg, presence, presence_index, offset, value);
break;
case Cardinality_REPEATED:
AddField(msg, offset, value);
break;
case Cardinality_ONEOF:
ClearOneofField(table.fields[presence[presence_index]],
GetArena<InternalMetadata>(msg, table.arena_offset),
msg);
SetOneofField(msg, presence, presence_index, offset, field_number,
value);
break;
}
} else {
UnknownFieldHandler::Varint(msg, table, tag, value);
}
return true;
}
// RepeatedMessageTypeHandler allows us to operate on RepeatedPtrField fields
// without instantiating the specific template.
class RepeatedMessageTypeHandler {
public:
typedef MessageLite Type;
static Arena* GetArena(Type* t) { return t->GetArena(); }
static void* GetMaybeArenaPointer(Type* t) {
return t->GetMaybeArenaPointer();
}
static inline Type* NewFromPrototype(const Type* prototype,
Arena* arena = NULL) {
return prototype->New(arena);
}
static void Delete(Type* t, Arena* arena = NULL) {
if (arena == NULL) {
delete t;
}
}
};
inline bool ReadGroup(int field_number, io::CodedInputStream* input,
MessageLite* value) {
if (GOOGLE_PREDICT_FALSE(!input->IncrementRecursionDepth())) {
return false;
}
if (GOOGLE_PREDICT_FALSE(!value->MergePartialFromCodedStream(input))) {
return false;
}
input->DecrementRecursionDepth();
// Make sure the last thing read was an end tag for this group.
if (GOOGLE_PREDICT_FALSE(!input->LastTagWas(WireFormatLite::MakeTag(
field_number, WireFormatLite::WIRETYPE_END_GROUP)))) {
return false;
}
return true;
}
inline bool ReadMessage(io::CodedInputStream* input, MessageLite* value) {
int length;
if (GOOGLE_PREDICT_FALSE(!input->ReadVarintSizeAsInt(&length))) {
return false;
}
std::pair<io::CodedInputStream::Limit, int> p =
input->IncrementRecursionDepthAndPushLimit(length);
if (GOOGLE_PREDICT_FALSE(p.second < 0 ||
!value->MergePartialFromCodedStream(input))) {
return false;
}
// Make sure that parsing stopped when the limit was hit, not at an endgroup
// tag.
return input->DecrementRecursionDepthAndPopLimit(p.first);
}
class MergePartialFromCodedStreamHelper {
public:
static MessageLite* Add(RepeatedPtrFieldBase* field,
const MessageLite* prototype) {
return field->Add<RepeatedMessageTypeHandler>(
const_cast<MessageLite*>(prototype));
}
};
template <typename UnknownFieldHandler, typename InternalMetadata>
bool MergePartialFromCodedStreamImpl(MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input) {
// We require that has_bits are present, as to avoid having to check for them
// for every field.
//
// TODO(ckennelly): Make this a compile-time parameter with templates.
GOOGLE_DCHECK_GE(table.has_bits_offset, 0);
uint32* has_bits = Raw<uint32>(msg, table.has_bits_offset);
GOOGLE_DCHECK(has_bits != NULL);
while (true) {
uint32 tag = input->ReadTag();
const WireFormatLite::WireType wire_type =
WireFormatLite::GetTagWireType(tag);
const int field_number = WireFormatLite::GetTagFieldNumber(tag);
if (field_number > table.max_field_number) {
// check for possible extensions
if (UnknownFieldHandler::ParseExtension(msg, table, input, tag)) {
// successfully parsed
continue;
}
if (GOOGLE_PREDICT_FALSE(!UnknownFieldHandler::Skip(msg, table, input, tag))) {
return false;
}
continue;
}
// We implicitly verify that data points to a valid field as we check the
// wire types. Entries in table.fields[i] that do not correspond to valid
// field numbers have their normal_wiretype and packed_wiretype fields set
// with the kInvalidMask value. As wire_type cannot take on that value, we
// will never match.
const ParseTableField* data = table.fields + field_number;
// TODO(ckennelly): Avoid sign extension
const int64 presence_index = data->presence_index;
const int64 offset = data->offset;
const unsigned char processing_type = data->processing_type;
if (data->normal_wiretype == static_cast<unsigned char>(wire_type)) {
// TODO(ckennelly): Use a computed goto on GCC/LLVM or otherwise eliminate
// the bounds check on processing_type.
switch (processing_type) {
#define HANDLE_TYPE(TYPE, CPPTYPE) \
case (WireFormatLite::TYPE_##TYPE): { \
CPPTYPE value; \
if (GOOGLE_PREDICT_FALSE( \
(!WireFormatLite::ReadPrimitive< \
CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \
return false; \
} \
SetField(msg, has_bits, presence_index, offset, value); \
break; \
} \
case (WireFormatLite::TYPE_##TYPE) | kRepeatedMask: { \
google::protobuf::RepeatedField<CPPTYPE>* values = \
Raw<google::protobuf::RepeatedField<CPPTYPE> >(msg, offset); \
if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadRepeatedPrimitive< \
CPPTYPE, WireFormatLite::TYPE_##TYPE>( \
data->tag_size, tag, input, values)))) { \
return false; \
} \
break; \
} \
case (WireFormatLite::TYPE_##TYPE) | kOneofMask: { \
uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); \
CPPTYPE value; \
if (GOOGLE_PREDICT_FALSE( \
(!WireFormatLite::ReadPrimitive< \
CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \
return false; \
} \
ClearOneofField(table.fields[oneof_case[presence_index]], \
GetArena<InternalMetadata>(msg, table.arena_offset), msg); \
SetOneofField(msg, oneof_case, presence_index, offset, field_number, \
value); \
break; \
}
HANDLE_TYPE(INT32, int32)
HANDLE_TYPE(INT64, int64)
HANDLE_TYPE(SINT32, int32)
HANDLE_TYPE(SINT64, int64)
HANDLE_TYPE(UINT32, uint32)
HANDLE_TYPE(UINT64, uint64)
HANDLE_TYPE(FIXED32, uint32)
HANDLE_TYPE(FIXED64, uint64)
HANDLE_TYPE(SFIXED32, int32)
HANDLE_TYPE(SFIXED64, int64)
HANDLE_TYPE(FLOAT, float)
HANDLE_TYPE(DOUBLE, double)
HANDLE_TYPE(BOOL, bool)
#undef HANDLE_TYPE
case WireFormatLite::TYPE_BYTES:
#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
case WireFormatLite::TYPE_STRING:
#endif
{
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
const void* default_ptr = table.aux[field_number].strings.default_ptr;
if (GOOGLE_PREDICT_FALSE((
!HandleString<Cardinality_SINGULAR, false, StringType_STRING>(
input, msg, arena, has_bits, presence_index, offset,
default_ptr, NULL)))) {
return false;
}
break;
}
case WireFormatLite::TYPE_BYTES | kOneofMask:
#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
case WireFormatLite::TYPE_STRING | kOneofMask:
#endif
{
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
const void* default_ptr = table.aux[field_number].strings.default_ptr;
ResetOneofField<ProcessingType_STRING>(
table, field_number, arena, msg, oneof_case + presence_index,
offset, default_ptr);
if (GOOGLE_PREDICT_FALSE(
(!HandleString<Cardinality_ONEOF, false, StringType_STRING>(
input, msg, arena, has_bits, presence_index, offset,
default_ptr, NULL)))) {
return false;
}
break;
}
case (WireFormatLite::TYPE_BYTES) | kRepeatedMask:
#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
case (WireFormatLite::TYPE_STRING) | kRepeatedMask:
#endif
{
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
const void* default_ptr =
table.aux[field_number].strings.default_ptr;
if (GOOGLE_PREDICT_FALSE((
!HandleString<Cardinality_REPEATED, false, StringType_STRING>(
input, msg, arena, has_bits, presence_index, offset,
default_ptr, NULL)))) {
return false;
}
break;
}
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
case (WireFormatLite::TYPE_STRING): {
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
const void* default_ptr = table.aux[field_number].strings.default_ptr;
const char* field_name = table.aux[field_number].strings.field_name;
if (GOOGLE_PREDICT_FALSE(
(!HandleString<Cardinality_SINGULAR, true, StringType_STRING>(
input, msg, arena, has_bits, presence_index, offset,
default_ptr, field_name)))) {
return false;
}
break;
}
case (WireFormatLite::TYPE_STRING) | kRepeatedMask: {
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
const void* default_ptr = table.aux[field_number].strings.default_ptr;
const char* field_name = table.aux[field_number].strings.field_name;
if (GOOGLE_PREDICT_FALSE(
(!HandleString<Cardinality_REPEATED, true, StringType_STRING>(
input, msg, arena, has_bits, presence_index, offset,
default_ptr, field_name)))) {
return false;
}
break;
}
case (WireFormatLite::TYPE_STRING) | kOneofMask: {
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
const void* default_ptr = table.aux[field_number].strings.default_ptr;
const char* field_name = table.aux[field_number].strings.field_name;
ResetOneofField<ProcessingType_STRING>(
table, field_number, arena, msg, oneof_case + presence_index,
offset, default_ptr);
if (GOOGLE_PREDICT_FALSE(
(!HandleString<Cardinality_ONEOF, true, StringType_STRING>(
input, msg, arena, has_bits, presence_index, offset,
default_ptr, field_name)))) {
return false;
}
break;
}
#endif
case WireFormatLite::TYPE_ENUM: {
if (GOOGLE_PREDICT_FALSE((!HandleEnum<UnknownFieldHandler, InternalMetadata,
Cardinality_SINGULAR>(
table, input, msg, has_bits, presence_index, offset, tag,
field_number)))) {
return false;
}
break;
}
case WireFormatLite::TYPE_ENUM | kRepeatedMask: {
if (GOOGLE_PREDICT_FALSE((!HandleEnum<UnknownFieldHandler, InternalMetadata,
Cardinality_REPEATED>(
table, input, msg, has_bits, presence_index, offset, tag,
field_number)))) {
return false;
}
break;
}
case WireFormatLite::TYPE_ENUM | kOneofMask: {
uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
if (GOOGLE_PREDICT_FALSE((!HandleEnum<UnknownFieldHandler, InternalMetadata,
Cardinality_ONEOF>(
table, input, msg, oneof_case, presence_index, offset, tag,
field_number)))) {
return false;
}
break;
}
case WireFormatLite::TYPE_GROUP: {
MessageLite** submsg_holder =
MutableField<MessageLite*>(msg, has_bits, presence_index, offset);
MessageLite* submsg = *submsg_holder;
if (submsg == NULL) {
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
submsg = prototype->New(arena);
*submsg_holder = submsg;
}
if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadGroup(
field_number, input, submsg))) {
return false;
}
break;
}
case WireFormatLite::TYPE_GROUP | kRepeatedMask: {
RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
GOOGLE_DCHECK(prototype != NULL);
MessageLite* submsg =
MergePartialFromCodedStreamHelper::Add(field, prototype);
if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadGroup(
field_number, input, submsg))) {
return false;
}
break;
}
case WireFormatLite::TYPE_MESSAGE: {
MessageLite** submsg_holder =
MutableField<MessageLite*>(msg, has_bits, presence_index, offset);
MessageLite* submsg = *submsg_holder;
if (submsg == NULL) {
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
submsg = prototype->New(arena);
*submsg_holder = submsg;
}
if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadMessage(input, submsg))) {
return false;
}
break;
}
// TODO(ckennelly): Adapt ReadMessageNoVirtualNoRecursionDepth and
// manage input->IncrementRecursionDepth() here.
case WireFormatLite::TYPE_MESSAGE | kRepeatedMask: {
RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
GOOGLE_DCHECK(prototype != NULL);
MessageLite* submsg =
MergePartialFromCodedStreamHelper::Add(field, prototype);
if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadMessage(input, submsg))) {
return false;
}
break;
}
case WireFormatLite::TYPE_MESSAGE | kOneofMask: {
Arena* const arena =
GetArena<InternalMetadata>(msg, table.arena_offset);
uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset);
MessageLite** submsg_holder = Raw<MessageLite*>(msg, offset);
ResetOneofField<ProcessingType_MESSAGE>(
table, field_number, arena, msg, oneof_case + presence_index,
offset, NULL);
MessageLite* submsg = *submsg_holder;
if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadMessage(input, submsg))) {
return false;
}
break;
}
case TYPE_MAP: {
if (GOOGLE_PREDICT_FALSE(!(*table.aux[field_number].maps.parse_map)(
input, Raw<void>(msg, offset)))) {
return false;
}
break;
}
case 0: {
// Done.
return true;
}
default:
break;
}
} else if (data->packed_wiretype == static_cast<unsigned char>(wire_type)) {
// Non-packable fields have their packed_wiretype masked with
// kNotPackedMask, which is impossible to match here.
GOOGLE_DCHECK(processing_type & kRepeatedMask);
GOOGLE_DCHECK_NE(processing_type, kRepeatedMask);
GOOGLE_DCHECK_EQ(0, processing_type & kOneofMask);
// TODO(ckennelly): Use a computed goto on GCC/LLVM.
//
// Mask out kRepeatedMask bit, allowing the jump table to be smaller.
switch (static_cast<WireFormatLite::FieldType>(
processing_type ^ kRepeatedMask)) {
#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \
case WireFormatLite::TYPE_##TYPE: { \
google::protobuf::RepeatedField<CPPTYPE>* values = \
Raw<google::protobuf::RepeatedField<CPPTYPE> >(msg, offset); \
if (GOOGLE_PREDICT_FALSE( \
(!WireFormatLite::ReadPackedPrimitive< \
CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, values)))) { \
return false; \
} \
break; \
}
HANDLE_PACKED_TYPE(INT32, int32, Int32)
HANDLE_PACKED_TYPE(INT64, int64, Int64)
HANDLE_PACKED_TYPE(SINT32, int32, Int32)
HANDLE_PACKED_TYPE(SINT64, int64, Int64)
HANDLE_PACKED_TYPE(UINT32, uint32, UInt32)
HANDLE_PACKED_TYPE(UINT64, uint64, UInt64)
HANDLE_PACKED_TYPE(FIXED32, uint32, UInt32)
HANDLE_PACKED_TYPE(FIXED64, uint64, UInt64)
HANDLE_PACKED_TYPE(SFIXED32, int32, Int32)
HANDLE_PACKED_TYPE(SFIXED64, int64, Int64)
HANDLE_PACKED_TYPE(FLOAT, float, Float)
HANDLE_PACKED_TYPE(DOUBLE, double, Double)
HANDLE_PACKED_TYPE(BOOL, bool, Bool)
#undef HANDLE_PACKED_TYPE
case WireFormatLite::TYPE_ENUM: {
// To avoid unnecessarily calling MutableUnknownFields (which mutates
// InternalMetadataWithArena) when all inputs in the repeated series
// are valid, we implement our own parser rather than call
// WireFormat::ReadPackedEnumPreserveUnknowns.
uint32 length;
if (GOOGLE_PREDICT_FALSE(!input->ReadVarint32(&length))) {
return false;
}
AuxillaryParseTableField::EnumValidator validator =
table.aux[field_number].enums.validator;
google::protobuf::RepeatedField<int>* values =
Raw<google::protobuf::RepeatedField<int> >(msg, offset);
io::CodedInputStream::Limit limit = input->PushLimit(length);
while (input->BytesUntilLimit() > 0) {
int value;
if (GOOGLE_PREDICT_FALSE(
(!google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, WireFormatLite::TYPE_ENUM>(input, &value)))) {
return false;
}
if (validator(value)) {
values->Add(value);
} else {
// TODO(ckennelly): Consider caching here.
UnknownFieldHandler::Varint(msg, table, tag, value);
}
}
input->PopLimit(limit);
break;
}
case WireFormatLite::TYPE_STRING:
case WireFormatLite::TYPE_GROUP:
case WireFormatLite::TYPE_MESSAGE:
case WireFormatLite::TYPE_BYTES:
GOOGLE_DCHECK(false);
return false;
default:
break;
}
} else {
if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) {
// Must be the end of the message.
return true;
}
// check for possible extensions
if (UnknownFieldHandler::ParseExtension(msg, table, input, tag)) {
// successfully parsed
continue;
}
// process unknown field.
if (GOOGLE_PREDICT_FALSE(!UnknownFieldHandler::Skip(msg, table, input, tag))) {
return false;
}
}
}
}
} // namespace internal
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__
@@ -35,12 +35,25 @@
#include <google/protobuf/generated_message_util.h>
#include <limits>
#include <vector>
#include <google/protobuf/io/coded_stream_inl.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
namespace protobuf {
namespace internal {
double Infinity() {
return std::numeric_limits<double>::infinity();
}
@@ -51,16 +64,14 @@ double NaN() {
ExplicitlyConstructed< ::std::string> fixed_address_empty_string;
GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_);
void DeleteEmptyString() {
GetEmptyStringAlreadyInited().~string();
}
void DeleteEmptyString() { fixed_address_empty_string.Destruct(); }
void InitEmptyString() {
fixed_address_empty_string.DefaultConstruct();
OnShutdown(&DeleteEmptyString);
}
int StringSpaceUsedExcludingSelf(const string& str) {
size_t StringSpaceUsedExcludingSelfLong(const string& str) {
const void* start = &str;
const void* end = &str + 1;
if (start <= str.data() && str.data() < end) {
@@ -73,10 +84,645 @@ int StringSpaceUsedExcludingSelf(const string& str) {
void MergeFromFail(const char* file, int line) {
GOOGLE_CHECK(false) << file << ":" << line;
// Open-source GOOGLE_CHECK(false) is not NORETURN.
exit(1);
void InitProtobufDefaults() {
GetEmptyString();
}
template <typename T>
const T& Get(const void* ptr) {
return *static_cast<const T*>(ptr);
}
// PrimitiveTypeHelper is a wrapper around the interface of WireFormatLite.
// WireFormatLite has a very inconvenient interface with respect to template
// meta-programming. This class wraps the different named functions into
// a single Serialize / SerializeToArray interface.
template <int type>
struct PrimitiveTypeHelper;
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_BOOL> {
typedef bool Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteBoolNoTag(Get<bool>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteBoolNoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_INT32> {
typedef int32 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteInt32NoTag(Get<int32>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteInt32NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_SINT32> {
typedef int32 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteSInt32NoTag(Get<int32>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteSInt32NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_UINT32> {
typedef uint32 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteUInt32NoTag(Get<uint32>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteUInt32NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_INT64> {
typedef int64 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteInt64NoTag(Get<int64>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteInt64NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_SINT64> {
typedef int64 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteSInt64NoTag(Get<int64>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteSInt64NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_UINT64> {
typedef uint64 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteUInt64NoTag(Get<uint64>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteUInt64NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED32> {
typedef uint32 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteFixed32NoTag(Get<uint32>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteFixed32NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED64> {
typedef uint64 Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
WireFormatLite::WriteFixed64NoTag(Get<uint64>(ptr), output);
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
return WireFormatLite::WriteFixed64NoTagToArray(Get<Type>(ptr), buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_ENUM>
: PrimitiveTypeHelper<WireFormatLite::TYPE_INT32> {};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_SFIXED32>
: PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED32> {
typedef int32 Type;
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_SFIXED64>
: PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED64> {
typedef int64 Type;
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_FLOAT>
: PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED32> {
typedef float Type;
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_DOUBLE>
: PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED64> {
typedef double Type;
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_STRING> {
typedef string Type;
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
const Type& value = *static_cast<const Type*>(ptr);
output->WriteVarint32(value.size());
output->WriteRawMaybeAliased(value.data(), value.size());
}
static uint8* SerializeToArray(const void* ptr, uint8* buffer) {
const Type& value = *static_cast<const Type*>(ptr);
return io::CodedOutputStream::WriteStringWithSizeToArray(value, buffer);
}
};
template <>
struct PrimitiveTypeHelper<WireFormatLite::TYPE_BYTES>
: PrimitiveTypeHelper<WireFormatLite::TYPE_STRING> {};
// We want to serialize to both CodedOutputStream and directly into byte arrays
// without duplicating the code. In fact we might want extra output channels in
// the future.
template <typename O, int type>
struct OutputHelper;
template <int type, typename O>
void SerializeTo(const void* ptr, O* output) {
OutputHelper<O, type>::Serialize(ptr, output);
}
template <typename O>
void WriteTagTo(uint32 tag, O* output) {
SerializeTo<WireFormatLite::TYPE_UINT32>(&tag, output);
}
template <typename O>
void WriteLengthTo(uint32 length, O* output) {
SerializeTo<WireFormatLite::TYPE_UINT32>(&length, output);
}
// Specialization for coded output stream
template <int type>
struct OutputHelper< ::google::protobuf::io::CodedOutputStream, type> {
static void Serialize(const void* ptr,
::google::protobuf::io::CodedOutputStream* output) {
PrimitiveTypeHelper<type>::Serialize(ptr, output);
}
};
// Specialization for writing into a plain array
struct ArrayOutput {
uint8* ptr;
bool is_deterministic;
};
template <int type>
struct OutputHelper<ArrayOutput, type> {
static void Serialize(const void* ptr, ArrayOutput* output) {
output->ptr = PrimitiveTypeHelper<type>::SerializeToArray(ptr, output->ptr);
}
};
void SerializeMessageNoTable(const MessageLite* msg,
::google::protobuf::io::CodedOutputStream* output) {
msg->SerializeWithCachedSizes(output);
}
void SerializeMessageNoTable(const MessageLite* msg, ArrayOutput* output) {
output->ptr = msg->InternalSerializeWithCachedSizesToArray(
output->is_deterministic, output->ptr);
}
// Helper to branch to fast path if possible
void SerializeMessageDispatch(const ::google::protobuf::MessageLite& msg,
const FieldMetadata* field_table, int num_fields,
int32 cached_size,
::google::protobuf::io::CodedOutputStream* output) {
const uint8* base = reinterpret_cast<const uint8*>(&msg);
// Try the fast path
uint8* ptr = output->GetDirectBufferForNBytesAndAdvance(cached_size);
if (ptr) {
// We use virtual dispatch to enable dedicated generated code for the
// fast path.
msg.InternalSerializeWithCachedSizesToArray(
output->IsSerializationDeterministic(), ptr);
return;
}
SerializeInternal(base, field_table, num_fields, output);
}
// Helper to branch to fast path if possible
void SerializeMessageDispatch(const ::google::protobuf::MessageLite& msg,
const FieldMetadata* field_table, int num_fields,
int32 cached_size, ArrayOutput* output) {
const uint8* base = reinterpret_cast<const uint8*>(&msg);
output->ptr = SerializeInternalToArray(base, field_table, num_fields,
output->is_deterministic, output->ptr);
}
// Serializing messages is special as it's not a primitive type and needs an
// explicit overload for each output type.
template <typename O>
void SerializeMessageTo(const MessageLite* msg, const void* table_ptr,
O* output) {
const SerializationTable* table =
static_cast<const SerializationTable*>(table_ptr);
if (!table) {
// Proto1
WriteLengthTo(msg->GetCachedSize(), output);
SerializeMessageNoTable(msg, output);
return;
}
const FieldMetadata* field_table = table->field_table;
const uint8* base = reinterpret_cast<const uint8*>(msg);
int cached_size = *reinterpret_cast<const int32*>(base + field_table->offset);
WriteLengthTo(cached_size, output);
int num_fields = table->num_fields - 1;
SerializeMessageDispatch(*msg, field_table + 1, num_fields, cached_size,
output);
}
// Almost the same as above only it doesn't output the length field.
template <typename O>
void SerializeGroupTo(const MessageLite* msg, const void* table_ptr,
O* output) {
const SerializationTable* table =
static_cast<const SerializationTable*>(table_ptr);
if (!table) {
// Proto1
SerializeMessageNoTable(msg, output);
return;
}
const FieldMetadata* field_table = table->field_table;
const uint8* base = reinterpret_cast<const uint8*>(msg);
int cached_size = *reinterpret_cast<const int32*>(base + field_table->offset);
int num_fields = table->num_fields - 1;
SerializeMessageDispatch(*msg, field_table + 1, num_fields, cached_size,
output);
}
template <int type>
struct SingularFieldHelper {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
WriteTagTo(md.tag, output);
SerializeTo<type>(field, output);
}
};
template <>
struct SingularFieldHelper<WireFormatLite::TYPE_STRING> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
WriteTagTo(md.tag, output);
SerializeTo<WireFormatLite::TYPE_STRING>(&Get<ArenaStringPtr>(field).Get(),
output);
}
};
template <>
struct SingularFieldHelper<WireFormatLite::TYPE_BYTES>
: SingularFieldHelper<WireFormatLite::TYPE_STRING> {};
template <>
struct SingularFieldHelper<WireFormatLite::TYPE_GROUP> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
WriteTagTo(md.tag, output);
SerializeGroupTo(Get<const MessageLite*>(field),
static_cast<const SerializationTable*>(md.ptr), output);
WriteTagTo(md.tag + 1, output);
}
};
template <>
struct SingularFieldHelper<WireFormatLite::TYPE_MESSAGE> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
WriteTagTo(md.tag, output);
SerializeMessageTo(Get<const MessageLite*>(field),
static_cast<const SerializationTable*>(md.ptr), output);
}
};
template <int type>
struct RepeatedFieldHelper {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
typedef typename PrimitiveTypeHelper<type>::Type T;
const RepeatedField<T>& array = Get<RepeatedField<T> >(field);
for (int i = 0; i < array.size(); i++) {
WriteTagTo(md.tag, output);
SerializeTo<type>(&array[i], output);
}
}
};
// We need to use a helper class to get access to the private members
class AccessorHelper {
public:
static int Size(const RepeatedPtrFieldBase& x) { return x.size(); }
static void const* Get(const RepeatedPtrFieldBase& x, int idx) {
return x.raw_data()[idx];
}
};
template <>
struct RepeatedFieldHelper<WireFormatLite::TYPE_STRING> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
const internal::RepeatedPtrFieldBase& array =
Get<internal::RepeatedPtrFieldBase>(field);
for (int i = 0; i < AccessorHelper::Size(array); i++) {
WriteTagTo(md.tag, output);
SerializeTo<WireFormatLite::TYPE_STRING>(AccessorHelper::Get(array, i),
output);
}
}
};
template <>
struct RepeatedFieldHelper<WireFormatLite::TYPE_BYTES>
: RepeatedFieldHelper<WireFormatLite::TYPE_STRING> {};
template <>
struct RepeatedFieldHelper<WireFormatLite::TYPE_GROUP> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
const internal::RepeatedPtrFieldBase& array =
Get<internal::RepeatedPtrFieldBase>(field);
for (int i = 0; i < AccessorHelper::Size(array); i++) {
WriteTagTo(md.tag, output);
SerializeGroupTo(
static_cast<const MessageLite*>(AccessorHelper::Get(array, i)),
static_cast<const SerializationTable*>(md.ptr), output);
WriteTagTo(md.tag + 1, output);
}
}
};
template <>
struct RepeatedFieldHelper<WireFormatLite::TYPE_MESSAGE> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
const internal::RepeatedPtrFieldBase& array =
Get<internal::RepeatedPtrFieldBase>(field);
for (int i = 0; i < AccessorHelper::Size(array); i++) {
WriteTagTo(md.tag, output);
SerializeMessageTo(
static_cast<const MessageLite*>(AccessorHelper::Get(array, i)), md.ptr,
output);
}
}
};
template <int type>
struct PackedFieldHelper {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
typedef typename PrimitiveTypeHelper<type>::Type T;
const RepeatedField<T>& array = Get<RepeatedField<T> >(field);
if (array.empty()) return;
WriteTagTo(md.tag, output);
int cached_size =
Get<int>(static_cast<const uint8*>(field) + sizeof(RepeatedField<T>));
WriteLengthTo(cached_size, output);
for (int i = 0; i < array.size(); i++) {
SerializeTo<type>(&array[i], output);
}
}
};
template <>
struct PackedFieldHelper<WireFormatLite::TYPE_STRING> {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
GOOGLE_LOG(FATAL) << "Not implemented field number " << md.tag << " with type "
<< md.type;
}
};
template <>
struct PackedFieldHelper<WireFormatLite::TYPE_BYTES>
: PackedFieldHelper<WireFormatLite::TYPE_STRING> {};
template <>
struct PackedFieldHelper<WireFormatLite::TYPE_GROUP>
: PackedFieldHelper<WireFormatLite::TYPE_STRING> {};
template <>
struct PackedFieldHelper<WireFormatLite::TYPE_MESSAGE>
: PackedFieldHelper<WireFormatLite::TYPE_STRING> {};
template <int type>
struct OneOfFieldHelper {
template <typename O>
static void Serialize(const void* field, const FieldMetadata& md, O* output) {
SingularFieldHelper<type>::Serialize(field, md, output);
}
};
void SerializeNotImplemented(int field) {
GOOGLE_LOG(FATAL) << "Not implemented field number " << field;
}
// When switching to c++11 we should make these constexpr functions
#define SERIALIZE_TABLE_OP(type, type_class) \
((type - 1) + static_cast<int>(type_class) * FieldMetadata::kNumTypes)
int FieldMetadata::CalculateType(int type,
FieldMetadata::FieldTypeClass type_class) {
return SERIALIZE_TABLE_OP(type, type_class);
}
template <int type>
bool IsNull(const void* ptr) {
return *static_cast<const typename PrimitiveTypeHelper<type>::Type*>(ptr) ==
0;
}
template <>
bool IsNull<WireFormatLite::TYPE_STRING>(const void* ptr) {
return static_cast<const ArenaStringPtr*>(ptr)->Get().size() == 0;
}
template <>
bool IsNull<WireFormatLite::TYPE_BYTES>(const void* ptr) {
return static_cast<const ArenaStringPtr*>(ptr)->Get().size() == 0;
}
template <>
bool IsNull<WireFormatLite::TYPE_GROUP>(const void* ptr) {
return Get<const MessageLite*>(ptr) == NULL;
}
template <>
bool IsNull<WireFormatLite::TYPE_MESSAGE>(const void* ptr) {
return Get<const MessageLite*>(ptr) == NULL;
}
#define SERIALIZERS_FOR_TYPE(type) \
case SERIALIZE_TABLE_OP(type, FieldMetadata::kPresence): \
if (!IsPresent(base, field_metadata.has_offset)) continue; \
SingularFieldHelper<type>::Serialize(ptr, field_metadata, output); \
break; \
case SERIALIZE_TABLE_OP(type, FieldMetadata::kNoPresence): \
if (IsNull<type>(ptr)) continue; \
SingularFieldHelper<type>::Serialize(ptr, field_metadata, output); \
break; \
case SERIALIZE_TABLE_OP(type, FieldMetadata::kRepeated): \
RepeatedFieldHelper<type>::Serialize(ptr, field_metadata, output); \
break; \
case SERIALIZE_TABLE_OP(type, FieldMetadata::kPacked): \
PackedFieldHelper<type>::Serialize(ptr, field_metadata, output); \
break; \
case SERIALIZE_TABLE_OP(type, FieldMetadata::kOneOf): \
if (!IsOneofPresent(base, field_metadata.has_offset, field_metadata.tag)) \
continue; \
OneOfFieldHelper<type>::Serialize(ptr, field_metadata, output); \
break
void SerializeInternal(const uint8* base,
const FieldMetadata* field_metadata_table,
int32 num_fields,
::google::protobuf::io::CodedOutputStream* output) {
for (int i = 0; i < num_fields; i++) {
const FieldMetadata& field_metadata = field_metadata_table[i];
const uint8* ptr = base + field_metadata.offset;
switch (field_metadata.type) {
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_DOUBLE);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FLOAT);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BOOL);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_STRING);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_GROUP);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_MESSAGE);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BYTES);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_ENUM);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT64);
// Special cases
case FieldMetadata::kSpecial:
reinterpret_cast<SpecialSerializer>(
const_cast<void*>(field_metadata.ptr))(
base, field_metadata.offset, field_metadata.tag,
field_metadata.has_offset, output);
break;
default:
// __builtin_unreachable()
SerializeNotImplemented(field_metadata.type);
}
}
}
uint8* SerializeInternalToArray(const uint8* base,
const FieldMetadata* field_metadata_table,
int32 num_fields, bool is_deterministic,
uint8* buffer) {
ArrayOutput array_output = {buffer, is_deterministic};
ArrayOutput* output = &array_output;
for (int i = 0; i < num_fields; i++) {
const FieldMetadata& field_metadata = field_metadata_table[i];
const uint8* ptr = base + field_metadata.offset;
switch (field_metadata.type) {
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_DOUBLE);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FLOAT);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BOOL);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_STRING);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_GROUP);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_MESSAGE);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BYTES);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_ENUM);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED64);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT32);
SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT64);
// Special cases
case FieldMetadata::kSpecial: {
io::ArrayOutputStream array_stream(array_output.ptr, INT_MAX);
io::CodedOutputStream output(&array_stream);
output.SetSerializationDeterministic(is_deterministic);
reinterpret_cast<SpecialSerializer>(
const_cast<void*>(field_metadata.ptr))(
base, field_metadata.offset, field_metadata.tag,
field_metadata.has_offset, &output);
array_output.ptr += output.ByteCount();
} break;
default:
// __builtin_unreachable()
SerializeNotImplemented(field_metadata.type);
}
}
return array_output.ptr;
}
#undef SERIALIZERS_FOR_TYPE
void ExtensionSerializer(const uint8* ptr, uint32 offset, uint32 tag,
uint32 has_offset,
::google::protobuf::io::CodedOutputStream* output) {
reinterpret_cast<const ExtensionSet*>(ptr + offset)
->SerializeWithCachedSizes(tag, has_offset, output);
}
void UnknownFieldSerializerLite(const uint8* ptr, uint32 offset, uint32 tag,
uint32 has_offset,
::google::protobuf::io::CodedOutputStream* output) {
output->WriteString(
reinterpret_cast<const InternalMetadataWithArenaLite*>(ptr + offset)
->unknown_fields());
}
MessageLite* DuplicateIfNonNullInternal(MessageLite* message, Arena* arena) {
if (message) {
MessageLite* ret = message->New(arena);
ret->CheckTypeAndMergeFrom(*message);
return ret;
} else {
return NULL;
}
}
// Returns a message owned by this Arena. This may require Own()ing or
// duplicating the message.
MessageLite* GetOwnedMessageInternal(Arena* message_arena,
MessageLite* submessage,
Arena* submessage_arena) {
GOOGLE_DCHECK(submessage->GetArena() == submessage_arena);
GOOGLE_DCHECK(message_arena != submessage_arena);
if (message_arena != NULL && submessage_arena == NULL) {
message_arena->Own(submessage);
return submessage;
} else {
MessageLite* ret = submessage->New(message_arena);
ret->CheckTypeAndMergeFrom(*submessage);
return ret;
}
}
} // namespace internal
+224 -73
View File
@@ -39,17 +39,24 @@
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__
#include <assert.h>
#include <climits>
#include <string>
#include <vector>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/has_bits.h>
#include <google/protobuf/map_entry_lite.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/wire_format_lite.h>
namespace google {
namespace protobuf {
class Arena;
namespace io { class CodedInputStream; }
namespace internal {
@@ -67,66 +74,39 @@ namespace internal {
#define GOOGLE_PROTOBUF_DEPRECATED_ATTR
// 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 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
__builtin_offsetof(TYPE, FIELD) \
_Pragma("clang diagnostic pop")
#else
// 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 GOOGLE_PROTOBUF_GENERATED_MESSAGE_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
// Constants for special floating point values.
LIBPROTOBUF_EXPORT double Infinity();
LIBPROTOBUF_EXPORT double NaN();
// This type is used to define a global variable, without it's 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.
template <typename T>
class ExplicitlyConstructed {
public:
void DefaultConstruct() {
new (&union_) T();
init_ = true;
}
bool IsInitialized() { return init_; }
void Shutdown() {
if (init_) {
init_ = false;
get_mutable()->~T();
}
}
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_;
bool init_; // false by linker
};
// TODO(jieluo): Change to template. We have tried to use template,
// but it causes net/rpc/python:rpcutil_test fail (the empty string will
// init twice). It may related to swig. Change to template after we
// found the solution.
// Default empty string object. Don't use this directly. Instead, call
// GetEmptyString() to get the reference.
extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string;
LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_;
LIBPROTOBUF_EXPORT void InitEmptyString();
LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() {
return fixed_address_empty_string.get();
}
LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() {
::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString);
return GetEmptyStringAlreadyInited();
}
LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str);
// 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
@@ -140,26 +120,197 @@ template <class Type> bool AllAreInitialized(const Type& t) {
return true;
}
// Helper function to crash on merge failure.
// Moved out of generated code to reduce binary size.
LIBPROTOBUF_EXPORT void MergeFromFail(const char* file, int line) GOOGLE_ATTRIBUTE_NORETURN;
LIBPROTOBUF_EXPORT void InitProtobufDefaults();
// 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.
inline int ToCachedSize(size_t size) {
return static_cast<int>(size);
struct LIBPROTOBUF_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,
kNumTypes = 20,
kSpecial = kNumTypes * kNumTypeClasses,
};
static int CalculateType(int fundamental_type, FieldTypeClass type_class);
};
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));
}
// 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);
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,
::google::protobuf::io::CodedOutputStream* output);
LIBPROTOBUF_EXPORT void ExtensionSerializer(const uint8* base, uint32 offset, uint32 tag,
uint32 has_offset,
::google::protobuf::io::CodedOutputStream* output);
LIBPROTOBUF_EXPORT void UnknownFieldSerializerLite(const uint8* base, uint32 offset, uint32 tag,
uint32 has_offset,
::google::protobuf::io::CodedOutputStream* output);
struct SerializationTable {
int num_fields;
const FieldMetadata* field_table;
};
LIBPROTOBUF_EXPORT void SerializeInternal(const uint8* base, const FieldMetadata* table,
int num_fields, ::google::protobuf::io::CodedOutputStream* output);
inline void TableSerialize(const ::google::protobuf::MessageLite& msg,
const SerializationTable* table,
::google::protobuf::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,
int num_fields, bool is_deterministic,
uint8* buffer);
inline uint8* TableSerializeToArray(const ::google::protobuf::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) { return a < b; }
};
template <>
struct CompareHelper<ArenaStringPtr> {
bool operator()(const ArenaStringPtr& a, const ArenaStringPtr& b) {
return a.Get() < b.Get();
}
};
struct CompareMapKey {
template <typename T>
bool operator()(const MapEntryHelper<T>& a, const MapEntryHelper<T>& b) {
return Compare(a.key_, b.key_);
}
template <typename T>
bool Compare(const T& a, const T& b) {
return CompareHelper<T>()(a, b);
}
};
template <typename MapFieldType, const SerializationTable* table>
void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag,
uint32 has_offset,
::google::protobuf::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);
}
}
}
LIBPROTOBUF_EXPORT MessageLite* DuplicateIfNonNullInternal(MessageLite* message, Arena* arena);
LIBPROTOBUF_EXPORT MessageLite* GetOwnedMessageInternal(Arena* message_arena,
MessageLite* submessage,
Arena* submessage_arena);
template <typename T>
T* DuplicateIfNonNull(T* message, Arena* 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*>(DuplicateIfNonNullInternal(
reinterpret_cast<MessageLite*>(message), arena));
}
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));
}
// Returns a message owned by this Arena. This may require Own()ing or
// duplicating the message.
template <typename T>
T* GetOwnedMessage(T* message, Arena* arena) {
GOOGLE_DCHECK(message);
Arena* message_arena = google::protobuf::Arena::GetArena(message);
if (message_arena == arena) {
return message;
} else if (arena != NULL && message_arena == NULL) {
arena->Own(message);
return message;
} else {
return DuplicateIfNonNull(message, arena);
}
}
} // namespace internal
+37 -4
View File
@@ -32,6 +32,7 @@
#define GOOGLE_PROTOBUF_HAS_BITS_H__
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/port.h>
namespace google {
namespace protobuf {
@@ -40,17 +41,18 @@ namespace internal {
template<size_t doublewords>
class HasBits {
public:
HasBits() GOOGLE_ATTRIBUTE_ALWAYS_INLINE { Clear(); }
HasBits() GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE { Clear(); }
void Clear() GOOGLE_ATTRIBUTE_ALWAYS_INLINE {
void Clear() GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE {
memset(has_bits_, 0, sizeof(has_bits_));
}
::google::protobuf::uint32& operator[](int index) GOOGLE_ATTRIBUTE_ALWAYS_INLINE {
::google::protobuf::uint32& operator[](int index) GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE {
return has_bits_[index];
}
const ::google::protobuf::uint32& operator[](int index) const GOOGLE_ATTRIBUTE_ALWAYS_INLINE {
const ::google::protobuf::uint32& operator[](int index) const
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE {
return has_bits_[index];
}
@@ -61,10 +63,41 @@ class HasBits {
bool operator!=(const HasBits<doublewords>& rhs) const {
return !(*this == rhs);
}
bool empty() const;
private:
::google::protobuf::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
+29 -167
View File
@@ -47,7 +47,6 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stl_util.h>
#include <google/protobuf/stubs/port.h>
namespace google {
@@ -77,10 +76,6 @@ CodedInputStream::~CodedInputStream() {
if (input_ != NULL) {
BackUpInputToCurrentPosition();
}
if (total_bytes_warning_threshold_ == -2) {
GOOGLE_LOG(WARNING) << "The total number of bytes read was " << total_bytes_read_;
}
}
// Static.
@@ -124,21 +119,15 @@ CodedInputStream::Limit CodedInputStream::PushLimit(int byte_limit) {
Limit old_limit = current_limit_;
// security: byte_limit is possibly evil, so check for negative values
// and overflow.
if (byte_limit >= 0 &&
byte_limit <= INT_MAX - current_position) {
// and overflow. Also check that the new requested limit is before the
// previous limit; otherwise we continue to enforce the previous limit.
if GOOGLE_PREDICT_TRUE(byte_limit >= 0 &&
byte_limit <= INT_MAX - current_position &&
byte_limit < current_limit_ - current_position) {
current_limit_ = current_position + byte_limit;
} else {
// Negative or overflow.
current_limit_ = INT_MAX;
RecomputeBufferLimits();
}
// We need to enforce all limits, not just the new one, so if the previous
// limit was before the new requested limit, we continue to enforce the
// previous limit.
current_limit_ = std::min(current_limit_, old_limit);
RecomputeBufferLimits();
return old_limit;
}
@@ -186,16 +175,12 @@ int CodedInputStream::BytesUntilLimit() const {
void CodedInputStream::SetTotalBytesLimit(
int total_bytes_limit, int warning_threshold) {
(void) warning_threshold;
// Make sure the limit isn't already past, since this could confuse other
// code.
int current_position = CurrentPosition();
total_bytes_limit_ = std::max(current_position, total_bytes_limit);
if (warning_threshold >= 0) {
total_bytes_warning_threshold_ = warning_threshold;
} else {
// warning_threshold is negative
total_bytes_warning_threshold_ = -1;
}
RecomputeBufferLimits();
}
@@ -212,17 +197,7 @@ void CodedInputStream::PrintTotalBytesLimitError() {
"in google/protobuf/io/coded_stream.h.";
}
bool CodedInputStream::Skip(int count) {
if (count < 0) return false; // security: count is often user-supplied
const int original_buffer_size = BufferSize();
if (count <= original_buffer_size) {
// Just skipping within the current buffer. Easy.
Advance(count);
return true;
}
bool CodedInputStream::SkipFallback(int count, int original_buffer_size) {
if (buffer_size_after_limit_ > 0) {
// We hit a limit inside this buffer. Advance to the limit and fail.
Advance(original_buffer_size);
@@ -340,7 +315,8 @@ namespace {
// The first part of the pair is true iff the read was successful. The second
// part is buffer + (number of bytes read). This function is always inlined,
// so returning a pair is costless.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE ::std::pair<bool, const uint8*> ReadVarint32FromArray(
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
::std::pair<bool, const uint8*> ReadVarint32FromArray(
uint32 first_byte, const uint8* buffer,
uint32* value);
inline ::std::pair<bool, const uint8*> ReadVarint32FromArray(
@@ -377,8 +353,8 @@ inline ::std::pair<bool, const uint8*> ReadVarint32FromArray(
return std::make_pair(true, ptr);
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE::std::pair<bool, const uint8*> ReadVarint64FromArray(
const uint8* buffer, uint64* value);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE::std::pair<bool, const uint8*>
ReadVarint64FromArray(const uint8* buffer, uint64* value);
inline ::std::pair<bool, const uint8*> ReadVarint64FromArray(
const uint8* buffer, uint64* value) {
const uint8* ptr = buffer;
@@ -550,9 +526,15 @@ bool CodedInputStream::ReadVarint64Slow(uint64* value) {
uint32 b;
do {
if (count == kMaxVarintBytes) return false;
if (count == kMaxVarintBytes) {
*value = 0;
return false;
}
while (buffer_ == buffer_end_) {
if (!Refresh()) return false;
if (!Refresh()) {
*value = 0;
return false;
}
}
b = *buffer_;
result |= static_cast<uint64>(b & 0x7F) << (7 * count);
@@ -577,7 +559,7 @@ std::pair<uint64, bool> CodedInputStream::ReadVarint64Fallback() {
buffer_ = p.second;
return std::make_pair(temp, true);
} else {
uint64 temp = 0;
uint64 temp;
bool success = ReadVarint64Slow(&temp);
return std::make_pair(temp, success);
}
@@ -600,20 +582,6 @@ bool CodedInputStream::Refresh() {
return false;
}
if (total_bytes_warning_threshold_ >= 0 &&
total_bytes_read_ >= total_bytes_warning_threshold_) {
GOOGLE_LOG(WARNING) << "Reading dangerously large protocol message. If the "
"message turns out to be larger than "
<< total_bytes_limit_ << " bytes, parsing will be halted "
"for security reasons. To increase the limit (or to "
"disable these warnings), see "
"CodedInputStream::SetTotalBytesLimit() in "
"google/protobuf/io/coded_stream.h.";
// Don't warn again for this stream, and print total size at the end.
total_bytes_warning_threshold_ = -2;
}
const void* void_buffer;
int buffer_size;
if (NextNonEmpty(input_, &void_buffer, &buffer_size)) {
@@ -650,7 +618,7 @@ bool CodedInputStream::Refresh() {
// CodedOutputStream =================================================
bool CodedOutputStream::default_serialization_deterministic_ = false;
google::protobuf::internal::AtomicWord CodedOutputStream::default_serialization_deterministic_ = 0;
CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output)
: output_(output),
@@ -789,104 +757,12 @@ void CodedOutputStream::WriteVarint32SlowPath(uint32 value) {
WriteRaw(bytes, size);
}
inline uint8* CodedOutputStream::WriteVarint64ToArrayInline(
uint64 value, uint8* target) {
// Splitting into 32-bit pieces gives better performance on 32-bit
// processors.
uint32 part0 = static_cast<uint32>(value );
uint32 part1 = static_cast<uint32>(value >> 28);
uint32 part2 = static_cast<uint32>(value >> 56);
int size;
// Here we can't really optimize for small numbers, since the value is
// split into three parts. Cheking for numbers < 128, for instance,
// would require three comparisons, since you'd have to make sure part1
// and part2 are zero. However, if the caller is using 64-bit integers,
// it is likely that they expect the numbers to often be very large, so
// we probably don't want to optimize for small numbers anyway. Thus,
// we end up with a hardcoded binary search tree...
if (part2 == 0) {
if (part1 == 0) {
if (part0 < (1 << 14)) {
if (part0 < (1 << 7)) {
size = 1; goto size1;
} else {
size = 2; goto size2;
}
} else {
if (part0 < (1 << 21)) {
size = 3; goto size3;
} else {
size = 4; goto size4;
}
}
} else {
if (part1 < (1 << 14)) {
if (part1 < (1 << 7)) {
size = 5; goto size5;
} else {
size = 6; goto size6;
}
} else {
if (part1 < (1 << 21)) {
size = 7; goto size7;
} else {
size = 8; goto size8;
}
}
}
} else {
if (part2 < (1 << 7)) {
size = 9; goto size9;
} else {
size = 10; goto size10;
}
}
GOOGLE_LOG(FATAL) << "Can't get here.";
size10: target[9] = static_cast<uint8>((part2 >> 7) | 0x80);
size9 : target[8] = static_cast<uint8>((part2 ) | 0x80);
size8 : target[7] = static_cast<uint8>((part1 >> 21) | 0x80);
size7 : target[6] = static_cast<uint8>((part1 >> 14) | 0x80);
size6 : target[5] = static_cast<uint8>((part1 >> 7) | 0x80);
size5 : target[4] = static_cast<uint8>((part1 ) | 0x80);
size4 : target[3] = static_cast<uint8>((part0 >> 21) | 0x80);
size3 : target[2] = static_cast<uint8>((part0 >> 14) | 0x80);
size2 : target[1] = static_cast<uint8>((part0 >> 7) | 0x80);
size1 : target[0] = static_cast<uint8>((part0 ) | 0x80);
target[size-1] &= 0x7F;
return target + size;
}
void CodedOutputStream::WriteVarint64(uint64 value) {
if (buffer_size_ >= kMaxVarintBytes) {
// Fast path: We have enough bytes left in the buffer to guarantee that
// this write won't cross the end, so we can skip the checks.
uint8* target = buffer_;
uint8* end = WriteVarint64ToArrayInline(value, target);
int size = end - target;
Advance(size);
} else {
// Slow path: This write might cross the end of the buffer, so we
// compose the bytes first then use WriteRaw().
uint8 bytes[kMaxVarintBytes];
int size = 0;
while (value > 0x7F) {
bytes[size++] = (static_cast<uint8>(value) & 0x7F) | 0x80;
value >>= 7;
}
bytes[size++] = static_cast<uint8>(value) & 0x7F;
WriteRaw(bytes, size);
}
}
uint8* CodedOutputStream::WriteVarint64ToArray(
uint64 value, uint8* target) {
return WriteVarint64ToArrayInline(value, target);
void CodedOutputStream::WriteVarint64SlowPath(uint64 value) {
uint8 bytes[kMaxVarintBytes];
uint8* target = &bytes[0];
uint8* end = WriteVarint64ToArray(value, target);
int size = end - target;
WriteRaw(bytes, size);
}
bool CodedOutputStream::Refresh() {
@@ -903,20 +779,6 @@ bool CodedOutputStream::Refresh() {
}
}
size_t CodedOutputStream::VarintSize32Fallback(uint32 value) {
GOOGLE_DCHECK_NE(0, value); // This is enforced by our caller.
return 1 + Bits::Log2FloorNonZero(value) / 7;
}
size_t CodedOutputStream::VarintSize64(uint64 value) {
if (value < (1 << 7)) {
return 1;
}
return 1 + Bits::Log2FloorNonZero64(value) / 7;
}
uint8* CodedOutputStream::WriteStringWithSizeToArray(const string& str,
uint8* target) {
GOOGLE_DCHECK_LE(str.size(), kuint32max);
+145 -90
View File
@@ -110,6 +110,7 @@
#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
#include <assert.h>
#include <climits>
#include <string>
#include <utility>
#ifdef _MSC_VER
@@ -130,7 +131,10 @@
#define PROTOBUF_LITTLE_ENDIAN 1
#endif
#endif
#include <google/protobuf/stubs/atomicops.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/stubs/port.h>
namespace google {
@@ -139,6 +143,8 @@ namespace protobuf {
class DescriptorPool;
class MessageFactory;
namespace internal { void MapTestForceDeterministic(); }
namespace io {
// Defined in this file.
@@ -179,7 +185,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Skips a number of bytes. Returns false if an underlying read error
// occurs.
bool Skip(int count);
inline bool Skip(int count);
// Sets *data to point directly at the unread part of the CodedInputStream's
// underlying buffer, and *size to the size of that buffer, but does not
@@ -192,28 +198,23 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Like GetDirectBufferPointer, but this method is inlined, and does not
// attempt to Refresh() if the buffer is currently empty.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE void GetDirectBufferPointerInline(const void** data,
int* size);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
void GetDirectBufferPointerInline(const void** data, int* size);
// Read raw bytes, copying them into the given buffer.
bool ReadRaw(void* buffer, int size);
// Like the above, with inlined optimizations. This should only be used
// by the protobuf implementation.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InternalReadRawInline(void* buffer, int size);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
bool InternalReadRawInline(void* buffer, int size);
// Like ReadRaw, but reads into a string.
//
// Implementation Note: ReadString() grows the string gradually as it
// reads in the data, rather than allocating the entire requested size
// upfront. This prevents denial-of-service attacks in which a client
// could claim that a string is going to be MAX_INT bytes long in order to
// crash the server because it can't allocate this much space at once.
bool ReadString(string* buffer, int size);
// Like the above, with inlined optimizations. This should only be used
// by the protobuf implementation.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InternalReadStringInline(string* buffer,
int size);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
bool InternalReadStringInline(string* buffer, int size);
// Read a 32-bit little-endian integer.
@@ -249,12 +250,19 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
bool ReadVarintSizeAsInt(int* value);
// Read a tag. This calls ReadVarint32() and returns the result, or returns
// zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates
// the last tag value, which can be checked with LastTagWas().
// zero (which is not a valid tag) if ReadVarint32() fails. Also, ReadTag
// (but not ReadTagNoLastTag) updates the last tag value, which can be checked
// with LastTagWas().
//
// Always inline because this is only called in one place per parse loop
// but it is called for every iteration of said loop, so it should be fast.
// GCC doesn't want to inline this by default.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag();
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag() {
return last_tag_ = ReadTagNoLastTag();
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagNoLastTag();
// This usually a faster alternative to ReadTag() when cutoff is a manifest
// constant. It does particularly well for cutoff >= 127. The first part
@@ -264,8 +272,15 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// above cutoff or is 0. (There's intentional wiggle room when tag is 0,
// because that can arise in several ways, and for best performance we want
// to avoid an extra "is tag == 0?" check here.)
GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoff(
uint32 cutoff);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
std::pair<uint32, bool> ReadTagWithCutoff(uint32 cutoff) {
std::pair<uint32, bool> result = ReadTagWithCutoffNoLastTag(cutoff);
last_tag_ = result.first;
return result;
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
std::pair<uint32, bool> ReadTagWithCutoffNoLastTag(uint32 cutoff);
// Usually returns true if calling ReadVarint32() now would produce the given
// value. Will always return false if ReadVarint32() would not return the
@@ -274,7 +289,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// parameter.
// Always inline because this collapses to a small number of instructions
// when given a constant parameter, but GCC doesn't want to inline by default.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool ExpectTag(uint32 expected);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool ExpectTag(uint32 expected);
// Like above, except this reads from the specified buffer. The caller is
// responsible for ensuring that the buffer is large enough to read a varint
@@ -283,9 +298,8 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
//
// Returns a pointer beyond the expected tag if it was found, or NULL if it
// was not.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE static const uint8* ExpectTagFromArray(
const uint8* buffer,
uint32 expected);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
static const uint8* ExpectTagFromArray(const uint8* buffer, uint32 expected);
// Usually returns true if no more bytes can be read. Always returns false
// if more bytes can be read. If ExpectAtEnd() returns true, a subsequent
@@ -293,8 +307,10 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// zero, and ConsumedEntireMessage() will return true.
bool ExpectAtEnd();
// If the last call to ReadTag() or ReadTagWithCutoff() returned the
// given value, returns true. Otherwise, returns false;
// If the last call to ReadTag() or ReadTagWithCutoff() returned the given
// value, returns true. Otherwise, returns false.
// ReadTagNoLastTag/ReadTagWithCutoffNoLastTag do not preserve the last
// returned value.
//
// This is needed because parsers for some types of embedded messages
// (with field type TYPE_GROUP) don't actually know that they've reached the
@@ -303,6 +319,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// tag to make sure it had the right number, so it calls LastTagWas() on
// return from the embedded parser to check.
bool LastTagWas(uint32 expected);
void SetLastTag(uint32 tag) { last_tag_ = tag; }
// When parsing message (but NOT a group), this method must be called
// immediately after MergeFromCodedStream() returns (if it returns true)
@@ -360,11 +377,10 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// maximum message length should be limited to the shortest length that
// will not harm usability. The theoretical shortest message that could
// cause integer overflows is 512MB. The default limit is 64MB. Apps
// should set shorter limits if possible. If warning_threshold is not -1,
// a warning will be printed to stderr after warning_threshold bytes are
// read. For backwards compatibility all negative values get squashed to -1,
// as other negative values might have special internal meanings.
// An error will always be printed to stderr if the limit is reached.
// should set shorter limits if possible. For backwards compatibility all
// negative values get squashed to -1, as other negative values might have
// special internal meanings. An error will always be printed to stderr if
// the limit is reached.
//
// This is unrelated to PushLimit()/PopLimit().
//
@@ -380,9 +396,9 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Message::ParseFromString(). In this case, you will need to change
// your code to instead construct some sort of ZeroCopyInputStream
// (e.g. an ArrayInputStream), construct a CodedInputStream around
// that, then call Message::ParseFromCodedStream() instead. Then
// you can adjust the limit. Yes, it's more work, but you're doing
// something unusual.
// that, then you can adjust the limit. Then call
// Message::ParseFromCodedStream() instead. Yes, it's more work, but
// you're doing something unusual.
void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold);
// The Total Bytes Limit minus the Current Position, or -1 if there
@@ -557,12 +573,6 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// current_limit_. Set using SetTotalBytesLimit().
int total_bytes_limit_;
// If positive/0: Limit for bytes read after which a warning due to size
// should be logged.
// If -1: Printing of warning disabled. Can be set by client.
// If -2: Internal: Limit has been reached, print full size when destructing.
int total_bytes_warning_threshold_;
// Current recursion budget, controlled by IncrementRecursionDepth() and
// similar. Starts at recursion_limit_ and goes down: if this reaches
// -1 we are over budget.
@@ -570,12 +580,17 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Recursion depth limit, set by SetRecursionLimit().
int recursion_limit_;
bool disable_strict_correctness_enforcement_;
// See SetExtensionRegistry().
const DescriptorPool* extension_pool_;
MessageFactory* extension_factory_;
// Private member functions.
// Fallback when Skip() goes past the end of the current buffer.
bool SkipFallback(int count, int original_buffer_size);
// Advance the buffer by a given number of bytes.
void Advance(int amount);
@@ -612,6 +627,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
int ReadVarintSizeAsIntSlow();
bool ReadLittleEndian32Fallback(uint32* value);
bool ReadLittleEndian64Fallback(uint64* value);
// Fallback/slow methods for reading tags. These do not update last_tag_,
// but will set legitimate_message_end_ if we are at the end of the input
// stream.
@@ -622,9 +638,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Return the size of the buffer.
int BufferSize() const;
static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB
static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB
static const int kDefaultTotalBytesLimit = INT_MAX;
static int default_recursion_limit_; // 100 by default.
};
@@ -780,8 +794,8 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// but GCC by default doesn't want to inline this.
void WriteTag(uint32 value);
// Like WriteTag() but writing directly to the target array.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteTagToArray(uint32 value,
uint8* target);
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
static uint8* WriteTagToArray(uint32 value, uint8* target);
// Returns the number of bytes needed to encode the given value as a varint.
static size_t VarintSize32(uint32 value);
@@ -842,13 +856,17 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
serialization_deterministic_override_ = value;
}
// See above. Also, note that users of this CodedOutputStream may need to
// call IsSerializationDeterminstic() to serialize in the intended way. This
// call IsSerializationDeterministic() to serialize in the intended way. This
// CodedOutputStream cannot enforce a desire for deterministic serialization
// by itself.
bool IsSerializationDeterminstic() const {
bool IsSerializationDeterministic() const {
return serialization_deterministic_is_overridden_ ?
serialization_deterministic_override_ :
default_serialization_deterministic_;
IsDefaultSerializationDeterministic();
}
static bool IsDefaultSerializationDeterministic() {
return google::protobuf::internal::NoBarrier_Load(&default_serialization_deterministic_);
}
private:
@@ -863,7 +881,9 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// See SetSerializationDeterministic() regarding these three fields.
bool serialization_deterministic_is_overridden_;
bool serialization_deterministic_override_;
static bool default_serialization_deterministic_;
// Conceptually, default_serialization_deterministic_ is an atomic bool.
// TODO(haberman): replace with std::atomic<bool> when we move to C++11.
static google::protobuf::internal::AtomicWord default_serialization_deterministic_;
// Advance the buffer by a given number of bytes.
void Advance(int amount);
@@ -879,22 +899,18 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// If this write might cross the end of the buffer, we compose the bytes first
// then use WriteRaw().
void WriteVarint32SlowPath(uint32 value);
// Always-inlined versions of WriteVarint* functions so that code can be
// reused, while still controlling size. For instance, WriteVarint32ToArray()
// should not directly call this: since it is inlined itself, doing so
// would greatly increase the size of generated code. Instead, it should call
// WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already
// out-of-line, so it should just invoke this directly to avoid any extra
// function call overhead.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteVarint64ToArrayInline(
uint64 value, uint8* target);
static size_t VarintSize32Fallback(uint32 value);
void WriteVarint64SlowPath(uint64 value);
// See above. Other projects may use "friend" to allow them to call this.
// After SetDefaultSerializationDeterministic() completes, all protocol
// buffer serializations will be deterministic by default. Thread safe.
// However, the meaning of "after" is subtle here: to be safe, each thread
// that wants deterministic serialization by default needs to call
// SetDefaultSerializationDeterministic() or ensure on its own that another
// thread has done so.
friend void ::google::protobuf::internal::MapTestForceDeterministic();
static void SetDefaultSerializationDeterministic() {
default_serialization_deterministic_ = true;
google::protobuf::internal::NoBarrier_Store(&default_serialization_deterministic_, 1);
}
};
@@ -981,8 +997,7 @@ inline const uint8* CodedInputStream::ReadLittleEndian64FromArray(
inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {
#if defined(PROTOBUF_LITTLE_ENDIAN)
if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
memcpy(value, buffer_, sizeof(*value));
Advance(sizeof(*value));
buffer_ = ReadLittleEndian32FromArray(buffer_, value);
return true;
} else {
return ReadLittleEndian32Fallback(value);
@@ -995,8 +1010,7 @@ inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {
inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {
#if defined(PROTOBUF_LITTLE_ENDIAN)
if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
memcpy(value, buffer_, sizeof(*value));
Advance(sizeof(*value));
buffer_ = ReadLittleEndian64FromArray(buffer_, value);
return true;
} else {
return ReadLittleEndian64Fallback(value);
@@ -1006,21 +1020,20 @@ inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {
#endif
}
inline uint32 CodedInputStream::ReadTag() {
inline uint32 CodedInputStream::ReadTagNoLastTag() {
uint32 v = 0;
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) {
v = *buffer_;
if (v < 0x80) {
last_tag_ = v;
Advance(1);
return v;
}
}
last_tag_ = ReadTagFallback(v);
return last_tag_;
v = ReadTagFallback(v);
return v;
}
inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoffNoLastTag(
uint32 cutoff) {
// In performance-sensitive code we can expect cutoff to be a compile-time
// constant, and things like "cutoff >= kMax1ByteVarint" to be evaluated at
@@ -1033,7 +1046,7 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
first_byte_or_zero = buffer_[0];
if (static_cast<int8>(buffer_[0]) > 0) {
const uint32 kMax1ByteVarint = 0x7f;
uint32 tag = last_tag_ = buffer_[0];
uint32 tag = buffer_[0];
Advance(1);
return std::make_pair(tag, cutoff >= kMax1ByteVarint || tag <= cutoff);
}
@@ -1044,7 +1057,7 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
GOOGLE_PREDICT_TRUE(buffer_ + 1 < buffer_end_) &&
GOOGLE_PREDICT_TRUE((buffer_[0] & ~buffer_[1]) >= 0x80)) {
const uint32 kMax2ByteVarint = (0x7f << 7) + 0x7f;
uint32 tag = last_tag_ = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80);
uint32 tag = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80);
Advance(2);
// It might make sense to test for tag == 0 now, but it is so rare that
// that we don't bother. A varint-encoded 0 should be one byte unless
@@ -1057,8 +1070,8 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
}
}
// Slow path
last_tag_ = ReadTagFallback(first_byte_or_zero);
return std::make_pair(last_tag_, static_cast<uint32>(last_tag_ - 1) < cutoff);
const uint32 tag = ReadTagFallback(first_byte_or_zero);
return std::make_pair(tag, static_cast<uint32>(tag - 1) < cutoff);
}
inline bool CodedInputStream::LastTagWas(uint32 expected) {
@@ -1153,21 +1166,24 @@ inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value,
return target + 1;
}
inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) {
if (value < 0) {
WriteVarint64(static_cast<uint64>(value));
} else {
WriteVarint32(static_cast<uint32>(value));
inline uint8* CodedOutputStream::WriteVarint64ToArray(uint64 value,
uint8* target) {
while (value >= 0x80) {
*target = static_cast<uint8>(value | 0x80);
value >>= 7;
++target;
}
*target = static_cast<uint8>(value);
return target + 1;
}
inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) {
WriteVarint64(static_cast<uint64>(value));
}
inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray(
int32 value, uint8* target) {
if (value < 0) {
return WriteVarint64ToArray(static_cast<uint64>(value), target);
} else {
return WriteVarint32ToArray(static_cast<uint32>(value), target);
}
return WriteVarint64ToArray(static_cast<uint64>(value), target);
}
inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value,
@@ -1216,6 +1232,19 @@ inline void CodedOutputStream::WriteVarint32(uint32 value) {
}
}
inline void CodedOutputStream::WriteVarint64(uint64 value) {
if (buffer_size_ >= 10) {
// Fast path: We have enough bytes left in the buffer to guarantee that
// this write won't cross the end, so we can skip the checks.
uint8* target = buffer_;
uint8* end = WriteVarint64ToArray(value, target);
int size = static_cast<int>(end - target);
Advance(size);
} else {
WriteVarint64SlowPath(value);
}
}
inline void CodedOutputStream::WriteTag(uint32 value) {
WriteVarint32(value);
}
@@ -1226,11 +1255,23 @@ inline uint8* CodedOutputStream::WriteTagToArray(
}
inline size_t CodedOutputStream::VarintSize32(uint32 value) {
if (value < (1 << 7)) {
return 1;
} else {
return VarintSize32Fallback(value);
}
// This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1
// Use an explicit multiplication to implement the divide of
// a number in the 1..31 range.
// Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is
// undefined.
uint32 log2value = Bits::Log2FloorNonZero(value | 0x1);
return static_cast<size_t>((log2value * 9 + 73) / 64);
}
inline size_t CodedOutputStream::VarintSize64(uint64 value) {
// This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1
// Use an explicit multiplication to implement the divide of
// a number in the 1..63 range.
// Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is
// undefined.
uint32 log2value = Bits::Log2FloorNonZero64(value | 0x1);
return static_cast<size_t>((log2value * 9 + 73) / 64);
}
inline size_t CodedOutputStream::VarintSize32SignExtended(int32 value) {
@@ -1321,9 +1362,9 @@ inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input)
current_limit_(kint32max),
buffer_size_after_limit_(0),
total_bytes_limit_(kDefaultTotalBytesLimit),
total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
recursion_budget_(default_recursion_limit_),
recursion_limit_(default_recursion_limit_),
disable_strict_correctness_enforcement_(true),
extension_pool_(NULL),
extension_factory_(NULL) {
// Eagerly Refresh() so buffer space is immediately available.
@@ -1342,9 +1383,9 @@ inline CodedInputStream::CodedInputStream(const uint8* buffer, int size)
current_limit_(size),
buffer_size_after_limit_(0),
total_bytes_limit_(kDefaultTotalBytesLimit),
total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold),
recursion_budget_(default_recursion_limit_),
recursion_limit_(default_recursion_limit_),
disable_strict_correctness_enforcement_(true),
extension_pool_(NULL),
extension_factory_(NULL) {
// Note that setting current_limit_ == size is important to prevent some
@@ -1355,11 +1396,25 @@ inline bool CodedInputStream::IsFlat() const {
return input_ == NULL;
}
inline bool CodedInputStream::Skip(int count) {
if (count < 0) return false; // security: count is often user-supplied
const int original_buffer_size = BufferSize();
if (count <= original_buffer_size) {
// Just skipping within the current buffer. Easy.
Advance(count);
return true;
}
return SkipFallback(count, original_buffer_size);
}
} // namespace io
} // namespace protobuf
#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
#if defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
#pragma runtime_checks("c", restore)
#endif // _MSC_VER && !defined(__INTEL_COMPILER)
+1 -1
View File
@@ -168,7 +168,7 @@ void GzipInputStream::BackUp(int count) {
}
bool GzipInputStream::Skip(int count) {
const void* data;
int size;
int size = 0;
bool ok = Next(&data, &size);
while (ok && (size < count)) {
count -= size;
+46 -20
View File
@@ -70,8 +70,8 @@ Printer::~Printer() {
}
bool Printer::GetSubstitutionRange(const char* varname,
pair<size_t, size_t>* range) {
map<string, pair<size_t, size_t> >::const_iterator iter =
std::pair<size_t, size_t>* range) {
std::map<string, std::pair<size_t, size_t> >::const_iterator iter =
substitutions_.find(varname);
if (iter == substitutions_.end()) {
GOOGLE_LOG(DFATAL) << " Undefined variable in annotation: " << varname;
@@ -87,12 +87,12 @@ bool Printer::GetSubstitutionRange(const char* varname,
}
void Printer::Annotate(const char* begin_varname, const char* end_varname,
const string& file_path, const vector<int>& path) {
const string& file_path, const std::vector<int>& path) {
if (annotation_collector_ == NULL) {
// Can't generate signatures with this Printer.
return;
}
pair<size_t, size_t> begin, end;
std::pair<size_t, size_t> begin, end;
if (!GetSubstitutionRange(begin_varname, &begin) ||
!GetSubstitutionRange(end_varname, &end)) {
return;
@@ -106,10 +106,12 @@ void Printer::Annotate(const char* begin_varname, const char* end_varname,
}
}
void Printer::Print(const map<string, string>& variables, const char* text) {
void Printer::Print(const std::map<string, string>& variables,
const char* text) {
int size = strlen(text);
int pos = 0; // The number of bytes we've written so far.
substitutions_.clear();
line_start_variables_.clear();
for (int i = 0; i < size; i++) {
if (text[i] == '\n') {
@@ -121,6 +123,7 @@ void Printer::Print(const map<string, string>& variables, const char* text) {
// Setting this true will cause the next WriteRaw() to insert an indent
// first.
at_start_of_line_ = true;
line_start_variables_.clear();
} else if (text[i] == variable_delimiter_) {
// Saw the start of a variable name.
@@ -143,15 +146,19 @@ void Printer::Print(const map<string, string>& variables, const char* text) {
WriteRaw(&variable_delimiter_, 1);
} else {
// Replace with the variable's value.
map<string, string>::const_iterator iter = variables.find(varname);
std::map<string, string>::const_iterator iter = variables.find(varname);
if (iter == variables.end()) {
GOOGLE_LOG(DFATAL) << " Undefined variable: " << varname;
} else {
size_t begin = offset_;
if (at_start_of_line_ && iter->second.empty()) {
line_start_variables_.push_back(varname);
}
WriteRaw(iter->second.data(), iter->second.size());
pair<map<string, pair<size_t, size_t> >::iterator, bool> inserted =
substitutions_.insert(
std::make_pair(varname, std::make_pair(begin, offset_)));
std::pair<std::map<string, std::pair<size_t, size_t> >::iterator,
bool>
inserted = substitutions_.insert(std::make_pair(
varname,
std::make_pair(offset_ - iter->second.size(), offset_)));
if (!inserted.second) {
// This variable was used multiple times. Make its span have
// negative length so we can detect it if it gets used in an
@@ -172,13 +179,13 @@ void Printer::Print(const map<string, string>& variables, const char* text) {
}
void Printer::Print(const char* text) {
static map<string, string> empty;
static std::map<string, string> empty;
Print(empty, text);
}
void Printer::Print(const char* text,
const char* variable, const string& value) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable] = value;
Print(vars, text);
}
@@ -186,7 +193,7 @@ void Printer::Print(const char* text,
void Printer::Print(const char* text,
const char* variable1, const string& value1,
const char* variable2, const string& value2) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
Print(vars, text);
@@ -196,7 +203,7 @@ void Printer::Print(const char* text,
const char* variable1, const string& value1,
const char* variable2, const string& value2,
const char* variable3, const string& value3) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -208,7 +215,7 @@ void Printer::Print(const char* text,
const char* variable2, const string& value2,
const char* variable3, const string& value3,
const char* variable4, const string& value4) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -222,7 +229,7 @@ void Printer::Print(const char* text,
const char* variable3, const string& value3,
const char* variable4, const string& value4,
const char* variable5, const string& value5) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -238,7 +245,7 @@ void Printer::Print(const char* text,
const char* variable4, const string& value4,
const char* variable5, const string& value5,
const char* variable6, const string& value6) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -256,7 +263,7 @@ void Printer::Print(const char* text,
const char* variable5, const string& value5,
const char* variable6, const string& value6,
const char* variable7, const string& value7) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -276,7 +283,7 @@ void Printer::Print(const char* text,
const char* variable6, const string& value6,
const char* variable7, const string& value7,
const char* variable8, const string& value8) {
map<string, string> vars;
std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -317,10 +324,29 @@ void Printer::WriteRaw(const char* data, int size) {
if (at_start_of_line_ && (size > 0) && (data[0] != '\n')) {
// Insert an indent.
at_start_of_line_ = false;
WriteRaw(indent_.data(), indent_.size());
CopyToBuffer(indent_.data(), indent_.size());
if (failed_) return;
// Fix up empty variables (e.g., "{") that should be annotated as
// coming after the indent.
for (std::vector<string>::iterator i = line_start_variables_.begin();
i != line_start_variables_.end(); ++i) {
substitutions_[*i].first += indent_.size();
substitutions_[*i].second += indent_.size();
}
}
// If we're going to write any data, clear line_start_variables_, since
// we've either updated them in the block above or they no longer refer to
// the current line.
line_start_variables_.clear();
CopyToBuffer(data, size);
}
void Printer::CopyToBuffer(const char* data, int size) {
if (failed_) return;
if (size == 0) return;
while (size > buffer_size_) {
// Data exceeds space in the buffer. Copy what we can and request a
// new buffer.
+19 -9
View File
@@ -55,7 +55,7 @@ class LIBPROTOBUF_EXPORT AnnotationCollector {
// before end_offset are associated with the SourceCodeInfo-style path.
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
const string& file_path,
const vector<int>& path) = 0;
const std::vector<int>& path) = 0;
virtual ~AnnotationCollector() {}
};
@@ -73,7 +73,8 @@ class AnnotationProtoCollector : public AnnotationCollector {
// Override for AnnotationCollector::AddAnnotation.
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
const string& file_path, const vector<int>& path) {
const string& file_path,
const std::vector<int>& path) {
typename AnnotationProto::Annotation* annotation =
annotation_proto_->add_annotation();
for (int i = 0; i < path.size(); ++i) {
@@ -156,7 +157,7 @@ class AnnotationProtoCollector : public AnnotationCollector {
// vars["function"] = "call";
// vars["mark"] = "";
// printer.Print(vars, "$function$($foo$,$foo$)$mark$");
// printer.Annotate("function", "rmark", call_);
// printer.Annotate("function", "mark", call_);
//
// This code associates the span covering "call(bar,bar)" in the output with the
// call_ descriptor.
@@ -195,7 +196,7 @@ class LIBPROTOBUF_EXPORT Printer {
// of building the location path.
return;
}
vector<int> path;
std::vector<int> path;
descriptor->GetLocationPath(&path);
Annotate(begin_varname, end_varname, descriptor->file()->name(), path);
}
@@ -216,7 +217,7 @@ class LIBPROTOBUF_EXPORT Printer {
// Annotations aren't turned on for this Printer.
return;
}
vector<int> empty_path;
std::vector<int> empty_path;
Annotate(begin_varname, end_varname, file_name, empty_path);
}
@@ -225,7 +226,7 @@ class LIBPROTOBUF_EXPORT Printer {
// 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 map<string, string>& variables, const char* text);
void Print(const std::map<string, string>& variables, const char* text);
// Like the first Print(), except the substitutions are given as parameters.
void Print(const char* text);
@@ -308,7 +309,10 @@ class LIBPROTOBUF_EXPORT Printer {
// 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 string& file_path, const vector<int>& path);
const string& file_path, const std::vector<int>& path);
// Copy size worth of bytes from data to buffer_.
void CopyToBuffer(const char* data, int size);
const char variable_delimiter_;
@@ -331,13 +335,19 @@ class LIBPROTOBUF_EXPORT Printer {
// 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).
map<string, pair<size_t, size_t> > substitutions_;
std::map<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<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, pair<size_t, size_t>* range);
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.
+3 -3
View File
@@ -665,7 +665,7 @@ namespace {
class CommentCollector {
public:
CommentCollector(string* prev_trailing_comments,
vector<string>* detached_comments,
std::vector<string>* detached_comments,
string* next_leading_comments)
: prev_trailing_comments_(prev_trailing_comments),
detached_comments_(detached_comments),
@@ -737,7 +737,7 @@ class CommentCollector {
private:
string* prev_trailing_comments_;
vector<string>* detached_comments_;
std::vector<string>* detached_comments_;
string* next_leading_comments_;
string comment_buffer_;
@@ -757,7 +757,7 @@ class CommentCollector {
} // namespace
bool Tokenizer::NextWithComments(string* prev_trailing_comments,
vector<string>* detached_comments,
std::vector<string>* detached_comments,
string* next_leading_comments) {
CommentCollector collector(prev_trailing_comments, detached_comments,
next_leading_comments);
+1 -1
View File
@@ -191,7 +191,7 @@ class LIBPROTOBUF_EXPORT Tokenizer {
// * grault. */
// optional int32 grault = 6;
bool NextWithComments(string* prev_trailing_comments,
vector<string>* detached_comments,
std::vector<string>* detached_comments,
string* next_leading_comments);
// Parse helpers ---------------------------------------------------
@@ -41,9 +41,6 @@ namespace google {
namespace protobuf {
namespace io {
ZeroCopyInputStream::~ZeroCopyInputStream() {}
ZeroCopyOutputStream::~ZeroCopyOutputStream() {}
bool ZeroCopyOutputStream::WriteAliasedRaw(const void* /* data */,
int /* size */) {
@@ -123,8 +123,8 @@ class ZeroCopyOutputStream;
// copying.
class LIBPROTOBUF_EXPORT ZeroCopyInputStream {
public:
inline ZeroCopyInputStream() {}
virtual ~ZeroCopyInputStream();
ZeroCopyInputStream() {}
virtual ~ZeroCopyInputStream() {}
// Obtains a chunk of data from the stream.
//
@@ -180,8 +180,8 @@ class LIBPROTOBUF_EXPORT ZeroCopyInputStream {
// copying.
class LIBPROTOBUF_EXPORT ZeroCopyOutputStream {
public:
inline ZeroCopyOutputStream() {}
virtual ~ZeroCopyOutputStream();
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)
@@ -32,9 +32,7 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#ifdef _MSC_VER
#include <io.h>
#else
#ifndef _MSC_VER
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -43,11 +41,11 @@
#include <errno.h>
#include <iostream>
#include <algorithm>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/stl_util.h>
#include <google/protobuf/stubs/io_win32.h>
namespace google {
@@ -58,6 +56,13 @@ namespace io {
// Win32 lseek is broken: If invoked on a non-seekable file descriptor, its
// return value is undefined. We re-define it to always produce an error.
#define lseek(fd, offset, origin) ((off_t)-1)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
using google::protobuf::internal::win32::close;
using google::protobuf::internal::win32::open;
using google::protobuf::internal::win32::read;
using google::protobuf::internal::win32::write;
#endif
namespace {
@@ -81,8 +86,6 @@ FileInputStream::FileInputStream(int file_descriptor, int block_size)
impl_(&copying_input_, block_size) {
}
FileInputStream::~FileInputStream() {}
bool FileInputStream::Close() {
return copying_input_.Close();
}
@@ -270,12 +273,8 @@ bool FileOutputStream::CopyingFileOutputStream::Write(
// ===================================================================
IstreamInputStream::IstreamInputStream(istream* input, int block_size)
: copying_input_(input),
impl_(&copying_input_, block_size) {
}
IstreamInputStream::~IstreamInputStream() {}
IstreamInputStream::IstreamInputStream(std::istream* input, int block_size)
: copying_input_(input), impl_(&copying_input_, block_size) {}
bool IstreamInputStream::Next(const void** data, int* size) {
return impl_.Next(data, size);
@@ -294,9 +293,8 @@ int64 IstreamInputStream::ByteCount() const {
}
IstreamInputStream::CopyingIstreamInputStream::CopyingIstreamInputStream(
istream* input)
: input_(input) {
}
std::istream* input)
: input_(input) {}
IstreamInputStream::CopyingIstreamInputStream::~CopyingIstreamInputStream() {}
@@ -312,10 +310,8 @@ int IstreamInputStream::CopyingIstreamInputStream::Read(
// ===================================================================
OstreamOutputStream::OstreamOutputStream(ostream* output, int block_size)
: copying_output_(output),
impl_(&copying_output_, block_size) {
}
OstreamOutputStream::OstreamOutputStream(std::ostream* output, int block_size)
: copying_output_(output), impl_(&copying_output_, block_size) {}
OstreamOutputStream::~OstreamOutputStream() {
impl_.Flush();
@@ -334,9 +330,8 @@ int64 OstreamOutputStream::ByteCount() const {
}
OstreamOutputStream::CopyingOstreamOutputStream::CopyingOstreamOutputStream(
ostream* output)
: output_(output) {
}
std::ostream* output)
: output_(output) {}
OstreamOutputStream::CopyingOstreamOutputStream::~CopyingOstreamOutputStream() {
}
@@ -354,9 +349,6 @@ ConcatenatingInputStream::ConcatenatingInputStream(
: streams_(streams), stream_count_(count), bytes_retired_(0) {
}
ConcatenatingInputStream::~ConcatenatingInputStream() {
}
bool ConcatenatingInputStream::Next(const void** data, int* size) {
while (stream_count_ > 0) {
if (streams_[0]->Next(data, size)) return true;
@@ -67,7 +67,6 @@ class LIBPROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream {
// 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);
~FileInputStream();
// Flushes any buffers and closes the underlying file. Returns false if
// an error occurs during the process; use GetErrno() to examine the error.
@@ -219,7 +218,6 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream {
// 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);
~IstreamInputStream();
// implements ZeroCopyInputStream ----------------------------------
bool Next(const void** data, int* size);
@@ -306,7 +304,6 @@ class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream {
// 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();
// implements ZeroCopyInputStream ----------------------------------
bool Next(const void** data, int* size);
@@ -64,9 +64,6 @@ ArrayInputStream::ArrayInputStream(const void* data, int size,
last_returned_size_(0) {
}
ArrayInputStream::~ArrayInputStream() {
}
bool ArrayInputStream::Next(const void** data, int* size) {
if (position_ < size_) {
last_returned_size_ = std::min(block_size_, size_ - position_);
@@ -117,9 +114,6 @@ ArrayOutputStream::ArrayOutputStream(void* data, int size, int block_size)
last_returned_size_(0) {
}
ArrayOutputStream::~ArrayOutputStream() {
}
bool ArrayOutputStream::Next(void** data, int* size) {
if (position_ < size_) {
last_returned_size_ = std::min(block_size_, size_ - position_);
@@ -153,9 +147,6 @@ StringOutputStream::StringOutputStream(string* target)
: target_(target) {
}
StringOutputStream::~StringOutputStream() {
}
bool StringOutputStream::Next(void** data, int* size) {
GOOGLE_CHECK(target_ != NULL);
int old_size = target_->size();
@@ -205,32 +196,6 @@ void StringOutputStream::SetString(string* target) {
// ===================================================================
LazyStringOutputStream::LazyStringOutputStream(
ResultCallback<string*>* callback)
: StringOutputStream(NULL),
callback_(GOOGLE_CHECK_NOTNULL(callback)),
string_is_set_(false) {
}
LazyStringOutputStream::~LazyStringOutputStream() {
}
bool LazyStringOutputStream::Next(void** data, int* size) {
if (!string_is_set_) {
SetString(callback_->Run());
string_is_set_ = true;
}
return StringOutputStream::Next(data, size);
}
int64 LazyStringOutputStream::ByteCount() const {
return string_is_set_ ? StringOutputStream::ByteCount() : 0;
}
// ===================================================================
CopyingInputStream::~CopyingInputStream() {}
int CopyingInputStream::Skip(int count) {
char junk[4096];
int skipped = 0;
@@ -350,8 +315,6 @@ void CopyingInputStreamAdaptor::FreeBuffer() {
// ===================================================================
CopyingOutputStream::~CopyingOutputStream() {}
CopyingOutputStreamAdaptor::CopyingOutputStreamAdaptor(
CopyingOutputStream* copying_stream, int block_size)
: copying_stream_(copying_stream),
@@ -73,7 +73,6 @@ class LIBPROTOBUF_EXPORT ArrayInputStream : public ZeroCopyInputStream {
// useful for testing; in production you would probably never want to set
// it.
ArrayInputStream(const void* data, int size, int block_size = -1);
~ArrayInputStream();
// implements ZeroCopyInputStream ----------------------------------
bool Next(const void** data, int* size);
@@ -107,7 +106,6 @@ class LIBPROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream {
// useful for testing; in production you would probably never want to set
// it.
ArrayOutputStream(void* data, int size, int block_size = -1);
~ArrayOutputStream();
// implements ZeroCopyOutputStream ---------------------------------
bool Next(void** data, int* size);
@@ -141,7 +139,6 @@ class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream {
// the first call to Next() will return at least n bytes of buffer
// space.
explicit StringOutputStream(string* target);
~StringOutputStream();
// implements ZeroCopyOutputStream ---------------------------------
bool Next(void** data, int* size);
@@ -159,27 +156,6 @@ class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream);
};
// LazyStringOutputStream is a StringOutputStream with lazy acquisition of
// the output string from a callback. The string is owned externally, and not
// deleted in the stream destructor.
class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream {
public:
// Callback should be permanent (non-self-deleting). Ownership is transferred
// to the LazyStringOutputStream.
explicit LazyStringOutputStream(ResultCallback<string*>* callback);
~LazyStringOutputStream();
// implements ZeroCopyOutputStream, overriding StringOutputStream -----------
bool Next(void** data, int* size);
int64 ByteCount() const;
private:
const google::protobuf::scoped_ptr<ResultCallback<string*> > callback_;
bool string_is_set_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyStringOutputStream);
};
// Note: There is no StringInputStream. Instead, just create an
// ArrayInputStream as follows:
// ArrayInputStream input(str.data(), str.size());
@@ -199,7 +175,7 @@ class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream {
// in large blocks.
class LIBPROTOBUF_EXPORT CopyingInputStream {
public:
virtual ~CopyingInputStream();
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
@@ -293,7 +269,7 @@ class LIBPROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream
// in large blocks.
class LIBPROTOBUF_EXPORT CopyingOutputStream {
public:
virtual ~CopyingOutputStream();
virtual ~CopyingOutputStream() {}
// Writes "size" bytes from the given buffer to the output. Returns true
// if successful, false on a write error.
@@ -399,7 +375,7 @@ inline std::pair<char*, bool> as_string_data(string* s) {
#ifdef LANG_CXX11
return std::make_pair(p, true);
#else
return make_pair(p, p != NULL);
return std::make_pair(p, p != NULL);
#endif
}
File diff suppressed because it is too large Load Diff
+41 -211
View File
@@ -43,10 +43,9 @@ namespace google {
namespace protobuf {
class Arena;
namespace internal {
template <typename Key, typename Value,
template <typename Derived, typename Key, typename Value,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
class MapField;
}
}
@@ -54,30 +53,6 @@ class MapField;
namespace protobuf {
namespace internal {
// Register all MapEntry default instances so we can delete them in
// ShutdownProtobufLibrary().
void LIBPROTOBUF_EXPORT RegisterMapEntryDefaultInstance(
MessageLite* default_instance);
// This is the common base class for MapEntry. It is used by MapFieldBase in
// reflection api, in which the static type of key and value is unknown.
class LIBPROTOBUF_EXPORT MapEntryBase : public Message {
public:
::google::protobuf::Metadata GetMetadata() const {
::google::protobuf::Metadata metadata;
metadata.descriptor = descriptor_;
metadata.reflection = reflection_;
return metadata;
}
protected:
MapEntryBase() : descriptor_(NULL), reflection_(NULL) { }
virtual ~MapEntryBase() {}
const Descriptor* descriptor_;
const Reflection* reflection_;
};
// 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
@@ -105,202 +80,57 @@ class LIBPROTOBUF_EXPORT MapEntryBase : public Message {
// 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 Key, typename Value,
template <typename Derived, typename Key, typename Value,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
class MapEntry : public MapEntryBase {
// Provide utilities to parse/serialize key/value. Provide utilities to
// manipulate internal stored type.
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;
typedef MapTypeHandler<kValueFieldType, Value> ValueTypeHandler;
// 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;
// Abbreviation for MapEntry
typedef typename google::protobuf::internal::MapEntry<
Key, Value, kKeyFieldType, kValueFieldType, default_enum_value> EntryType;
// Abbreviation for MapEntryLite
typedef typename google::protobuf::internal::MapEntryLite<
Key, Value, kKeyFieldType, kValueFieldType, default_enum_value>
EntryLiteType;
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
class MapEntry
: public MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
kValueFieldType, default_enum_value> {
public:
~MapEntry() {
if (this == default_instance_) {
delete reflection_;
}
}
// accessors ======================================================
virtual inline const KeyMapEntryAccessorType& key() const {
return entry_lite_.key();
}
inline KeyMapEntryAccessorType* mutable_key() {
return entry_lite_.mutable_key();
}
virtual inline const ValueMapEntryAccessorType& value() const {
return entry_lite_.value();
}
inline ValueMapEntryAccessorType* mutable_value() {
return entry_lite_.mutable_value();
}
// implements Message =============================================
bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) {
return entry_lite_.MergePartialFromCodedStream(input);
}
size_t ByteSizeLong() const {
return entry_lite_.ByteSizeLong();
}
void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const {
entry_lite_.SerializeWithCachedSizes(output);
}
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(bool deterministic,
::google::protobuf::uint8* output) const {
return entry_lite_.InternalSerializeWithCachedSizesToArray(deterministic,
output);
}
int GetCachedSize() const {
return entry_lite_.GetCachedSize();
}
bool IsInitialized() const {
return entry_lite_.IsInitialized();
}
Message* New() const {
MapEntry* entry = new MapEntry;
entry->descriptor_ = descriptor_;
entry->reflection_ = reflection_;
entry->set_default_instance(default_instance_);
return entry;
}
Message* New(Arena* arena) const {
MapEntry* entry = Arena::CreateMessage<MapEntry>(arena);
entry->descriptor_ = descriptor_;
entry->reflection_ = reflection_;
entry->set_default_instance(default_instance_);
return entry;
}
int SpaceUsed() const {
int size = sizeof(MapEntry);
size += entry_lite_.SpaceUsed();
return size;
}
void CopyFrom(const ::google::protobuf::Message& from) {
Clear();
MergeFrom(from);
}
void MergeFrom(const ::google::protobuf::Message& from) {
GOOGLE_CHECK_NE(&from, this);
const MapEntry* source = dynamic_cast_if_available<const MapEntry*>(&from);
if (source == NULL) {
ReflectionOps::Merge(from, this);
} else {
MergeFrom(*source);
}
}
void CopyFrom(const MapEntry& from) {
Clear();
MergeFrom(from);
}
void MergeFrom(const MapEntry& from) {
entry_lite_.MergeFrom(from.entry_lite_);
}
void Clear() {
entry_lite_.Clear();
}
void InitAsDefaultInstance() {
entry_lite_.InitAsDefaultInstance();
}
Arena* GetArena() const {
return entry_lite_.GetArena();
}
// Create default MapEntry instance for given descriptor. Descriptor has to be
// given when creating default MapEntry instance because different map field
// may have the same type and MapEntry class. The given descriptor is needed
// to distinguish instances of the same MapEntry class.
static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) {
MapEntry* entry = new MapEntry;
const Reflection* reflection = new GeneratedMessageReflection(
descriptor, entry, offsets_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._has_bits_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _unknown_fields_), -1,
DescriptorPool::generated_pool(),
::google::protobuf::MessageFactory::generated_factory(),
sizeof(MapEntry),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metadata_));
entry->descriptor_ = descriptor;
entry->reflection_ = reflection;
entry->set_default_instance(entry);
entry->InitAsDefaultInstance();
RegisterMapEntryDefaultInstance(entry);
return entry;
}
private:
MapEntry()
: _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {}
MapEntry() : _internal_metadata_(NULL) {}
explicit MapEntry(Arena* arena)
: _internal_metadata_(arena),
default_instance_(NULL),
entry_lite_(arena) {}
inline Arena* GetArenaNoVirtual() const {
return entry_lite_.GetArenaNoVirtual();
}
void set_default_instance(MapEntry* default_instance) {
default_instance_ = default_instance;
entry_lite_.set_default_instance(&default_instance->entry_lite_);
}
static int offsets_[2];
UnknownFieldSet _unknown_fields_;
InternalMetadataWithArena _internal_metadata_;
MapEntry* default_instance_;
EntryLiteType entry_lite_;
friend class ::google::protobuf::Arena;
: MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
kValueFieldType, default_enum_value>(arena),
_internal_metadata_(arena) {}
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
template <typename K, typename V, WireFormatLite::FieldType k_wire_type,
WireFormatLite::FieldType, int default_enum>
InternalMetadataWithArena _internal_metadata_;
private:
friend class ::google::protobuf::Arena;
template <typename C, typename K, typename V,
WireFormatLite::FieldType k_wire_type, WireFormatLite::FieldType,
int default_enum>
friend class internal::MapField;
friend class internal::GeneratedMessageReflection;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry);
};
template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType,
// Specialization for the full runtime
template <typename Derived, typename Key, typename Value,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
int MapEntry<Key, Value, kKeyFieldType, kValueFieldType,
default_enum_value>::offsets_[2] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.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 const WireFormatLite::FieldType kKeyFieldType = key;
static const WireFormatLite::FieldType kValueFieldType = value;
static const int default_enum_value = default_enum;
};
} // namespace internal
+217 -119
View File
@@ -32,22 +32,23 @@
#define GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__
#include <assert.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/map.h>
#include <google/protobuf/map_type_handler.h>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
namespace protobuf {
class Arena;
namespace internal {
template <typename Key, typename Value,
template <typename Derived, typename Key, typename Value,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
class MapEntry;
template <typename Key, typename Value,
template <typename Derived, typename Key, typename Value,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
class MapFieldLite;
} // namespace internal
} // namespace protobuf
@@ -87,13 +88,14 @@ struct MoveHelper<false, false, true, T> { // strings and similar
}
};
// MapEntryLite is used to implement parsing and serialization of map for lite
// runtime.
template <typename Key, typename 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 MapEntryLite : public MessageLite {
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
class MapEntryImpl : public Base {
protected:
// Provide utilities to parse/serialize key/value. Provide utilities to
// manipulate internal stored type.
typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler;
@@ -122,12 +124,33 @@ class MapEntryLite : public MessageLite {
static const size_t kTagSize = 1;
public:
~MapEntryLite() {
if (this != default_instance_) {
if (GetArenaNoVirtual() != NULL) return;
KeyTypeHandler::DeleteNoArena(key_);
ValueTypeHandler::DeleteNoArena(value_);
}
// 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() : arena_(NULL) {
KeyTypeHandler::Initialize(&key_, NULL);
ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value,
NULL);
_has_bits_[0] = 0;
}
explicit MapEntryImpl(Arena* arena) : arena_(arena) {
KeyTypeHandler::Initialize(&key_, arena);
ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value,
arena);
_has_bits_[0] = 0;
}
~MapEntryImpl() {
if (GetArenaNoVirtual() != NULL) return;
KeyTypeHandler::DeleteNoArena(key_);
ValueTypeHandler::DeleteNoArena(value_);
}
// accessors ======================================================
@@ -136,9 +159,8 @@ class MapEntryLite : public MessageLite {
return KeyTypeHandler::GetExternalReference(key_);
}
virtual inline const ValueMapEntryAccessorType& value() const {
GOOGLE_CHECK(default_instance_ != NULL);
return ValueTypeHandler::DefaultIfNotInitialized(value_,
default_instance_->value_);
return ValueTypeHandler::DefaultIfNotInitialized(
value_, Derived::internal_default_instance()->value_);
}
inline KeyMapEntryAccessorType* mutable_key() {
set_has_key();
@@ -151,12 +173,12 @@ class MapEntryLite : public MessageLite {
// implements MessageLite =========================================
// MapEntryLite is for implementation only and this function isn't called
// MapEntryImpl is for implementation only and this function isn't called
// anywhere. Just provide a fake implementation here for MessageLite.
string GetTypeName() const { return ""; }
void CheckTypeAndMergeFrom(const MessageLite& other) {
MergeFrom(*::google::protobuf::down_cast<const MapEntryLite*>(&other));
MergeFromInternal(*::google::protobuf::down_cast<const Derived*>(&other));
}
bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) {
@@ -171,7 +193,7 @@ class MapEntryLite : public MessageLite {
// need to care whether the value is unknown enum;
// 4) missing key/value: missed key/value will have default value. caller
// should take this entry as if key/value is set to default value.
tag = input->ReadTag();
tag = input->ReadTagNoLastTag();
switch (tag) {
case kKeyTag:
if (!KeyTypeHandler::Read(input, mutable_key())) {
@@ -203,8 +225,10 @@ class MapEntryLite : public MessageLite {
size_t ByteSizeLong() const {
size_t size = 0;
size += has_key() ? kTagSize + KeyTypeHandler::ByteSize(key()) : 0;
size += has_value() ? kTagSize + ValueTypeHandler::ByteSize(value()) : 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;
}
@@ -221,44 +245,43 @@ class MapEntryLite : public MessageLite {
deterministic, output);
return output;
}
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
// Don't override SerializeWithCachedSizesToArray. Use MessageLite's.
int GetCachedSize() const {
int size = 0;
size += has_key()
? kTagSize + KeyTypeHandler::GetCachedSize(key())
? static_cast<int>(kTagSize) + KeyTypeHandler::GetCachedSize(key())
: 0;
size += has_value()
? kTagSize + ValueTypeHandler::GetCachedSize(
value())
? static_cast<int>(kTagSize) + ValueTypeHandler::GetCachedSize(value())
: 0;
return size;
}
bool IsInitialized() const { return ValueTypeHandler::IsInitialized(value_); }
MessageLite* New() const {
MapEntryLite* entry = new MapEntryLite;
entry->default_instance_ = default_instance_;
Base* New() const {
Derived* entry = new Derived;
return entry;
}
MessageLite* New(Arena* arena) const {
MapEntryLite* entry = Arena::CreateMessage<MapEntryLite>(arena);
entry->default_instance_ = default_instance_;
Base* New(Arena* arena) const {
Derived* entry = Arena::CreateMessage<Derived>(arena);
return entry;
}
int SpaceUsed() const {
int size = sizeof(MapEntryLite);
size += KeyTypeHandler::SpaceUsedInMapEntry(key_);
size += ValueTypeHandler::SpaceUsedInMapEntry(value_);
size_t SpaceUsedLong() const {
size_t size = sizeof(Derived);
size += KeyTypeHandler::SpaceUsedInMapEntryLong(key_);
size += ValueTypeHandler::SpaceUsedInMapEntryLong(value_);
return size;
}
void MergeFrom(const MapEntryLite& from) {
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_, GetArenaNoVirtual());
@@ -273,6 +296,7 @@ class MapEntryLite : public MessageLite {
}
}
public:
void Clear() {
KeyTypeHandler::Clear(&key_, GetArenaNoVirtual());
ValueTypeHandler::ClearMaybeByDefaultEnum(
@@ -281,33 +305,28 @@ class MapEntryLite : public MessageLite {
clear_has_value();
}
void InitAsDefaultInstance() {
KeyTypeHandler::AssignDefaultValue(&key_);
ValueTypeHandler::AssignDefaultValue(&value_);
static void InitAsDefaultInstance() {
Derived* d = const_cast<Derived*>(Derived::internal_default_instance());
KeyTypeHandler::AssignDefaultValue(&d->key_);
ValueTypeHandler::AssignDefaultValue(&d->value_);
}
Arena* GetArena() const {
return GetArenaNoVirtual();
}
// Create a MapEntryLite for given key and value from google::protobuf::Map in
// Create a MapEntryImpl for given key and value from google::protobuf::Map in
// serialization. This function is only called when value is enum. Enum is
// treated differently because its type in MapEntry is int and its type in
// google::protobuf::Map is enum. We cannot create a reference to int from an enum.
static MapEntryLite* EnumWrap(const Key& key, const Value value,
Arena* arena) {
return Arena::CreateMessage<MapEnumEntryWrapper<
Key, Value, kKeyFieldType, kValueFieldType, default_enum_value> >(
arena, key, value);
static Derived* EnumWrap(const Key& key, const Value value, Arena* arena) {
return Arena::CreateMessage<MapEnumEntryWrapper>(arena, key, value);
}
// Like above, but for all the other types. This avoids value copy to create
// MapEntryLite from google::protobuf::Map in serialization.
static MapEntryLite* Wrap(const Key& key, const Value& value, Arena* arena) {
return Arena::CreateMessage<MapEntryWrapper<Key, Value, kKeyFieldType,
kValueFieldType,
default_enum_value> >(
arena, key, value);
// MapEntryImpl from google::protobuf::Map in serialization.
static Derived* Wrap(const Key& key, const Value& value, Arena* arena) {
return Arena::CreateMessage<MapEntryWrapper>(arena, key, value);
}
// Parsing using MergePartialFromCodedStream, above, is not as
@@ -333,7 +352,7 @@ class MapEntryLite : public MessageLite {
int size;
input->GetDirectBufferPointerInline(&data, &size);
// We could use memcmp here, but we don't bother. The tag is one byte.
assert(kTagSize == 1);
GOOGLE_COMPILE_ASSERT(kTagSize == 1, tag_size_error);
if (size > 0 && *reinterpret_cast<const char*>(data) == kValueTag) {
typename Map::size_type size = map_->size();
value_ptr_ = &(*map_)[key_];
@@ -357,15 +376,17 @@ class MapEntryLite : public MessageLite {
entry_.reset(mf_->NewEntry());
*entry_->mutable_key() = key_;
if (!entry_->MergePartialFromCodedStream(input)) return false;
return UseKeyAndValueFromEntry();
const bool result = entry_->MergePartialFromCodedStream(input);
if (result) UseKeyAndValueFromEntry();
if (entry_->GetArena() != NULL) entry_.release();
return result;
}
const Key& key() const { return key_; }
const Value& value() const { return *value_ptr_; }
private:
bool UseKeyAndValueFromEntry() GOOGLE_ATTRIBUTE_COLD {
void UseKeyAndValueFromEntry() GOOGLE_PROTOBUF_ATTRIBUTE_COLD {
// 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
@@ -377,15 +398,13 @@ class MapEntryLite : public MessageLite {
ValueTypeHandler::kWireType ==
WireFormatLite::WIRETYPE_LENGTH_DELIMITED,
Value>::Move(entry_->mutable_value(), value_ptr_);
if (entry_->GetArena() != NULL) entry_.release();
return true;
}
// 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(::google::protobuf::io::CodedInputStream* input)
GOOGLE_ATTRIBUTE_COLD {
GOOGLE_PROTOBUF_ATTRIBUTE_COLD {
typedef MoveHelper<KeyTypeHandler::kIsEnum,
KeyTypeHandler::kIsMessage,
KeyTypeHandler::kWireType ==
@@ -400,16 +419,19 @@ class MapEntryLite : public MessageLite {
ValueMover::Move(value_ptr_, entry_->mutable_value());
map_->erase(key_);
KeyMover::Move(&key_, entry_->mutable_key());
if (!entry_->MergePartialFromCodedStream(input)) return false;
return UseKeyAndValueFromEntry();
const bool result = entry_->MergePartialFromCodedStream(input);
if (result) UseKeyAndValueFromEntry();
if (entry_->GetArena() != NULL) entry_.release();
return result;
}
MapField* const mf_;
Map* const map_;
Key key_;
Value* value_ptr_;
// On the fast path entry_ is not used.
google::protobuf::scoped_ptr<MapEntryLite> entry_;
// On the fast path entry_ is not used. And, when entry_ is used, it's set
// to mf_->NewEntry(), so in the arena case we must call entry_.release.
google::protobuf::scoped_ptr<MapEntryImpl> entry_;
};
protected:
@@ -431,21 +453,17 @@ class MapEntryLite : public MessageLite {
// involves copy of key and value to construct a MapEntry. In order to avoid
// this copy in constructing a MapEntry, we need the following class which
// only takes references of given key and value.
template <typename K, typename V, WireFormatLite::FieldType k_wire_type,
WireFormatLite::FieldType v_wire_type, int default_enum>
class MapEntryWrapper
: public MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> {
typedef MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> Base;
typedef typename Base::KeyMapEntryAccessorType KeyMapEntryAccessorType;
typedef typename Base::ValueMapEntryAccessorType ValueMapEntryAccessorType;
class MapEntryWrapper : public Derived {
typedef Derived BaseClass;
typedef typename BaseClass::KeyMapEntryAccessorType KeyMapEntryAccessorType;
typedef
typename BaseClass::ValueMapEntryAccessorType ValueMapEntryAccessorType;
public:
MapEntryWrapper(Arena* arena, const K& key, const V& value)
: MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum>(arena),
key_(key),
value_(value) {
Base::set_has_key();
Base::set_has_value();
MapEntryWrapper(Arena* arena, const Key& key, const Value& value)
: Derived(arena), key_(key), value_(value) {
BaseClass::set_has_key();
BaseClass::set_has_value();
}
inline const KeyMapEntryAccessorType& key() const { return key_; }
inline const ValueMapEntryAccessorType& value() const { return value_; }
@@ -465,21 +483,17 @@ class MapEntryLite : public MessageLite {
// initialize a reference to int with a reference to enum, compiler will
// generate a temporary int from enum and initialize the reference to int with
// the temporary.
template <typename K, typename V, WireFormatLite::FieldType k_wire_type,
WireFormatLite::FieldType v_wire_type, int default_enum>
class MapEnumEntryWrapper
: public MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> {
typedef MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> Base;
typedef typename Base::KeyMapEntryAccessorType KeyMapEntryAccessorType;
typedef typename Base::ValueMapEntryAccessorType ValueMapEntryAccessorType;
class MapEnumEntryWrapper : public Derived {
typedef Derived BaseClass;
typedef typename BaseClass::KeyMapEntryAccessorType KeyMapEntryAccessorType;
typedef
typename BaseClass::ValueMapEntryAccessorType ValueMapEntryAccessorType;
public:
MapEnumEntryWrapper(Arena* arena, const K& key, const V& value)
: MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum>(arena),
key_(key),
value_(value) {
Base::set_has_key();
Base::set_has_value();
MapEnumEntryWrapper(Arena* arena, const Key& key, const Value& value)
: Derived(arena), key_(key), value_(value) {
BaseClass::set_has_key();
BaseClass::set_has_value();
}
inline const KeyMapEntryAccessorType& key() const { return key_; }
inline const ValueMapEntryAccessorType& value() const { return value_; }
@@ -492,48 +506,62 @@ class MapEntryLite : public MessageLite {
typedef void DestructorSkippable_;
};
MapEntryLite() : default_instance_(NULL), arena_(NULL) {
KeyTypeHandler::Initialize(&key_, NULL);
ValueTypeHandler::InitializeMaybeByDefaultEnum(
&value_, default_enum_value, NULL);
_has_bits_[0] = 0;
}
explicit MapEntryLite(Arena* arena)
: default_instance_(NULL), arena_(arena) {
KeyTypeHandler::Initialize(&key_, arena);
ValueTypeHandler::InitializeMaybeByDefaultEnum(
&value_, default_enum_value, arena);
_has_bits_[0] = 0;
}
inline Arena* GetArenaNoVirtual() const {
return arena_;
}
void set_default_instance(MapEntryLite* default_instance) {
default_instance_ = default_instance;
}
MapEntryLite* default_instance_;
public: // Needed for constructing tables
KeyOnMemory key_;
ValueOnMemory value_;
Arena* arena_;
uint32 _has_bits_[1];
private:
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
template <typename K, typename V, WireFormatLite::FieldType,
template <typename C, typename K, typename V, WireFormatLite::FieldType,
WireFormatLite::FieldType, int>
friend class internal::MapEntry;
template <typename K, typename V, WireFormatLite::FieldType,
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) {}
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 =============================
@@ -561,6 +589,76 @@ template <typename T> struct CompareByDerefFirst {
}
};
// 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 string& x) {
ArenaStringPtr res;
*res.UnsafeRawStringPointer() = const_cast<string*>(&x);
return res;
}
};
template <>
struct FromHelper<WireFormatLite::TYPE_BYTES> {
static ArenaStringPtr From(const string& x) {
ArenaStringPtr res;
*res.UnsafeRawStringPointer() = const_cast<string*>(&x);
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 folowing 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
+21 -38
View File
@@ -37,31 +37,6 @@ namespace google {
namespace protobuf {
namespace internal {
ProtobufOnceType map_entry_default_instances_once_;
Mutex* map_entry_default_instances_mutex_;
vector<MessageLite*>* map_entry_default_instances_;
void DeleteMapEntryDefaultInstances() {
for (int i = 0; i < map_entry_default_instances_->size(); ++i) {
delete map_entry_default_instances_->at(i);
}
delete map_entry_default_instances_mutex_;
delete map_entry_default_instances_;
}
void InitMapEntryDefaultInstances() {
map_entry_default_instances_mutex_ = new Mutex();
map_entry_default_instances_ = new vector<MessageLite*>();
OnShutdown(&DeleteMapEntryDefaultInstances);
}
void RegisterMapEntryDefaultInstance(MessageLite* default_instance) {
::google::protobuf::GoogleOnceInit(&map_entry_default_instances_once_,
&InitMapEntryDefaultInstances);
MutexLock lock(map_entry_default_instances_mutex_);
map_entry_default_instances_->push_back(default_instance);
}
MapFieldBase::~MapFieldBase() {
if (repeated_field_ != NULL && arena_ == NULL) delete repeated_field_;
}
@@ -77,25 +52,26 @@ RepeatedPtrFieldBase* MapFieldBase::MutableRepeatedField() {
return repeated_field_;
}
int MapFieldBase::SpaceUsedExcludingSelf() const {
size_t MapFieldBase::SpaceUsedExcludingSelfLong() const {
mutex_.Lock();
int size = SpaceUsedExcludingSelfNoLock();
size_t size = SpaceUsedExcludingSelfNoLock();
mutex_.Unlock();
return size;
}
int MapFieldBase::SpaceUsedExcludingSelfNoLock() const {
size_t MapFieldBase::SpaceUsedExcludingSelfNoLock() const {
if (repeated_field_ != NULL) {
return repeated_field_->SpaceUsedExcludingSelf();
return repeated_field_->SpaceUsedExcludingSelfLong();
} else {
return 0;
}
}
void MapFieldBase::InitMetadataOnce() const {
GOOGLE_CHECK(entry_descriptor_ != NULL);
GOOGLE_CHECK(assign_descriptor_callback_ != NULL);
(*assign_descriptor_callback_)();
bool MapFieldBase::IsMapValid() const {
// "Acquire" insures the operation after SyncRepeatedFieldWithMap won't get
// executed before state_ is checked.
Atomic32 state = google::protobuf::internal::Acquire_Load(&state_);
return state != STATE_MODIFIED_REPEATED;
}
void MapFieldBase::SetMapDirty() { state_ = STATE_MODIFIED_MAP; }
@@ -390,6 +366,13 @@ void DynamicMapField::SyncMapWithRepeatedFieldNoLock() const {
GOOGLE_LOG(FATAL) << "Can't get here.";
break;
}
// Remove existing map value with same key.
Map<MapKey, MapValueRef>::iterator iter = map->find(map_key);
if (iter != map->end()) {
iter->second.DeleteData();
}
MapValueRef& map_val = (*map)[map_key];
map_val.SetType(val_des->cpp_type());
switch (val_des->cpp_type()) {
@@ -421,13 +404,13 @@ void DynamicMapField::SyncMapWithRepeatedFieldNoLock() const {
}
}
int DynamicMapField::SpaceUsedExcludingSelfNoLock() const {
int size = 0;
size_t DynamicMapField::SpaceUsedExcludingSelfNoLock() const {
size_t size = 0;
if (MapFieldBase::repeated_field_ != NULL) {
size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelf();
size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelfLong();
}
size += sizeof(map_);
int map_size = map_.size();
size_t map_size = map_.size();
if (map_size) {
Map<MapKey, MapValueRef>::const_iterator it = map_.begin();
size += sizeof(it->first) * map_size;
@@ -456,7 +439,7 @@ int DynamicMapField::SpaceUsedExcludingSelfNoLock() const {
case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: {
while (it != map_.end()) {
const Message& message = it->second.GetMessageValue();
size += message.GetReflection()->SpaceUsed(message);
size += message.GetReflection()->SpaceUsedLong(message);
++it;
}
break;
+501 -60
View File
@@ -36,6 +36,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/map_entry.h>
#include <google/protobuf/map_field_lite.h>
#include <google/protobuf/map_type_handler.h>
@@ -62,14 +63,10 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
MapFieldBase()
: arena_(NULL),
repeated_field_(NULL),
entry_descriptor_(NULL),
assign_descriptor_callback_(NULL),
state_(STATE_MODIFIED_MAP) {}
explicit MapFieldBase(Arena* arena)
: arena_(arena),
repeated_field_(NULL),
entry_descriptor_(NULL),
assign_descriptor_callback_(NULL),
state_(STATE_MODIFIED_MAP) {
// Mutex's destructor needs to be called explicitly to release resources
// acquired in its constructor.
@@ -89,6 +86,8 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
virtual bool ContainsMapKey(const MapKey& map_key) const = 0;
virtual bool InsertOrLookupMapValue(
const MapKey& map_key, MapValueRef* val) = 0;
// 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;
@@ -99,11 +98,15 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
// Returns the number of bytes used by the repeated field, excluding
// sizeof(*this)
int SpaceUsedExcludingSelf() const;
size_t SpaceUsedExcludingSelfLong() const;
int SpaceUsedExcludingSelf() const {
return internal::ToIntSize(SpaceUsedExcludingSelfLong());
}
protected:
// Gets the size of space used by map field.
virtual int SpaceUsedExcludingSelfNoLock() const;
virtual size_t SpaceUsedExcludingSelfNoLock() const;
// Synchronizes the content in Map to RepeatedPtrField if there is any change
// to Map after last synchronization.
@@ -124,9 +127,6 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
// Provides derived class the access to repeated field.
void* MutableRepeatedPtrField() const;
// Creates descriptor for only one time.
void InitMetadataOnce() const;
enum State {
STATE_MODIFIED_MAP = 0, // map has newly added data that has not been
// synchronized to repeated field
@@ -137,13 +137,6 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
Arena* arena_;
mutable RepeatedPtrField<Message>* repeated_field_;
// MapEntry can only be created from MapField. To create MapEntry, MapField
// needs to know its descriptor, because MapEntry is not generated class which
// cannot initialize its own descriptor by calling generated
// descriptor-assign-function. Thus, we need to register a callback to
// initialize MapEntry's descriptor.
const Descriptor** entry_descriptor_;
void (*assign_descriptor_callback_)();
mutable Mutex mutex_; // The thread to synchronize map and repeated field
// needs to get lock first;
@@ -177,6 +170,7 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
// 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
@@ -206,32 +200,31 @@ class TypeDefinedMapFieldBase : public MapFieldBase {
void IncreaseIterator(MapIterator* map_iter) const;
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 Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value = 0>
class MapField : public TypeDefinedMapFieldBase<Key, T>,
public MapFieldLite<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value> {
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 MapEntry<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>
EntryType;
typedef MapEntryLite<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value> EntryLiteType;
typedef Derived EntryType;
typedef MapEntryLite<Derived, Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>
EntryLiteType;
// Define abbreviation for parent MapFieldLite
typedef MapFieldLite<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value> MapFieldLiteType;
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 google::protobuf::Map's api and repeated field's api. For
@@ -241,58 +234,76 @@ class MapField : public TypeDefinedMapFieldBase<Key, T>,
typedef typename MapIf<kIsValueEnum, T, const T&>::type CastValueType;
public:
MapField();
explicit MapField(Arena* arena);
// MapField doesn't own the default_entry, which means default_entry must
// outlive the lifetime of MapField.
MapField(const Message* default_entry);
// For tests only.
MapField(Arena* arena, const Message* default_entry);
~MapField();
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;
bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val);
bool DeleteMapValue(const MapKey& map_key);
// Accessors
const Map<Key, T>& GetMap() const;
Map<Key, T>* MutableMap();
const Map<Key, T>& GetMap() const {
MapFieldBase::SyncMapWithRepeatedField();
return impl_.GetMap();
}
Map<Key, T>* MutableMap() {
MapFieldBase::SyncMapWithRepeatedField();
Map<Key, T>* result = impl_.MutableMap();
MapFieldBase::SetMapDirty();
return result;
}
// Convenient methods for generated message implementation.
int size() const;
void Clear();
void MergeFrom(const MapFieldLiteType& other);
void Swap(MapFieldLiteType* other);
void MergeFrom(const MapField& other);
void Swap(MapField* other);
// Allocates metadata only if this MapField is part of a generated message.
void SetEntryDescriptor(const Descriptor** descriptor);
void SetAssignDescriptorCallback(void (*callback)());
// 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);
}
private:
MapFieldLiteType impl_;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
// MapField needs MapEntry's default instance to create new MapEntry.
void InitDefaultEntryOnce() const;
// Manually set default entry instance. For test only.
void SetDefaultEntryOnce(const EntryType* default_entry) const;
// Convenient methods to get internal google::protobuf::Map
const Map<Key, T>& GetInternalMap() const;
Map<Key, T>* MutableInternalMap();
// Implements MapFieldBase
void SyncRepeatedFieldWithMapNoLock() const;
void SyncMapWithRepeatedFieldNoLock() const;
int SpaceUsedExcludingSelfNoLock() const;
size_t SpaceUsedExcludingSelfNoLock() const;
void SetMapIteratorValue(MapIterator* map_iter) const;
mutable const EntryType* default_entry_;
friend class ::google::protobuf::Arena;
friend class MapFieldStateTest; // For testing, it needs raw access to impl_
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapField);
};
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 LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase<MapKey, MapValueRef> {
@@ -318,12 +329,401 @@ class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase<MapKey,
// Implements MapFieldBase
void SyncRepeatedFieldWithMapNoLock() const;
void SyncMapWithRepeatedFieldNoLock() const;
int SpaceUsedExcludingSelfNoLock() const;
size_t SpaceUsedExcludingSelfNoLock() const;
void SetMapIteratorValue(MapIterator* map_iter) const;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMapField);
};
} // namespace internal
#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 LIBPROTOBUF_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) {
delete val_.string_value_;
}
}
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(const string& val) {
SetType(FieldDescriptor::CPPTYPE_STRING);
*val_.string_value_ = 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 string& GetStringValue() const {
TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING,
"MapKey::GetStringValue");
return *val_.string_value_;
}
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_ < *other.val_.string_value_;
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_ == *other.val_.string_value_;
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_ = *other.val_.string_value_;
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 MapIterator;
friend class internal::DynamicMapField;
union KeyValue {
KeyValue() {}
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) {
delete val_.string_value_;
}
type_ = type;
if (type_ == FieldDescriptor::CPPTYPE_STRING) {
val_.string_value_ = new string;
}
}
// type_ is 0 or a valid FieldDescriptor::CppType.
int type_;
};
// MapValueRef points to a map value.
class LIBPROTOBUF_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 string& value) {
TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING,
"MapValueRef::SetStringValue");
*reinterpret_cast<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 string& GetStringValue() const {
TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING,
"MapValueRef::GetStringValue");
return *reinterpret_cast<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 MapIterator;
friend class internal::GeneratedMessageReflection;
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 google::protobuf::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, 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_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapValueRef);
};
#undef TYPE_CHECK
class LIBPROTOBUF_EXPORT MapIterator {
public:
MapIterator(Message* message, const FieldDescriptor* field) {
@@ -341,6 +741,11 @@ class LIBPROTOBUF_EXPORT MapIterator {
~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);
}
@@ -373,7 +778,7 @@ class LIBPROTOBUF_EXPORT MapIterator {
template <typename Key, typename T>
friend class internal::TypeDefinedMapFieldBase;
friend class internal::DynamicMapField;
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
internal::WireFormatLite::FieldType kKeyFieldType,
internal::WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
@@ -392,6 +797,42 @@ class LIBPROTOBUF_EXPORT MapIterator {
};
} // namespace protobuf
} // namespace google
GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START
template<>
struct hash<google::protobuf::MapKey> {
size_t
operator()(const google::protobuf::MapKey& map_key) const {
switch (map_key.type()) {
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM:
case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE:
GOOGLE_LOG(FATAL) << "Unsupported";
break;
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
return hash<string>()(map_key.GetStringValue());
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
return hash< ::google::protobuf::int64>()(map_key.GetInt64Value());
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
return hash< ::google::protobuf::int32>()(map_key.GetInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value());
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
return hash<bool>()(map_key.GetBoolValue());
}
GOOGLE_LOG(FATAL) << "Can't get here.";
return 0;
}
bool
operator()(const google::protobuf::MapKey& map_key1,
const google::protobuf::MapKey& map_key2) const {
return map_key1 < map_key2;
}
};
GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END
#endif // GOOGLE_PROTOBUF_MAP_FIELD_H__
+80 -228
View File
@@ -162,81 +162,32 @@ void TypeDefinedMapFieldBase<Key, T>::CopyIterator(
// ----------------------------------------------------------------------
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
MapField<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>::MapField()
: default_entry_(NULL) {}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
MapField<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>::MapField(
Arena* arena)
: TypeDefinedMapFieldBase<Key, T>(arena),
MapFieldLite<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>(
arena),
default_entry_(NULL) {}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
MapField<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>::MapField(
const Message* default_entry)
: default_entry_(down_cast<const EntryType*>(default_entry)) {}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
MapField<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>::MapField(
Arena* arena, const Message* default_entry)
: TypeDefinedMapFieldBase<Key, T>(arena),
MapFieldLite<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>(
arena),
default_entry_(down_cast<const EntryType*>(default_entry)) {}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::~MapField() {}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
int
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::size() const {
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
int MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::size() const {
MapFieldBase::SyncMapWithRepeatedField();
return MapFieldLiteType::GetInternalMap().size();
return static_cast<int>(impl_.GetMap().size());
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::Clear() {
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::Clear() {
MapFieldBase::SyncMapWithRepeatedField();
MapFieldLiteType::MutableInternalMap()->clear();
impl_.MutableMap()->clear();
MapFieldBase::SetMapDirty();
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetMapIteratorValue(
MapIterator* map_iter) const {
const Map<Key, T>& map = GetMap();
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;
@@ -244,27 +195,23 @@ void MapField<Key, T, kKeyFieldType, kValueFieldType,
map_iter->value_.SetValue(&iter->second);
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
bool MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::ContainsMapKey(
const MapKey& map_key) const {
const Map<Key, T>& map = GetMap();
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 Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
bool MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::InsertOrLookupMapValue(
const MapKey& map_key,
MapValueRef* val) {
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();
@@ -280,158 +227,83 @@ bool MapField<Key, T, kKeyFieldType, kValueFieldType,
return false;
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
bool MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::DeleteMapValue(
const MapKey& map_key) {
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 Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
const Map<Key, T>&
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::GetMap() const {
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::MergeFrom(const MapField& other) {
MapFieldBase::SyncMapWithRepeatedField();
return MapFieldLiteType::GetInternalMap();
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
Map<Key, T>*
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::MutableMap() {
MapFieldBase::SyncMapWithRepeatedField();
Map<Key, T>* result = MapFieldLiteType::MutableInternalMap();
MapFieldBase::SetMapDirty();
return result;
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::MergeFrom(
const MapFieldLiteType& other) {
const MapField& down_other = down_cast<const MapField&>(other);
MapFieldBase::SyncMapWithRepeatedField();
down_other.SyncMapWithRepeatedField();
MapFieldLiteType::MergeFrom(other);
other.SyncMapWithRepeatedField();
impl_.MergeFrom(other.impl_);
MapFieldBase::SetMapDirty();
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::Swap(
MapFieldLiteType* other) {
MapField* down_other = down_cast<MapField*>(other);
std::swap(MapFieldBase::repeated_field_, down_other->repeated_field_);
MapFieldLiteType::Swap(other);
std::swap(MapFieldBase::state_, down_other->state_);
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
void MapField<Derived, Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::Swap(MapField* other) {
std::swap(this->MapFieldBase::repeated_field_, other->repeated_field_);
impl_.Swap(&other->impl_);
std::swap(this->MapFieldBase::state_, other->state_);
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetEntryDescriptor(
const Descriptor** descriptor) {
MapFieldBase::entry_descriptor_ = descriptor;
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetAssignDescriptorCallback(void (*callback)()) {
MapFieldBase::assign_descriptor_callback_ = callback;
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
const Map<Key, T>&
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::GetInternalMap() const {
return MapFieldLiteType::GetInternalMap();
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
Map<Key, T>*
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::MutableInternalMap() {
return MapFieldLiteType::MutableInternalMap();
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SyncRepeatedFieldWithMapNoLock() const {
if (MapFieldBase::repeated_field_ == NULL) {
if (MapFieldBase::arena_ == NULL) {
MapFieldBase::repeated_field_ = new RepeatedPtrField<Message>();
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 {
MapFieldBase::repeated_field_ =
this->MapFieldBase::repeated_field_ =
Arena::CreateMessage<RepeatedPtrField<Message> >(
MapFieldBase::arena_);
this->MapFieldBase::arena_);
}
}
const Map<Key, T>& map = GetInternalMap();
const Map<Key, T>& map = impl_.GetMap();
RepeatedPtrField<EntryType>* repeated_field =
reinterpret_cast<RepeatedPtrField<EntryType>*>(
MapFieldBase::repeated_field_);
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) {
InitDefaultEntryOnce();
GOOGLE_CHECK(default_entry_ != NULL);
EntryType* new_entry =
down_cast<EntryType*>(default_entry_->New(MapFieldBase::arena_));
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 Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SyncMapWithRepeatedFieldNoLock() const {
Map<Key, T>* map = const_cast<MapField*>(this)->MutableInternalMap();
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>*>(
MapFieldBase::repeated_field_);
GOOGLE_CHECK(MapFieldBase::repeated_field_ != NULL);
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) {
@@ -444,44 +316,24 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
}
}
template <typename Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
int
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SpaceUsedExcludingSelfNoLock() const {
int size = 0;
if (MapFieldBase::repeated_field_ != NULL) {
size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelf();
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)->MutableInternalMap();
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::SpaceUsedInMap(it->first);
size += ValueTypeHandler::SpaceUsedInMap(it->second);
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;
}
template <typename Key, typename T,
WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType,
int default_enum_value>
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::InitDefaultEntryOnce()
const {
if (default_entry_ == NULL) {
MapFieldBase::InitMetadataOnce();
GOOGLE_CHECK(*MapFieldBase::entry_descriptor_ != NULL);
default_entry_ = down_cast<const EntryType*>(
MessageFactory::generated_factory()->GetPrototype(
*MapFieldBase::entry_descriptor_));
}
}
} // namespace internal
} // namespace protobuf
+59 -194
View File
@@ -33,6 +33,7 @@
#include <google/protobuf/map.h>
#include <google/protobuf/map_entry_lite.h>
#include <google/protobuf/wire_format_lite.h>
namespace google {
namespace protobuf {
@@ -41,223 +42,72 @@ 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 Key, typename T,
template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value = 0>
WireFormatLite::FieldType value_wire_type, int default_enum_value = 0>
class MapFieldLite {
// Define message type for internal repeated field.
typedef MapEntryLite<Key, T, key_wire_type, value_wire_type,
default_enum_value> EntryType;
typedef Derived EntryType;
public:
MapFieldLite();
explicit MapFieldLite(Arena* arena);
virtual ~MapFieldLite();
typedef Map<Key, T> MapType;
typedef EntryType EntryTypeTrait;
MapFieldLite() : arena_(NULL) { SetDefaultEnumValue(); }
explicit MapFieldLite(Arena* arena) : arena_(arena), map_(arena) {
SetDefaultEnumValue();
}
// Accessors
virtual const Map<Key, T>& GetMap() const;
virtual Map<Key, T>* MutableMap();
const Map<Key, T>& GetMap() const { return map_; }
Map<Key, T>* MutableMap() { return &map_; }
// Convenient methods for generated message implementation.
virtual int size() const;
virtual void Clear();
virtual void MergeFrom(const MapFieldLite& other);
virtual void Swap(MapFieldLite* other);
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();
void SetDefaultEnumValue() {
MutableMap()->SetDefaultEnumValue(default_enum_value);
}
// Used in the implementation of parsing. Caller should take the ownership.
EntryType* NewEntry() const;
// Used in the implementation of parsing. Caller should take the ownership iff
// arena_ is NULL.
EntryType* NewEntry() const {
if (arena_ == NULL) {
return new EntryType();
} else {
return Arena::CreateMessage<EntryType>(arena_);
}
}
// Used in the implementation of serializing enum value type. Caller should
// take the ownership.
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const;
// take the ownership iff arena_ is NULL.
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const {
return EntryType::EnumWrap(key, t, arena_);
}
// Used in the implementation of serializing other value types. Caller should
// take the ownership.
EntryType* NewEntryWrapper(const Key& key, const T& t) const;
protected:
// Convenient methods to get internal google::protobuf::Map
virtual const Map<Key, T>& GetInternalMap() const;
virtual Map<Key, T>* MutableInternalMap();
// take the ownership iff arena_ is NULL.
EntryType* NewEntryWrapper(const Key& key, const T& t) const {
return EntryType::Wrap(key, t, arena_);
}
private:
typedef void DestructorSkippable_;
Arena* arena_;
Map<Key, T>* map_;
Map<Key, T> map_;
friend class ::google::protobuf::Arena;
};
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::MapFieldLite()
: arena_(NULL) {
map_ = new Map<Key, T>;
SetDefaultEnumValue();
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::MapFieldLite(Arena* arena)
: arena_(arena) {
map_ = Arena::CreateMessage<Map<Key, T> >(arena);
SetDefaultEnumValue();
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::~MapFieldLite() {
delete map_;
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
const Map<Key, T>&
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::GetMap() const {
return *map_;
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
Map<Key, T>*
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::MutableMap() {
return map_;
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
int
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::size() const {
return map_->size();
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
void
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::Clear() {
map_->clear();
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
void
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::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;
}
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
void
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::Swap(
MapFieldLite* other) {
std::swap(map_, other->map_);
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
void
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::SetDefaultEnumValue() {
MutableInternalMap()->SetDefaultEnumValue(default_enum_value);
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
const Map<Key, T>&
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::GetInternalMap() const {
return *map_;
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
Map<Key, T>*
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::MutableInternalMap() {
return map_;
}
#define EntryType \
MapEntryLite<Key, T, key_wire_type, value_wire_type, default_enum_value>
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
EntryType*
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::NewEntry() const {
if (arena_ == NULL) {
return new EntryType();
} else {
return Arena::CreateMessage<EntryType>(arena_);
}
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
EntryType*
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::NewEnumEntryWrapper(const Key& key,
const T t) const {
return EntryType::EnumWrap(key, t, arena_);
}
template <typename Key, typename T,
WireFormatLite::FieldType key_wire_type,
WireFormatLite::FieldType value_wire_type,
int default_enum_value>
EntryType*
MapFieldLite<Key, T, key_wire_type, value_wire_type,
default_enum_value>::NewEntryWrapper(const Key& key,
const T& t) const {
return EntryType::Wrap(key, t, arena_);
}
#undef EntryType
// 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.
@@ -271,6 +121,21 @@ bool AllAreInitialized(const Map<Key, T>& t) {
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
+73 -77
View File
@@ -32,7 +32,6 @@
#define GOOGLE_PROTOBUF_TYPE_HANDLER_H__
#include <google/protobuf/arena.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/wire_format_lite_inl.h>
namespace google {
@@ -73,7 +72,7 @@ class MapValueInitializer<true, Type> {
template <typename Type>
class MapValueInitializer<false, Type> {
public:
static inline void Initialize(Type& value, int default_enum_value) {}
static inline void Initialize(Type& /* value */, int /* default_enum_value */) {}
};
template <typename Type, bool is_arena_constructable>
@@ -186,9 +185,9 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> {
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 int SpaceUsedInMapEntry(const Type* value);
static inline size_t SpaceUsedInMapEntryLong(const Type* value);
// Return bytes used by value in Map.
static inline int SpaceUsedInMap(const Type& value);
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
@@ -224,9 +223,7 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> {
static inline void Write(int field, const MapEntryAccessorType& value, \
io::CodedOutputStream* output); \
static inline uint8* InternalWriteToArray( \
int field, \
const MapEntryAccessorType& value, \
bool deterministic, \
int field, const MapEntryAccessorType& value, bool deterministic, \
uint8* target); \
static inline uint8* WriteToArray(int field, \
const MapEntryAccessorType& value, \
@@ -242,9 +239,9 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> {
static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \
Arena* arena, \
int default_enum); \
static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \
static inline int SpaceUsedInMap(const TypeOnMemory& value); \
static inline int SpaceUsedInMap(const string& value); \
static inline size_t SpaceUsedInMapEntryLong(const TypeOnMemory& value); \
static inline size_t SpaceUsedInMapLong(const TypeOnMemory& value); \
static inline size_t SpaceUsedInMapLong(const string& value); \
static inline void AssignDefaultValue(TypeOnMemory* value); \
static inline const MapEntryAccessorType& DefaultIfNotInitialized( \
const TypeOnMemory& value, const TypeOnMemory& default_value); \
@@ -286,7 +283,7 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize(
template <typename Type> \
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \
const MapEntryAccessorType& value) { \
return WireFormatLite::DeclaredType##Size(value); \
return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \
}
GOOGLE_PROTOBUF_BYTE_SIZE(STRING, String)
@@ -304,7 +301,7 @@ GOOGLE_PROTOBUF_BYTE_SIZE(ENUM , Enum)
#define FIXED_BYTE_SIZE(FieldType, DeclaredType) \
template <typename Type> \
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \
const MapEntryAccessorType& value) { \
const MapEntryAccessorType& /* value */) { \
return WireFormatLite::k##DeclaredType##Size; \
}
@@ -322,7 +319,9 @@ template <typename Type>
inline int
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize(
const MapEntryAccessorType& value) {
return WireFormatLite::LengthDelimitedSize(value.GetCachedSize());
return static_cast<int>(
WireFormatLite::LengthDelimitedSize(
static_cast<size_t>(value.GetCachedSize())));
}
#define GET_CACHED_SIZE(FieldType, DeclaredType) \
@@ -330,7 +329,7 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize(
inline int \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \
const MapEntryAccessorType& value) { \
return WireFormatLite::DeclaredType##Size(value); \
return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \
}
GET_CACHED_SIZE(STRING, String)
@@ -349,7 +348,7 @@ GET_CACHED_SIZE(ENUM , Enum)
template <typename Type> \
inline int \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \
const MapEntryAccessorType& value) { \
const MapEntryAccessorType& /* value */) { \
return WireFormatLite::k##DeclaredType##Size; \
}
@@ -467,34 +466,33 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
}
template <typename Type>
inline int
MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::SpaceUsedInMapEntry(const Type* value) {
return value->SpaceUsed();
inline size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::SpaceUsedInMapEntryLong(const Type* value) {
return value->SpaceUsedLong();
}
template <typename Type>
int MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::SpaceUsedInMap(
size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::SpaceUsedInMapLong(
const Type& value) {
return value.SpaceUsed();
return value.SpaceUsedLong();
}
template <typename Type>
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Clear(
Type** value, Arena* arena) {
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) {
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) {
const Type& from, Type** to, Arena* /* arena */) {
(*to)->MergeFrom(from);
}
@@ -507,20 +505,20 @@ void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::DeleteNoArena(
template <typename Type>
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::AssignDefaultValue(Type** value) {
*value = const_cast<Type*>(&Type::default_instance());
*value = const_cast<Type*>(Type::internal_default_instance());
}
template <typename Type>
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::Initialize(Type** x,
Arena* arena) {
Arena* /* arena */) {
*x = NULL;
}
template <typename Type>
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::
InitializeMaybeByDefaultEnum(Type** x, int default_enum_value,
Arena* arena) {
InitializeMaybeByDefaultEnum(Type** x, int /* default_enum_value */,
Arena* /* arena */) {
*x = NULL;
}
@@ -556,22 +554,24 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::MapEntryAccessorType& \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::GetExternalReference(const TypeOnMemory& value) { \
return value.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \
return value.Get(); \
} \
template <typename Type> \
inline int \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \
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 int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::SpaceUsedInMap(const TypeOnMemory& value) { \
return sizeof(value); \
} \
template <typename Type> \
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::SpaceUsedInMap(const string& value) { \
inline size_t \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \
const string& value) { \
return sizeof(value); \
} \
template <typename Type> \
@@ -581,11 +581,9 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
arena); \
} \
template <typename Type> \
inline void \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \
Arena* arena, \
int default_enum) { \
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \
int /* default_enum */) { \
Clear(value, arena); \
} \
template <typename Type> \
@@ -600,20 +598,19 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
} \
template <typename Type> \
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::AssignDefaultValue(TypeOnMemory* value) {} \
Type>::AssignDefaultValue(TypeOnMemory* /* value */) {} \
template <typename Type> \
inline void \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \
TypeOnMemory* value, Arena* arena) { \
TypeOnMemory* value, Arena* /* arena */) { \
value->UnsafeSetDefault( \
&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \
} \
template <typename Type> \
inline void \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \
int default_enum_value, \
Arena* arena) { \
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
InitializeMaybeByDefaultEnum(TypeOnMemory* value, \
int /* default_enum_value */, \
Arena* arena) { \
Initialize(value, arena); \
} \
template <typename Type> \
@@ -630,12 +627,12 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \
const TypeOnMemory& \
default_value) { \
return value.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \
/* default_value */) { \
return value.Get(); \
} \
template <typename Type> \
inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::IsInitialized(const TypeOnMemory& value) { \
Type>::IsInitialized(const TypeOnMemory& /* value */) { \
return true; \
}
STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING)
@@ -651,59 +648,58 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES)
return value; \
} \
template <typename Type> \
inline int \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \
const TypeOnMemory& value) { \
inline size_t \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::SpaceUsedInMapEntryLong(const TypeOnMemory& /* value */) { \
return 0; \
} \
template <typename Type> \
inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::SpaceUsedInMap(const TypeOnMemory& value) { \
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) { \
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) { \
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) { \
const MapEntryAccessorType& from, TypeOnMemory* to, \
Arena* /* arena */) { \
*to = from; \
} \
template <typename Type> \
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::DeleteNoArena(TypeOnMemory& x) {} \
Type>::DeleteNoArena(TypeOnMemory& /* x */) {} \
template <typename Type> \
inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::AssignDefaultValue(TypeOnMemory* value) {} \
Type>::AssignDefaultValue(TypeOnMemory* /* value */) {} \
template <typename Type> \
inline void \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \
TypeOnMemory* value, Arena* arena) { \
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) { \
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) { \
TypeOnMemory* value, Arena* /* arena */) { \
return value; \
} \
template <typename Type> \
@@ -712,12 +708,12 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES)
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \
const TypeOnMemory& \
default_value) { \
/* default_value */) { \
return value; \
} \
template <typename Type> \
inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::IsInitialized(const TypeOnMemory& value) { \
Type>::IsInitialized(const TypeOnMemory& /* value */) { \
return true; \
}
PRIMITIVE_HANDLER_FUNCTIONS(INT64)
+30 -52
View File
@@ -96,12 +96,12 @@ bool Message::IsInitialized() const {
return ReflectionOps::IsInitialized(*this);
}
void Message::FindInitializationErrors(vector<string>* errors) const {
void Message::FindInitializationErrors(std::vector<string>* errors) const {
return ReflectionOps::FindInitializationErrors(*this, "", errors);
}
string Message::InitializationErrorString() const {
vector<string> errors;
std::vector<string> errors;
FindInitializationErrors(&errors);
return Join(errors, ", ");
}
@@ -130,12 +130,12 @@ bool Message::ParsePartialFromFileDescriptor(int file_descriptor) {
return ParsePartialFromZeroCopyStream(&input) && input.GetErrno() == 0;
}
bool Message::ParseFromIstream(istream* input) {
bool Message::ParseFromIstream(std::istream* input) {
io::IstreamInputStream zero_copy_input(input);
return ParseFromZeroCopyStream(&zero_copy_input) && input->eof();
}
bool Message::ParsePartialFromIstream(istream* input) {
bool Message::ParsePartialFromIstream(std::istream* input) {
io::IstreamInputStream zero_copy_input(input);
return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();
}
@@ -143,7 +143,13 @@ bool Message::ParsePartialFromIstream(istream* input) {
void Message::SerializeWithCachedSizes(
io::CodedOutputStream* output) const {
WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output);
const internal::SerializationTable* table =
static_cast<const internal::SerializationTable*>(InternalGetTable());
if (table == 0) {
WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output);
} else {
internal::TableSerialize(*this, table, output);
}
}
size_t Message::ByteSizeLong() const {
@@ -158,21 +164,21 @@ void Message::SetCachedSize(int /* size */) const {
"Must implement one or the other.";
}
int Message::SpaceUsed() const {
return GetReflection()->SpaceUsed(*this);
size_t Message::SpaceUsedLong() const {
return GetReflection()->SpaceUsedLong(*this);
}
bool Message::SerializeToFileDescriptor(int file_descriptor) const {
io::FileOutputStream output(file_descriptor);
return SerializeToZeroCopyStream(&output);
return SerializeToZeroCopyStream(&output) && output.Flush();
}
bool Message::SerializePartialToFileDescriptor(int file_descriptor) const {
io::FileOutputStream output(file_descriptor);
return SerializePartialToZeroCopyStream(&output);
return SerializePartialToZeroCopyStream(&output) && output.Flush();
}
bool Message::SerializeToOstream(ostream* output) const {
bool Message::SerializeToOstream(std::ostream* output) const {
{
io::OstreamOutputStream zero_copy_output(output);
if (!SerializeToZeroCopyStream(&zero_copy_output)) return false;
@@ -180,7 +186,7 @@ bool Message::SerializeToOstream(ostream* output) const {
return output->good();
}
bool Message::SerializePartialToOstream(ostream* output) const {
bool Message::SerializePartialToOstream(std::ostream* output) const {
io::OstreamOutputStream zero_copy_output(output);
return SerializePartialToZeroCopyStream(&zero_copy_output);
}
@@ -191,6 +197,10 @@ bool Message::SerializePartialToOstream(ostream* output) const {
Reflection::~Reflection() {}
void Reflection::AddAllocatedMessage(Message* /* message */,
const FieldDescriptor* /*field */,
Message* /* new_entry */) const {}
#define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \
template<> \
const RepeatedField<TYPE>& Reflection::GetRepeatedField<TYPE>( \
@@ -225,38 +235,6 @@ void* Reflection::MutableRawRepeatedString(
}
// Default EnumValue API implementations. Real reflection implementations should
// override these. However, there are several legacy implementations that do
// not, and cannot easily be changed at the same time as the Reflection API, so
// we provide these for now.
// TODO: Remove these once all Reflection implementations are updated.
int Reflection::GetEnumValue(const Message& message,
const FieldDescriptor* field) const {
GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
return 0;
}
void Reflection::SetEnumValue(Message* message,
const FieldDescriptor* field,
int value) const {
GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
}
int Reflection::GetRepeatedEnumValue(
const Message& message,
const FieldDescriptor* field, int index) const {
GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
return 0;
}
void Reflection::SetRepeatedEnumValue(Message* message,
const FieldDescriptor* field, int index,
int value) const {
GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
}
void Reflection::AddEnumValue(Message* message,
const FieldDescriptor* field,
int value) const {
GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
}
MapIterator Reflection::MapBegin(
Message* message,
const FieldDescriptor* field) const {
@@ -483,27 +461,27 @@ struct ShutdownRepeatedFieldRegister {
namespace internal {
template<>
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
GOOGLE_ATTRIBUTE_NOINLINE
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
#endif
Message* GenericTypeHandler<Message>::NewFromPrototype(
const Message* prototype, google::protobuf::Arena* arena) {
return prototype->New(arena);
}
template<>
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
GOOGLE_ATTRIBUTE_NOINLINE
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
#endif
google::protobuf::Arena* GenericTypeHandler<Message>::GetArena(
Message* value) {
return value->GetArena();
}
template<>
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
GOOGLE_ATTRIBUTE_NOINLINE
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
#endif
void* GenericTypeHandler<Message>::GetMaybeArenaPointer(
Message* value) {
+63 -43
View File
@@ -154,6 +154,13 @@ class MapReflectionFriend; // scalar_map_container.h
}
namespace internal {
class ReflectionOps; // reflection_ops.h
class MapKeySorter; // wire_format.cc
class WireFormat; // wire_format.h
class MapFieldReflectionTest; // map_test.cc
}
template<typename T>
class RepeatedField; // repeated_field.h
@@ -245,7 +252,10 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// using reflection (rather than the generated code implementation for
// ByteSize()). Like ByteSize(), its CPU time is linear in the number of
// fields defined for the proto.
virtual int SpaceUsed() const;
virtual size_t SpaceUsedLong() const;
PROTOBUF_RUNTIME_DEPRECATED("Please use SpaceUsedLong() instead")
int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); }
// Debugging & Testing----------------------------------------------
@@ -317,18 +327,19 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite {
// Typedef for backwards-compatibility.
typedef google::protobuf::Reflection Reflection;
// Get a Descriptor for this message's type. This describes what
// fields the message contains, the types of those fields, etc.
// Get a non-owning pointer to a Descriptor for this message's type. This
// describes what fields the message contains, the types of those fields, etc.
// This object remains property of the Message.
const Descriptor* GetDescriptor() const { return GetMetadata().descriptor; }
// Get the Reflection interface for this Message, which can be used to
// read and modify the fields of the Message dynamically (in other words,
// without knowing the message type at compile time). This object remains
// property of the Message.
// Get a non-owning pointer to the Reflection interface for this Message,
// which can be used to read and modify the fields of the Message dynamically
// (in other words, without knowing the message type at compile time). This
// object remains property of the Message.
//
// This method remains virtual in case a subclass does not implement
// reflection and wants to override the default behavior.
virtual const Reflection* GetReflection() const {
virtual const Reflection* GetReflection() const PROTOBUF_FINAL {
return GetMetadata().reflection;
}
@@ -417,7 +428,12 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0;
// Estimate the amount of memory used by the message object.
virtual int SpaceUsed(const Message& message) const = 0;
virtual size_t SpaceUsedLong(const Message& message) const = 0;
PROTOBUF_RUNTIME_DEPRECATED("Please use SpaceUsedLong() instead")
int SpaceUsed(const Message& message) const {
return internal::ToIntSize(SpaceUsedLong(message));
}
// Check if the given non-repeated field is set.
virtual bool HasField(const Message& message,
@@ -481,11 +497,14 @@ class LIBPROTOBUF_EXPORT Reflection {
int index1,
int index2) const = 0;
// List all fields of the message which are currently set. This includes
// extensions. Singular fields will only be listed if HasField(field) would
// return true and repeated fields will only be listed if FieldSize(field)
// would return non-zero. Fields (both normal fields and extension fields)
// will be listed ordered by field number.
// List all fields of the message which are currently set, except for unknown
// fields, but including extension known to the parser (i.e. compiled in).
// Singular fields will only be listed if HasField(field) would return true
// and repeated fields will only be listed if FieldSize(field) would return
// non-zero. Fields (both normal fields and extension fields) will be listed
// ordered by field number.
// Use Reflection::GetUnknownFields() or message.unknown_fields() to also get
// access to fields/extensions unknown to the parser.
virtual void ListFields(
const Message& message,
std::vector<const FieldDescriptor*>* output) const = 0;
@@ -519,7 +538,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// will only be present when the new unknown-enum-value semantics are enabled
// for a message.)
virtual int GetEnumValue(
const Message& message, const FieldDescriptor* field) const;
const Message& message, const FieldDescriptor* field) const = 0;
// See MutableMessage() for the meaning of the "factory" parameter.
virtual const Message& GetMessage(const Message& message,
@@ -575,7 +594,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// messages with new unknown-enum-value semantics.
virtual void SetEnumValue(Message* message,
const FieldDescriptor* field,
int value) const;
int value) const = 0;
// Get a mutable pointer to a field with a message type. If a MessageFactory
// is provided, it will be used to construct instances of the sub-message;
@@ -646,7 +665,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// for a message.)
virtual int GetRepeatedEnumValue(
const Message& message,
const FieldDescriptor* field, int index) const;
const FieldDescriptor* field, int index) const = 0;
virtual const Message& GetRepeatedMessage(
const Message& message,
const FieldDescriptor* field, int index) const = 0;
@@ -693,7 +712,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// messages with new unknown-enum-value semantics.
virtual void SetRepeatedEnumValue(Message* message,
const FieldDescriptor* field, int index,
int value) const;
int value) const = 0;
// Get a mutable pointer to an element of a repeated field with a message
// type.
virtual Message* MutableRepeatedMessage(
@@ -729,7 +748,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// messages with new unknown-enum-value semantics.
virtual void AddEnumValue(Message* message,
const FieldDescriptor* field,
int value) const;
int value) const = 0;
// See MutableMessage() for comments on the "factory" parameter.
virtual Message* AddMessage(Message* message,
const FieldDescriptor* field,
@@ -739,9 +758,9 @@ class LIBPROTOBUF_EXPORT Reflection {
// specifyed by 'field' passing ownership to the message.
// TODO(tmarek): Make virtual after all subclasses have been
// updated.
virtual void AddAllocatedMessage(Message* /* message */,
const FieldDescriptor* /*field */,
Message* /* new_entry */) const {}
virtual void AddAllocatedMessage(Message* message,
const FieldDescriptor* field,
Message* new_entry) const;
// Get a RepeatedFieldRef object that can be used to read the underlying
@@ -848,34 +867,31 @@ class LIBPROTOBUF_EXPORT Reflection {
// downgrade to a compatible value or use the UnknownFieldSet if not. For
// example:
//
// int new_value = GetValueFromApplicationLogic();
// if (reflection->SupportsUnknownEnumValues()) {
// int new_value = GetValueFromApplicationLogic();
// if (reflection->SupportsUnknownEnumValues()) {
// reflection->SetEnumValue(message, field, new_value);
// } else {
// } else {
// if (field_descriptor->enum_type()->
// FindValueByNumver(new_value) != NULL) {
// reflection->SetEnumValue(message, field, new_value);
// FindValueByNumber(new_value) != NULL) {
// reflection->SetEnumValue(message, field, new_value);
// } else if (emit_unknown_enum_values) {
// reflection->MutableUnknownFields(message)->AddVarint(
// field->number(),
// new_value);
// reflection->MutableUnknownFields(message)->AddVarint(
// field->number(), new_value);
// } else {
// // convert value to a compatible/default value.
// new_value = CompatibleDowngrade(new_value);
// reflection->SetEnumValue(message, field, new_value);
// // convert value to a compatible/default value.
// new_value = CompatibleDowngrade(new_value);
// reflection->SetEnumValue(message, field, new_value);
// }
// }
// }
virtual bool SupportsUnknownEnumValues() const { return false; }
// Returns the MessageFactory associated with this message. This can be
// useful for determining if a message is a generated message or not, for
// example:
//
// if (message->GetReflection()->GetMessageFactory() ==
// google::protobuf::MessageFactory::generated_factory()) {
// // This is a generated message.
// }
//
// if (message->GetReflection()->GetMessageFactory() ==
// google::protobuf::MessageFactory::generated_factory()) {
// // This is a generated message.
// }
// It can also be used to create more messages of this type, though
// Message::New() is an easier way to accomplish this.
virtual MessageFactory* GetMessageFactory() const;
@@ -910,7 +926,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// Returns a raw pointer to the repeated field
//
// "cpp_type" and "message_type" are decuded from the type parameter T passed
// "cpp_type" and "message_type" are deduced from the type parameter T passed
// to Get(Mutable)RepeatedFieldRef. If T is a generated message type,
// "message_type" should be set to its descriptor. Otherwise "message_type"
// should be set to NULL. Implementations of this method should check whether
@@ -933,6 +949,10 @@ class LIBPROTOBUF_EXPORT Reflection {
template<typename T, typename Enable>
friend class MutableRepeatedFieldRef;
friend class ::google::protobuf::python::MapReflectionFriend;
friend class internal::MapFieldReflectionTest;
friend class internal::MapKeySorter;
friend class internal::WireFormat;
friend class internal::ReflectionOps;
// Special version for specialized implementations of string. We can't call
// MutableRawRepeatedField directly here because we don't have access to
@@ -947,7 +967,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// TODO(jieluo) - make the map APIs pure virtual after updating
// all the subclasses.
// Returns true if key is in map. Returns false if key is not in map field.
virtual bool ContainsMapKey(const Message& /* message*/,
virtual bool ContainsMapKey(const Message& /* message */,
const FieldDescriptor* /* field */,
const MapKey& /* key */) const {
return false;
@@ -965,7 +985,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// Delete and returns true if key is in the map field. Returns false
// otherwise.
virtual bool DeleteMapValue(Message* /* mesage */,
virtual bool DeleteMapValue(Message* /* message */,
const FieldDescriptor* /* field */,
const MapKey& /* key */) const {
return false;
+55 -22
View File
@@ -33,6 +33,8 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#include <climits>
#include <google/protobuf/arena.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message_lite.h>
@@ -101,15 +103,15 @@ string InitializationErrorMessage(const char* action,
// call MergePartialFromCodedStream(). However, when parsing very small
// messages, every function call introduces significant overhead. To avoid
// this without reproducing code, we use these forced-inline helpers.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineMergeFromCodedStream(
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool InlineMergeFromCodedStream(
io::CodedInputStream* input, MessageLite* message);
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromCodedStream(
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromCodedStream(
io::CodedInputStream* input, MessageLite* message);
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromCodedStream(
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromCodedStream(
io::CodedInputStream* input, MessageLite* message);
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromArray(
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromArray(
const void* data, int size, MessageLite* message);
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromArray(
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromArray(
const void* data, int size, MessageLite* message);
inline bool InlineMergeFromCodedStream(io::CodedInputStream* input,
@@ -220,16 +222,9 @@ bool MessageLite::ParsePartialFromArray(const void* data, int size) {
// ===================================================================
uint8* MessageLite::InternalSerializeWithCachedSizesToArray(
bool deterministic, uint8* target) const {
// We only optimize this when using optimize_for = SPEED. In other cases
// we just use the CodedOutputStream path.
int size = GetCachedSize();
io::ArrayOutputStream out(target, size);
io::CodedOutputStream coded_out(&out);
SerializeWithCachedSizes(&coded_out);
GOOGLE_CHECK(!coded_out.HadError());
return target + size;
uint8* MessageLite::SerializeWithCachedSizesToArray(uint8* target) const {
return InternalSerializeWithCachedSizesToArray(
io::CodedOutputStream::IsDefaultSerializationDeterministic(), target);
}
bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const {
@@ -237,21 +232,18 @@ bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const {
return SerializePartialToCodedStream(output);
}
size_t MessageLite::ByteSizeLong() const {
return internal::FromIntSize(ByteSize());
}
bool MessageLite::SerializePartialToCodedStream(
io::CodedOutputStream* output) const {
const size_t size = ByteSizeLong(); // Force size to be cached.
if (size > INT_MAX) {
GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB.";
GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB: " << size;
return false;
}
uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size);
if (buffer != NULL) {
uint8* end = SerializeWithCachedSizesToArray(buffer);
uint8* end = InternalSerializeWithCachedSizesToArray(
output->IsSerializationDeterministic(), buffer);
if (end - buffer != size) {
ByteSizeConsistencyError(size, ByteSizeLong(), end - buffer, *this);
}
@@ -294,7 +286,7 @@ bool MessageLite::AppendPartialToString(string* output) const {
size_t old_size = output->size();
size_t byte_size = ByteSizeLong();
if (byte_size > INT_MAX) {
GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB.";
GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB: " << byte_size;
return false;
}
@@ -352,6 +344,39 @@ string MessageLite::SerializePartialAsString() const {
return output;
}
void MessageLite::SerializeWithCachedSizes(
io::CodedOutputStream* output) const {
GOOGLE_DCHECK(InternalGetTable());
internal::TableSerialize(
*this,
static_cast<const internal::SerializationTable*>(InternalGetTable()),
output);
}
// The table driven code optimizes the case that the CodedOutputStream buffer
// is large enough to serialize into it directly.
// If the proto is optimized for speed, this method will be overridden by
// generated code for maximum speed. If the proto is optimized for size or
// is lite, then we need to specialize this to avoid infinite recursion.
uint8* MessageLite::InternalSerializeWithCachedSizesToArray(
bool deterministic, uint8* target) const {
const internal::SerializationTable* table =
static_cast<const internal::SerializationTable*>(InternalGetTable());
if (table == NULL) {
// We only optimize this when using optimize_for = SPEED. In other cases
// we just use the CodedOutputStream path.
int size = GetCachedSize();
io::ArrayOutputStream out(target, size);
io::CodedOutputStream coded_out(&out);
coded_out.SetSerializationDeterministic(deterministic);
SerializeWithCachedSizes(&coded_out);
GOOGLE_CHECK(!coded_out.HadError());
return target + size;
} else {
return internal::TableSerializeToArray(*this, table, deterministic, target);
}
}
namespace internal {
template<>
MessageLite* GenericTypeHandler<MessageLite>::NewFromPrototype(
@@ -368,6 +393,14 @@ void GenericTypeHandler<string>::Merge(const string& from,
string* to) {
*to = from;
}
bool proto3_preserve_unknown_ = true;
void SetProto3PreserveUnknownsDefault(bool preserve) {
proto3_preserve_unknown_ = preserve;
}
} // namespace internal
} // namespace protobuf
+164 -49
View File
@@ -39,22 +39,115 @@
#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__
#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__
#include <climits>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/stubs/port.h>
namespace google {
namespace protobuf {
class Arena;
class Arena;
namespace io {
class CodedInputStream;
class CodedOutputStream;
class ZeroCopyInputStream;
class ZeroCopyOutputStream;
class CodedInputStream;
class CodedOutputStream;
class ZeroCopyInputStream;
class ZeroCopyOutputStream;
}
namespace internal {
class WireFormatLite;
class WireFormatLite;
#ifndef SWIG
// 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 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();
}
void Destruct() {
get_mutable()->~T();
}
#if LANG_CXX11
constexpr
#endif
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.
extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string;
LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_;
LIBPROTOBUF_EXPORT void InitEmptyString();
LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() {
return fixed_address_empty_string.get();
}
LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() {
::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString);
return GetEmptyStringAlreadyInited();
}
LIBPROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const string& str);
#endif // SWIG
} // namespace internal
// Interface to light weight protocol messages.
//
// This interface is implemented by all protocol message objects. Non-lite
@@ -99,18 +192,19 @@ class LIBPROTOBUF_EXPORT MessageLite {
// Get the arena, if any, associated with this message. Virtual method
// required for generic operations but most arena-related operations should
// use the GetArenaNoVirtual() generated-code method. Default implementation
// to reduce code size by avoiding the need for per-type implementations when
// types do not implement arena support.
// to reduce code size by avoiding the need for per-type implementations
// when types do not implement arena support.
virtual ::google::protobuf::Arena* GetArena() const { return NULL; }
// 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.
// 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.
virtual void* GetMaybeArenaPointer() const { return GetArena(); }
// Clear all fields of the message and set them to their default values.
@@ -128,19 +222,20 @@ class LIBPROTOBUF_EXPORT MessageLite {
// for full messages. See message.h.
virtual string InitializationErrorString() const;
// If |other| is the exact same class as this, calls MergeFrom(). Otherwise,
// If |other| is the exact same class as this, calls MergeFrom(). Otherwise,
// results are undefined (probably crash).
virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0;
// 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.
// 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.
// 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.
@@ -239,26 +334,36 @@ class LIBPROTOBUF_EXPORT MessageLite {
bool AppendPartialToString(string* output) const;
// Computes the serialized size of the message. This recursively calls
// ByteSize() on all embedded messages. Subclasses MUST override either
// ByteSize() or ByteSizeLong() (overriding both is fine).
// ByteSizeLong() on all embedded messages.
//
// ByteSize() is generally linear in the number of fields defined for the
// ByteSizeLong() is generally linear in the number of fields defined for the
// proto.
virtual int ByteSize() const { return ByteSizeLong(); }
virtual size_t ByteSizeLong() const;
virtual size_t ByteSizeLong() const = 0;
// Serializes the message without recomputing the size. The message must
// not have changed since the last call to ByteSize(); if it has, the results
// are undefined.
virtual void SerializeWithCachedSizes(
io::CodedOutputStream* output) const = 0;
// A version of SerializeWithCachedSizesToArray, below, that does
// not guarantee deterministic serialization.
virtual uint8* SerializeWithCachedSizesToArray(uint8* target) const {
return InternalSerializeWithCachedSizesToArray(false, target);
// Legacy ByteSize() API.
PROTOBUF_RUNTIME_DEPRECATED("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.
virtual void SerializeWithCachedSizes(
io::CodedOutputStream* output) const;
// 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().
virtual 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
@@ -272,25 +377,35 @@ class LIBPROTOBUF_EXPORT MessageLite {
// method.)
virtual int GetCachedSize() const = 0;
// 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. If deterministic
// is true then we use deterministic serialization, e.g., map keys are sorted.
// FOR INTERNAL USE ONLY!
virtual uint8* InternalSerializeWithCachedSizesToArray(bool deterministic,
uint8* target) const;
private:
// TODO(gerbens) make this a pure abstract function
virtual const void* InternalGetTable() const { return NULL; }
friend class internal::WireFormatLite;
friend class Message;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite);
};
namespace internal {
extern bool LIBPROTOBUF_EXPORT proto3_preserve_unknown_;
// DO NOT USE: For migration only. Will be removed when Proto3 defaults to
// preserve unknowns.
inline bool GetProto3PreserveUnknownsDefault() {
return proto3_preserve_unknown_;
}
// DO NOT USE: For migration only. Will be removed when Proto3 defaults to
// preserve unknowns.
void LIBPROTOBUF_EXPORT SetProto3PreserveUnknownsDefault(bool preserve);
} // namespace internal
} // namespace protobuf
} // namespace google
+15 -96
View File
@@ -38,117 +38,36 @@
#ifndef GOOGLE_PROTOBUF_METADATA_H__
#define GOOGLE_PROTOBUF_METADATA_H__
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/unknown_field_set.h>
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 LIBPROTOBUF_EXPORT InternalMetadataWithArena {
class InternalMetadataWithArena
: public InternalMetadataWithArenaBase<UnknownFieldSet,
InternalMetadataWithArena> {
public:
InternalMetadataWithArena() : ptr_(NULL) {}
InternalMetadataWithArena() {}
explicit InternalMetadataWithArena(Arena* arena)
: ptr_ (arena) {}
: InternalMetadataWithArenaBase<UnknownFieldSet,
InternalMetadataWithArena>(arena) {}
~InternalMetadataWithArena() {
if (have_unknown_fields() && arena() == NULL) {
delete PtrValue<Container>();
}
ptr_ = NULL;
void DoSwap(UnknownFieldSet* other) {
mutable_unknown_fields()->Swap(other);
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE const UnknownFieldSet& unknown_fields() const {
if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) {
return PtrValue<Container>()->unknown_fields_;
} else {
return *UnknownFieldSet::default_instance();
}
void DoMergeFrom(const UnknownFieldSet& other) {
mutable_unknown_fields()->MergeFrom(other);
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE UnknownFieldSet* mutable_unknown_fields() {
if (GOOGLE_PREDICT_TRUE(have_unknown_fields())) {
return &PtrValue<Container>()->unknown_fields_;
} else {
return mutable_unknown_fields_slow();
}
void DoClear() {
mutable_unknown_fields()->Clear();
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE Arena* arena() const {
if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) {
return PtrValue<Container>()->arena_;
} else {
return PtrValue<Arena>();
}
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool have_unknown_fields() const {
return PtrTag() == kTagContainer;
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(InternalMetadataWithArena* 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()) {
mutable_unknown_fields()->Swap(other->mutable_unknown_fields());
}
}
GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* raw_arena_ptr() const {
return ptr_;
}
private:
void* ptr_;
// Tagged pointer implementation.
enum {
// ptr_ is an Arena*.
kTagArena = 0,
// ptr_ is a Container*.
kTagContainer = 1,
};
static const intptr_t kPtrTagMask = 1;
static const intptr_t kPtrValueMask = ~kPtrTagMask;
// Accessors for pointer tag and pointer value.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE int PtrTag() const {
return reinterpret_cast<intptr_t>(ptr_) & kPtrTagMask;
}
template<typename T> T* PtrValue() const {
return reinterpret_cast<T*>(
reinterpret_cast<intptr_t>(ptr_) & kPtrValueMask);
}
// If ptr_'s tag is kTagContainer, it points to an instance of this struct.
struct Container {
UnknownFieldSet unknown_fields_;
Arena* arena_;
};
GOOGLE_ATTRIBUTE_NOINLINE UnknownFieldSet* mutable_unknown_fields_slow() {
Arena* my_arena = arena();
Container* container = Arena::Create<Container>(my_arena);
ptr_ = reinterpret_cast<void*>(
reinterpret_cast<intptr_t>(container) | kTagContainer);
container->arena_ = my_arena;
return &(container->unknown_fields_);
static const UnknownFieldSet& default_instance() {
return *UnknownFieldSet::default_instance();
}
};
+224
View File
@@ -0,0 +1,224 @@
// 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 <google/protobuf/stubs/common.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/stubs/port.h>
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.
template <class T, class Derived>
class InternalMetadataWithArenaBase {
public:
InternalMetadataWithArenaBase() : ptr_(NULL) {}
explicit InternalMetadataWithArenaBase(Arena* arena) : ptr_(arena) {}
~InternalMetadataWithArenaBase() {
if (have_unknown_fields() && arena() == NULL) {
delete PtrValue<Container>();
}
ptr_ = NULL;
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE const T& unknown_fields() const {
if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) {
return PtrValue<Container>()->unknown_fields;
} else {
return Derived::default_instance();
}
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE T* mutable_unknown_fields() {
if (GOOGLE_PREDICT_TRUE(have_unknown_fields())) {
return &PtrValue<Container>()->unknown_fields;
} else {
return mutable_unknown_fields_slow();
}
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE Arena* arena() const {
if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) {
return PtrValue<Container>()->arena;
} else {
return PtrValue<Arena>();
}
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool have_unknown_fields() const {
return PtrTag() == kTagContainer;
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE void Swap(Derived* 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()) {
static_cast<Derived*>(this)->DoSwap(other->mutable_unknown_fields());
}
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE void MergeFrom(const Derived& other) {
if (other.have_unknown_fields()) {
static_cast<Derived*>(this)->DoMergeFrom(other.unknown_fields());
}
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE void Clear() {
if (have_unknown_fields()) {
static_cast<Derived*>(this)->DoClear();
}
}
GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE void* raw_arena_ptr() const {
return ptr_;
}
private:
void* ptr_;
// Tagged pointer implementation.
enum {
// ptr_ is an Arena*.
kTagArena = 0,
// ptr_ is a Container*.
kTagContainer = 1,
};
static const intptr_t kPtrTagMask = 1;
static const intptr_t kPtrValueMask = ~kPtrTagMask;
// Accessors for pointer tag and pointer value.
GOOGLE_PROTOBUF_ATTRIBUTE_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 Container {
T unknown_fields;
Arena* arena;
};
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE T* mutable_unknown_fields_slow() {
Arena* my_arena = arena();
Container* container = Arena::Create<Container>(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);
}
};
// We store unknown fields as a string right now, because there is currently no
// good interface for reading unknown fields into an ArenaString. We may want
// to revisit this to allow unknown fields to be parsed onto the Arena.
class InternalMetadataWithArenaLite
: public InternalMetadataWithArenaBase<string,
InternalMetadataWithArenaLite> {
public:
InternalMetadataWithArenaLite() {}
explicit InternalMetadataWithArenaLite(Arena* arena)
: InternalMetadataWithArenaBase<string,
InternalMetadataWithArenaLite>(arena) {}
void DoSwap(string* other) {
mutable_unknown_fields()->swap(*other);
}
void DoMergeFrom(const string& other) {
mutable_unknown_fields()->append(other);
}
void DoClear() {
mutable_unknown_fields()->clear();
}
static const string& default_instance() {
return GetEmptyStringAlreadyInited();
}
};
// 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 LIBPROTOBUF_EXPORT LiteUnknownFieldSetter {
public:
explicit LiteUnknownFieldSetter(InternalMetadataWithArenaLite* metadata)
: metadata_(metadata) {
if (metadata->have_unknown_fields()) {
buffer_.swap(*metadata->mutable_unknown_fields());
}
}
~LiteUnknownFieldSetter() {
if (!buffer_.empty()) metadata_->mutable_unknown_fields()->swap(buffer_);
}
string* buffer() { return &buffer_; }
private:
InternalMetadataWithArenaLite* metadata_;
string buffer_;
};
} // namespace internal
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_METADATA_LITE_H__
+2 -2
View File
@@ -570,8 +570,8 @@ struct RefTypeTraits<
typedef RepeatedFieldRefIterator<T> iterator;
typedef RepeatedFieldAccessor AccessorType;
typedef string AccessorValueType;
typedef string IteratorValueType;
typedef string* IteratorPointerType;
typedef const string IteratorValueType;
typedef const string* IteratorPointerType;
static const FieldDescriptor::CppType cpp_type =
FieldDescriptor::CPPTYPE_STRING;
static const Descriptor* GetMessageFieldDescriptor() {
+28 -6
View File
@@ -38,6 +38,7 @@
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/map_field.h>
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/stubs/strutil.h>
@@ -63,7 +64,7 @@ void ReflectionOps::Merge(const Message& from, Message* to) {
const Reflection* from_reflection = from.GetReflection();
const Reflection* to_reflection = to->GetReflection();
vector<const FieldDescriptor*> fields;
std::vector<const FieldDescriptor*> fields;
from_reflection->ListFields(from, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
@@ -129,7 +130,7 @@ void ReflectionOps::Merge(const Message& from, Message* to) {
void ReflectionOps::Clear(Message* message) {
const Reflection* reflection = message->GetReflection();
vector<const FieldDescriptor*> fields;
std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*message, &fields);
for (int i = 0; i < fields.size(); i++) {
reflection->ClearField(message, fields[i]);
@@ -152,12 +153,33 @@ bool ReflectionOps::IsInitialized(const Message& message) {
}
// Check that sub-messages are initialized.
vector<const FieldDescriptor*> fields;
std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
if (field->is_map()) {
const FieldDescriptor* value_field = field->message_type()->field(1);
if (value_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
MapFieldBase* map_field =
reflection->MapData(const_cast<Message*>(&message), field);
if (map_field->IsMapValid()) {
MapIterator iter(const_cast<Message*>(&message), field);
MapIterator end(const_cast<Message*>(&message), field);
for (map_field->MapBegin(&iter), map_field->MapEnd(&end);
iter != end; ++iter) {
if (!iter.GetValueRef().GetMessageValue().IsInitialized()) {
return false;
}
}
continue;
}
} else {
continue;
}
}
if (field->is_repeated()) {
int size = reflection->FieldSize(message, field);
@@ -183,7 +205,7 @@ void ReflectionOps::DiscardUnknownFields(Message* message) {
reflection->MutableUnknownFields(message)->Clear();
vector<const FieldDescriptor*> fields;
std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*message, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
@@ -224,7 +246,7 @@ static string SubMessagePrefix(const string& prefix,
void ReflectionOps::FindInitializationErrors(
const Message& message,
const string& prefix,
vector<string>* errors) {
std::vector<string>* errors) {
const Descriptor* descriptor = message.GetDescriptor();
const Reflection* reflection = message.GetReflection();
@@ -238,7 +260,7 @@ void ReflectionOps::FindInitializationErrors(
}
// Check sub-messages.
vector<const FieldDescriptor*> fields;
std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
+283 -130
View File
@@ -51,18 +51,20 @@
#include <algorithm>
#endif
#include <string>
#include <iterator>
#include <limits>
#include <string>
#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/type_traits.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/stubs/port.h>
// Forward-declare these so that we can make them friends.
namespace google {
namespace upb {
namespace google_opensource {
class GMR_Handlers;
@@ -75,6 +77,8 @@ class Message;
namespace internal {
class MergePartialFromCodedStreamHelper;
static const int kMinRepeatedFieldAllocationSize = 4;
// A utility function for logging that doesn't need any template types.
@@ -104,7 +108,7 @@ inline int CalculateReserve(Iter begin, Iter end) {
// not ever use a RepeatedField directly; they will use the get-by-index,
// set-by-index, and add accessors that are generated for all repeated fields.
template <typename Element>
class RepeatedField {
class RepeatedField PROTOBUF_FINAL {
public:
RepeatedField();
explicit RepeatedField(Arena* arena);
@@ -115,6 +119,11 @@ class RepeatedField {
RepeatedField& operator=(const RepeatedField& other);
#if LANG_CXX11
RepeatedField(RepeatedField&& other) noexcept;
RepeatedField& operator=(RepeatedField&& other) noexcept;
#endif
bool empty() const;
int size() const;
@@ -126,6 +135,8 @@ class RepeatedField {
void Set(int index, const Element& value);
void Add(const Element& value);
// Appends a new element and return a pointer to it.
// The new element is uninitialized if |Element| is a POD type.
Element* Add();
// Remove the last element in the array.
void RemoveLast();
@@ -138,7 +149,6 @@ class RepeatedField {
void Clear();
void MergeFrom(const RepeatedField& other);
void UnsafeMergeFrom(const RepeatedField& other);
void CopyFrom(const RepeatedField& other);
// Reserve space to expand the field to at least the given size. If the
@@ -149,7 +159,11 @@ class RepeatedField {
void Truncate(int new_size);
void AddAlreadyReserved(const Element& value);
// Appends a new element and return a pointer to it.
// The new element is uninitialized if |Element| is a POD type.
// Should be called only if Capacity() > Size().
Element* AddAlreadyReserved();
Element* AddNAlreadyReserved(int elements);
int Capacity() const;
// Like STL resize. Uses value to fill appended elements.
@@ -211,7 +225,11 @@ class RepeatedField {
// Returns the number of bytes used by the repeated field, excluding
// sizeof(*this)
int SpaceUsedExcludingSelf() const;
size_t SpaceUsedExcludingSelfLong() const;
int SpaceUsedExcludingSelf() const {
return internal::ToIntSize(SpaceUsedExcludingSelfLong());
}
// Removes the element referenced by position.
//
@@ -233,6 +251,11 @@ class RepeatedField {
return GetArenaNoVirtual();
}
// For internal use only.
//
// This is public due to it being called by generated code.
inline void InternalSwap(RepeatedField* other);
private:
static const int kInitialSize = 0;
// A note on the representation here (see also comment below for
@@ -263,6 +286,7 @@ class RepeatedField {
friend class Arena;
typedef void InternalArenaConstructable_;
// Move the contents of |from| into |to|, possibly clobbering |from| in the
// process. For primitive types this is just a memcpy(), but it could be
// specialized for non-primitive types to, say, swap each element instead.
@@ -271,8 +295,6 @@ class RepeatedField {
// Copy the elements of |from| into |to|.
void CopyArray(Element* to, const Element* from, int size);
inline void InternalSwap(RepeatedField* other);
// Internal helper expected by Arena methods.
inline Arena* GetArenaNoVirtual() const {
return (rep_ == NULL) ? NULL : rep_->arena;
@@ -286,7 +308,7 @@ class RepeatedField {
Element* e = &rep->elements[0];
Element* limit = &rep->elements[size];
for (; e < limit; e++) {
e->Element::~Element();
e->~Element();
}
if (rep->arena == NULL) {
#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
@@ -298,6 +320,9 @@ class RepeatedField {
}
}
}
friend class internal::WireFormatLite;
const Element* unsafe_data() const;
};
template<typename Element>
@@ -311,12 +336,13 @@ template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator;
namespace internal {
// This is a helper template to copy an array of elements effeciently when they
// This is a helper template to copy an array of elements efficiently when they
// have a trivial copy constructor, and correctly otherwise. This really
// shouldn't be necessary, but our compiler doesn't optimize std::copy very
// effectively.
template <typename Element,
bool HasTrivialCopy = has_trivial_copy<Element>::value>
bool HasTrivialCopy =
has_trivial_copy<Element>::value>
struct ElementCopier {
void operator()(Element* to, const Element* from, int array_size);
};
@@ -330,8 +356,8 @@ namespace internal {
// exist on the contained type. In particular, we rely on MergeFrom() existing
// as a general proxy for the fact that a copy will work, and we also provide a
// specific override for string*.
template<typename T>
struct TypeImplementsMergeBehavior {
template <typename T>
struct TypeImplementsMergeBehaviorProbeForMergeFrom {
typedef char HasMerge;
typedef long HasNoMerge;
@@ -350,13 +376,18 @@ struct TypeImplementsMergeBehavior {
CheckType<U, bool, &U::MergeFrom>*);
template<typename U> static HasNoMerge Check(...);
// Resovles to either google::protobuf::internal::true_type or google::protobuf::internal::false_type.
// Resolves to either google::protobuf::internal::true_type or google::protobuf::internal::false_type.
typedef google::protobuf::internal::integral_constant<bool,
(sizeof(Check<T>(0)) == sizeof(HasMerge))> type;
};
template<>
struct TypeImplementsMergeBehavior< ::std::string > {
template <typename T, typename = void>
struct TypeImplementsMergeBehavior :
TypeImplementsMergeBehaviorProbeForMergeFrom<T> {};
template <>
struct TypeImplementsMergeBehavior< ::std::string> {
typedef google::protobuf::internal::true_type type;
};
@@ -374,7 +405,7 @@ struct TypeImplementsMergeBehavior< ::std::string > {
// static void Merge(const Type& from, Type* to);
//
// // Only needs to be implemented if SpaceUsedExcludingSelf() is called.
// static int SpaceUsed(const Type&);
// static int SpaceUsedLong(const Type&);
// };
class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
protected:
@@ -384,10 +415,10 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
friend class GeneratedMessageReflection;
// ExtensionSet stores repeated message extensions as
// RepeatedPtrField<MessageLite>, but non-lite ExtensionSets need to
// implement SpaceUsed(), and thus need to call SpaceUsedExcludingSelf()
// reinterpreting MessageLite as Message. ExtensionSet also needs to make
// use of AddFromCleared(), which is not part of the public interface.
// RepeatedPtrField<MessageLite>, but non-lite ExtensionSets need to implement
// SpaceUsedLong(), and thus need to call SpaceUsedExcludingSelfLong()
// reinterpreting MessageLite as Message. ExtensionSet also needs to make use
// of AddFromCleared(), which is not part of the public interface.
friend class ExtensionSet;
// The MapFieldBase implementation needs to call protected methods directly,
@@ -395,6 +426,10 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
// subclass.
friend class MapFieldBase;
// The table-driven MergePartialFromCodedStream implementation needs to
// operate on RepeatedPtrField<MessageLite>.
friend class MergePartialFromCodedStreamHelper;
// To parse directly into a proto2 generated class, the upb class GMR_Handlers
// needs to be able to modify a RepeatedPtrFieldBase directly.
friend class upb::google_opensource::GMR_Handlers;
@@ -418,6 +453,11 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
void Delete(int index);
template <typename TypeHandler>
typename TypeHandler::Type* Add(typename TypeHandler::Type* prototype = NULL);
#if LANG_CXX11
template <typename TypeHandler>
void Add(typename TypeHandler::Type&& value,
internal::enable_if<TypeHandler::Moveable>* dummy = NULL);
#endif
template <typename TypeHandler>
void RemoveLast();
@@ -443,13 +483,13 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
template <typename TypeHandler>
const typename TypeHandler::Type* const* data() const;
template <typename TypeHandler>
GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(RepeatedPtrFieldBase* other);
template <typename TypeHandler> GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
void Swap(RepeatedPtrFieldBase* other);
void SwapElements(int index1, int index2);
template <typename TypeHandler>
int SpaceUsedExcludingSelf() const;
size_t SpaceUsedExcludingSelfLong() const;
// Advanced memory management --------------------------------------
@@ -488,17 +528,15 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
inline void InternalSwap(RepeatedPtrFieldBase* other);
template <typename TypeHandler>
void AddAllocatedInternal(typename TypeHandler::Type* value,
google::protobuf::internal::true_type);
void AddAllocatedInternal(typename TypeHandler::Type* value, google::protobuf::internal::true_type);
template <typename TypeHandler>
void AddAllocatedInternal(typename TypeHandler::Type* value,
google::protobuf::internal::false_type);
void AddAllocatedInternal(typename TypeHandler::Type* value, google::protobuf::internal::false_type);
template <typename TypeHandler> GOOGLE_ATTRIBUTE_NOINLINE
template <typename TypeHandler> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
void AddAllocatedSlowWithCopy(typename TypeHandler::Type* value,
Arena* value_arena,
Arena* my_arena);
template <typename TypeHandler> GOOGLE_ATTRIBUTE_NOINLINE
template <typename TypeHandler> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
void AddAllocatedSlowWithoutCopy(typename TypeHandler::Type* value);
template <typename TypeHandler>
@@ -506,7 +544,7 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
template <typename TypeHandler>
typename TypeHandler::Type* ReleaseLastInternal(google::protobuf::internal::false_type);
template<typename TypeHandler> GOOGLE_ATTRIBUTE_NOINLINE
template<typename TypeHandler> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
void SwapFallback(RepeatedPtrFieldBase* other);
inline Arena* GetArenaNoVirtual() const {
@@ -563,6 +601,7 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
// Reserve() and MergeFrom() to reduce code size. |extend_amount| must be > 0.
void** InternalExtend(int extend_amount);
friend class AccessorHelper;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrFieldBase);
};
@@ -570,14 +609,14 @@ template <typename GenericType>
class GenericTypeHandler {
public:
typedef GenericType Type;
#if LANG_CXX11
static const bool Moveable = false;
#endif
static inline GenericType* New(Arena* arena) {
return ::google::protobuf::Arena::CreateMaybeMessage<Type>(
arena, static_cast<GenericType*>(0));
return ::google::protobuf::Arena::CreateMaybeMessage<Type>(arena);
}
// We force NewFromPrototype() to be non-inline to reduce code size:
// else, several other methods get inlined copies of message types'
// constructors.
GOOGLE_ATTRIBUTE_NOINLINE static GenericType* NewFromPrototype(
static inline GenericType* NewFromPrototype(
const GenericType* prototype, ::google::protobuf::Arena* arena = NULL);
static inline void Delete(GenericType* value, Arena* arena) {
if (arena == NULL) {
@@ -592,10 +631,10 @@ class GenericTypeHandler {
}
static inline void Clear(GenericType* value) { value->Clear(); }
GOOGLE_ATTRIBUTE_NOINLINE static void Merge(const GenericType& from,
GenericType* to);
static inline int SpaceUsed(const GenericType& value) {
return value.SpaceUsed();
GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
static void Merge(const GenericType& from, GenericType* to);
static inline size_t SpaceUsedLong(const GenericType& value) {
return value.SpaceUsedLong();
}
static inline const Type& default_instance() {
return Type::default_instance();
@@ -613,11 +652,9 @@ void GenericTypeHandler<GenericType>::Merge(const GenericType& from,
to->MergeFrom(from);
}
// NewFromPrototype() and Merge() cannot be defined here; if they're declared
// inline the compiler will complain about not matching GOOGLE_ATTRIBUTE_NOINLINE
// above, and if not, compilation will result in multiple definitions. These
// are therefore declared as specializations here and defined in
// message_lite.cc.
// NewFromPrototype() and Merge() are not defined inline here, as we will need
// to do a virtual function dispatch anyways to go from Message* to call
// New/Merge.
template<>
MessageLite* GenericTypeHandler<MessageLite>::NewFromPrototype(
const MessageLite* prototype, google::protobuf::Arena* arena);
@@ -682,22 +719,23 @@ inline const Message& GenericTypeHandler<Message>::default_instance() {
}
// HACK: If a class is declared as DLL-exported in MSVC, it insists on
// generating copies of all its methods -- even inline ones -- to include
// in the DLL. But SpaceUsed() calls StringSpaceUsedExcludingSelf() which
// isn't in the lite library, therefore the lite library cannot link if
// StringTypeHandler is exported. So, we factor out StringTypeHandlerBase,
// export that, then make StringTypeHandler be a subclass which is NOT
// exported.
// TODO(kenton): Now that StringSpaceUsedExcludingSelf() is in the lite
// library, this can be cleaned up.
class LIBPROTOBUF_EXPORT StringTypeHandlerBase {
class StringTypeHandler {
public:
typedef string Type;
#if LANG_CXX11
static const bool Moveable =
std::is_move_constructible<Type>::value &&
std::is_move_assignable<Type>::value;
#endif
static inline string* New(Arena* arena) {
return Arena::Create<string>(arena);
}
#if LANG_CXX11
static inline string* New(Arena* arena, string&& value) {
return Arena::Create<string>(arena, std::move(value));
}
#endif
static inline string* NewFromPrototype(const string*,
::google::protobuf::Arena* arena) {
return New(arena);
@@ -718,22 +756,17 @@ class LIBPROTOBUF_EXPORT StringTypeHandlerBase {
static inline const Type& default_instance() {
return ::google::protobuf::internal::GetEmptyString();
}
};
class StringTypeHandler : public StringTypeHandlerBase {
public:
static int SpaceUsed(const string& value) {
return static_cast<int>(sizeof(value)) + StringSpaceUsedExcludingSelf(value);
static size_t SpaceUsedLong(const string& value) {
return sizeof(value) + StringSpaceUsedExcludingSelfLong(value);
}
};
} // namespace internal
// RepeatedPtrField is like RepeatedField, but used for repeated strings or
// Messages.
template <typename Element>
class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
class RepeatedPtrField PROTOBUF_FINAL : public internal::RepeatedPtrFieldBase {
public:
RepeatedPtrField();
explicit RepeatedPtrField(::google::protobuf::Arena* arena);
@@ -745,12 +778,20 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
RepeatedPtrField& operator=(const RepeatedPtrField& other);
#if LANG_CXX11
RepeatedPtrField(RepeatedPtrField&& other) noexcept;
RepeatedPtrField& operator=(RepeatedPtrField&& other) noexcept;
#endif
bool empty() const;
int size() const;
const Element& Get(int index) const;
Element* Mutable(int index);
Element* Add();
#if LANG_CXX11
void Add(Element&& value);
#endif
const Element& operator[](int index) const { return Get(index); }
Element& operator[](int index) { return *Mutable(index); }
@@ -766,7 +807,6 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
void Clear();
void MergeFrom(const RepeatedPtrField& other);
void UnsafeMergeFrom(const RepeatedPtrField& other) { MergeFrom(other); }
void CopyFrom(const RepeatedPtrField& other);
// Reserve space to expand the field to at least the given size. This only
@@ -830,10 +870,11 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
// Custom STL-like iterator that iterates over and returns the underlying
// pointers to Element rather than Element itself.
typedef internal::RepeatedPtrOverPtrsIterator<Element, void*>
pointer_iterator;
typedef internal::RepeatedPtrOverPtrsIterator<const Element, const void*>
const_pointer_iterator;
typedef internal::RepeatedPtrOverPtrsIterator<Element*, void*>
pointer_iterator;
typedef internal::RepeatedPtrOverPtrsIterator<const Element* const,
const void* const>
const_pointer_iterator;
pointer_iterator pointer_begin();
const_pointer_iterator pointer_begin() const;
pointer_iterator pointer_end();
@@ -841,7 +882,11 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
// Returns (an estimate of) the number of bytes used by the repeated field,
// excluding sizeof(*this).
int SpaceUsedExcludingSelf() const;
size_t SpaceUsedExcludingSelfLong() const;
int SpaceUsedExcludingSelf() const {
return internal::ToIntSize(SpaceUsedExcludingSelfLong());
}
// Advanced memory management --------------------------------------
// When hardcore memory management becomes necessary -- as it sometimes
@@ -873,10 +918,10 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
// RepeatedPtrField.
// It is also useful in legacy code that uses temporary ownership to avoid
// copies. Example:
// RepeatedPtrField<T> temp_field;
// temp_field.AddAllocated(new T);
// ... // Do something with temp_field
// temp_field.ExtractSubrange(0, temp_field.size(), NULL);
// RepeatedPtrField<T> temp_field;
// temp_field.AddAllocated(new T);
// ... // Do something with temp_field
// temp_field.ExtractSubrange(0, temp_field.size(), NULL);
// If you put temp_field on the arena this fails, because the ownership
// transfers to the arena at the "AddAllocated" call and is not released
// anymore causing a double delete. UnsafeArenaAddAllocated prevents this.
@@ -958,17 +1003,18 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
return GetArenaNoVirtual();
}
protected:
// Note: RepeatedPtrField SHOULD NOT be subclassed by users. We only
// subclass it in one place as a hack for compatibility with proto1. The
// subclass needs to know about TypeHandler in order to call protected
// methods on RepeatedPtrFieldBase.
// For internal use only.
//
// This is public due to it being called by generated code.
using RepeatedPtrFieldBase::InternalSwap;
private:
// Note: RepeatedPtrField SHOULD NOT be subclassed by users.
class TypeHandler;
// Internal arena accessor expected by helpers in Arena.
inline Arena* GetArenaNoVirtual() const;
private:
// Implementations for ExtractSubrange(). The copying behavior must be
// included only if the type supports the necessary operations (e.g.,
// MergeFrom()), so we must resolve this at compile time. ExtractSubrange()
@@ -997,13 +1043,13 @@ inline RepeatedField<Element>::RepeatedField(Arena* arena)
: current_size_(0),
total_size_(0),
rep_(NULL) {
// In case arena is NULL, then we do not create rep_, as code has an invariant
// `rep_ == NULL then arena == NULL`.
if (arena != NULL) {
rep_ = reinterpret_cast<Rep*>(
::google::protobuf::Arena::CreateArray<char>(arena, kRepHeaderSize));
rep_->arena = arena;
}
// In case arena is NULL, then we do not create rep_, as code has an invariant
// `rep_ == NULL then arena == NULL`.
if (arena != NULL) {
rep_ = reinterpret_cast<Rep*>(
::google::protobuf::Arena::CreateArray<char>(arena, kRepHeaderSize));
rep_->arena = arena;
}
}
template <typename Element>
@@ -1011,7 +1057,12 @@ inline RepeatedField<Element>::RepeatedField(const RepeatedField& other)
: current_size_(0),
total_size_(0),
rep_(NULL) {
CopyFrom(other);
if (other.current_size_ != 0) {
Reserve(other.current_size_);
CopyArray(rep_->elements,
other.rep_->elements, other.current_size_);
current_size_ = other.current_size_;
}
}
template <typename Element>
@@ -1048,6 +1099,37 @@ RepeatedField<Element>::operator=(const RepeatedField& other) {
return *this;
}
#if LANG_CXX11
template <typename Element>
inline RepeatedField<Element>::RepeatedField(RepeatedField&& other) noexcept
: RepeatedField() {
// We don't just call Swap(&other) here because it would perform 3 copies if
// the two fields are on different arenas.
if (other.GetArenaNoVirtual()) {
CopyFrom(other);
} else {
InternalSwap(&other);
}
}
template <typename Element>
inline RepeatedField<Element>& RepeatedField<Element>::operator=(
RepeatedField&& other) noexcept {
// We don't just call Swap(&other) here because it would perform 3 copies if
// the two fields are on different arenas.
if (this != &other) {
if (this->GetArenaNoVirtual() != other.GetArenaNoVirtual()) {
CopyFrom(other);
} else {
InternalSwap(&other);
}
}
return *this;
}
#endif // LANG_CXX11
template <typename Element>
inline bool RepeatedField<Element>::empty() const {
return current_size_ == 0;
@@ -1075,6 +1157,14 @@ inline Element* RepeatedField<Element>::AddAlreadyReserved() {
return &rep_->elements[current_size_++];
}
template<typename Element>
inline Element* RepeatedField<Element>::AddNAlreadyReserved(int elements) {
GOOGLE_DCHECK_LE(current_size_ + elements, total_size_);
Element* ret = &rep_->elements[current_size_];
current_size_ += elements;
return ret;
}
template<typename Element>
inline void RepeatedField<Element>::Resize(int new_size, const Element& value) {
GOOGLE_DCHECK_GE(new_size, 0);
@@ -1152,7 +1242,8 @@ inline void RepeatedField<Element>::Clear() {
}
template <typename Element>
inline void RepeatedField<Element>::UnsafeMergeFrom(const RepeatedField& other) {
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& other) {
GOOGLE_DCHECK_NE(&other, this);
if (other.current_size_ != 0) {
Reserve(current_size_ + other.current_size_);
CopyArray(rep_->elements + current_size_,
@@ -1161,12 +1252,6 @@ inline void RepeatedField<Element>::UnsafeMergeFrom(const RepeatedField& other)
}
}
template <typename Element>
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& other) {
GOOGLE_CHECK_NE(&other, this);
UnsafeMergeFrom(other);
}
template <typename Element>
inline void RepeatedField<Element>::CopyFrom(const RepeatedField& other) {
if (&other == this) return;
@@ -1200,9 +1285,17 @@ inline const Element* RepeatedField<Element>::data() const {
return rep_ ? rep_->elements : NULL;
}
template <typename Element>
inline const Element* RepeatedField<Element>::unsafe_data() const {
GOOGLE_DCHECK(rep_);
return rep_->elements;
}
template <typename Element>
inline void RepeatedField<Element>::InternalSwap(RepeatedField* other) {
GOOGLE_DCHECK(this != other);
GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
std::swap(rep_, other->rep_);
std::swap(current_size_, other->current_size_);
std::swap(total_size_, other->total_size_);
@@ -1211,7 +1304,7 @@ inline void RepeatedField<Element>::InternalSwap(RepeatedField* other) {
template <typename Element>
void RepeatedField<Element>::Swap(RepeatedField* other) {
if (this == other) return;
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
RepeatedField<Element> temp(other->GetArenaNoVirtual());
@@ -1224,7 +1317,6 @@ void RepeatedField<Element>::Swap(RepeatedField* other) {
template <typename Element>
void RepeatedField<Element>::UnsafeArenaSwap(RepeatedField* other) {
if (this == other) return;
GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
@@ -1266,9 +1358,8 @@ RepeatedField<Element>::cend() const {
}
template <typename Element>
inline int RepeatedField<Element>::SpaceUsedExcludingSelf() const {
return rep_ ?
(total_size_ * sizeof(Element) + kRepHeaderSize) : 0;
inline size_t RepeatedField<Element>::SpaceUsedExcludingSelfLong() const {
return rep_ ? (total_size_ * sizeof(Element) + kRepHeaderSize) : 0;
}
// Avoid inlining of Reserve(): new, copy, and delete[] lead to a significant
@@ -1280,11 +1371,11 @@ void RepeatedField<Element>::Reserve(int new_size) {
Arena* arena = GetArenaNoVirtual();
new_size = std::max(google::protobuf::internal::kMinRepeatedFieldAllocationSize,
std::max(total_size_ * 2, new_size));
GOOGLE_CHECK_LE(static_cast<size_t>(new_size),
(std::numeric_limits<size_t>::max() - kRepHeaderSize) /
sizeof(Element))
GOOGLE_DCHECK_LE(
static_cast<size_t>(new_size),
(std::numeric_limits<size_t>::max() - kRepHeaderSize) / sizeof(Element))
<< "Requested size is too large to fit into size_t.";
size_t bytes = kRepHeaderSize + sizeof(Element) * new_size;
size_t bytes = kRepHeaderSize + sizeof(Element) * static_cast<size_t>(new_size);
if (arena == NULL) {
rep_ = static_cast<Rep*>(::operator new(bytes));
} else {
@@ -1306,7 +1397,7 @@ void RepeatedField<Element>::Reserve(int new_size) {
Element* e = &rep_->elements[0];
Element* limit = &rep_->elements[total_size_];
for (; e < limit; e++) {
new (e) Element();
new (e) Element;
}
if (current_size_ > 0) {
MoveArray(rep_->elements, old_rep->elements, current_size_);
@@ -1348,7 +1439,7 @@ void ElementCopier<Element, HasTrivialCopy>::operator()(
template <typename Element>
struct ElementCopier<Element, true> {
void operator()(Element* to, const Element* from, int array_size) {
memcpy(to, from, array_size * sizeof(Element));
memcpy(to, from, static_cast<size_t>(array_size) * sizeof(Element));
}
};
@@ -1464,6 +1555,25 @@ inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add(
return result;
}
#if LANG_CXX11
template <typename TypeHandler>
inline void RepeatedPtrFieldBase::Add(
typename TypeHandler::Type&& value,
internal::enable_if<TypeHandler::Moveable>*) {
if (rep_ != NULL && current_size_ < rep_->allocated_size) {
*cast<TypeHandler>(rep_->elements[current_size_++]) = std::move(value);
return;
}
if (!rep_ || rep_->allocated_size == total_size_) {
Reserve(total_size_ + 1);
}
++rep_->allocated_size;
typename TypeHandler::Type* result =
TypeHandler::New(arena_, std::move(value));
rep_->elements[current_size_++] = result;
}
#endif
template <typename TypeHandler>
inline void RepeatedPtrFieldBase::RemoveLast() {
GOOGLE_DCHECK_GT(current_size_, 0);
@@ -1580,11 +1690,11 @@ inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) {
}
template <typename TypeHandler>
inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const {
int allocated_bytes = total_size_ * sizeof(void*);
inline size_t RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() const {
size_t allocated_bytes = static_cast<size_t>(total_size_) * sizeof(void*);
if (rep_ != NULL) {
for (int i = 0; i < rep_->allocated_size; ++i) {
allocated_bytes += TypeHandler::SpaceUsed(
allocated_bytes += TypeHandler::SpaceUsedLong(
*cast<TypeHandler>(rep_->elements[i]));
}
allocated_bytes += kRepHeaderSize;
@@ -1623,7 +1733,6 @@ void RepeatedPtrFieldBase::AddAllocatedInternal(
elems[current_size_] = value;
current_size_ = current_size_ + 1;
rep_->allocated_size = rep_->allocated_size + 1;
return;
} else {
AddAllocatedSlowWithCopy<TypeHandler>(
value, TypeHandler::GetArena(value), arena);
@@ -1670,7 +1779,6 @@ void RepeatedPtrFieldBase::AddAllocatedInternal(
elems[current_size_] = value;
current_size_ = current_size_ + 1;
++rep_->allocated_size;
return;
} else {
UnsafeArenaAddAllocated<TypeHandler>(value);
}
@@ -1793,7 +1901,6 @@ class RepeatedPtrField<string>::TypeHandler
: public internal::StringTypeHandler {
};
template <typename Element>
inline RepeatedPtrField<Element>::RepeatedPtrField()
: RepeatedPtrFieldBase() {}
@@ -1806,7 +1913,7 @@ template <typename Element>
inline RepeatedPtrField<Element>::RepeatedPtrField(
const RepeatedPtrField& other)
: RepeatedPtrFieldBase() {
CopyFrom(other);
MergeFrom(other);
}
template <typename Element>
@@ -1835,6 +1942,38 @@ inline RepeatedPtrField<Element>& RepeatedPtrField<Element>::operator=(
return *this;
}
#if LANG_CXX11
template <typename Element>
inline RepeatedPtrField<Element>::RepeatedPtrField(
RepeatedPtrField&& other) noexcept
: RepeatedPtrField() {
// We don't just call Swap(&other) here because it would perform 3 copies if
// the two fields are on different arenas.
if (other.GetArenaNoVirtual()) {
CopyFrom(other);
} else {
InternalSwap(&other);
}
}
template <typename Element>
inline RepeatedPtrField<Element>& RepeatedPtrField<Element>::operator=(
RepeatedPtrField&& other) noexcept {
// We don't just call Swap(&other) here because it would perform 3 copies if
// the two fields are on different arenas.
if (this != &other) {
if (this->GetArenaNoVirtual() != other.GetArenaNoVirtual()) {
CopyFrom(other);
} else {
InternalSwap(&other);
}
}
return *this;
}
#endif // LANG_CXX11
template <typename Element>
inline bool RepeatedPtrField<Element>::empty() const {
return RepeatedPtrFieldBase::empty();
@@ -1861,6 +2000,13 @@ inline Element* RepeatedPtrField<Element>::Add() {
return RepeatedPtrFieldBase::Add<TypeHandler>();
}
#if LANG_CXX11
template <typename Element>
inline void RepeatedPtrField<Element>::Add(Element&& value) {
RepeatedPtrFieldBase::Add<TypeHandler>(std::move(value));
}
#endif
template <typename Element>
inline void RepeatedPtrField<Element>::RemoveLast() {
RepeatedPtrFieldBase::RemoveLast<TypeHandler>();
@@ -2003,7 +2149,6 @@ inline void RepeatedPtrField<Element>::Swap(RepeatedPtrField* other) {
template <typename Element>
inline void RepeatedPtrField<Element>::UnsafeArenaSwap(
RepeatedPtrField* other) {
GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
if (this == other)
return;
RepeatedPtrFieldBase::InternalSwap(other);
@@ -2020,8 +2165,8 @@ inline Arena* RepeatedPtrField<Element>::GetArenaNoVirtual() const {
}
template <typename Element>
inline int RepeatedPtrField<Element>::SpaceUsedExcludingSelf() const {
return RepeatedPtrFieldBase::SpaceUsedExcludingSelf<TypeHandler>();
inline size_t RepeatedPtrField<Element>::SpaceUsedExcludingSelfLong() const {
return RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong<TypeHandler>();
}
template <typename Element>
@@ -2113,7 +2258,7 @@ class RepeatedPtrIterator
: it_(other.it_) {
// Force a compiler error if the other type is not convertible to ours.
if (false) {
implicit_cast<Element*, OtherElement*>(0);
implicit_cast<Element*>(static_cast<OtherElement*>(NULL));
}
}
@@ -2179,18 +2324,17 @@ class RepeatedPtrIterator
// the array.
// The VoidPtr template parameter holds the type-agnostic pointer value
// referenced by the iterator. It should either be "void *" for a mutable
// iterator, or "const void *" for a constant iterator.
template<typename Element, typename VoidPtr>
// iterator, or "const void* const" for a constant iterator.
template <typename Element, typename VoidPtr>
class RepeatedPtrOverPtrsIterator
: public std::iterator<std::random_access_iterator_tag, Element*> {
: public std::iterator<std::random_access_iterator_tag, Element> {
public:
typedef RepeatedPtrOverPtrsIterator<Element, VoidPtr> iterator;
typedef std::iterator<
std::random_access_iterator_tag, Element*> superclass;
typedef std::iterator<std::random_access_iterator_tag, Element> superclass;
// Shadow the value_type in std::iterator<> because const_iterator::value_type
// needs to be T, not const T.
typedef typename remove_const<Element*>::type value_type;
typedef typename remove_const<Element>::type value_type;
// Let the compiler know that these are type names, so we don't have to
// write "typename" in front of them everywhere.
@@ -2202,7 +2346,7 @@ class RepeatedPtrOverPtrsIterator
explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {}
// dereferenceable
reference operator*() const { return *reinterpret_cast<Element**>(it_); }
reference operator*() const { return *reinterpret_cast<Element*>(it_); }
pointer operator->() const { return &(operator*()); }
// {inc,dec}rementable
@@ -2258,6 +2402,9 @@ class RepeatedPtrOverPtrsIterator
};
void RepeatedPtrFieldBase::InternalSwap(RepeatedPtrFieldBase* other) {
GOOGLE_DCHECK(this != other);
GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
std::swap(rep_, other->rep_);
std::swap(current_size_, other->current_size_);
std::swap(total_size_, other->total_size_);
@@ -2304,7 +2451,7 @@ RepeatedPtrField<Element>::pointer_begin() {
template <typename Element>
inline typename RepeatedPtrField<Element>::const_pointer_iterator
RepeatedPtrField<Element>::pointer_begin() const {
return const_pointer_iterator(const_cast<const void**>(raw_mutable_data()));
return const_pointer_iterator(const_cast<const void* const*>(raw_data()));
}
template <typename Element>
inline typename RepeatedPtrField<Element>::pointer_iterator
@@ -2315,7 +2462,7 @@ template <typename Element>
inline typename RepeatedPtrField<Element>::const_pointer_iterator
RepeatedPtrField<Element>::pointer_end() const {
return const_pointer_iterator(
const_cast<const void**>(raw_mutable_data() + size()));
const_cast<const void* const*>(raw_data() + size()));
}
@@ -2372,6 +2519,12 @@ template<typename T> class RepeatedPtrFieldBackInsertIterator
*field_->Add() = *ptr_to_value;
return *this;
}
#if LANG_CXX11
RepeatedPtrFieldBackInsertIterator<T>& operator=(T&& value) {
*field_->Add() = std::move(value);
return *this;
}
#endif
RepeatedPtrFieldBackInsertIterator<T>& operator*() {
return *this;
}
@@ -2483,10 +2636,10 @@ AllocatedRepeatedPtrFieldBackInserter(
// UnsafeArenaAddAllocated instead of AddAllocated.
// This is slightly faster if that matters. It is also useful in legacy code
// that uses temporary ownership to avoid copies. Example:
// RepeatedPtrField<T> temp_field;
// temp_field.AddAllocated(new T);
// ... // Do something with temp_field
// temp_field.ExtractSubrange(0, temp_field.size(), NULL);
// RepeatedPtrField<T> temp_field;
// temp_field.AddAllocated(new T);
// ... // Do something with temp_field
// temp_field.ExtractSubrange(0, temp_field.size(), NULL);
// If you put temp_field on the arena this fails, because the ownership
// transfers to the arena at the "AddAllocated" call and is not released anymore
// causing a double delete. Using UnsafeArenaAddAllocated prevents this.
+162 -202
View File
@@ -1,7 +1,6 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/source_context.proto
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include <google/protobuf/source_context.pb.h>
#include <algorithm>
@@ -15,136 +14,135 @@
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// This is a temporary google only hack
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
#include "third_party/protobuf/version.h"
#endif
// @@protoc_insertion_point(includes)
namespace google {
namespace protobuf {
class SourceContextDefaultTypeInternal {
public:
::google::protobuf::internal::ExplicitlyConstructed<SourceContext>
_instance;
} _SourceContext_default_instance_;
} // namespace protobuf
} // namespace google
namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto {
void InitDefaultsSourceContextImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
::google::protobuf::internal::InitProtobufDefaultsForceUnique();
#else
::google::protobuf::internal::InitProtobufDefaults();
#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
{
void* ptr = &::google::protobuf::_SourceContext_default_instance_;
new (ptr) ::google::protobuf::SourceContext();
::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
}
::google::protobuf::SourceContext::InitAsDefaultInstance();
}
void InitDefaultsSourceContext() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &InitDefaultsSourceContextImpl);
}
::google::protobuf::Metadata file_level_metadata[1];
const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
~0u, // no _has_bits_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::SourceContext, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::google::protobuf::SourceContext, file_name_),
};
static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
{ 0, -1, sizeof(::google::protobuf::SourceContext)},
};
static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_SourceContext_default_instance_),
};
void protobuf_AssignDescriptors() {
AddDescriptors();
::google::protobuf::MessageFactory* factory = NULL;
AssignDescriptors(
"google/protobuf/source_context.proto", schemas, file_default_instances, TableStruct::offsets, factory,
file_level_metadata, NULL, NULL);
}
void protobuf_AssignDescriptorsOnce() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n$google/protobuf/source_context.proto\022\017"
"google.protobuf\"\"\n\rSourceContext\022\021\n\tfile"
"_name\030\001 \001(\tB\225\001\n\023com.google.protobufB\022Sou"
"rceContextProtoP\001ZAgoogle.golang.org/gen"
"proto/protobuf/source_context;source_con"
"text\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTy"
"pesb\006proto3"
};
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
descriptor, 251);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/source_context.proto", &protobuf_RegisterTypes);
}
void AddDescriptors() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
}
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
StaticDescriptorInitializer() {
AddDescriptors();
}
} static_descriptor_initializer;
} // namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto
namespace google {
namespace protobuf {
namespace {
const ::google::protobuf::Descriptor* SourceContext_descriptor_ = NULL;
const ::google::protobuf::internal::GeneratedMessageReflection*
SourceContext_reflection_ = NULL;
} // namespace
void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
const ::google::protobuf::FileDescriptor* file =
::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
"google/protobuf/source_context.proto");
GOOGLE_CHECK(file != NULL);
SourceContext_descriptor_ = file->message_type(0);
static const int SourceContext_offsets_[1] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, file_name_),
};
SourceContext_reflection_ =
::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
SourceContext_descriptor_,
SourceContext::internal_default_instance(),
SourceContext_offsets_,
-1,
-1,
-1,
sizeof(SourceContext),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _internal_metadata_));
}
namespace {
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
void protobuf_AssignDescriptorsOnce() {
::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
&protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
SourceContext_descriptor_, SourceContext::internal_default_instance());
}
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto() {
SourceContext_default_instance_.Shutdown();
delete SourceContext_reflection_;
}
void protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
::google::protobuf::internal::GetEmptyString();
SourceContext_default_instance_.DefaultConstruct();
SourceContext_default_instance_.get_mutable()->InitAsDefaultInstance();
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_once_);
void protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_once_,
&protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl);
}
void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto();
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
"\n$google/protobuf/source_context.proto\022\017"
"google.protobuf\"\"\n\rSourceContext\022\021\n\tfile"
"_name\030\001 \001(\tBR\n\023com.google.protobufB\022Sour"
"ceContextProtoP\001\242\002\003GPB\252\002\036Google.Protobuf"
".WellKnownTypesb\006proto3", 183);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/source_context.proto", &protobuf_RegisterTypes);
::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_once_);
void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() {
::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_once_,
&protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl);
}
// Force AddDescriptors() to be called at static initialization time.
struct StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto {
StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto() {
protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
}
} static_descriptor_initializer_google_2fprotobuf_2fsource_5fcontext_2eproto_;
namespace {
static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN;
static void MergeFromFail(int line) {
::google::protobuf::internal::MergeFromFail(__FILE__, line);
}
} // namespace
// ===================================================================
void SourceContext::InitAsDefaultInstance() {
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int SourceContext::kFileNameFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
SourceContext::SourceContext()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto();
if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaultsSourceContext();
}
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.SourceContext)
}
void SourceContext::InitAsDefaultInstance() {
}
SourceContext::SourceContext(const SourceContext& from)
: ::google::protobuf::Message(),
_internal_metadata_(NULL) {
SharedCtor();
UnsafeMergeFrom(from);
_internal_metadata_(NULL),
_cached_size_(0) {
_internal_metadata_.MergeFrom(from._internal_metadata_);
file_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (from.file_name().size() > 0) {
file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_);
}
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext)
}
@@ -168,17 +166,15 @@ void SourceContext::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* SourceContext::descriptor() {
protobuf_AssignDescriptorsOnce();
return SourceContext_descriptor_;
::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
}
const SourceContext& SourceContext::default_instance() {
protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto();
::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaultsSourceContext();
return *internal_default_instance();
}
::google::protobuf::internal::ExplicitlyConstructed<SourceContext> SourceContext_default_instance_;
SourceContext* SourceContext::New(::google::protobuf::Arena* arena) const {
SourceContext* n = new SourceContext;
if (arena != NULL) {
@@ -189,7 +185,12 @@ SourceContext* SourceContext::New(::google::protobuf::Arena* arena) const {
void SourceContext::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.SourceContext)
::google::protobuf::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
_internal_metadata_.Clear();
}
bool SourceContext::MergePartialFromCodedStream(
@@ -198,34 +199,33 @@ bool SourceContext::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.SourceContext)
for (;;) {
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string file_name = 1;
// string file_name = 1;
case 1: {
if (tag == 10) {
if (static_cast< ::google::protobuf::uint8>(tag) ==
static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_file_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
this->file_name().data(), static_cast<int>(this->file_name().length()),
::google::protobuf::internal::WireFormatLite::PARSE,
"google.protobuf.SourceContext.file_name"));
} else {
goto handle_unusual;
}
if (input->ExpectAtEnd()) goto success;
break;
}
default: {
handle_unusual:
if (tag == 0 ||
::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
if (tag == 0) {
goto success;
}
DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));
DO_(::google::protobuf::internal::WireFormat::SkipField(
input, tag, _internal_metadata_.mutable_unknown_fields()));
break;
}
}
@@ -242,16 +242,23 @@ failure:
void SourceContext::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.SourceContext)
// optional string file_name = 1;
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// string file_name = 1;
if (this->file_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
this->file_name().data(), static_cast<int>(this->file_name().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.SourceContext.file_name");
::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
1, this->file_name(), output);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output);
}
// @@protoc_insertion_point(serialize_end:google.protobuf.SourceContext)
}
@@ -259,10 +266,13 @@ void SourceContext::SerializeWithCachedSizes(
bool deterministic, ::google::protobuf::uint8* target) const {
(void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext)
// optional string file_name = 1;
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// string file_name = 1;
if (this->file_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
this->file_name().data(), static_cast<int>(this->file_name().length()),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
"google.protobuf.SourceContext.file_name");
target =
@@ -270,6 +280,10 @@ void SourceContext::SerializeWithCachedSizes(
1, this->file_name(), target);
}
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target);
}
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.SourceContext)
return target;
}
@@ -278,7 +292,12 @@ size_t SourceContext::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceContext)
size_t total_size = 0;
// optional string file_name = 1;
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()));
}
// string file_name = 1;
if (this->file_name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
@@ -294,7 +313,7 @@ size_t SourceContext::ByteSizeLong() const {
void SourceContext::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceContext)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
GOOGLE_DCHECK_NE(&from, this);
const SourceContext* source =
::google::protobuf::internal::DynamicCastToGenerated<const SourceContext>(
&from);
@@ -303,21 +322,17 @@ void SourceContext::MergeFrom(const ::google::protobuf::Message& from) {
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
// @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.SourceContext)
UnsafeMergeFrom(*source);
MergeFrom(*source);
}
}
void SourceContext::MergeFrom(const SourceContext& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext)
if (GOOGLE_PREDICT_TRUE(&from != this)) {
UnsafeMergeFrom(from);
} else {
MergeFromFail(__LINE__);
}
}
GOOGLE_DCHECK_NE(&from, this);
_internal_metadata_.MergeFrom(from._internal_metadata_);
::google::protobuf::uint32 cached_has_bits = 0;
(void) cached_has_bits;
void SourceContext::UnsafeMergeFrom(const SourceContext& from) {
GOOGLE_DCHECK(&from != this);
if (from.file_name().size() > 0) {
file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_);
@@ -335,11 +350,10 @@ void SourceContext::CopyFrom(const SourceContext& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.SourceContext)
if (&from == this) return;
Clear();
UnsafeMergeFrom(from);
MergeFrom(from);
}
bool SourceContext::IsInitialized() const {
return true;
}
@@ -348,73 +362,19 @@ void SourceContext::Swap(SourceContext* other) {
InternalSwap(other);
}
void SourceContext::InternalSwap(SourceContext* other) {
using std::swap;
file_name_.Swap(&other->file_name_);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata SourceContext::GetMetadata() const {
protobuf_AssignDescriptorsOnce();
::google::protobuf::Metadata metadata;
metadata.descriptor = SourceContext_descriptor_;
metadata.reflection = SourceContext_reflection_;
return metadata;
protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::protobuf_AssignDescriptorsOnce();
return ::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[kIndexInFileMessages];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// SourceContext
// optional string file_name = 1;
void SourceContext::clear_file_name() {
file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
const ::std::string& SourceContext::file_name() const {
// @@protoc_insertion_point(field_get:google.protobuf.SourceContext.file_name)
return file_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void SourceContext::set_file_name(const ::std::string& value) {
file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name)
}
void SourceContext::set_file_name(const char* value) {
file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name)
}
void SourceContext::set_file_name(const char* value, size_t size) {
file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
::std::string(reinterpret_cast<const char*>(value), size));
// @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceContext.file_name)
}
::std::string* SourceContext::mutable_file_name() {
// @@protoc_insertion_point(field_mutable:google.protobuf.SourceContext.file_name)
return file_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* SourceContext::release_file_name() {
// @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name)
return file_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void SourceContext::set_allocated_file_name(::std::string* file_name) {
if (file_name != NULL) {
} else {
}
file_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), file_name);
// @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name)
}
inline const SourceContext* SourceContext::internal_default_instance() {
return &SourceContext_default_instance_.get();
}
#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// @@protoc_insertion_point(namespace_scope)
} // namespace protobuf
} // namespace google
+92 -47
View File
@@ -8,37 +8,55 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.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)
namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[1];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsSourceContextImpl();
void LIBPROTOBUF_EXPORT InitDefaultsSourceContext();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsSourceContext();
}
} // namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto();
class SourceContext;
class SourceContextDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
// ===================================================================
@@ -53,63 +71,85 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @
CopyFrom(from);
return *this;
}
#if LANG_CXX11
SourceContext(SourceContext&& from) noexcept
: SourceContext() {
*this = ::std::move(from);
}
inline SourceContext& operator=(SourceContext&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
static const ::google::protobuf::Descriptor* descriptor();
static const SourceContext& default_instance();
static const SourceContext* internal_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 PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
0;
void Swap(SourceContext* other);
friend void swap(SourceContext& a, SourceContext& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline SourceContext* New() const { return New(NULL); }
inline SourceContext* New() const PROTOBUF_FINAL { return New(NULL); }
SourceContext* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
SourceContext* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const SourceContext& from);
void MergeFrom(const SourceContext& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(SourceContext* other);
void UnsafeMergeFrom(const SourceContext& from);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
return _internal_metadata_.arena();
return NULL;
}
inline void* MaybeArenaPtr() const {
return _internal_metadata_.raw_arena_ptr();
return NULL;
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional string file_name = 1;
// string file_name = 1;
void clear_file_name();
static const int kFileNameFieldNumber = 1;
const ::std::string& file_name() const;
void set_file_name(const ::std::string& value);
#if LANG_CXX11
void set_file_name(::std::string&& value);
#endif
void set_file_name(const char* value);
void set_file_name(const char* value, size_t size);
::std::string* mutable_file_name();
@@ -122,37 +162,43 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
::google::protobuf::internal::ArenaStringPtr file_name_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaultsSourceContextImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<SourceContext> SourceContext_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// SourceContext
// optional string file_name = 1;
// string file_name = 1;
inline void SourceContext::clear_file_name() {
file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& SourceContext::file_name() const {
// @@protoc_insertion_point(field_get:google.protobuf.SourceContext.file_name)
return file_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return file_name_.GetNoArena();
}
inline void SourceContext::set_file_name(const ::std::string& value) {
file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name)
}
#if LANG_CXX11
inline void SourceContext::set_file_name(::std::string&& value) {
file_name_.SetNoArena(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceContext.file_name)
}
#endif
inline void SourceContext::set_file_name(const char* value) {
GOOGLE_DCHECK(value != NULL);
file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
// @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name)
@@ -183,10 +229,9 @@ inline void SourceContext::set_allocated_file_name(::std::string* file_name) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name)
}
inline const SourceContext* SourceContext::internal_default_instance() {
return &SourceContext_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// @@protoc_insertion_point(namespace_scope)
File diff suppressed because it is too large Load Diff
+332 -273
View File
@@ -8,42 +8,68 @@
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 3001000
#if GOOGLE_PROTOBUF_VERSION < 3005000
#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 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#if 3005001 < GOOGLE_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/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/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/map.h>
#include <google/protobuf/repeated_field.h> // IWYU pragma: export
#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/map.h> // IWYU pragma: export
#include <google/protobuf/map_entry.h>
#include <google/protobuf/map_field_inl.h>
#include <google/protobuf/generated_enum_reflection.h>
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
namespace protobuf_google_2fprotobuf_2fstruct_2eproto {
// Internal implementation detail -- do not use these members.
struct LIBPROTOBUF_EXPORT TableStruct {
static const ::google::protobuf::internal::ParseTableField entries[];
static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
static const ::google::protobuf::internal::ParseTable schema[4];
static const ::google::protobuf::internal::FieldMetadata field_metadata[];
static const ::google::protobuf::internal::SerializationTable serialization_table[];
static const ::google::protobuf::uint32 offsets[];
};
void LIBPROTOBUF_EXPORT AddDescriptors();
void LIBPROTOBUF_EXPORT InitDefaultsListValueImpl();
void LIBPROTOBUF_EXPORT InitDefaultsListValue();
inline void LIBPROTOBUF_EXPORT InitDefaults() {
InitDefaultsListValue();
}
} // namespace protobuf_google_2fprotobuf_2fstruct_2eproto
namespace google {
namespace protobuf {
// Internal implementation detail -- do not call these.
void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto();
void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
class ListValue;
class ListValueDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern ListValueDefaultTypeInternal _ListValue_default_instance_;
class Struct;
class StructDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern StructDefaultTypeInternal _Struct_default_instance_;
class Struct_FieldsEntry_DoNotUse;
class Struct_FieldsEntry_DoNotUseDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_FieldsEntry_DoNotUse_default_instance_;
class Value;
class ValueDefaultTypeInternal;
LIBPROTOBUF_EXPORT extern ValueDefaultTypeInternal _Value_default_instance_;
} // namespace protobuf
} // namespace google
namespace google {
namespace protobuf {
enum NullValue {
NULL_VALUE = 0,
@@ -67,6 +93,27 @@ inline bool NullValue_Parse(
}
// ===================================================================
class Struct_FieldsEntry_DoNotUse : public ::google::protobuf::internal::MapEntry<Struct_FieldsEntry_DoNotUse,
::std::string, ::google::protobuf::Value,
::google::protobuf::internal::WireFormatLite::TYPE_STRING,
::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE,
0 > {
public:
typedef ::google::protobuf::internal::MapEntry<Struct_FieldsEntry_DoNotUse,
::std::string, ::google::protobuf::Value,
::google::protobuf::internal::WireFormatLite::TYPE_STRING,
::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE,
0 > SuperType;
Struct_FieldsEntry_DoNotUse();
Struct_FieldsEntry_DoNotUse(::google::protobuf::Arena* arena);
void MergeFrom(const Struct_FieldsEntry_DoNotUse& other);
static const Struct_FieldsEntry_DoNotUse* internal_default_instance() { return reinterpret_cast<const Struct_FieldsEntry_DoNotUse*>(&_Struct_FieldsEntry_DoNotUse_default_instance_); }
void MergeFrom(const ::google::protobuf::Message& other) PROTOBUF_FINAL;
::google::protobuf::Metadata GetMetadata() const;
};
// -------------------------------------------------------------------
class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Struct) */ {
public:
Struct();
@@ -78,48 +125,69 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Struct(Struct&& from) noexcept
: Struct() {
*this = ::std::move(from);
}
inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
inline void* GetMaybeArenaPointer() const {
inline Struct& operator=(Struct&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
return GetArenaNoVirtual();
}
inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Struct& default_instance();
static const Struct* internal_default_instance();
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
static inline const Struct* internal_default_instance() {
return reinterpret_cast<const Struct*>(
&_Struct_default_instance_);
}
static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
1;
void UnsafeArenaSwap(Struct* other);
void Swap(Struct* other);
friend void swap(Struct& a, Struct& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Struct* New() const { return New(NULL); }
inline Struct* New() const PROTOBUF_FINAL { return New(NULL); }
Struct* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Struct* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Struct& from);
void MergeFrom(const Struct& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Struct* other);
void UnsafeMergeFrom(const Struct& from);
protected:
explicit Struct(::google::protobuf::Arena* arena);
private:
@@ -134,7 +202,7 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -154,30 +222,19 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
friend class ::google::protobuf::Arena;
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
typedef ::google::protobuf::internal::MapEntryLite<
::std::string, ::google::protobuf::Value,
::google::protobuf::internal::WireFormatLite::TYPE_STRING,
::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE,
0 >
Struct_FieldsEntry;
::google::protobuf::internal::MapField<
Struct_FieldsEntry_DoNotUse,
::std::string, ::google::protobuf::Value,
::google::protobuf::internal::WireFormatLite::TYPE_STRING,
::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE,
0 > fields_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaultsListValueImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Struct> Struct_default_instance_;
// -------------------------------------------------------------------
class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Value) */ {
@@ -191,9 +248,25 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
CopyFrom(from);
return *this;
}
#if LANG_CXX11
Value(Value&& from) noexcept
: Value() {
*this = ::std::move(from);
}
inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
inline void* GetMaybeArenaPointer() const {
inline Value& operator=(Value&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
return GetArenaNoVirtual();
}
inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
@@ -209,40 +282,45 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
KIND_NOT_SET = 0,
};
static const Value* internal_default_instance();
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
static inline const Value* internal_default_instance() {
return reinterpret_cast<const Value*>(
&_Value_default_instance_);
}
static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
2;
void UnsafeArenaSwap(Value* other);
void Swap(Value* other);
friend void swap(Value& a, Value& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline Value* New() const { return New(NULL); }
inline Value* New() const PROTOBUF_FINAL { return New(NULL); }
Value* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
Value* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Value& from);
void MergeFrom(const Value& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Value* other);
void UnsafeMergeFrom(const Value& from);
protected:
explicit Value(::google::protobuf::Arena* arena);
private:
@@ -257,13 +335,13 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// optional .google.protobuf.NullValue null_value = 1;
// .google.protobuf.NullValue null_value = 1;
private:
bool has_null_value() const;
public:
@@ -272,7 +350,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
::google::protobuf::NullValue null_value() const;
void set_null_value(::google::protobuf::NullValue value);
// optional double number_value = 2;
// double number_value = 2;
private:
bool has_number_value() const;
public:
@@ -281,7 +359,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
double number_value() const;
void set_number_value(double value);
// optional string string_value = 3;
// string string_value = 3;
private:
bool has_string_value() const;
public:
@@ -289,16 +367,25 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
static const int kStringValueFieldNumber = 3;
const ::std::string& string_value() const;
void set_string_value(const ::std::string& value);
#if LANG_CXX11
void set_string_value(::std::string&& value);
#endif
void set_string_value(const char* value);
void set_string_value(const char* value, size_t size);
::std::string* mutable_string_value();
::std::string* release_string_value();
void set_allocated_string_value(::std::string* string_value);
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_string_value();
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_string_value(
::std::string* string_value);
// optional bool bool_value = 4;
// bool bool_value = 4;
private:
bool has_bool_value() const;
public:
@@ -307,58 +394,52 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
bool bool_value() const;
void set_bool_value(bool value);
// optional .google.protobuf.Struct struct_value = 5;
// .google.protobuf.Struct struct_value = 5;
bool has_struct_value() const;
void clear_struct_value();
static const int kStructValueFieldNumber = 5;
private:
void _slow_mutable_struct_value();
void _slow_set_allocated_struct_value(
::google::protobuf::Arena* message_arena, ::google::protobuf::Struct** struct_value);
::google::protobuf::Struct* _slow_release_struct_value();
public:
const ::google::protobuf::Struct& struct_value() const;
::google::protobuf::Struct* mutable_struct_value();
::google::protobuf::Struct* release_struct_value();
::google::protobuf::Struct* mutable_struct_value();
void set_allocated_struct_value(::google::protobuf::Struct* struct_value);
::google::protobuf::Struct* unsafe_arena_release_struct_value();
void unsafe_arena_set_allocated_struct_value(
::google::protobuf::Struct* struct_value);
::google::protobuf::Struct* unsafe_arena_release_struct_value();
// optional .google.protobuf.ListValue list_value = 6;
// .google.protobuf.ListValue list_value = 6;
bool has_list_value() const;
void clear_list_value();
static const int kListValueFieldNumber = 6;
private:
void _slow_mutable_list_value();
void _slow_set_allocated_list_value(
::google::protobuf::Arena* message_arena, ::google::protobuf::ListValue** list_value);
::google::protobuf::ListValue* _slow_release_list_value();
public:
const ::google::protobuf::ListValue& list_value() const;
::google::protobuf::ListValue* mutable_list_value();
::google::protobuf::ListValue* release_list_value();
::google::protobuf::ListValue* mutable_list_value();
void set_allocated_list_value(::google::protobuf::ListValue* list_value);
::google::protobuf::ListValue* unsafe_arena_release_list_value();
void unsafe_arena_set_allocated_list_value(
::google::protobuf::ListValue* list_value);
::google::protobuf::ListValue* unsafe_arena_release_list_value();
KindCase kind_case() const;
// @@protoc_insertion_point(class_scope:google.protobuf.Value)
private:
inline void set_has_null_value();
inline void set_has_number_value();
inline void set_has_string_value();
inline void set_has_bool_value();
inline void set_has_struct_value();
inline void set_has_list_value();
void set_has_null_value();
void set_has_number_value();
void set_has_string_value();
void set_has_bool_value();
void set_has_struct_value();
void set_has_list_value();
inline bool has_kind() const;
void clear_kind();
inline void clear_has_kind();
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
friend class ::google::protobuf::Arena;
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
union KindUnion {
@@ -373,15 +454,9 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
mutable int _cached_size_;
::google::protobuf::uint32 _oneof_case_[1];
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaultsListValueImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<Value> Value_default_instance_;
// -------------------------------------------------------------------
class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ListValue) */ {
@@ -395,48 +470,69 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro
CopyFrom(from);
return *this;
}
#if LANG_CXX11
ListValue(ListValue&& from) noexcept
: ListValue() {
*this = ::std::move(from);
}
inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
inline void* GetMaybeArenaPointer() const {
inline ListValue& operator=(ListValue&& from) noexcept {
if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
if (this != &from) InternalSwap(&from);
} else {
CopyFrom(from);
}
return *this;
}
#endif
inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
return GetArenaNoVirtual();
}
inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const ListValue& default_instance();
static const ListValue* internal_default_instance();
static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY
static inline const ListValue* internal_default_instance() {
return reinterpret_cast<const ListValue*>(
&_ListValue_default_instance_);
}
static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
3;
void UnsafeArenaSwap(ListValue* other);
void Swap(ListValue* other);
friend void swap(ListValue& a, ListValue& b) {
a.Swap(&b);
}
// implements Message ----------------------------------------------
inline ListValue* New() const { return New(NULL); }
inline ListValue* New() const PROTOBUF_FINAL { return New(NULL); }
ListValue* New(::google::protobuf::Arena* arena) const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
ListValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const ListValue& from);
void MergeFrom(const ListValue& from);
void Clear();
bool IsInitialized() const;
void Clear() PROTOBUF_FINAL;
bool IsInitialized() const PROTOBUF_FINAL;
size_t ByteSizeLong() const;
size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(ListValue* other);
void UnsafeMergeFrom(const ListValue& from);
protected:
explicit ListValue(::google::protobuf::Arena* arena);
private:
@@ -451,7 +547,7 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro
}
public:
::google::protobuf::Metadata GetMetadata() const;
::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -473,26 +569,25 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
friend class ::google::protobuf::Arena;
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::Value > values_;
mutable int _cached_size_;
friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl();
friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl();
friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
void InitAsDefaultInstance();
friend struct ::protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct;
friend void ::protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaultsListValueImpl();
};
extern ::google::protobuf::internal::ExplicitlyConstructed<ListValue> ListValue_default_instance_;
// ===================================================================
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif // __GNUC__
// -------------------------------------------------------------------
// Struct
// map<string, .google.protobuf.Value> fields = 1;
@@ -513,14 +608,11 @@ Struct::mutable_fields() {
return fields_.MutableMap();
}
inline const Struct* Struct::internal_default_instance() {
return &Struct_default_instance_.get();
}
// -------------------------------------------------------------------
// Value
// optional .google.protobuf.NullValue null_value = 1;
// .google.protobuf.NullValue null_value = 1;
inline bool Value::has_null_value() const {
return kind_case() == kNullValue;
}
@@ -549,7 +641,7 @@ inline void Value::set_null_value(::google::protobuf::NullValue value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.null_value)
}
// optional double number_value = 2;
// double number_value = 2;
inline bool Value::has_number_value() const {
return kind_case() == kNumberValue;
}
@@ -578,7 +670,7 @@ inline void Value::set_number_value(double value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.number_value)
}
// optional string string_value = 3;
// string string_value = 3;
inline bool Value::has_string_value() const {
return kind_case() == kStringValue;
}
@@ -595,7 +687,7 @@ inline void Value::clear_string_value() {
inline const ::std::string& Value::string_value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Value.string_value)
if (has_string_value()) {
return kind_.string_value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return kind_.string_value_.Get();
}
return *&::google::protobuf::internal::GetEmptyStringAlreadyInited();
}
@@ -609,7 +701,21 @@ inline void Value::set_string_value(const ::std::string& value) {
GetArenaNoVirtual());
// @@protoc_insertion_point(field_set:google.protobuf.Value.string_value)
}
#if LANG_CXX11
inline void Value::set_string_value(::std::string&& value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.string_value)
if (!has_string_value()) {
clear_kind();
set_has_string_value();
kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
kind_.string_value_.Set(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_rvalue:google.protobuf.Value.string_value)
}
#endif
inline void Value::set_string_value(const char* value) {
GOOGLE_DCHECK(value != NULL);
if (!has_string_value()) {
clear_kind();
set_has_string_value();
@@ -626,7 +732,8 @@ inline void Value::set_string_value(const char* value,
set_has_string_value();
kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
kind_.string_value_.Set(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
reinterpret_cast<const char*>(value), size),
GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Value.string_value)
@@ -651,17 +758,6 @@ inline ::std::string* Value::release_string_value() {
return NULL;
}
}
inline ::std::string* Value::unsafe_arena_release_string_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value)
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
if (has_string_value()) {
clear_has_kind();
return kind_.string_value_.UnsafeArenaRelease(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
} else {
return NULL;
}
}
inline void Value::set_allocated_string_value(::std::string* string_value) {
if (!has_string_value()) {
kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -674,6 +770,17 @@ inline void Value::set_allocated_string_value(::std::string* string_value) {
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value)
}
inline ::std::string* Value::unsafe_arena_release_string_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value)
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
if (has_string_value()) {
clear_has_kind();
return kind_.string_value_.UnsafeArenaRelease(
&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
} else {
return NULL;
}
}
inline void Value::unsafe_arena_set_allocated_string_value(::std::string* string_value) {
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
if (!has_string_value()) {
@@ -687,7 +794,7 @@ inline void Value::unsafe_arena_set_allocated_string_value(::std::string* string
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.string_value)
}
// optional bool bool_value = 4;
// bool bool_value = 4;
inline bool Value::has_bool_value() const {
return kind_case() == kBoolValue;
}
@@ -716,7 +823,7 @@ inline void Value::set_bool_value(bool value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.bool_value)
}
// optional .google.protobuf.Struct struct_value = 5;
// .google.protobuf.Struct struct_value = 5;
inline bool Value::has_struct_value() const {
return kind_case() == kStructValue;
}
@@ -731,11 +838,44 @@ inline void Value::clear_struct_value() {
clear_has_kind();
}
}
inline const ::google::protobuf::Struct& Value::struct_value() const {
inline ::google::protobuf::Struct* Value::release_struct_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value)
if (has_struct_value()) {
clear_has_kind();
::google::protobuf::Struct* temp = kind_.struct_value_;
if (GetArenaNoVirtual() != NULL) {
temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL);
}
kind_.struct_value_ = NULL;
return temp;
} else {
return NULL;
}
}
inline const ::google::protobuf::Struct& Value::struct_value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Value.struct_value)
return has_struct_value()
? *kind_.struct_value_
: ::google::protobuf::Struct::default_instance();
: *reinterpret_cast< ::google::protobuf::Struct*>(&::google::protobuf::_Struct_default_instance_);
}
inline ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value)
if (has_struct_value()) {
clear_has_kind();
::google::protobuf::Struct* temp = kind_.struct_value_;
kind_.struct_value_ = NULL;
return temp;
} else {
return NULL;
}
}
inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) {
clear_kind();
if (struct_value) {
set_has_struct_value();
kind_.struct_value_ = struct_value;
}
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.struct_value)
}
inline ::google::protobuf::Struct* Value::mutable_struct_value() {
if (!has_struct_value()) {
@@ -748,63 +888,8 @@ inline ::google::protobuf::Struct* Value::mutable_struct_value() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Value.struct_value)
return kind_.struct_value_;
}
inline ::google::protobuf::Struct* Value::release_struct_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value)
if (has_struct_value()) {
clear_has_kind();
if (GetArenaNoVirtual() != NULL) {
::google::protobuf::Struct* temp = new ::google::protobuf::Struct(*kind_.struct_value_);
kind_.struct_value_ = NULL;
return temp;
} else {
::google::protobuf::Struct* temp = kind_.struct_value_;
kind_.struct_value_ = NULL;
return temp;
}
} else {
return NULL;
}
}
inline void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) {
clear_kind();
if (struct_value) {
if (GetArenaNoVirtual() != NULL &&
::google::protobuf::Arena::GetArena(struct_value) == NULL) {
GetArenaNoVirtual()->Own(struct_value);
} else if (GetArenaNoVirtual() !=
::google::protobuf::Arena::GetArena(struct_value)) {
::google::protobuf::Struct* new_struct_value =
::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >(
GetArenaNoVirtual());
new_struct_value->CopyFrom(*struct_value);
struct_value = new_struct_value;
}
set_has_struct_value();
kind_.struct_value_ = struct_value;
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value)
}
inline ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value)
if (has_struct_value()) {
clear_has_kind();
::google::protobuf::Struct* temp = kind_.struct_value_;
kind_.struct_value_ = NULL;
return temp;
} else {
return NULL;
}
}
inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) {
clear_kind();
if (struct_value) {
set_has_struct_value();
kind_.struct_value_ = struct_value;
}
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.struct_value)
}
// optional .google.protobuf.ListValue list_value = 6;
// .google.protobuf.ListValue list_value = 6;
inline bool Value::has_list_value() const {
return kind_case() == kListValue;
}
@@ -819,11 +904,44 @@ inline void Value::clear_list_value() {
clear_has_kind();
}
}
inline const ::google::protobuf::ListValue& Value::list_value() const {
inline ::google::protobuf::ListValue* Value::release_list_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Value.list_value)
if (has_list_value()) {
clear_has_kind();
::google::protobuf::ListValue* temp = kind_.list_value_;
if (GetArenaNoVirtual() != NULL) {
temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL);
}
kind_.list_value_ = NULL;
return temp;
} else {
return NULL;
}
}
inline const ::google::protobuf::ListValue& Value::list_value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Value.list_value)
return has_list_value()
? *kind_.list_value_
: ::google::protobuf::ListValue::default_instance();
: *reinterpret_cast< ::google::protobuf::ListValue*>(&::google::protobuf::_ListValue_default_instance_);
}
inline ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value)
if (has_list_value()) {
clear_has_kind();
::google::protobuf::ListValue* temp = kind_.list_value_;
kind_.list_value_ = NULL;
return temp;
} else {
return NULL;
}
}
inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) {
clear_kind();
if (list_value) {
set_has_list_value();
kind_.list_value_ = list_value;
}
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.list_value)
}
inline ::google::protobuf::ListValue* Value::mutable_list_value() {
if (!has_list_value()) {
@@ -836,61 +954,6 @@ inline ::google::protobuf::ListValue* Value::mutable_list_value() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Value.list_value)
return kind_.list_value_;
}
inline ::google::protobuf::ListValue* Value::release_list_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Value.list_value)
if (has_list_value()) {
clear_has_kind();
if (GetArenaNoVirtual() != NULL) {
::google::protobuf::ListValue* temp = new ::google::protobuf::ListValue(*kind_.list_value_);
kind_.list_value_ = NULL;
return temp;
} else {
::google::protobuf::ListValue* temp = kind_.list_value_;
kind_.list_value_ = NULL;
return temp;
}
} else {
return NULL;
}
}
inline void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) {
clear_kind();
if (list_value) {
if (GetArenaNoVirtual() != NULL &&
::google::protobuf::Arena::GetArena(list_value) == NULL) {
GetArenaNoVirtual()->Own(list_value);
} else if (GetArenaNoVirtual() !=
::google::protobuf::Arena::GetArena(list_value)) {
::google::protobuf::ListValue* new_list_value =
::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >(
GetArenaNoVirtual());
new_list_value->CopyFrom(*list_value);
list_value = new_list_value;
}
set_has_list_value();
kind_.list_value_ = list_value;
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value)
}
inline ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value)
if (has_list_value()) {
clear_has_kind();
::google::protobuf::ListValue* temp = kind_.list_value_;
kind_.list_value_ = NULL;
return temp;
} else {
return NULL;
}
}
inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) {
clear_kind();
if (list_value) {
set_has_list_value();
kind_.list_value_ = list_value;
}
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.list_value)
}
inline bool Value::has_kind() const {
return kind_case() != KIND_NOT_SET;
@@ -901,9 +964,6 @@ inline void Value::clear_has_kind() {
inline Value::KindCase Value::kind_case() const {
return Value::KindCase(_oneof_case_[0]);
}
inline const Value* Value::internal_default_instance() {
return &Value_default_instance_.get();
}
// -------------------------------------------------------------------
// ListValue
@@ -938,10 +998,11 @@ ListValue::values() const {
return values_;
}
inline const ListValue* ListValue::internal_default_instance() {
return &ListValue_default_instance_.get();
}
#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif // __GNUC__
// -------------------------------------------------------------------
// -------------------------------------------------------------------
// -------------------------------------------------------------------
@@ -952,7 +1013,6 @@ inline const ListValue* ListValue::internal_default_instance() {
} // namespace protobuf
} // namespace google
#ifndef SWIG
namespace google {
namespace protobuf {
@@ -964,7 +1024,6 @@ inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::NullValue>()
} // namespace protobuf
} // namespace google
#endif // SWIG
// @@protoc_insertion_point(global_scope)
+30 -39
View File
@@ -63,28 +63,22 @@ namespace google {
namespace protobuf {
namespace internal {
#if defined(GOOGLE_PROTOBUF_ARCH_POWER)
#if defined(_LP64) || defined(__LP64__)
typedef int32 Atomic32;
typedef intptr_t Atomic64;
#ifdef GOOGLE_PROTOBUF_ARCH_32_BIT
typedef intptr_t Atomic32;
typedef int64 Atomic64;
#else
typedef intptr_t Atomic32;
typedef int64 Atomic64;
#endif
#else
typedef int32 Atomic32;
#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT
// We need to be able to go between Atomic64 and AtomicWord implicitly. This
// means Atomic64 and AtomicWord should be the same type on 64-bit.
#if defined(__ILP32__) || defined(GOOGLE_PROTOBUF_OS_NACL)
// NaCl's intptr_t is not actually 64-bits on 64-bit!
// http://code.google.com/p/nativeclient/issues/detail?id=1162
// sparcv9's pointer type is 32bits
typedef int64 Atomic64;
#else
typedef intptr_t Atomic64;
#endif
#endif
// We need to be able to go between Atomic64 and AtomicWord implicitly. This
// means Atomic64 and AtomicWord should be the same type on 64-bit.
#if defined(__ILP32__) || defined(GOOGLE_PROTOBUF_OS_NACL)
// NaCl's intptr_t is not actually 64-bits on 64-bit!
// http://code.google.com/p/nativeclient/issues/detail?id=1162
// sparcv9's pointer type is 32bits
typedef intptr_t Atomic32;
typedef int64 Atomic64;
#else
typedef int32 Atomic32;
typedef intptr_t Atomic64;
#endif
#endif
// Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or
@@ -123,8 +117,8 @@ Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
// access.
// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no
// memory access.
Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
@@ -132,10 +126,10 @@ Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
#if defined(__MINGW32__) && defined(MemoryBarrier)
#undef MemoryBarrier
#endif
void MemoryBarrier();
// This function was renamed from MemoryBarrier to MemoryBarrierInternal
// because MemoryBarrier is a define in Windows ARM builds and we do not
// undefine it because we call it from this function.
void MemoryBarrierInternal();
void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
void Release_Store(volatile Atomic32* ptr, Atomic32 value);
@@ -180,7 +174,7 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#include <google/protobuf/stubs/atomicops_internals_tsan.h>
// MSVC.
#elif defined(_MSC_VER)
#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64)
#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) || defined(GOOGLE_PROTOBUF_ARCH_ARM)
#include <google/protobuf/stubs/atomicops_internals_x86_msvc.h>
#else
#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR
@@ -194,16 +188,16 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#elif defined(GOOGLE_PROTOBUF_OS_AIX)
#include <google/protobuf/stubs/atomicops_internals_power.h>
// Apple.
#elif defined(GOOGLE_PROTOBUF_OS_APPLE)
#include <google/protobuf/stubs/atomicops_internals_macosx.h>
// GCC.
#elif defined(__GNUC__)
#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64)
#include <google/protobuf/stubs/atomicops_internals_x86_gcc.h>
#elif defined(GOOGLE_PROTOBUF_ARCH_ARM) && defined(__linux__)
#if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4))
#include <google/protobuf/stubs/atomicops_internals_generic_gcc.h>
#else
#include <google/protobuf/stubs/atomicops_internals_arm_gcc.h>
#endif
#elif defined(GOOGLE_PROTOBUF_ARCH_AARCH64)
#include <google/protobuf/stubs/atomicops_internals_arm64_gcc.h>
#elif defined(GOOGLE_PROTOBUF_ARCH_ARM_QNX)
@@ -213,7 +207,10 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#elif defined(GOOGLE_PROTOBUF_ARCH_POWER)
#include <google/protobuf/stubs/atomicops_internals_power.h>
#elif defined(__native_client__)
#include <google/protobuf/stubs/atomicops_internals_pnacl.h>
// The static_asserts in the C++11 atomics implementation cause it to fail
// with certain compilers, e.g. nvcc on macOS. Don't use elsewhere unless
// the TODO in that file is addressed.
#include <google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h>
#elif defined(GOOGLE_PROTOBUF_ARCH_PPC)
#include <google/protobuf/stubs/atomicops_internals_ppc_gcc.h>
#elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4))
@@ -233,12 +230,6 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR
#endif
// On some platforms we need additional declarations to make AtomicWord
// compatible with our other Atomic* types.
#if defined(GOOGLE_PROTOBUF_OS_APPLE)
#include <google/protobuf/stubs/atomicops_internals_atomicword_compat.h>
#endif
#undef GOOGLE_PROTOBUF_ATOMICOPS_ERROR
#endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY
@@ -37,7 +37,7 @@ namespace google {
namespace protobuf {
namespace internal {
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
__asm__ __volatile__ ("dmb ish" ::: "memory"); // NOLINT
}
@@ -117,9 +117,9 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic32 result = NoBarrier_AtomicIncrement(ptr, increment);
MemoryBarrier();
MemoryBarrierInternal();
return result;
}
@@ -128,7 +128,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
MemoryBarrier();
MemoryBarrierInternal();
return prev;
}
@@ -136,7 +136,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
return prev;
@@ -148,7 +148,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
@@ -178,7 +178,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -253,9 +253,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic64 result = NoBarrier_AtomicIncrement(ptr, increment);
MemoryBarrier();
MemoryBarrierInternal();
return result;
}
@@ -264,7 +264,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
MemoryBarrier();
MemoryBarrierInternal();
return prev;
}
@@ -272,7 +272,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
return prev;
@@ -284,7 +284,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
@@ -314,7 +314,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -115,17 +115,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
pLinuxKernelMemoryBarrier();
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
MemoryBarrier();
MemoryBarrierInternal();
*ptr = value;
}
@@ -135,12 +135,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -110,17 +110,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
__sync_synchronize();
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
MemoryBarrier();
MemoryBarrierInternal();
*ptr = value;
}
@@ -130,12 +130,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -1,122 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2012 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 is an internal atomic implementation, use atomicops.h instead.
#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
// AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32,
// which in turn means int. On some LP32 platforms, intptr_t is an int, but
// on others, it's a long. When AtomicWord and Atomic32 are based on different
// fundamental types, their pointers are incompatible.
//
// This file defines function overloads to allow both AtomicWord and Atomic32
// data to be used with this interface.
//
// On LP64 platforms, AtomicWord and Atomic64 are both always long,
// so this problem doesn't occur.
#if !defined(GOOGLE_PROTOBUF_ARCH_64_BIT)
namespace google {
namespace protobuf {
namespace internal {
inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr,
AtomicWord old_value,
AtomicWord new_value) {
return NoBarrier_CompareAndSwap(
reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
}
inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr,
AtomicWord new_value) {
return NoBarrier_AtomicExchange(
reinterpret_cast<volatile Atomic32*>(ptr), new_value);
}
inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr,
AtomicWord increment) {
return NoBarrier_AtomicIncrement(
reinterpret_cast<volatile Atomic32*>(ptr), increment);
}
inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr,
AtomicWord increment) {
return Barrier_AtomicIncrement(
reinterpret_cast<volatile Atomic32*>(ptr), increment);
}
inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr,
AtomicWord old_value,
AtomicWord new_value) {
return Acquire_CompareAndSwap(
reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
}
inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr,
AtomicWord old_value,
AtomicWord new_value) {
return Release_CompareAndSwap(
reinterpret_cast<volatile Atomic32*>(ptr), old_value, new_value);
}
inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) {
NoBarrier_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
}
inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) {
return Acquire_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
}
inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) {
return Release_Store(reinterpret_cast<volatile Atomic32*>(ptr), value);
}
inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) {
return NoBarrier_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
}
inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) {
return Acquire_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
}
inline AtomicWord Release_Load(volatile const AtomicWord* ptr) {
return Release_Load(reinterpret_cast<volatile const Atomic32*>(ptr));
}
} // namespace internal
} // namespace protobuf
} // namespace google
#endif // !defined(GOOGLE_PROTOBUF_ARCH_64_BIT)
#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
@@ -30,8 +30,8 @@
// This file is an internal atomic implementation, use atomicops.h instead.
#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_
#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_
#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_
#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_
#include <atomic>
@@ -52,7 +52,7 @@ typedef volatile std::atomic<Atomic32>* AtomicLocation32;
static_assert(sizeof(*(AtomicLocation32) nullptr) == sizeof(Atomic32),
"incompatible 32-bit atomic layout");
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
#if defined(__GLIBCXX__)
// Work around libstdc++ bug 51038 where atomic_thread_fence was declared but
// not defined, leading to the linker complaining about undefined references.
@@ -119,7 +119,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
((AtomicLocation32)ptr)->store(value, std::memory_order_relaxed);
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
@@ -135,7 +135,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return ((AtomicLocation32)ptr)->load(std::memory_order_relaxed);
}
@@ -202,7 +202,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
((AtomicLocation64)ptr)->store(value, std::memory_order_relaxed);
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
@@ -218,7 +218,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed);
}
@@ -228,4 +228,4 @@ inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_
#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_
@@ -38,7 +38,7 @@ namespace internal {
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, true,
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELAXED, __ATOMIC_RELAXED);
return old_value;
}
@@ -61,7 +61,7 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, true,
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
return old_value;
}
@@ -69,7 +69,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, true,
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELEASE, __ATOMIC_ACQUIRE);
return old_value;
}
@@ -78,7 +78,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
__atomic_store_n(ptr, value, __ATOMIC_RELAXED);
}
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
__sync_synchronize();
}
@@ -115,7 +115,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, true,
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
return old_value;
}
@@ -123,7 +123,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
__atomic_compare_exchange_n(ptr, &old_value, new_value, true,
__atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELAXED, __ATOMIC_RELAXED);
return old_value;
}
@@ -1,225 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2012 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 is an internal atomic implementation, use atomicops.h instead.
#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_
#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_
#include <libkern/OSAtomic.h>
namespace google {
namespace protobuf {
namespace internal {
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev_value;
do {
if (OSAtomicCompareAndSwap32(old_value, new_value,
const_cast<Atomic32*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
Atomic32 new_value) {
Atomic32 old_value;
do {
old_value = *ptr;
} while (!OSAtomicCompareAndSwap32(old_value, new_value,
const_cast<Atomic32*>(ptr)));
return old_value;
}
inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
return OSAtomicAdd32(increment, const_cast<Atomic32*>(ptr));
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
return OSAtomicAdd32Barrier(increment, const_cast<Atomic32*>(ptr));
}
inline void MemoryBarrier() {
OSMemoryBarrier();
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev_value;
do {
if (OSAtomicCompareAndSwap32Barrier(old_value, new_value,
const_cast<Atomic32*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
return Acquire_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
MemoryBarrier();
*ptr = value;
}
inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
return *ptr;
}
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
return *ptr;
}
#ifdef __LP64__
// 64-bit implementation on 64-bit platform
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev_value;
do {
if (OSAtomicCompareAndSwap64(old_value, new_value,
reinterpret_cast<volatile int64_t*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
Atomic64 new_value) {
Atomic64 old_value;
do {
old_value = *ptr;
} while (!OSAtomicCompareAndSwap64(old_value, new_value,
reinterpret_cast<volatile int64_t*>(ptr)));
return old_value;
}
inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
return OSAtomicAdd64(increment, reinterpret_cast<volatile int64_t*>(ptr));
}
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
return OSAtomicAdd64Barrier(increment,
reinterpret_cast<volatile int64_t*>(ptr));
}
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev_value;
do {
if (OSAtomicCompareAndSwap64Barrier(
old_value, new_value, reinterpret_cast<volatile int64_t*>(ptr))) {
return old_value;
}
prev_value = *ptr;
} while (prev_value == old_value);
return prev_value;
}
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
// The lib kern interface does not distinguish between
// Acquire and Release memory barriers; they are equivalent.
return Acquire_CompareAndSwap(ptr, old_value, new_value);
}
inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
}
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
MemoryBarrier();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
MemoryBarrier();
*ptr = value;
}
inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
return *ptr;
}
inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
Atomic64 value = *ptr;
MemoryBarrier();
return value;
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
return *ptr;
}
#endif // defined(__LP64__)
} // namespace internal
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_
@@ -125,8 +125,8 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
// access.
// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no
// memory access.
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
@@ -149,17 +149,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
__asm__ __volatile__("sync" : : : "memory");
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
MemoryBarrier();
MemoryBarrierInternal();
*ptr = value;
}
@@ -169,12 +169,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -247,9 +247,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic64 res = NoBarrier_AtomicIncrement(ptr, increment);
MemoryBarrier();
MemoryBarrierInternal();
return res;
}
@@ -257,20 +257,20 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
// access.
// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no
// memory access.
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
MemoryBarrier();
MemoryBarrierInternal();
return res;
}
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
MemoryBarrier();
MemoryBarrierInternal();
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
@@ -280,11 +280,11 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
MemoryBarrier();
MemoryBarrierInternal();
*ptr = value;
}
@@ -294,12 +294,12 @@ inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
Atomic64 value = *ptr;
MemoryBarrier();
MemoryBarrierInternal();
return value;
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
#endif
@@ -93,7 +93,7 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
return result;
}
inline void MemoryBarrier(void) {
inline void MemoryBarrierInternal(void) {
asm volatile (
" lwsync \n\t"
" isync \n\t"
@@ -97,22 +97,22 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr,
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr,
Atomic32 increment) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment);
MemoryBarrier();
MemoryBarrierInternal();
return res;
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value, Atomic32 new_value) {
Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
MemoryBarrier();
MemoryBarrierInternal();
return res;
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value, Atomic32 new_value) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
return res;
}
@@ -121,15 +121,15 @@ inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) {
*ptr = value;
}
inline void MemoryBarrier() { __asm__ __volatile__("sync" : : : "memory"); }
inline void MemoryBarrierInternal() { __asm__ __volatile__("sync" : : : "memory"); }
inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) {
MemoryBarrier();
MemoryBarrierInternal();
*ptr = value;
}
@@ -137,12 +137,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) { return *ptr; }
inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) {
Atomic32 value = *ptr;
MemoryBarrier();
MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32 *ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -54,16 +54,16 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
return (Atomic32)atomic_add_32_nv((volatile uint32_t*)ptr, (uint32_t)increment);
}
inline void MemoryBarrier(void) {
inline void MemoryBarrierInternal(void) {
membar_producer();
membar_consumer();
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic32 ret = NoBarrier_AtomicIncrement(ptr, increment);
MemoryBarrier();
MemoryBarrierInternal();
return ret;
}
@@ -72,7 +72,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
MemoryBarrier();
MemoryBarrierInternal();
return ret;
}
@@ -80,7 +80,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
MemoryBarrier();
MemoryBarrierInternal();
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
@@ -129,9 +129,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 incre
}
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) {
MemoryBarrier();
MemoryBarrierInternal();
Atomic64 ret = atomic_add_64_nv((volatile uint64_t*)ptr, increment);
MemoryBarrier();
MemoryBarrierInternal();
return ret;
}
@@ -139,14 +139,14 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
MemoryBarrier();
MemoryBarrierInternal();
return ret;
}
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
MemoryBarrier();
MemoryBarrierInternal();
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
@@ -206,7 +206,7 @@ inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr,
return cmp;
}
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
__tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
}
@@ -119,18 +119,18 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
// 64-bit implementations of memory barrier can be simpler, because it
// "mfence" is guaranteed to exist.
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
__asm__ __volatile__("mfence" : : : "memory");
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
#else
inline void MemoryBarrier() {
inline void MemoryBarrierInternal() {
if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
__asm__ __volatile__("mfence" : : : "memory");
} else { // mfence is faster but not present on PIII
@@ -168,7 +168,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}
@@ -225,7 +225,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
MemoryBarrier();
MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
@@ -262,7 +262,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
MemoryBarrier();
MemoryBarrierInternal();
return *ptr;
}

Some files were not shown because too many files have changed in this diff Show More