{"_id":"@agile-dev/wx-protobuf","_rev":"1-b45480bffab5d3c28620de70a51c9251","name":"@agile-dev/wx-protobuf","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@agile-dev/wx-protobuf","version":"1.0.0","description":"微信小程序使用的 protobuf 协议开发工具","main":"index.js","publishConfig":{"access":"public"},"scripts":{"test":"jest"},"repository":{"type":"git","url":"git+https://github.com/J-Boss-Os/wx-protobuf.git"},"keywords":["protobufjs","js","weChat"],"author":{"name":"JBoss"},"license":"ISC","bugs":{"url":"https://github.com/J-Boss-Os/wx-protobuf/issues"},"homepage":"https://github.com/J-Boss-Os/wx-protobuf#readme","gitHead":"4556df2c74e4ef1dcb081c10cbc905627ad03708","_id":"@agile-dev/wx-protobuf@1.0.0","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-/ak6ZCcDpaSdAdORQSzF/Kfzr/z5t9maYqfmBQ3u0bMM01K2zefZalP+fD6nFV2g7Q6gI5SBlN5lBfD0pdd+eQ==","shasum":"6da4cdab2df298ce93c2ba6253a16fdcaed99873","tarball":"https://registry.npmjs.org/@agile-dev/wx-protobuf/-/wx-protobuf-1.0.0.tgz","fileCount":40,"unpackedSize":289106,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeRjUHCRA9TVsSAnZWagAAMe8P/iUHLgMS7Y67UXEEa8mV\n8JsuJAWKcqF1s33Orm4uSpBbQe8n4FoDqicquqCJFQaTgAtg+C4tyBbkTGH5\n/4GE4/GxhjtCgGhg/k2O9HUWgagWi/+hmKvPTOWfPLQQD9OtNzkobpZRCjJz\nJj4/HVu/zxDB0j8S3krppQteR7xmirWCcr9or/0gNGDJPYZMrMkhxYIeZ+Qo\nLqLJmpSzibPMhmXiIntLjuYpQSZSi6f7GiZMuKxMrQ3xCYSR7S3iXzcXS6tf\nkW5nA/2rzIPAayWaKFmHYA53kMxcamyduyib0T+/uwNsZjwAj9BgV0xD8nwI\nIKQ+ir3q6qRrtoAhjBXyUWMjtg8ZGpdnLNkjN5+cM2Y1B/BUt06yfscVW2K/\nlUpN35TO3A6mvAJGkJk75RXUXtqRtWeeSja1wfDy75hu4ysF9u2Q8lyF6Who\nZgjke6k/w4U5BoDaVdhize9a4XXxY/whZbZ5b4AvQQV8xE/hUV7TSuQC5Weo\nNSMd6rxw/5l4qR8xJYjC9KxyMLuVuohpB37PN9O95XYeYv/uIFzU0ZUJzwHz\nVXPBm8mwNIgot27ySLSDMlti6aaHx8Jgs23+BIjRvtyfKCAyJSEts0OdgZMt\nwaY9TzTKPB6sDVLdVVmqxwrnWaYOyTeWWSEu1P9kOSObUQccWSL5BZW6zg2I\n6Umo\r\n=LPG7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD5PQ0iZZLwBBtIMViSUq8lhTrtxWWQ3oKWpkPrEK5lzQIhAJ0c9KlMeDDqcSO0trNT9jUpry8llj5Q8zhXXs0y/1Pl"}]},"maintainers":[{"name":"j-boss","email":"j_boss_os@163.com"}],"_npmUser":{"name":"j-boss","email":"j_boss_os@163.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wx-protobuf_1.0.0_1581659398816_0.7718125854102842"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-14T05:49:58.577Z","1.0.0":"2020-02-14T05:49:58.930Z","modified":"2022-04-04T11:57:22.587Z"},"maintainers":[{"name":"j-boss","email":"j_boss_os@163.com"}],"description":"微信小程序使用的 protobuf 协议开发工具","homepage":"https://github.com/J-Boss-Os/wx-protobuf#readme","keywords":["protobufjs","js","weChat"],"repository":{"type":"git","url":"git+https://github.com/J-Boss-Os/wx-protobuf.git"},"author":{"name":"JBoss"},"bugs":{"url":"https://github.com/J-Boss-Os/wx-protobuf/issues"},"license":"ISC","readme":"# wx-protobuf\n\n微信小程序使用的 protobuf 协议开发工具\n\n## 使用教程\n\n* 全局安装 `protobufjs` 对`.proto`文件进行转换成`json`\n\n``` cmd\n$ npm install -g protobufjs\n```\n\n* 检测是否安装成功\n\n``` cmd\n $ pbjs\n```\n\n* 先创建一个 `test.proto` 文件\n``` proto\n// awesome.proto\n syntax = \"proto3\";\n\n message Test {\n \tnumber userId = 1;\n \tstaring userName = 2;\n }\n```\n\n* 接下来我们来转换 `test.proto` 文件;\n\n``` cmd\n$ pbjs -t json test.proto > test.json\n```\n* 这时我们就会得到一个 test.json 文件\n\n``` json\n {\n  \"nested\": {\n  \t\"Test\": {\n   \t\t\"fields\": {\n     \t  \"userId\": {\n       \t   \"type\": \"number\",\n       \t   \"id\": 1\n     \t  },\n     \t  \"userName\": {\n       \t   \"type\": \"string\",\n       \t   \"id\": 2\n     \t  }\n   \t   }\n     }\n   }\n }\n```\n\n* 由于Json 文件不能直接在微信小程序内使用，所以我们需要用js把协议配置导出来\n\n``` js\nexport default {\n  \"nested\": {\n  \t\"Test\": {\n   \t\t\"fields\": {\n     \t  \"userId\": {\n       \t   \"type\": \"number\",\n       \t   \"id\": 1\n     \t  },\n     \t  \"userName\": {\n       \t   \"type\": \"string\",\n       \t   \"id\": 2\n     \t  }\n   \t   }\n     }\n   }\n }\n```\n\n* 直接下载全部文件到你的微信制定的目录地址中，然后使用SE6语法\n``` js\nimport wxProtobuf from '你放置的地址/wxProtobuf/index' \n```\n\n## 初始化 wxProtobuf 程序\n\n由于使用的是单例模式，所以不要多次初始化，初始化后的配置全局获取到的都是同一个实例.\n\n``` js\nimport wxProtobuf from '你放置的地址/wxProtobuf/index';\nimport textRoot from '你放置的地址/test.json';\n\nwxProtobuf.init({\n  roots:{ // roots 的 key 会变成 存在 this._rootArray 里 的 key\n    textRoot: textRoot,\n    ...\n  }\n})\n\n// 如果在init 的时候 传入了 root ，就会自动 执行 root.lookupType 这个方法 挂载 json 文件内的所有的 message\n\n```\n\n## 加密\n\n``` js\nimport wxProtobuf from '你放置的地址/wxProtobuf/index';\n\nconst buffer = wxProtobuf.encode('Test',{userId:1,userName:'user'});\n\nconsole.log(buffer) // 这个就是我们要传给后台的 二进制流\n\n```\n\n## 解密\n\n``` js\nimport wxProtobuf from '你放置的地址/wxProtobuf/index';\n\nconst buffer = wxProtobuf.encode('Test',{userId:1,userName:'user'});\n\nconsole.log(buffer) // 这个就是我们要传给后台的 二进制流\n\nconst loginData = wxProtobuf.decode('Test',buffer);\n\nconsole.log(loginData) // 这个就是 讲 二进制 转换成 可以用的 obj 数据\n```","readmeFilename":"README.md"}