{"id":65938,"date":"2026-01-25T22:32:44","date_gmt":"2026-01-25T14:32:44","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/65938.html"},"modified":"2026-01-25T22:32:44","modified_gmt":"2026-01-25T14:32:44","slug":"protobuf%e4%bb%8b%e7%bb%8d%e4%b8%8e%e5%bf%ab%e9%80%9f%e4%b8%8a%e6%89%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/65938.html","title":{"rendered":"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b"},"content":{"rendered":"<h2>protobuf\u4ecb\u7ecd<\/h2>\n<p>\u6839\u636egoogle\u5b98\u65b9\u7684\u4ecb\u7ecd:<\/p>\n<p>Protocol Buffers\u662fGoogle\u7684\u4e00\u79cd\u8bed\u8a00\u65e0\u5173,\u5e73\u53f0\u65e0\u5173,\u53ef\u6269\u5c55\u7684\u5e8f\u5217\u5316\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5,\u5b83\u53ef\u7528\u4e8e\u6570\u636e\u901a\u4fe1\u534f\u8bae,\u6570\u636e\u5b58\u50a8\u7b49.<\/p>\n<p>Protocol Buffer\u7c7b\u6bd4XML\/JSON,\u662f\u4e00\u79cd\u7075\u6d3b,\u9ad8\u6548,\u81ea\u52a8\u5316\u673a\u5236\u7684\u7ed3\u6784\u6570\u636e\u5e8f\u5217\u65b9\u6cd5,\u4f46\u662f\u6bd4XML\/JSON\u66f4\u5c0f,\u66f4\u5feb,\u66f4\u7b80\u5355.<\/p>\n<p>\u4f60\u53ef\u4ee5\u5b9a\u4e49\u6570\u636e\u7ed3\u6784,\u7136\u540e\u4f7f\u7528\u7279\u6b8a\u751f\u6210\u7684\u6e90\u4ee3\u7801\u8f7b\u677e\u7684\u5728\u5404\u79cd\u6570\u636e\u6d41\u4e2d\u4f7f\u7528\u5404\u79cd\u8bed\u8a00\u7f16\u5199\u548c\u8bfb\u53d6\u6570\u636e\u7ed3\u6784.\u4f60\u751a\u81f3\u53ef\u4ee5\u66f4\u65b0\u6570\u636e\u7ed3\u6784,\u800c\u4e0d\u7834\u574f\u65e7\u6570\u636e\u7ed3\u6784\u7f16\u8bd1\u7684\u4ee5\u90e8\u7f72\u7a0b\u5e8f.<\/p>\n<h3>\u6982\u5ff5\u8865\u5145<\/h3>\n<p>\u5e8f\u5217\u5316\u6982\u5ff5:<\/p>\n<p>\u5e38\u89c1\u7684\u5b9e\u73b0\u5e8f\u8bdd\u7684\u65b9\u5f0f\u6709:XML,JSON,protobuf<\/p>\n<p>\u5e8f\u5217\u5316\u662f\u6307: \u628a\u5bf9\u8c61\u8f6c\u5316\u4e3a\u5b57\u8282\u5e8f\u5217\u7684\u8fc7\u7a0b,\u79f0\u4e3a\u5bf9\u8c61\u7684\u5e8f\u5217\u5316.<\/p>\n<p>\u53cd\u5e8f\u5217\u5316\u662f\u6307: \u628a\u5b57\u8282\u5e8f\u5217\u6062\u590d\u4e3a\u5bf9\u8c61\u7684\u8fc7\u7a0b\u79f0\u4e3a\u5bf9\u8c61\u7684\u53cd\u5e8f\u5217\u5316<\/p>\n<p>\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\u9700\u8981\u5e8f\u5217\u5316<\/p>\n<li>\n<p>\u5b58\u50a8\u6570\u636e: \u9700\u8981\u628a\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5b58\u50a8\u5230\u6587\u4ef6\u6216\u8005\u6570\u636e\u5e93\u4e2d\u65f6.<\/p>\n<\/li>\n<li>\n<p>\u7f51\u7edc\u4f20\u8f93: \u7f51\u7edc\u76f4\u63a5\u4f20\u8f93\u6570\u636e,\u4f46\u662f\u65e0\u6cd5\u4f20\u8f93\u5bf9\u8c61,\u6240\u4ee5\u8981\u5728\u4f20\u8f93\u524d\u8fdb\u884c\u5e8f\u5217\u5316\u5b8c\u6210\u4f20\u8f93\u540e\u518d\u8fdb\u884c\u53cd\u5e8f\u5217\u5316.<\/p>\n<\/li>\n<h2>Protobuf\u4f7f\u7528\u6d41\u7a0b<\/h2>\n<li>\n<p>\u7f16\u5199&#034;.ptoto&#034;\u6587\u4ef6,\u786e\u5b9a\u7ed3\u6784\u5bf9\u8c61\u4ee5\u53ca\u5c5e\u6027\u5185\u5bb9.<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528protoc\u7f16\u8bd1\u5668\u7f16\u8bd1&#034;.proto&#034;\u6587\u4ef6,\u7f16\u8bd1\u8fc7\u540e\u4f1a\u81ea\u52a8\u751f\u6210\u63a5\u53e3\u4ee3\u7801<\/p>\n<\/li>\n<li>\n<p>\u4f9d\u8d56\u751f\u6210\u7684\u63a5\u53e3,\u5c06\u7f16\u8bd1\u751f\u6210\u7684\u5934\u6587\u4ef6\u5305\u542b\u8fdb\u6211\u4eec\u7684\u4ee3\u7801\u4e2d,\u5b9e\u73b0\u5bf9&#034;.proto&#034;\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u5b57\u6bb5\u8fdb\u884c\u8bbe\u7f6e\u548c\u83b7\u53d6,\u548c\u5bf9&#034;message&#034;\u5bf9\u8c61\u8fdb\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316.<\/p>\n<\/li>\n<p>\u4f7f\u7528\u6d41\u7a0b\u5c0f\u7ed3:<\/p>\n<p>protobuf\u662f\u9700\u8981\u4f9d\u8d56\u7f16\u8bd1\u751f\u6210\u7684\u5934\u6587\u4ef6\u548c\u6e90\u6587\u4ef6\u4f7f\u7528\u7684.\u6709\u4e86\u8fd9\u79cd\u4ee3\u7801\u751f\u6210\u673a\u5236,\u7a0b\u5e8f&#x1f412;\u5c31\u4e0d\u9700\u8981\u5728\u5403\u529b\u7684\u7f16\u5199\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u4ee3\u7801\u4e86.<\/p>\n<p>\u6682\u65f6\u65e0\u6cd5\u5728\u98de\u4e66\u6587\u6863\u5916\u5c55\u793a\u6b64\u5185\u5bb9<\/p>\n<h2>\u5feb\u901f\u4e0a\u624bProtobuf<\/h2>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u4f7f\u7528\u6d41\u7a0b\u6765\u5feb\u901f\u4e0a\u624bProtobuf,\u4e0b\u9762\u6211\u4f1a\u901a\u8fc7\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4e2a\u4eba\u4fe1\u606f\u5bf9\u8c61\u6765\u6f14\u793aprotobuf\u7684\u4f7f\u7528.<\/p>\n<li>\n<p>\u7f16\u5199.proto\u6587\u4ef6,\u786e\u5b9a\u5bf9\u8c61\u7ed3\u6784<\/p>\n<\/li>\n<p>\/\/\u6587\u4ef6\u540d\u4e3acontacts.proto<br \/>\nsyntax &#061; &#034;proto3&#034;;<br \/>\npackage contacts;<\/p>\n<p>message PeopleInfo {<br \/>\n    string name &#061; 1;<br \/>\n    int32 age &#061; 2;<br \/>\n}<\/p>\n<p>\u89e3\u6790:<\/p>\n<ul>\n<li>\n<p>syntax &#061; &#034;proto3&#034;;<\/p>\n<ul>\n<li>\n<p>\u8868\u793a\u4f7f\u7528\u7684\u8bed\u6cd5\u7248\u672c\u4e3a&#034;proto3&#034;,\u8fd9\u662fprotobuf\u7684\u6700\u65b0\u8bed\u6cd5\u7248\u672c,\u66f4\u6613\u4e8e\u4f7f\u7528,\u540c\u65f6\u652f\u6301\u7684\u8bed\u8a00\u4e5f\u66f4\u591a\u4e86.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>package contacts;<\/p>\n<ul>\n<li>\n<p>package \u662f\u4e00\u4e2a\u53ef\u9009\u7684\u58f0\u660e\u7b26,\u8868\u793a&#034;.proto&#034;\u6587\u4ef6\u7684\u547d\u540d\u7a7a\u95f4.\u53ef\u4ee5\u7c7b\u6bd4\u4e0eC&#043;&#043;\u7684namespace<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>message PeopleInfo<\/p>\n<ul>\n<li>\n<p>\u5b9a\u4e49\u7684\u7ed3\u6784\u5316\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>\u547d\u540d\u89c4\u8303\u4e3a\u5927\u9a7c\u5cf0\u547d\u540d\u6cd5<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>string name &#061; 1<\/p>\n<ul>\n<li>\n<p>\u5b9a\u4e49\u6d88\u606f\u5b57\u6bb5,\u683c\u5f0f\u4e3a:\u5b57\u6bb5\u7c7b\u578b \u5b57\u6bb5\u540d &#061; \u5b57\u6bb5\u552f\u4e00\u7f16\u53f7.<\/p>\n<\/li>\n<li>\n<p>\u547d\u540d\u89c4\u8303:\u5168\u5c0f\u5199\u5b57\u6bcd&#xff0c;\u591a\u4e2a\u5b57\u6bcd\u4e4b\u95f4\u7528 _ \u8fde\u63a5<\/p>\n<\/li>\n<li>\n<p>\u5b57\u6bb5\u7c7b\u578b\u5206\u4e3a&#xff1a;\u6807\u91cf\u6570\u636e\u7c7b\u578b \u548c \u7279\u6b8a\u7c7b\u578b&#xff08;\u5305\u62ec\u679a\u4e3e\u3001\u5176\u4ed6\u6d88\u606f\u7c7b\u578b\u7b49&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b57\u6bb5\u552f\u4e00\u7f16\u53f7&#xff1a;\u7528\u6765\u6807\u8bc6\u5b57\u6bb5&#xff0c;\u4e00\u65e6\u5f00\u59cb\u4f7f\u7528\u5c31\u4e0d\u80fd\u591f\u518d\u6539\u53d8<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>protobuf\u652f\u6301\u7684\u6807\u91cf\u6570\u636e\u7c7b\u578b\u4e0e\u5176\u5bf9\u5e94\u7684C&#043;&#043;\u7c7b\u578b\u89c1\u9644\u5f55<\/p>\n<li>\n<p>\u4f7f\u7528protoc\u7f16\u8bd1\u5668\u7f16\u8bd1&#034;.proto&#034;\u6587\u4ef6,\u7f16\u8bd1\u8fc7\u540e\u4f1a\u81ea\u52a8\u751f\u6210\u63a5\u53e3\u4ee3\u7801<\/p>\n<\/li>\n<p>\u5728\u7ec8\u7aef\u8f93\u5165:<\/p>\n<p>protoc &#8211;cpp_out&#061;. contacts.proto<\/p>\n<p>\u89e3\u6790:<\/p>\n<ul>\n<li>\n<p>&#8211;cpp_out&#061;.<\/p>\n<ul>\n<li>\n<p>&#034;&#8211;cpp_out&#034;\u8868\u793a\u7f16\u8bd1\u540e\u7684\u6587\u4ef6\u4e3aC&#043;&#043;\u6587\u4ef6,&#034;&#061;.&#034;\u8868\u793a\u751f\u6210\u7684\u6587\u4ef6\u5b58\u50a8\u5728\u5f53\u524d\u76ee\u5f55\u4e0b<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>contacts.proto<\/p>\n<ul>\n<li>\n<p>\u8981\u88ab\u7f16\u8bd1\u7684&#034;.proto&#034;\u6587\u4ef6<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6267\u884c\u6307\u4ee4\u540e\u5bf9\u4e8e\u76ee\u5f55\u4e0b\u9762\u4f1a\u751f\u6210\u5bf9\u5e94\u7684\u58f0\u660e\u6587\u4ef6\u548c\u5b9e\u73b0\u6587\u4ef6:<\/p>\n<p>root&#064;instance-5a74bdri:~\/protobuf\/fast_start# ls<br \/>\ncontacts.pb.cc  contacts.pb.h  contacts.proto  main.cc<\/p>\n<p>\u5bf9\u4e8e\u7f16\u8bd1\u751f\u6210\u7684C&#043;&#043;\u4ee3\u7801,\u5305\u542b\u4e86\u4ee5\u4e0b\u5185\u5bb9:<\/p>\n<ul>\n<li>\n<p>\u5bf9\u4e8e\u6bcf\u4e2amessage,\u90fd\u4f1a\u751f\u6210\u4e00\u4e2a\u5bf9\u5e94\u7684\u6d88\u606f\u7c7b.<\/p>\n<\/li>\n<li>\n<p>\u5728\u6d88\u606f\u7c7b\u4e2d,\u7f16\u8bd1\u5668\u4e3a\u6bcf\u4e2a\u5b57\u6bb5\u63d0\u4f9b\u4e86\u83b7\u53d6\u548c\u8bbe\u7f6e\u65b9\u6cd5&#xff0c;\u4ee5\u53ca\u4e00\u4e0b\u5176\u4ed6\u80fd\u591f\u64cd\u4f5c\u5b57\u6bb5\u7684\u65b9\u6cd5\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f16\u8bd1\u5668\u4f1a\u9488\u5bf9\u6bcf\u4e2a&#034;.proto&#034;\u6587\u4ef6\u751f\u6210&#034;.h&#034;\u548c&#034;.cc&#034;\u6587\u4ef6,\u5206\u522b\u5b58\u50a8\u7c7b\u7684\u58f0\u660e\u548c\u7c7b\u7684\u5b9e\u73b0.<\/p>\n<\/li>\n<\/ul>\n<p>&#034;contacts.pb.h&#034;\u6587\u4ef6(\u5c40\u90e8)<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"454\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260125143242-6976298ad6a8b.png\" width=\"1358\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230proto\u7f16\u8bd1\u5668\u4e3a\u6211\u4eec\u751f\u6210\u7684\u547d\u540d\u7a7a\u95f4&#034;contacts&#034;\u548c\u7c7b&#034;PeopleInfo&#034;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"557\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260125143243-6976298b33602.png\" width=\"1384\" \/><\/p>\n<ul>\n<li>\n<p>\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u6709\u8bbe\u7f6e\u548c\u83b7\u53d6\u7684\u65b9\u6cd5,getter\u548c\u540d\u79f0\u4e0e\u5c0f\u5199\u5b57\u6bb5\u5b8c\u5168\u76f8\u540c,setter\u65b9\u6cd5\u4ee5set_\u5f00\u5934<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u6709clear_\u65b9\u6cd5,\u53ef\u4ee5\u5c06\u5b57\u6bb5\u91cd\u65b0\u8bbe\u7f6e\u56deempty\u72b6\u6001<\/p>\n<\/li>\n<\/ul>\n<p>\u4ed4\u7ec6\u89c2\u5bdf&#034;contacts.pb.h&#034;\u6587\u4ef6,\u5e76\u6ca1\u6709\u53d1\u73b0\u6709\u5173\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u51fd\u6570,\u8fd9\u662f\u56e0\u4e3a\u5b83\u4eec\u5728\u6d88\u606f\u7c7b\u7684\u7236\u7c7b&#034;MessageLite&#034;\u4e2d.<\/p>\n<p>class MessageLite{<br \/>\npublic:<br \/>\n    \/\/\u5e8f\u5217\u5316<br \/>\n    bool SerializeToOstream(ostream* output) const; \/\/\u5c06\u5e8f\u5217\u5316\u540e\u7684\u6570\u636e\u5199\u5165\u6587\u4ef6<br \/>\n    bool SerializeToArray(void *data, int size) const;\/\/\u5e8f\u5217\u5316\u540e\u7684\u6570\u636e\u5199\u5165\u6307\u5b9a\u7684\u5185\u5b58\u6570\u7ec4,size\u8868\u793a\u6700\u5927\u53ef\u7528\u5b57\u8282\u6570\u3002<br \/>\n    bool SerializeToString(string* output) const;\/\/\u5c06\u5e8f\u5217\u5316\u540e\u7684\u6570\u636e\u5199\u5165\u5b57\u7b26\u4e32<br \/>\n    \/\/\u53cd\u5e8f\u5217\u5316<br \/>\n    bool ParseFromIstream(istream* input);\/\/\u4ece\u6d41\u4e2d\u8bfb\u53d6\u6570\u636e&#xff0c;\u518d\u8fdb\u884c\u53cd\u5e8f\u5217\u5316<br \/>\n    bool ParseFromArray(const void* data, int size);<br \/>\n    bool ParseFromString(const string&amp; data);\/\/\u4ece\u5b57\u7b26\u4e32\u4e2d\u8bfb\u53d6\u6570\u636e,\u518d\u8fdb\u884c\u53cd\u5e8f\u5217\u5316<br \/>\n}<\/p>\n<li>\n<p>\u4f9d\u8d56\u751f\u6210\u7684\u63a5\u53e3,\u5c06\u7f16\u8bd1\u751f\u6210\u7684\u5934\u6587\u4ef6\u5305\u542b\u8fdb\u6211\u4eec\u7684\u4ee3\u7801\u4e2d,\u5b9e\u73b0\u5bf9&#034;.proto&#034;\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u5b57\u6bb5\u8fdb\u884c\u8bbe\u7f6e\u548c\u83b7\u53d6,\u548c\u5bf9&#034;message&#034;\u5bf9\u8c61\u8fdb\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316.<\/p>\n<\/li>\n<p>\/\/\u6587\u4ef6\u540d: main.cc<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &#034;contacts.pb.h&#034;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    std::string data;<br \/>\n    {<br \/>\n        contacts::PeopleInfo peopleInfo;<br \/>\n        peopleInfo.set_name(&#034;yui&#034;);<br \/>\n        peopleInfo.set_age(17);<br \/>\n        peopleInfo.SerializeToString(&amp;data);<br \/>\n    }<\/p>\n<p>    {<br \/>\n        contacts::PeopleInfo peopleInfo;<br \/>\n        peopleInfo.ParseFromString(data);<br \/>\n        std::cout&lt;&lt;peopleInfo.name()&lt;&lt;std::endl;<br \/>\n        std::cout&lt;&lt;peopleInfo.age()&lt;&lt;std::endl;<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p>\u7f16\u5199makefile<\/p>\n<p>main:main.cc g&#043;&#043; -o $&#064; $^ contacts.pb.cc -std&#061;c&#043;&#043;11 -lprotobuf<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c:<\/p>\n<p>root&#064;instance-5a74bdri:~\/protobuf\/fast_start# make<br \/>\ng&#043;&#043; -o main main.cc contacts.pb.cc -std&#061;c&#043;&#043;11 -lprotobuf<br \/>\nroot&#064;instance-5a74bdri:~\/protobuf\/fast_start# .\/main<br \/>\nyui<br \/>\n17<\/p>\n<h2>\u9644\u5f55<\/h2>\n<p>\u6807\u91cf\u6570\u636e\u7c7b\u578b<\/p>\n<table>\n<tbody>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>.proto Type<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>Notes<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>C&#043;&#043; Type<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>double<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>double<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>float<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>float<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int32<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4f7f\u7528\u53d8\u957f\u7f16\u7801\u3002\u8d1f\u6570\u7684\u7f16\u7801\u6548\u7387\u8f83\u4f4e\u2014\u2014\u82e5\u5b57\u6bb5\u53ef\u80fd\u4e3a\u8d1f\u503c&#xff0c;\u5e94\u4f7f\u7528 sint32 \u4ee3\u66ff\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int32<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int64<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4f7f\u7528\u53d8\u957f\u7f16\u7801\u3002\u8d1f\u6570\u7684\u7f16\u7801\u6548\u7387\u8f83\u4f4e\u2014\u2014\u82e5\u5b57\u6bb5\u53ef\u80fd\u4e3a\u8d1f\u503c&#xff0c;\u5e94\u4f7f\u7528 sint64 \u4ee3\u66ff\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int64<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>uint32<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4f7f\u7528\u53d8\u957f\u7f16\u7801\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>uint32<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>uint64<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4f7f\u7528\u53d8\u957f\u7f16\u7801\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>uint64<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>sint32<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4f7f\u7528\u53d8\u957f\u7f16\u7801\u3002\u7b26\u53f7\u6574\u578b\u3002\u8d1f\u503c\u7684\u7f16\u7801\u6548\u7387\u9ad8\u4e8e\u5e38\u89c4\u7684 int32 \u7c7b\u578b\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int32<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>sint64<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4f7f\u7528\u53d8\u957f\u7f16\u7801\u3002\u7b26\u53f7\u6574\u578b\u3002\u8d1f\u503c\u7684\u7f16\u7801\u6548\u7387\u9ad8\u4e8e\u5e38\u89c4\u7684 int64 \u7c7b\u578b\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int64<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>fixed32<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5b9a\u957f 4 \u5b57\u8282\u3002\u82e5\u503c\u5e38\u5927\u4e8e 2^28 \u5219\u4f1a\u6bd4 uint32 \u66f4\u9ad8\u6548\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>uint32<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>fixed64<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5b9a\u957f 8 \u5b57\u8282\u3002\u82e5\u503c\u5e38\u5927\u4e8e 2^56 \u5219\u4f1a\u6bd4 uint64 \u66f4\u9ad8\u6548\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>uint64<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>sfixed32<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5b9a\u957f 4 \u5b57\u8282\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int32<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>sfixed64<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5b9a\u957f 8 \u5b57\u8282\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>int64<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>bool<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>bool<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>string<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5305\u542b UTF-8 \u548c ASCII \u7f16\u7801\u7684\u5b57\u7b26\u4e32&#xff0c;\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc7 2^32\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>string<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>bytes<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53ef\u5305\u542b\u4efb\u610f\u7684\u5b57\u8282\u5e8f\u5217\u4f46\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc7 2^32\u3002<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>string<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/p>\n","protected":false},"excerpt":{"rendered":"<p>protobuf\u4ecb\u7ecd\u6839\u636egoogle\u5b98\u65b9\u7684\u4ecb\u7ecd:Protocol Buffers\u662fGoogle\u7684\u4e00\u79cd\u8bed\u8a00\u65e0\u5173,\u5e73\u53f0\u65e0\u5173,\u53ef\u6269\u5c55\u7684\u5e8f\u5217\u5316\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5,\u5b83\u53ef\u7528\u4e8e\u6570\u636e\u901a\u4fe1\u534f\u8bae,\u6570\u636e\u5b58\u50a8\u7b49.Protocol Buffer\u7c7b\u6bd4XML\/JSON,\u662f\u4e00\u79cd\u7075\u6d3b,\u9ad8\u6548,\u81ea\u52a8\u5316\u673a\u5236\u7684\u7ed3\u6784\u6570\u636e\u5e8f\u5217\u65b9\u6cd5,\u4f46\u662f\u6bd4XML\/JSON\u66f4\u5c0f,\u66f4\u5feb,\u66f4\u7b80\u5355.\u4f60\u53ef\u4ee5\u5b9a\u4e49\u6570\u636e\u7ed3\u6784,\u7136\u540e\u4f7f\u7528\u7279\u6b8a\u751f\u6210\u7684\u6e90\u4ee3\u7801\u8f7b\u677e\u7684\u5728\u5404\u79cd\u6570\u636e\u6d41\u4e2d\u4f7f\u7528\u5404\u79cd\u8bed\u8a00\u7f16\u5199\u548c\u8bfb\u53d6\u6570\u636e\u7ed3\u6784.\u4f60\u751a\u81f3\u53ef\u4ee5\u66f4\u65b0\u6570\u636e\u7ed3\u6784,\u800c\u4e0d\u7834\u574f\u65e7\u6570\u636e\u7ed3\u6784\u7f16\u8bd1\u7684\u4ee5\u90e8\u7f72\u7a0b\u5e8f<\/p>\n","protected":false},"author":2,"featured_media":65936,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[567,99,43],"topic":[],"class_list":["post-65938","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-html","tag-java","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/65938.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"protobuf\u4ecb\u7ecd\u6839\u636egoogle\u5b98\u65b9\u7684\u4ecb\u7ecd:Protocol Buffers\u662fGoogle\u7684\u4e00\u79cd\u8bed\u8a00\u65e0\u5173,\u5e73\u53f0\u65e0\u5173,\u53ef\u6269\u5c55\u7684\u5e8f\u5217\u5316\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5,\u5b83\u53ef\u7528\u4e8e\u6570\u636e\u901a\u4fe1\u534f\u8bae,\u6570\u636e\u5b58\u50a8\u7b49.Protocol Buffer\u7c7b\u6bd4XML\/JSON,\u662f\u4e00\u79cd\u7075\u6d3b,\u9ad8\u6548,\u81ea\u52a8\u5316\u673a\u5236\u7684\u7ed3\u6784\u6570\u636e\u5e8f\u5217\u65b9\u6cd5,\u4f46\u662f\u6bd4XML\/JSON\u66f4\u5c0f,\u66f4\u5feb,\u66f4\u7b80\u5355.\u4f60\u53ef\u4ee5\u5b9a\u4e49\u6570\u636e\u7ed3\u6784,\u7136\u540e\u4f7f\u7528\u7279\u6b8a\u751f\u6210\u7684\u6e90\u4ee3\u7801\u8f7b\u677e\u7684\u5728\u5404\u79cd\u6570\u636e\u6d41\u4e2d\u4f7f\u7528\u5404\u79cd\u8bed\u8a00\u7f16\u5199\u548c\u8bfb\u53d6\u6570\u636e\u7ed3\u6784.\u4f60\u751a\u81f3\u53ef\u4ee5\u66f4\u65b0\u6570\u636e\u7ed3\u6784,\u800c\u4e0d\u7834\u574f\u65e7\u6570\u636e\u7ed3\u6784\u7f16\u8bd1\u7684\u4ee5\u90e8\u7f72\u7a0b\u5e8f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/65938.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-25T14:32:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260125143242-6976298ad6a8b.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65938.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/65938.html\",\"name\":\"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-25T14:32:44+00:00\",\"dateModified\":\"2026-01-25T14:32:44+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/65938.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/65938.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65938.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/65938.html","og_locale":"zh_CN","og_type":"article","og_title":"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"protobuf\u4ecb\u7ecd\u6839\u636egoogle\u5b98\u65b9\u7684\u4ecb\u7ecd:Protocol Buffers\u662fGoogle\u7684\u4e00\u79cd\u8bed\u8a00\u65e0\u5173,\u5e73\u53f0\u65e0\u5173,\u53ef\u6269\u5c55\u7684\u5e8f\u5217\u5316\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5,\u5b83\u53ef\u7528\u4e8e\u6570\u636e\u901a\u4fe1\u534f\u8bae,\u6570\u636e\u5b58\u50a8\u7b49.Protocol Buffer\u7c7b\u6bd4XML\/JSON,\u662f\u4e00\u79cd\u7075\u6d3b,\u9ad8\u6548,\u81ea\u52a8\u5316\u673a\u5236\u7684\u7ed3\u6784\u6570\u636e\u5e8f\u5217\u65b9\u6cd5,\u4f46\u662f\u6bd4XML\/JSON\u66f4\u5c0f,\u66f4\u5feb,\u66f4\u7b80\u5355.\u4f60\u53ef\u4ee5\u5b9a\u4e49\u6570\u636e\u7ed3\u6784,\u7136\u540e\u4f7f\u7528\u7279\u6b8a\u751f\u6210\u7684\u6e90\u4ee3\u7801\u8f7b\u677e\u7684\u5728\u5404\u79cd\u6570\u636e\u6d41\u4e2d\u4f7f\u7528\u5404\u79cd\u8bed\u8a00\u7f16\u5199\u548c\u8bfb\u53d6\u6570\u636e\u7ed3\u6784.\u4f60\u751a\u81f3\u53ef\u4ee5\u66f4\u65b0\u6570\u636e\u7ed3\u6784,\u800c\u4e0d\u7834\u574f\u65e7\u6570\u636e\u7ed3\u6784\u7f16\u8bd1\u7684\u4ee5\u90e8\u7f72\u7a0b\u5e8f","og_url":"https:\/\/www.wsisp.com\/helps\/65938.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-25T14:32:44+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260125143242-6976298ad6a8b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/65938.html","url":"https:\/\/www.wsisp.com\/helps\/65938.html","name":"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-25T14:32:44+00:00","dateModified":"2026-01-25T14:32:44+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/65938.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/65938.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/65938.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"protobuf\u4ecb\u7ecd\u4e0e\u5feb\u901f\u4e0a\u624b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=65938"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65938\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/65936"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=65938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=65938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=65938"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=65938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}