{"id":4625,"date":"2023-05-13T12:58:31","date_gmt":"2023-05-13T04:58:31","guid":{"rendered":"https:\/\/blog.coderfan.org\/?p=4625"},"modified":"2024-01-08T17:21:13","modified_gmt":"2024-01-08T09:21:13","slug":"how-to-use-google-protobuf-in-android12","status":"publish","type":"post","link":"https:\/\/blog.coderfan.org\/en\/how-to-use-google-protobuf-in-android12.html","title":{"rendered":"Android 12\u4e2d\u4f7f\u7528Google Protobuf"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>5 Minute, 34 Second                <\/div>\n\n            <\/div>\n<p class=\"has-text-align-justify\">Google Protobuf\u662f\u7531Google\u5b98\u65b9\u63a8\u51fa\u7684\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\u6846\u67b6\uff0c\u5176\u652f\u6301\u8de8\u8bed\u8a00\u3001\u8de8\u5e73\u53f0\uff0c\u5177\u6709\u826f\u597d\u7684\u62d3\u5c55\u6027\u3002Protobuf\u548c\u5176\u4ed6\u6240\u6709\u7684\u5e8f\u5217\u5316\u6846\u67b6\u4e00\u6837\uff08\u5982Json\u3001xml\u3001toml\u7b49\uff09\uff0c\u90fd\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u5b58\u50a8\u3001\u901a\u8baf\u534f\u8bae\u3002\u5728SOA\uff08Service-Oriented Architecture\uff09\u6846\u67b6\u4e0b\uff0cGoogle Protobuf\u5f97\u5230\u6781\u5927\u7a0b\u5ea6\u7684\u63a8\u5e7f\u3002\u5176\u4f18\u70b9\u5305\u62ec\uff1a<\/p>\n\n\n\n<p class=\"has-text-align-justify\">1.\u66f4\u5c0f\u7684\u8d44\u6e90\u6d88\u8017\uff0cPortobuf\u7684\u5e8f\u5217\u5316\u7684\u7ed3\u679c\u4f53\u79ef\u8981\u6bd4XML\u3001JSON\u5c0f\u5f88\u591a\uff0c\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u7a7a\u95f4\u7684\u5360\u7528\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">2.\u66f4\u5feb\u7684\u54cd\u5e94\u901f\u5ea6\u3002Portobuf\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u901f\u5ea6\u6bd4XML\u3001JSON\u5feb\u5f88\u591a\uff0c\u76f4\u63a5\u628a\u5bf9\u8c61\u548c\u5b57\u8282\u6570\u7ec4\u505a\u8f6c\u6362\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">3.\u826f\u597d\u7684\u540e\u5411\u517c\u5bb9\u6027\u3002Protobuf\u53ef\u4ee5\u4fdd\u8bc1\u5411\u4e0b\u517c\u5bb9\uff0c\u5373\u4f7f\u534f\u8bae\u53d8\u66f4\u4e5f\u80fd\u4fdd\u8bc1\u4ee5\u5f80\u7684\u5e94\u7528\u53ef\u7528\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">4.\u9ad8\u53ef\u590d\u7528\u7684\u5e94\u7528\u4ee3\u7801\u3002Protobuf\u63d0\u4f9b\u4e86IDL\u5de5\u5177\u53ef\u4ee5\u5feb\u901f\u5730\u5e2e\u52a9\u5f00\u53d1\u8005\u751f\u6210\u901a\u4fe1\u6240\u9700\u7684\u80f6\u6c34\u4ee3\u7801\uff0c\u63d0\u5347\u6548\u7387\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">5.\u8de8\u5e73\u53f0\u3001\u8de8\u8bed\u8a00\u3002Protobuf\u53ef\u4ee5\u652f\u6301C++\/C#\/JAVA\/Kotlin\/&nbsp;Objective-C\/PHP\/Python\/Ruby\/Go\/Dart\u7b49\u7f16\u7a0b\u8bed\u8a00\uff0c\u9002\u7528\u4e8e\u591a\u4e2a\u5e73\u53f0\uff0c\u81ea\u7136\u4e5f\u5305\u62ecAndroid\u7cfb\u7edf\u3002<\/p>\n\n\n\n<p>\u5176\u5b98\u65b9\u7f51\u7ad9\u53ef\u70b9\u51fb<a href=\"https:\/\/protobuf.dev\" class=\"ek-link\">here<\/a>\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5982\u4f55\u4f7f\u7528<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u5728Android\u4e2d\u4f7f\u7528Google Protobuf\u65f6\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fddAndroid\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u6709\u4e86Protobuf\u7684\u8fd0\u884c\u73af\u5883\uff0c\u4e5f\u5c31\u662fprotobuf\u7684\u8fd0\u884c\u5e93\u3002\u8fd9\u91cc\u4ee5Trout x86\u865a\u62df\u673a\u4e3a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">trout_x86:\/system\/lib # ls -la | grep protobuf                                                                                                                                                             \n-rw-r--r--  1 root root  2375220 2009-01-01 08:00 libprotobuf-cpp-full.so\n-rw-r--r--  1 root root   507396 2009-01-01 08:00 libprotobuf-cpp-lite.so\ntrout_x86:\/system\/lib # <\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8fd9\u91cc\u6709\u4e24\u4e2aProtobuf\u8fd0\u884c\u5e93\uff0c\u76f8\u5e94\u7684\u4e5f\u5bf9\u5e94\u4e24\u4e2a\u53d8\u4f53\uff1aProtobuf-Full\u4e0eProtobuf-Lite\u3002\u8fd9\u4e24\u4e2a\u53d8\u4f53\u7684\u5dee\u5f02\u5728\u4e8e\uff1a<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u5927\u5c0f<\/strong>\uff1alite\u7248\u672c\u76f8\u6bd4\u4e8efull\u7248\u672c\u8282\u770120%\u5de6\u53f3\u7684\u4ee3\u7801\u5bb9\u91cf\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u901f\u5ea6<\/strong>\uff1a lite\u7248\u672c\u76f8\u6bd4\u4e8efull\u7248\u672c\u4f7f\u7528\u901f\u5ea6\u4e0a\u5feb\u7ea620%\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u7279\u6027<\/strong>\uff1afull\u7248\u672c\u6bd4lite\u7248\u672c\u589e\u52a0\u4e86\u8bb8\u591a\u65b0\u7684\u7279\u6027\uff0c\u5982\u53cd\u5c04\uff0c\u591a\u8bed\u8a00\u652f\u6301\u7b49<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u5982\u4f55\u9009\u62e9\u4f7f\u7528\u54ea\u4e2a\u53d8\u4f53\u5462\uff0c\u5f88\u7b80\u5355\uff0c\u5982\u679c\u4f60\u6ce8\u91cd\u4f7f\u7528\u6548\u7387\u4e14\u4e0d\u9700\u8981\u53cd\u5c04\u7b49\u529f\u80fd\uff0c\u90a3\u4e48\u9009\u62e9lite\u7248\u672c\uff0c\u5426\u5219\u63a8\u8350\u4f7f\u7528full\u7248\u672c\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">AOSP\u4e2d\u662f\u901a\u8fc7\u6e90\u7801\u65b9\u5f0f\u6765\u7f16\u8bd1\u4f7f\u7528protobuf\u7684\uff0c\u5176\u6e90\u7801\u8def\u5f84\u4e3a\/external\/protobuf\uff0c\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u770b\u4e00\u4e0bAndroid.bp\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">\n\/\/ C++ full library for the platform and host\n\/\/ =======================================================\ncc_library {\n    name: \"libprotobuf-cpp-full\",\n    defaults: [\"libprotobuf-cpp-full-defaults\"],\n    host_supported: true,\n    vendor_available: true,\n    product_available: true,\n    \/\/ TODO(b\/153609531): remove when no longer needed.\n    native_bridge_supported: true,\n    target: {\n        android: {\n            static: {\n                enabled: false,\n            },\n        },\n        windows: {\n            enabled: true,\n        },\n    },\n    apex_available: [\n        \"\/\/apex_available:platform\",\n        \"com.android.appsearch\",\n        \"com.android.virt\",\n    ],\n}\n\n\/\/ C++ lite library for the platform and host.\n\/\/ =======================================================\ncc_library {\n    name: \"libprotobuf-cpp-lite\",\n    host_supported: true,\n    recovery_available: true,\n    vendor_available: true,\n    vendor_ramdisk_available: true,\n    product_available: true,\n    double_loadable: true,\n    defaults: [\"libprotobuf-cpp-lite-defaults\"],\n\n    target: {\n        windows: {\n            enabled: true,\n        },\n    },\n    apex_available: [\n        \"\/\/apex_available:platform\",\n        \"\/\/apex_available:anyapex\",\n    ],\n    min_sdk_version: \"29\",\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u8be5Android.bp\u9664\u4e86\u7f16\u8bd1\u4e0a\u8ff0\u4e24\u4e2a\u5e93\uff0c\u540c\u65f6\u4e5f\u7f16\u8bd1\u4e86Java\u4e0ePython\u7248\u672c\u7684\u5e93\uff0c\u5177\u4f53\u89c4\u5219\u53ef\u4ed4\u7ec6\u67e5\u770bAndroid.bp\u5185\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u6211\u4eec\u5728\u4f7f\u7528protobuf\u65f6\u5c31\u9700\u8981\u5f15\u7528\u5bf9\u5e94\u7684\u8fd0\u884c\u5e93\uff0c\u9664\u4e86\u8fd0\u884c\u5e93\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u53e6\u5916\u4e00\u4e2a\u57fa\u7840\u6750\u6599\u2014\u2014proto\u5b9a\u4e49\u6587\u4ef6\uff0c\u4e5f\u5c31\u662f\u540e\u7f00\u4e3a*.proto\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u800c\u5177\u4f53\u4f7f\u7528\u65f6\uff0c\u6211\u4eec\u4e3b\u8981\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u65b9\u5f0f\u4e00\uff1a\u5229\u7528AOSP soong\u7f16\u8bd1\u7cfb\u7edf\u7ed3\u5408Android.bp\u81ea\u52a8\u6839\u636e*.proto\u6587\u4ef6\u751f\u6210\u5bf9\u5e94\u7684\u80f6\u6c34\u4ee3\u7801\u8fdb\u884c\u7f16\u8bd1\u540e\u4f7f\u7528\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u65b9\u5f0f\u4e8c\uff1a\u624b\u52a8\u901a\u8fc7protoc\uff08protobuf compiler\uff09\u7ed3\u5408*.proto\u6587\u4ef6\u751f\u6210\u6e90\u4ee3\u7801\uff0c\u6839\u636e\u6e90\u4ee3\u7801\u7f16\u5199\u7f16\u8bd1\u914d\u7f6e\u6587\u4ef6\uff08Android.mk\u6216\u8005Android.bp\uff09\u8fdb\u884c\u7f16\u8bd1\u540e\u4f7f\u7528\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u6b64\u5904\u4e3e\u4f8b\u8bf4\u660e\uff0c\u6bd4\u5982\u6211\u4eec\u6709\u4e00\u5806\u7f16\u5199\u597d\u7684*&nbsp;.proto\u6587\u4ef6\uff0c\u60f3\u8981\u751f\u6210\u540d\u4e3alibfoo.so\u7684\u8fd9\u6837\u4e00\u4e2a\u5e93\u8fdb\u884c\u4f7f\u7528\u3002\u5728\u4f7f\u7528\u65b9\u5f0f\u4e00\u65f6\uff0c\u76f4\u63a5\u901a\u8fc7Android.bp\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">cc_library {\n    name: \"libfoo\",\n    srcs: [\n        \"example1.proto\",\n        \"example2.proto\",\n        \"example3.proto\"\n    ],\n    proto: {\n        export_proto_headers: true,\n        type: \"lite\",\n    },\n    shared_libs: [\n        \"libprotobuf-cpp-lite\",\n    ],\n    cppflags: [\n        \"-Wall\",\n        \"-Werror\",\n        \"-Wunused\",\n        \"-Wunreachable-code\",\n        \"-Wno-unknown-pragmas\",\n        \"-Wno-unused-parameter\",\n        \"-Wno-non-virtual-dtor\",\n        \"-Wno-macro-redefined\",\n        \"-Wno-unused-lambda-capture\",\n        \"-fexceptions\",\n        \"-fPIE\",\n        \"-fPIC\"\n    ],\n}<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u8fd9\u91cc\u6211\u4eec\u901a\u8fc7proto\u5b57\u6bb5\u6765\u8bbe\u7f6eprotobuf\u7684\u7c7b\u578b\uff0c\u8bbe\u7f6etype\u4e3alite\u5219\u4f7f\u7528libprotobuf-cpp-lite.so\u8fd0\u884c\u5e93\uff0c\u8bbe\u7f6etype\u4e3afull\u5219\u4f7f\u7528libprotobuf-cpp-full.so\u8fd0\u884c\u5e93\uff0c\u76f8\u5e94\u5730\u6211\u4eec\u5728shared_libs\u4e2d\u5f15\u7528\u5bf9\u5e94\u7684\u8fd0\u884c\u5e93\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u4f7f\u7528\u65b9\u5f0f\u4e8c\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528protoc\u5de5\u5177\u6765\u5c06proto\u914d\u7f6e\u751f\u6210\u6e90\u7801\u6587\u4ef6\uff0c\u8fd9\u91cc\u6211\u4eec\u770b\u4e00\u4e0bprotoc\u7684\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">FranzKafka@Franz:\/opt\/FranzKafkaYu\/Android12.1$ protoc\nUsage: protoc [OPTION] PROTO_FILES\nParse PROTO_FILES and generate output based on the options given:\n  --cpp_out=OUT_DIR           Generate C++ header and source.\n  --csharp_out=OUT_DIR        Generate C# source file.\n  --java_out=OUT_DIR          Generate Java source file.\n  --js_out=OUT_DIR            Generate JavaScript source.\n  --objc_out=OUT_DIR          Generate Objective C header and source.\n  --php_out=OUT_DIR           Generate PHP source file.\n  --python_out=OUT_DIR        Generate Python source file.\n  --ruby_out=OUT_DIR          Generate Ruby source file.\n  -IPATH, --proto_path=PATH   Specify the directory in which to search for\n                              imports.  May be specified multiple times;\n                              directories will be searched in order.  If not\n                              given, the current working directory is used.\n  --version                   Show version info and exit.\n  -h, --help                  Show this text and exit.\n  --encode=MESSAGE_TYPE       Read a text-format message of the given type\n                              from standard input and write it in binary\n                              to standard output.  The message type must\n                              be defined in PROTO_FILES or their imports.\n  --decode=MESSAGE_TYPE       Read a binary message of the given type from\n                              standard input and write it in text format\n                              to standard output.  The message type must\n                              be defined in PROTO_FILES or their imports.\n  --decode_raw                Read an arbitrary protocol message from\n                              standard input and write the raw tag\/value\n                              pairs in text format to standard output.  No\n                              PROTO_FILES should be given when using this\n                              flag.<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u8fd9\u91cc\u6211\u4eec\u751f\u6210C++\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">FranzKafka@Franz:\/opt\/FranzKafkaYu\/Android12.1$protoc adas_msg.proto --cpp_out=.\nFranzKafka@Franz:\/opt\/FranzKafkaYu\/Android12.1$ls -la\n-rw-rw-r-- 1 FranzKafkaYu FranzKafkaYu 197858 May 13 11:30 adas_msg.pb.cc\n-rw-rw-r-- 1 FranzKafkaYu FranzKafkaYu 151598 May 13 11:30 adas_msg.pb.h\n-rw-rw-r-- 1 FranzKafkaYu FranzKafkaYu   3972 Apr 17 18:15 adas_msg.proto\nFranzKafka@Franz:\/opt\/FranzKafkaYu\/Android12.1$<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5bf9\u5f62\u5982example.proto\u7684proto\u914d\u7f6e\u6587\u4ef6\uff0c\u4f1a\u751f\u6210example.pb.h\u7684\u5934\u6587\u4ef6\u548cexample.pb.cc\u6e90\u7801\u6587\u4ef6\uff0c\u5728\u751f\u6210\u8fd9\u4e9b\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u76f4\u63a5\u5f15\u7528\u751f\u6210\u7684\u6e90\u7801\u6587\u4ef6\u5c31\u597d\u4e86\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u8bed\u6cd5\u89c4\u5219<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u4f7f\u7528protobuf\u91cd\u8981\u7684\u5c31\u662fprotobuf\u7684\u914d\u7f6e\u6587\u4ef6\u7f16\u5199\uff0c\u8fd9\u91cc\u9700\u8981\u4e86\u89e3protbuf\u914d\u7f6e\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u5f53\u524dGoogle protobuf\u5206\u4e3a\u4e24\u4e2a\u7248\u672c\uff1aproto2\u4e0eproto3.\u8fd9\u91cc\u4ee5proto2\u4e3a\u4e3b\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n\n\n\n<p>\u6240\u6709\u7684\u6570\u636e\u7ed3\u6784\u5b9a\u4e49\u6587\u4ef6\u4ee5.proto\u7ed3\u5c3e\uff0c\u4ee5\u4e0b\u4e3a\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">syntax = \"proto2\";\n\nmessage SearchRequest {\n  optional string query = 1;\n  optional int32 page_number = 2;\n  optional int32 result_per_page = 3;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5176\u4e2d\u7b2c\u4e00\u884c\u89c4\u5b9a\u4e86proto\u7248\u672c\uff0c\u8fd9\u662f\u5fc5\u987b\u7684\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u7b2c\u4e8c\u884c\u5f00\u59cb\u5b9a\u4e49\u4e00\u4e2amessage\u7c7b\u578b\uff0cmessage\u4f5c\u4e3a\u5173\u952e\u5b57\u5b58\u5728\uff0c\u662fprotobuf\u4e2d\u6700\u5c0f\u7684\u6570\u636e\u5b9a\u4e49\u5355\u5143\uff0c\u800cSearchRequest\u4f5c\u4e3amessage\u7c7b\u578b\u7684\u540d\u79f0\u3002\u800cSearchRequest\u7c7b\u578b\u5185\u90e8\u5305\u542b\u4e09\u4e2a\u5b50field\uff0c\u8fd9\u4e9b\u5b50filed\u5c31\u662f\u6211\u4eec\u9700\u8981\u4f20\u8f93\u7684\u5177\u4f53\u7684\u6d88\u606f\u5b57\u6bb5\u3002Message\u6574\u4f53\u4e0a\u7c7b\u4f3c\u4e8eC\/C++\u4e2d\u7684struct\u7ed3\u6784\u4f53\u3002\u5728\u540c\u4e00\u4e2aproto\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u591a\u4e2amessage\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u9488\u5bf9\u8fd9\u4e9b\u5b50filed\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u5176\u6570\u636e\u7c7b\u578b\uff0c\u4e14\u5206\u914d\u4e00\u4e2a\u8303\u56f4\u4e3a1~536870911\u7684id\uff08\u6392\u966419000-19999,\u8fd9\u90e8\u5206id\u662f\u5c5e\u4e8ereserved\u4fdd\u7559\u5b57\u6bb5\uff09\uff0c\u9700\u8981\u4e3b\u6ce8\u610f\u7684\u662f\u8be5id\u5728\u5bf9\u5e94\u7684message\u7c7b\u578b\u5185\u5fc5\u987b\u662f\u5168\u5c40\u552f\u4e00\u7684\uff0c\u63a8\u8350\u4f7f\u75281~15\u7684id\uff08\u5360\u7528\u4e00\u4e2a\u5b57\u8282\uff09<\/p>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u5b9a\u4e49\u5b50field\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528optional\u3001repeated\u3001required\u7b49\u5173\u952e\u5b57\u4e3a\u5b50field\u5b9a\u4e49\u989d\u5916\u7684\u89c4\u5219\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>Optional<\/strong>\uff1a\u8868\u660e\u8be5field\u5728\u6d88\u606f\u4f53\u4e2d\u81f3\u591a\u53ea\u67091\u6b21\uff0c\u4e5f\u53ef\u80fd\u4e0d\u4f1a\u6709\u5bf9\u5e94\u7684\u503c<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>Repeated<\/strong>\uff1a\u8868\u660e\u8be5field\u5728\u6d88\u606f\u4f53\u4e2d\u53ef\u4ee5\u591a\u6b21\u51fa\u73b0<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>Reqiuired<\/strong>\uff1a\u5df2\u4e0d\u518d\u63a8\u8350\u4f7f\u7528\uff0c\u5728proto3\u4e2d\u5df2\u88ab\u79fb\u9664<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u6ce8\u91ca\uff1a<\/strong>proto\u6587\u4ef6\u4e2d\u53ef\u4ee5\u4f7f\u7528\u6ce8\u91ca\uff0c\u5176\u8bed\u6cd5\u89c4\u5219\u7c7b\u4f3c\u4e8eC\/C++\uff0c\u4f7f\u7528\/\/\u8fdb\u884c\u884c\u6ce8\u91ca\uff0c\u4f7f\u7528\/**\/\u8fdb\u884c\u5757\u6ce8\u91ca\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u6570\u636e\u7c7b\u578b\uff1a<\/strong>proto\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u4ee5\u53ca\u5bf9\u5e94\u5230C\/C++\u65f6\u7684\u53c2\u8003\u8868<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Proto<\/strong><strong>\u7c7b\u578b<\/strong><\/td><td><strong>\u5907\u6ce8<\/strong><\/td><td><strong>C\/C++<\/strong><strong>\u7c7b\u578b<\/strong><\/td><\/tr><tr><td><strong>doulble<\/strong><\/td><td><strong>&nbsp;<\/strong><\/td><td><strong>doulble<\/strong><\/td><\/tr><tr><td><strong>float<\/strong><\/td><td><strong>&nbsp;<\/strong><\/td><td><strong>float<\/strong><\/td><\/tr><tr><td><strong>int32<\/strong><\/td><td><strong>\u5bf9\u4e8e\u5b58\u5728\u8d1f\u6570\u7684\u6570\u503c\u7f16\u7801\u6548\u7387\u8f83\u4f4e<\/strong><\/td><td><strong>int32<\/strong><\/td><\/tr><tr><td><strong>int64<\/strong><\/td><td><strong>\u5bf9\u4e8e\u5b58\u5728\u8d1f\u6570\u7684\u6570\u503c\u7f16\u7801\u6548\u7387\u8f83\u4f4e<\/strong><\/td><td><strong>int64<\/strong><\/td><\/tr><tr><td><strong>sint32<\/strong><\/td><td><strong>\u6709\u7b26\u53f7int 32<\/strong><strong>\uff0c\u5f53\u503c<\/strong><\/td><td><strong>int32<\/strong><\/td><\/tr><tr><td><strong>sint64<\/strong><\/td><td><strong>&nbsp;<\/strong><\/td><td><strong>int64<\/strong><\/td><\/tr><tr><td><strong>uint32<\/strong><\/td><td><strong>\u65e0\u7b26\u53f7int 32<\/strong><\/td><td><strong>uint32<\/strong><\/td><\/tr><tr><td><strong>uint64<\/strong><\/td><td><strong>\u65e0\u7b26\u53f7int 64<\/strong><\/td><td><strong>uint64<\/strong><\/td><\/tr><tr><td><strong>string<\/strong><\/td><td><strong>UTF-8<\/strong><strong>\u7f16\u7801<\/strong><\/td><td><strong>string<\/strong><\/td><\/tr><tr><td><strong>bytes<\/strong><\/td><td><strong>&nbsp;<\/strong><\/td><td><strong>string<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6b64\u5916\uff0c\u6240\u6709\u7684\u6570\u636e\u7c7b\u578b\u90fd\u4f1a\u6267\u884c\u7c7b\u578b\u68c0\u67e5\u4ee5\u786e\u4fdd\u5176\u503c\u662f\u6709\u6548\u7684\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u9ed8\u8ba4\u503c\uff1a<\/strong>\u9488\u5bf9optional\u7684field\uff0c\u5728\u4f20\u8f93\u7684message\u4e2d\u53ef\u80fd\u662f\u4e0d\u5b58\u5728\u503c\u7684\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u4e3a\u67d0\u4e9b\u8fd9\u7c7b\u5b50field\u8bbe\u5b9a\u9ed8\u8ba4\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528default\u5173\u952e\u5b57\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>optional int32 result_per_page = 3 [default = 10];<\/strong> \u5982\u679c\u6ca1\u6709\u8fd9\u6837\u663e\u5f0f\u5730\u5b9a\u4e49\u5176\u9ed8\u8ba4\u503c\uff0c\u5c06\u4f1a\u6839\u636e\u6570\u636e\u7c7b\u578b\u81ea\u52a8\u6dfb\u52a0\u9ed8\u8ba4\u503c\uff0cstring\u7c7b\u578b\u7684\u9ed8\u8ba4\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0cbool\u7c7b\u578b\u9ed8\u8ba4\u503c\u4e3afalse\uff0c\u6570\u503c\u7c7b\u578b\u9ed8\u8ba4\u503c\u5219\u4e3a0\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u590d\u5408\u7c7b\u578b<\/strong><strong>\u4e4b\u679a\u4e3e\uff1a<\/strong>\u6211\u4eec\u53ef\u4ee5\u5728proto\u6587\u4ef6\u4e2d\u5b9a\u4e49\u679a\u4e3e\u4f53\uff0c\u4e0eC\/C++\u7c7b\u4f3c\uff0c\u5b9a\u4e49\u679a\u4e3e\u4f53\u4f7f\u7528enum\u5173\u952e\u5b57\uff0c\u5728\u4f7f\u7528\u4e0a\u4e5f\u4e0eC\/C++\u4e2d\u7684\u679a\u4e3e\u4f53\u7c7b\u4f3c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">enum Corpus {\n  CORPUS_UNSPECIFIED = 0;\n  CORPUS_UNIVERSAL = 1;\n  CORPUS_WEB = 2;\n  CORPUS_IMAGES = 3;\n  CORPUS_LOCAL = 4;\n  CORPUS_NEWS = 5;\n  CORPUS_PRODUCTS = 6;\n  CORPUS_VIDEO = 7;\n}\n\nmessage SearchRequest {\n  optional string query = 1;\n  optional int32 page_number = 2;\n  optional int32 result_per_page = 3 [default = 10];\n  optional Corpus corpus = 4 [default = CORPUS_UNIVERSAL];\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\"><strong>Message\u5d4c\u5957\uff1a<\/strong>\u6211\u4eec\u53ef\u4ee5\u5728message\u7684\u5b50field\u4e2d\u4f7f\u7528\u5b9a\u4e49\u597d\u7684\u5176\u4ed6message\u7c7b\u578b\uff0c\u4ece\u800c\u5b9e\u73b0\u5d4c\u5957\u4f7f\u7528\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u5bfc\u5165\u5176\u4ed6proto<\/strong><strong>\u6587\u4ef6\uff1a<\/strong>\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\u6211\u4eec\u53ef\u80fd\u4f1a\u5b9a\u4e49\u591a\u4e2aproto\u6587\u4ef6\uff0c\u5e76\u4e14\u9700\u8981\u5f15\u5165\u5176\u4ed6proto\u6587\u4ef6\u4e2d\u5b9a\u4e49\u597d\u7684message\u6216\u8005enum\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528import\u5173\u952e\u5b57\u8fdb\u884c\u5bfc\u5165\u3002<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong>\u5b9a\u4e49packages<\/strong>\uff1a\u5b9a\u4e49package\u53ef\u4ee5\u4e3a\u751f\u6210\u7684\u4ee3\u7801\u63d0\u4f9b\u7c7b\u4f3c\u4e8e\u547d\u540d\u7a7a\u95f4\u7684\u4f5c\u7528\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u751f\u6210\u7684\u4ee3\u7801\u4e0d\u4f1a\u6709\u90a3\u4e48\u591a\u7684\u51b2\u7a81\u3002<\/p>\n\n\n\n<p>\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">syntax = \"proto2\";\n\n\/\/\u5bfc\u5165\u5176\u4ed6proto\nimport \"plates.proto\";\nimport \"poles.proto\";\nimport \"calibration_state.proto\";\n\npackage autoplt;\n\nmessage AutoCalibMsg {\n    optional int32 example1 = 1;\n    optional int32 example2 = 2;\n    optional float example3 = 3;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u4e86\u89e3\u8bed\u6cd5\u89c4\u5219\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7f16\u5199\u81ea\u5df1\u7684proto\u914d\u7f6e\u6587\u4ef6\uff0c\u751f\u6210\u4ee3\u7801\u8fdb\u884c\u7f16\u8bd1\u4f7f\u7528\u4e86\uff0c\u63a5\u4e0b\u6765\u8bb2\u8bb2protobuf\u4e2d\u7684\u5e38\u7528API\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">API\u4f7f\u7528<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u4f7f\u7528protoc\u5c06*.proto\u751f\u6210\u5bf9\u5e94\u7684\u4ee3\u7801\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u4e00\u4e0b\u751f\u6210\u7684\u4ee3\u7801\u5185\u5bb9\uff0c\u4e86\u89e3Google protobuf\u6240\u63d0\u4f9b\u7684API\uff0c\u65b9\u4fbf\u540e\u7eed\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>\u68c0\u67e5\/\u7ba1\u7406API:<\/strong><\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">void CopyFrom(const ::google::protobuf::Message&amp; from) final;\nvoid MergeFrom(const ::google::protobuf::Message&amp; from) final;\nvoid CopyFrom(const xxxxxx&amp; from); \/\/\u7528\u5916\u90e8\u6d88\u606f\u7684\u503c\uff0c\u8986\u5199\u8c03\u7528\u8005\u6d88\u606f\u5185\u90e8\u7684\u503c\u3002\nvoid MergeFrom(const xxxxxx&amp; from); \/\/\u5c06\u5916\u90e8\u6d88\u606f\u7684\u503c\u5408\u5e76\u5230\u8c03\u7528\u8005\u6d88\u606f\u5185\u90e8\u7684\u503c\u3002\nvoid Clear() final;\/\/\u6e05\u9664\u6240\u6709\u7684\u6570\u636e\u4ee5\u53ca\u76f8\u5173\u6807\u5fd7\u4f4d\nbool IsInitialized() const final;\/\/\u68c0\u67e5\u6d88\u606f\u4e2d\u6240\u6709\u7684\u5b57\u6bb5\u662f\u5426\u8bbe\u5b9a\u521d\u59cb\u503c\nsize_t ByteSizeLong() const final; \/\/\u83b7\u53d6\u6d88\u606f\u7684\u5b57\u8282\u6570\u5927\u5c0f\nvoid Swap(xxxxxx* other); \/\/\u5c06\u5916\u90e8\u6d88\u606f\u7684\u503c\u4e0e\u8c03\u7528\u8005\u6d88\u606f\u5185\u90e8\u7684\u503c\u8fdb\u884c\u4ea4\u6362<\/code><\/pre>\n\n\n\n<p>\u8bca\u65ad\u76f8\u5173API:<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">string DebugString() const;\t\/\/\u5c06\u6d88\u606f\u5185\u5bb9\u4ee5\u53ef\u8bfb\u7684\u65b9\u5f0f\u8f93\u51fa\nstring ShortDebugString() const; \/\/\u529f\u80fd\u7c7b\u4f3c\u4e8e\uff0cDebugString(),\u8f93\u51fa\u65f6\u4f1a\u6709\u8f83\u5c11\u7684\u7a7a\u767d\nstring Utf8DebugString() const; \/\/Like DebugString()\nvoid PrintDebugString() const;\/\u3001GDB\u8c03\u8bd5\u65f6\u6253\u5370\u81f3stdout<\/code><\/pre>\n\n\n\n<p>\u4ee5traffic_sign.proto\u4e3a\u4f8b\uff0c\u5176\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">syntax = \"proto2\";\npackage example.vehicle;\nmessage TrafficSignHead{\nxxxx\n}\nmessage TrafficSignObject{\nxxxx\nxxx\n}\n\nmessage TrafficSignMsg {\n    optional TrafficSignHead head = 1;\n    repeated TrafficSignObject objects = 2;\n};<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5176\u5bf9\u5e94\u4f1a\u751f\u6210traffic_sign.pb.cc\u548ctrafic_sign.pb.h\u4e24\u4e2a\u6587\u4ef6;\u5728trafic_sign.pb.h\u5185\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e09\u4e2a\u547d\u540d\u7a7a\u95f4\uff0c\u5206\u522b\u4e3a\uff1aprotobuf_traffic_5fsign_2eproto\uff0c::example::vehicle,::google::protobuf<\/p>\n\n\n\n<p>\u5176\u4e2d::example::vehicle\u547d\u540d\u7a7a\u95f4\u5185\u5305\u542b\u4e09\u4e2a\u7c7b&nbsp;\uff0c\u5206\u522b\u4e3aTrafficSignHead\u3001TrafficSignObject\u3001TrafficSignMsg\uff0c\u8fd9\u4e09\u4e2a\u7c7b\u5c31\u662f\u6211\u4eec\u5728proto\u4e2d\u5b9a\u4e49\u597d\u7684message\uff0c\u9488\u5bf9message\u5185\u4e0d\u540c\u5c5e\u6027\u7684\u6210\u5458\uff08optional\/repeated\/required\uff09\uff0c\u5176\u751f\u6210\u7684\u5185\u5bb9\u4e5f\u6709\u5dee\u5f02\u3002<\/p>\n\n\n\n<p>optional\uff1a\u83b7\u53d6\u5bf9\u5e94\u7684\u5b50field\u5185\u5bb9\uff0c\u6709\u4e09\u4e2a\u6210\u5458\u51fd\u6570\u53ef\u9009\uff0c\u5982\u4e0a\u793a\u4f8b\u4e2d\u751f\u6210\u7684\u4ee3\u7801\u5982\u4e0b\uff0c\u5176\u4e2dhead\u4e3aoptional\u5c5e\u6027\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">  const ::example::vehicle::TrafficSignHead&amp; head() const;\n  ::example::vehicle::TrafficSignHead* release_head();\n  ::example::vehicle:TrafficSignHead* mutable_head();<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">repeated\uff1arepeated\u7684\u6210\u5458\u53ef\u80fd\u4f1a\u5728\u540c\u4e00\u5305message\u4e2d\u643a\u5e26\u591a\u6761\u91cd\u590d\u7684\u4fe1\u606f\uff0c\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528xxx_size()\u83b7\u53d6\u5177\u4f53\u7684size\u5927\u5c0f\uff0c\u8981\u83b7\u53d6\u5bf9\u5e94\u7684\u5b50field\u5185\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u6210\u5458\u51fd\u6570\uff1amutable_xxxx(int index),xxxx(int index),\u5176\u4e2dxxx\u4e3a\u5bf9\u5e94repeated\u5b50filed name\uff0c\u6b64\u5904\u5c06\u4ee5traffic_sign.proto\u4e3a\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"io-enlighter-pre\"><code class=\"gl\" data-enlighter-language=\"generic\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-highlight=\"\">::example::vehicle::TrafficSignObject* mutable_objects(int index); \/\/\u83b7\u53d6\u4e0d\u540cindex\u6240\u5bf9\u5e94\u7684\u6570\u636e\nconst ::example::vehicle::TrafficSignObject&amp; objects(int index) const;\/\/\u83b7\u53d6\u4e0d\u540cindex\u6240\u5bf9\u5e94\u7684\u6570\u636e<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-justify\">\u5173\u4e8emutable_xxxx(int index)\u4e0exxxx(int index),\u7684\u533a\u522b\uff1a\u4e24\u8005\u90fd\u5c5e\u4e8eRepeatedPtrField\u7c7b\u7684\u6210\u5458\u51fd\u6570\uff0c\u4e0d\u8fc7\u524d\u8005\u662f\u901a\u8fc7RepeatedPtrField\u7c7b\u7684Mutable(int index)\u6210\u5458\u51fd\u6570\u8fdb\u884c\u83b7\u53d6\uff0c\u83b7\u53d6\u7684\u662f\u5bf9\u8c61\u7684\u6307\u9488\uff1b\u800c\u540e\u8005\u901a\u8fc7Get(int index)\u6210\u5458\u51fd\u6570\u8fdb\u884c\u83b7\u53d6\uff0c\u83b7\u53d6\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Others<\/h4>\n\n\n\n<p class=\"has-text-align-justify\">\u5728\u4f7f\u7528protobuf\u65f6\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u6ce8\u610f\u5176\u7248\u672c\u8981\u6c42\uff0c\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u4e24\u4e2a\u7248\u672c\uff1a\u4e00\u662f\u8fd0\u884c\u5e93\u7684\u7248\u672c\u8981\u6c42\uff0c\u4e8c\u662fproto\u8bed\u6cd5\u7684\u7248\u672c\uff0c\u6211\u4eec\u4e0d\u80fd\u5728\u4e00\u4e2a\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u4e24\u4e2a\u8fd0\u884c\u5e93\u7248\u672c\u6216\u8005\u4e24\u4e2aproto\u8bed\u6cd5\u7248\u672c\u3002<\/p>\n        <div class=\"booster-block booster-reactions-block\">\n            <div class=\"twp-reactions-icons\">\n                \n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-1\" post-id=\"4625\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/happy.svg\" alt=\"Happy\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Happy                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">5<\/span>\n                        \n                                                <span class=\"twp-react-percent\"><span>100<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-2\" post-id=\"4625\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/sad.svg\" alt=\"Sad\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Sad                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-3\" post-id=\"4625\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/excited.svg\" alt=\"Excited\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Excited                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-6\" post-id=\"4625\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/sleepy.svg\" alt=\"Sleepy\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">\n                        Sleepy                    <\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                        \n                                                <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-4\" post-id=\"4625\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/angry.svg\" alt=\"Angry\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">Angry<\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                        \n                    <\/div>\n                <\/div>\n\n                <div class=\"twp-reacts-wrap\">\n                    <a react-data=\"be-react-5\" post-id=\"4625\" class=\"be-face-icons un-reacted\" href=\"javascript:void(0)\">\n                        <img decoding=\"async\" src=\"https:\/\/blog.coderfan.org\/wp-content\/plugins\/booster-extension\/\/assets\/icon\/surprise.svg\" alt=\"Surprise\">\n                    <\/a>\n                    <div class=\"twp-reaction-title\">Surprise<\/div>\n                    <div class=\"twp-count-percent\">\n                                                    <span style=\"display: none;\" class=\"twp-react-count\">0<\/span>\n                                                                        <span class=\"twp-react-percent\"><span>0<\/span> %<\/span>\n                                            <\/div>\n                <\/div>\n\n            <\/div>\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>Android12\u4e2d\u4f7f\u7528Google Protobuf<\/p>","protected":false},"author":1,"featured_media":4483,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":2,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[18],"tags":[46,69],"class_list":["post-4625","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-operating-system","tag-android","tag-protobuf"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[]}},"aioseo_notices":[],"featured_image_urls":{"full":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"thumbnail":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android-150x150.jpg",150,150,true],"medium":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android-300x158.jpg",300,158,true],"medium_large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"1536x1536":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"2048x2048":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"trp-custom-language-flag":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android-18x9.jpg",18,9,true]},"post_excerpt_stackable":"<p>Android12\u4e2d\u4f7f\u7528Google Protobuf<\/p>\n","category_list":"<a href=\"https:\/\/blog.coderfan.org\/en\/category\/operating-system\" rel=\"category tag\">\u64cd\u4f5c\u7cfb\u7edf<\/a>","author_info":{"name":"FranzKafka95","url":"https:\/\/blog.coderfan.org\/en\/author\/yushenglonely95"},"comments_num":"0 comments","featured_image_urls_v2":{"full":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"thumbnail":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android-150x150.jpg",150,150,true],"medium":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android-300x158.jpg",300,158,true],"medium_large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"large":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"1536x1536":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"2048x2048":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android.jpg",512,269,false],"trp-custom-language-flag":["https:\/\/blog.coderfan.org\/wp-content\/uploads\/2023\/04\/android-18x9.jpg",18,9,true]},"post_excerpt_stackable_v2":"<p>Android12\u4e2d\u4f7f\u7528Google Protobuf<\/p>\n","category_list_v2":"<a href=\"https:\/\/blog.coderfan.org\/en\/category\/operating-system\" rel=\"category tag\">\u64cd\u4f5c\u7cfb\u7edf<\/a>","author_info_v2":{"name":"FranzKafka95","url":"https:\/\/blog.coderfan.org\/en\/author\/yushenglonely95"},"comments_num_v2":"0 comments","_links":{"self":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts\/4625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/comments?post=4625"}],"version-history":[{"count":38,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts\/4625\/revisions"}],"predecessor-version":[{"id":5096,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/posts\/4625\/revisions\/5096"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/media\/4483"}],"wp:attachment":[{"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/media?parent=4625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/categories?post=4625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coderfan.org\/en\/wp-json\/wp\/v2\/tags?post=4625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}