{"id":9296,"date":"2024-04-28T14:36:30","date_gmt":"2024-04-28T06:36:30","guid":{"rendered":"\/?p=9296"},"modified":"2024-04-28T14:36:30","modified_gmt":"2024-04-28T06:36:30","slug":"protobuf%e5%8d%8f%e8%ae%ae%e9%80%86%e5%90%91%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"\/?p=9296","title":{"rendered":"Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790"},"content":{"rendered":"<p>\u5728\u505aAPP\u6293\u53d6\u65f6\uff0c\u4f1a\u53d1\u73b0\u6709\u7684APP Response\u56de\u6765\u7684\u6570\u636e\u6709\u201c\u52a0\u5bc6\u201d\u3002\u4e0d\u77e5\u9053\u8fd4\u56de\u7684\u5185\u5bb9\u662f\u4ec0\u4e48\u3002<\/p>\n<p>\u672c\u6587\u504f\u957f\uff0c\u7406\u8bba\u57fa\u7840\u504f\u591a\u3002<\/p>\n<p>\u5982\u4e0b\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress0-1583398723.jpg\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress2-1583398724.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u5982\u4e0a\uff0c\u5185\u5bb9\u4e0d\u662f\u660e\u6587\u7684\uff0c\u6ca1\u529e\u6cd5\u89e3\u6790\u6570\u636e\u3002<\/p>\n<p>APP\u5e38\u89c1\u7684\u5bf9\u6570\u636e\u52a0\u5bc6\u6709\u4e09\u79cd\u60c5\u51b5\uff1a<\/p>\n<p>\u7b2c\u4e00\u79cd\u662f\uff0c\u7528\u8bf8\u5982AES\u8fd9\u7c7b\u52a0\u5bc6\u7b97\u6cd5\u5bf9\u6570\u636e\u52a0\u5bc6\uff0c\u7136\u540e\u5728APP\u91cc\u7528key\u8fdb\u884c\u89e3\u5bc6\uff0c\u8fd9\u7c7b\u7684\u6570\u636e\u89e3\u5bc6\u7684\u96be\u5ea6\u4e0d\u662f\u5f88\u5927\uff0c\u5f04\u6e05\u695a\u662f\u7528\u7684\u4ec0\u4e48\u52a0\u5bc6\u7b97\u6cd5\u5c31\u80fd\u53cd\u89e3\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\u662f\uff0c\u7528\u201c\u79c1\u6709\u201d\u534f\u8bae\u628a\u6570\u636e\u5e8f\u5217\u5316\uff0c\u53ea\u6709\u4e86\u89e3\u8be5\u534f\u8bae\u7684\u7ec6\u8282\u624d\u6709\u53ef\u80fd\u628a\u6570\u636e\u53cd\u5e8f\u5217\u5316\u51fa\u6765\u3002\u8fd9\u4e2a\u7684\u96be\u5ea6\u8f83\u5927\uff0c\u6ca1\u6709\u529f\u5e95\uff0c\u5934\u53d1\u64b8\u767d\u90fd\u4e0d\u4e00\u5b9a\u64b8\u51fa\u6765\u3002\u6e38\u620f\u548c\u5927\u5382APP\u76db\u884c\u641e\u4e00\u4e2a\u81ea\u5df1\u7684\u79c1\u6709\u534f\u8bae\u6765\u4ea4\u6362\u6570\u636e\u3002<\/p>\n<p>\u7b2c\u4e09\u79cd\u662f\uff0c\u7528\u7b2c\u4e09\u65b9\u5382\u5546\u7684\u534f\u8bae\u6765\u6570\u636e\u5e8f\u5217\u5316\uff0c\u81ea\u5df1\u641e\u4e0d\u51fa\u6765\u79c1\u6709\u534f\u8bae\u7684\u5c31\u9009\u7528\u7b2c\u4e09\u65b9\u5382\u5546\u7684\u3002\u6bd4\u5982\u7528 Google \u7684 Protobuf \uff0c\u6765\u505a\u6570\u636e\u5e8f\u5217\u5316\uff0c\u4e5f\u5c31\u662f\u6570\u636e\u201c\u52a0\u5bc6\u201d\u3002<\/p>\n<p><strong>\u4eca\u5929\u804a\u7684\u5c31\u662f\u7b2c\u4e09\u79cd\uff0cProtobuf \u7684\u6570\u636e\u53cd\u89e3\u6790\u3002<\/strong><\/p>\n<p>\u5148\u6765\u770b\u4e00\u4e2a Protobuf \uff0c\u505a\u6570\u636e\u5e8f\u5217\u5316\u7684\u76f4\u89c2\u4f8b\u5b50\u3002<\/p>\n<p>\u6bd4\u5982\u4e00\u4e2a APP \u7684 Response \u539f\u5148\u662f\u4ee5 json \u683c\u5f0f\u8fd4\u56de\u7684\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress10-1583398725.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u8fd9\u6837\u5f88\u5bb9\u6613\u88ab\u89e3\u6790\uff0c\u7528Protobuf\u628a\u4e0a\u9762\u6570\u636e\u5e8f\u5217\u5316\u518d\u4f20\u8f93\u5c31\u53d8\u6210\u7c7b\u4f3c\u8fd9\u6837\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress10-1583398725-1.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u8fd9\u5f20\u56fe\u7247\u53ea\u662f\u6837\u4f8b\u8fd9\u6837\u5c31\u6ca1\u6cd5\u76f4\u63a5\u89e3\u6790\u6570\u636e\uff0c\u5982\u679c\u4e86\u89e3 Protobuf \u534f\u8bae\u7684\u8bdd\u5c31\u80fd\u52a0\u5feb\u53cd\u89e3\u901f\u5ea6\u3002<\/p>\n<p>\u6240\u4ee5\u8fd8\u5f97\u4ece\u5934\u6765\u804a Protobuf \u3002<\/p>\n<h2>\u4e00\u3001\u4ec0\u4e48\u662f Protobuf \uff1f<\/h2>\n<p>Protobuf \u662f Google \u5f00\u53d1\u7684\u4e00\u5957\u6570\u636e\u5b58\u50a8\u4f20\u8f93\u534f\u8bae\uff0c\u8ddf xml \u548c json \u4e00\u6837\u7684\uff0c\u90fd\u662f\u7528\u6765\u50a8\u5b58\u548c\u4f20\u8f93\u6570\u636e\u7684\u3002 \u56e0\u4e3a Protobuf \u80fd\u591f\u628a\u6570\u636e\u538b\u7f29\u5f97\u5f88\u5c0f\uff0c\u6240\u4ee5\u4f20\u8f93\u6570\u636e\u5c31\u6bd4 xml \u548c json \u5feb\u51e0\u500d\uff0cProtobuf \u89e3\u6790\u6570\u636e\u7684\u901f\u5ea6\u4e5f\u6bd4\u5b83\u4e24\u5feb\uff0c\u6240\u4ee5\u5728\u6570\u636e\u7f51\u7edc\u4f20\u8f93\u4e0a\uff0c\u7528 Protobuf \u800c\u4e0d\u7528 json \u5c31\u6709\u70b9\u53d7\u6b22\u8fce\u4e86\u3002<\/p>\n<p>\u4e0d\u8fc7 Protobuf \u50a8\u5b58\u3001\u538b\u7f29\u3001\u4f20\u8f93\u6548\u7387\u6bd4 json \u597d\uff0c\u4ed8\u51fa\u7684\u4ee3\u4ef7\u5c31\u662f\u7528\u6cd5\u9ebb\u70e6\uff0c\u4e0d\u50cf json.loads() json.dumps() \u4e00\u4e0b\u5c31\u641e\u5b9a\u4e86\u8fd9\u4e48\u7b80\u5355\u3002Protobuf \u6709\u4e00\u5957\u81ea\u5df1\u7684\u8bed\u6cd5\u3002\u4e0d\u4e86\u89e3 Protobuf \u534f\u8bae\u8bed\u6cd5\u548c\u7528\u6cd5\u7684\u8bdd\u4e5f\u65e0\u6cd5\u53cd\u89e3\u6570\u636e\u3002<\/p>\n<p><strong>\u5148\u4e86\u89e3\u4e0b Protobuf \u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u6574\u4e2a\u6d41\u7a0b\uff1a<\/strong><\/p>\n<p><strong>1.1.\u5148\u5b9a\u4e49\u4e00\u4e2a Protobuf \u8bed\u6cd5\u6587\u4ef6\uff08 .proto \u6587\u4ef6\uff09<\/strong><\/p>\n<p>\u8be5\u8bed\u6cd5\u6587\u4ef6\u7528\u6765\u8bf4\u660e\u8981\u4f20\u8f93\u54ea\u4e9b\u5b57\u6bb5\u3001\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\u3001\u6570\u636e\u95f4\u7684\u5d4c\u5957\u5173\u7cfb\u8fd9\u4e9b\u3002\u6bd4\u5982\u4e00\u4e2aAPP\u8981\u8fd4\u56de\u7684\u6570\u636e\u6709\u7535\u8bdd\u53f7\u7801\uff0c\u59d3\u540d\uff0c\u5e74\u9f84\u8fd9\u4e09\u4e2a\u5b57\u6bb5\uff0c\u4f60\u5c31\u9700\u8981\u628a\u8fd9\u4e09\u4e2a\u5b57\u6bb5\u5b9a\u4e49\u5728 .proto \u6587\u4ef6\u91cc\uff0c\u5e76\u4e14\u6307\u660e\u4ed6\u4eec\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u59d3\u540d\u548c\u7535\u8bdd\u662f\u5b57\u7b26\u4e32\uff0c \u5e74\u9f84\u662f\u6574\u578b\u3002<\/p>\n<p><strong>1.2.\u4f7f\u7528 Protobuf \u63d0\u4f9b\u7684\u5de5\u5177\u7f16\u8bd1\u8be5\u8bed\u6cd5\u6587\u4ef6\u3002<\/strong><\/p>\n<p>\u7528\u5de5\u5177\u7f16\u8bd1 .proto \u6587\u4ef6\u7684\u76ee\u7684\u662f\uff0c\u628a .proto \u6587\u4ef6\u7f16\u8bd1\u6210\u4ee3\u7801\uff0c\u5de5\u5177\u4f1a\u6839\u636e\u8be5 .proto \u6587\u4ef6\u81ea\u52a8\u751f\u4ea7\u4ee3\u7801\u3002 \u8fd9\u4e2a\u4ee3\u7801\u5c31\u662f\u7528\u6765\u505a\u6570\u636e\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u3002<\/p>\n<p><strong>1.3.\u670d\u52a1\u7aef\u7528\u7b2c2\u6b65\u4e2d\u7684\u4ee3\u7801\uff0c\u628a\u201c\u660e\u6587\u201d\u6570\u636e\u5e8f\u5217\u5316\uff0c\u53d8\u6210\u201c\u5bc6\u6587\u201d\u540e\uff0c\u8fd4\u56de\u7ed9APP\u3002<\/strong><\/p>\n<p><strong>1.4. APP \u5ba2\u6237\u7aef\u7528\u7b2c2\u6b65\u4e2d\u7684\u4ee3\u7801\uff0c\u628a\u201c\u5bc6\u6587\u201d\u6570\u636e\u53cd\u5e8f\u5217\u5316\uff0c\u5c31\u201c\u89e3\u5bc6\u201d\u6210\u660e\u6587\u62c9\u3002<\/strong><\/p>\n<p>\u7406\u8bba\u8bf4\u591a\u4e86\u5f88\u8ff7\u7cca\uff0c\u518d\u6574\u4e2a\u5b8c\u6574\u7684\u76f4\u89c2\u4f8b\u5b50\uff1a<\/p>\n<h2>\u4e8c\u3001Protobuf \u6b63\u5411\u5f00\u53d1\u6d41\u7a0b<\/h2>\n<p>2.1.\u5148\u914d\u7f6e Protobuf \u73af\u5883https:\/\/github.com\/protocolbuffers\/protobuf\/releases\/<\/p>\n<p>\u5728 Google \u5b98\u65b9 github \u5730\u5740\u4e0b\u8f7d Protobuf  \u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress8-1583398725.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u4e0b\u8f7d\u4e00\u4e2a Protobuf \u7f16\u8bd1\u5668\u548c\u4e00\u4e2a\u8c03\u7528\u7f16\u8bd1\u5668\u7684\u63a5\u53e3\u7a0b\u5e8f\uff0c\u6211\u4eec\u8fd9\u91cc\u7528Python\u7248\u7684\u3002\u5982\u4e0a\u56fe\uff0c\u7bad\u5934\u6240\u793a\uff0c\u89e3\u538b protoc.win64.zip \u91cc\u6709\u4e2a protoc \u547d\u4ee4\u5c31\u662f\u7f16\u8bd1\u5668\u3002PS\uff1a\u6ce8\u610f\u8981\u7ed9 protoc \u914d\u7f6e\u4e0a\u73af\u5883\u53d8\u91cf\uff0c\u4e0d\u7136\u6ca1\u6cd5\u5168\u5c40\u8c03\u7528\u8be5\u547d\u4ee4\u3002<\/p>\n<p>\u89e3\u538b protobuf-python-3.11.4.zip \u8fd9\u662fPython\u6a21\u5757\uff0ccd\u5230python\u76ee\u5f55\u91cc\u8fd0\u884c Python setup.py build \u548c Python setup.py install \u5b89\u88c5Python\u6a21\u5757\u3002Python\u7f16\u8f91\u5668\u91cc\u8fd0\u884c import google.protobuf \u53ef\u4ee5\u68c0\u6d4b\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress4-1583398726.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>example\u76ee\u5f55\u91cc\u6709\u5b98\u65b9\u5199\u597d\u7684Python\u793a\u4f8b\u7a0b\u5e8f \u548c \u793a\u4f8b .proto\u6587\u4ef6\u3002<\/p>\n<p>2.2.\u5199\u4e00\u4e2a .proto \u8bed\u6cd5\u6587\u4ef6\u8bed\u6cd5\u6587\u4ef6\u600e\u4e48\u5199\uff0c\u8981\u6839\u636e\u5177\u4f53\u7684\u4f20\u8f93\u6570\u636e\u6765\u5b9a\u5236\uff0c<\/p>\n<p>\u6bd4\u5982\u6309\u7167 example \u91cc\u7684\u793a\u4f8b\uff0c\u5982\u679c\u8981\u4f20\u8f93\u7684\u6570\u636e\u662f\u5982\u4e0b\u683c\u5f0f\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress6-1583398730.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u90a3\u4e48\u5b9a\u4e49\u7684 .proto \u8bed\u6cd5\u6587\u4ef6\u5c31\u5982\u4e0b\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress6-1583398731.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u8fd9\u6837\u5c31\u5b9a\u4e49\u597d\u4e86\u4e00\u4e2a .proto \u8bed\u6cd5\u6587\u4ef6\uff0c\u8bed\u6cd5\u6587\u4ef6\u5982\u4f55\u5b9a\u4e49\u8981\u6839\u636e\u4f20\u8f93\u6570\u636e\u7684\u4e0d\u540c\u800c\u53d8\u3002\u66f4\u5168\u7684 protobuf \u8bed\u6cd5 \u53ef\u4ee5\u770b\u8fd9\u4e2a\uff0c\u6709\u7f51\u53cb\u7ffb\u8bd1\u6210\u4e86\u4e2d\u6587\u7248\u7684\u3002<a href=\"https:\/\/colobu.com\/2017\/03\/16\/Protobuf3-language-guide\/\">https:\/\/colobu.com\/2017\/03\/16\/Protobuf3-language-guide\/<\/a><\/p>\n<p>2.3.\u4f7f\u7528\u7b2c\u4e00\u6b65\u4e2d\u4e0b\u8f7d\u7684 protoc \u7f16\u8bd1\u5668\u6765\u7f16\u8bd1 .proto \u6587\u4ef6<\/p>\n<p>protoc \u2013python_out=. addressbook.proto<\/p>\n<p>\u4e0a\u8ff0\u8868\u793a\u628a addressbook.proto \u6587\u4ef6\u7f16\u8bd1\u6210Python\u7248\u7684\u3002\u5982\u679c\u6587\u4ef6\u8bed\u6cd5\u9519\u8bef\uff0c\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u4f1a\u6709\u63d0\u793a\u3002\u7f16\u8bd1\u5b8c\u540e\uff0c\u4f1a\u591a\u51fa\u4e00\u4e2a.py\u6587\u4ef6<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress1-1583398731.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u6211\u4eec\u5c31\u53ef\u4ee5\u8c03\u7528\u8fd9\u4e2a .py \u6765\u5e8f\u5217\u5316\u4e0a\u9762\u7684\u6570\u636e\u30022.4.\u5f00\u59cb\u5e8f\u5217\u5316\u6570\u636e<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress5-1583398732.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>print\u91cc\u8f93\u51fa\u7684\u5c31\u662f\u5e8f\u5217\u5316\uff08\u201c\u52a0\u5bc6\u201d\uff09\u540e\u7684\u6570\u636e\u30022.5.\u5bf9\u5e8f\u5217\u5316\u540e\u7684\u6570\u636e\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\uff08\u201c\u89e3\u5bc6\u201d\uff09<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress0-1583398732.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u53cd\u5e8f\u5217\u5316\u5c31\u628a\u6570\u636e\u53c8\u8fd8\u539f\u5566\u3002<\/p>\n<p>\u4e0a\u8ff0\u8fc7\u7a0b\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u6b63\u5411\u6570\u636e protobuf \u5e8f\u5217\u5316\u8fc7\u7a0b\u3002\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\u6765\uff0c\u4e3b\u8981\u662f\u5b9a\u4e49\u4e00\u4e2a .proto \u6587\u4ef6\uff0c\u7136\u540e\u628a\u5b83\u7f16\u8bd1\u751f\u6210\u4ee3\u7801\u3002 \u540e\u9762\u5c31\u4e3b\u8981\u7528\u8fd9\u4e2a\u4ee3\u7801\u6765\u505a\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u5de5\u4f5c\u3002<\/p>\n<h2>\u4e09\u3001\u9006\u5411\u89e3\u6790 Protobuf<\/h2>\n<p>\u6b63\u5411\u8fc7\u7a0b\u6bd4\u8f83\u8f7b\u677e\uff0c\u56e0\u4e3a\u5bf9\u65b9\u5373\u6709 .proto \u6587\u4ef6\uff0c\u4e5f\u6709\u5e8f\u5217\u5316\u4ee3\u7801\uff0c\u4e5f\u77e5\u9053\u8981\u4f20\u8f93\u7684\u6570\u636e\u6837\u5f0f\u3002\u4f46\u662f\u9006\u5411\u8fd9\u4e2a\u8fc7\u7a0b\uff0cAPP\u91cc\u662f\u6ca1\u6709 .proto\u6587\u4ef6\u7684\uff0cAPP\u91cc\u662f\u6709\u53cd\u5e8f\u5217\u5316\u7684\u4ee3\u7801\uff0c\u4f46\u662f\u770b\u5f97\u4e5f\u5934\u6655\u3002\u90a3\u8be5\u600e\u4e48\u529e\u5462\uff1f<\/p>\n<p>\u501f\u52a9\u5de5\u5177\uff0c\u6211\u4eec\u4f7f\u7528\u4e0a\u9762\u4e0b\u8f7d\u7684protoc\u7f16\u8bd1\u5de5\u5177\uff0c\u8fd9\u4e2a\u5de5\u5177\u63d0\u4f9b\u53cd\u89e3\u6790\u53c2\u6570<\/p>\n<p>protoc \u2013decode_raw &lt; people.bin<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress10-1583398732.png\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u5982\u4e0a\uff0c\u4f7f\u7528 \u2013decode_raw \u53c2\u6570\u5c31\u80fd\u628a\u5e8f\u5217\u5316\u540e\u7684\u6570\u636e\uff0c\u53cd\u5e8f\u5217\u5316\uff08\u89e3\u5bc6\uff09\u51fa\u6765\u3002\u4e0a\u9762\u53ea\u662f\u628a\u6570\u636e\u8fd8\u539f\u4e86\uff0c\u90a3\u5982\u679c\u6211\u4eec\u8981\u5b8c\u5168\u628a .proto \u6587\u4ef6\u4e5f\u8fd8\u539f\u51fa\u6765\u8be5\u600e\u4e48\u529e\u5462\uff1f<\/p>\n<p>\u5982\u679c APP \u53d1\u9001 request \u7684\u6570\u636e\u8981\u5148\u5e8f\u5217\u5316\u540e\u518d\u53d1\u9001\u7ed9\u670d\u52a1\u7aef\u7684\u8bdd\uff0c\u90a3\u722c\u866b\u8981\u505a\u7684\u4e8b\u60c5\u5c31\u4e0d\u53ea\u53cd\u5e8f\u5217\u5316\uff0c\u8fd8\u8981\u80fd\u5e8f\u5217\u5316\u3002\u505a\u5e8f\u5217\u5316\u662f\u4e00\u4e2a\u6b63\u5411\u7684\u8fc7\u7a0b\uff0c\u6309\u7167\u4e0a\u9762\u6d41\u7a0b\uff0c\u5fc5\u987b\u5148\u8981\u6709 .proto \u6587\u4ef6\u624d\u884c\u3002<\/p>\n<p>\u6240\u4ee5\u7ee7\u7eed\u8fd8\u539f .proto \u6587\u4ef6\uff0c\u8fd8\u539f .proto \u662f\u4e2a\u4f53\u529b\u6d3b\u548c\u7ec6\u81f4\u6d3b\u3002\u5c31\u662f\u53c2\u7167\u53cd\u89e3\u6790\u51fa\u6765\u7684\u6570\u636e\uff0c\u8fd8\u539f\u51fa .proto \u6587\u4ef6\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/beepress9-1583398733.jpg\" alt=\"APP\u722c\u866b\u4e4b-Protobuf\u534f\u8bae\u9006\u5411\u89e3\u6790\" \/><\/p>\n<p>\u4e0a\u9762\u8fd9\u5f20\u56fe\u662f\u5173\u952e\uff0c\u770b\u61c2\u4e86\u5c31\u80fd\u8fd8\u539f\u51fa\u6765\u3002\u4e0a\u56fe\u5de6\u8fb9\u662f\u53cd\u89e3\u6790\u51fa\u6765\u7684\u6570\u636e\uff0c\u4e2d\u4e2d\u95f4\u662f\u53c2\u7167\u5de6\u8fb9\u5199\u51fa\u6765\u7684 .proto \u6587\u4ef6\uff0c\u53f3\u8fb9\u662f\u4eba\u5bb6\u539f\u672c\u7684 .proto \u6587\u4ef6\u3002\u5de6\u8fb9\u548c\u4e2d\u95f4\u56fe\u5bf9\u6bd4\u53ef\u4ee5\u770b\u51fa\uff0c\u5c31\u662f\u6839\u636e\u5de6\u8fb9\u7684\u5b57\u6bb5\uff0c\u6328\u4e2a\u628a\u5b57\u6bb5\u91cd\u65b0\u5b9a\u4e49\u51fa\u6765\u5c31OK\u5566\u3002<\/p>\n<p>\u9047\u5230 \u201c{\u201d \u5c31\u5b9a\u4e49\u4e00\u4e2amessage\u3002\u4e2d\u95f4\u548c\u53f3\u8fb9\u56fe\u5bf9\u6bd4\u53ef\u4ee5\u770b\u51fa\uff0c\u53d8\u91cf\u7684\u540d\u5b57\u662f\u65e0\u5173\u7d27\u8981\u7684\uff0c\u6570\u636e\u7c7b\u578b\u8fd8\u539f\u6b63\u786e\u5c31\u884c\u3002\u53d8\u91cf\u8d4b\u503c\u7684\u90a3\u4e9b1\uff0c2\uff0c3\u662f\u6807\u8bc6\u53f7\uff0cmessage\u91cc\u540c\u4e00\u5c42\u7ea7\u7684\u6807\u8bc6\u53f7\u4e0d\u80fd\u91cd\u590d\uff0c\u4e00\u822c\u662f\u6309\u7167\u53d8\u91cf\u987a\u5e8f\u4ece1\u5f00\u59cb\u9012\u589e\u3002\u6807\u8bc6\u53f7\u7684\u6570\u5b57\u662f\u4e2a\u5173\u952e\uff0c\u6570\u5b57\u5199\u9519\u4e86\u53cd\u89e3\u6790\u51fa\u6765\u7684\u6570\u636e\u4f1a\u4e0d\u5bf9\u3002\u8fd9\u6837\u5c31\u628a .proto \u6587\u4ef6\u8fd8\u539f\u51fa\u6765\u4e86\uff0c\u7136\u540e\u6309\u7167\u6b63\u5411\u6d41\u7a0b\u53c8\u53bb\u7f16\u8bd1\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5b83\u53bb\u5e8f\u5217\u5316\uff08\u201c\u52a0\u5bc6\u201d\uff09\u548c\u53cd\u5e8f\u5217\u5316\uff08\u201c\u89e3\u5bc6\u201d\uff09APP\u6570\u636e\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u505aAPP\u6293\u53d6\u65f6\uff0c\u4f1a\u53d1\u73b0\u6709\u7684APP Response\u56de\u6765\u7684\u6570\u636e\u6709\u201c\u52a0\u5bc6\u201d\u3002\u4e0d\u77e5\u9053\u8fd4\u56de\u7684\u5185\u5bb9\u662f\u4ec0\u4e48\u3002 \u672c\u6587\u504f\u957f\uff0c\u7406\u8bba\u57fa\u7840\u504f\u591a\u3002 \u5982\u4e0b\uff1a \u5982   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[189],"tags":[272],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9296"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9296"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9296\/revisions"}],"predecessor-version":[{"id":9297,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9296\/revisions\/9297"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9296"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}