【protobuf: protobufjs-cli 一文入门】

开篇引导,本文通过 什么是protobujs-cli,什么是protobufjs-cli中的反射,protobujs-cli怎么使用,protobujs-cli的各个版本有什么区别 来快速对protobufjs-cli进行讲解和演示。

protobufjs-cli 是什么

protobufjs-cli 是 Protocol Buffers 的 JavaScript 实现 protobuf.js 的命令行工具。它提供了一组命令行命令,用于从 .proto 文件生成 JavaScript 代码或 JSON 描述文件,使得在 JavaScript 环境中使用 Protocol Buffers 变得更加方便,效率更高。

protobufjs-cli 参数

protobufjs-cli 的参数有如下这些,划重点参数,这2个参数决定了生成的文件格式。后面有给出具体例子,

-t, --target

  • t, --target: 指定目标格式。也接受自定义目标的路径。
    • json: JSON 表示形式
    • json-module: 作为模块的 JSON 表示形式
    • proto2: Protocol Buffers 版本 2
    • proto3: Protocol Buffers 版本 3
    • static: 不包含反射功能的静态代码(自身不具备功能)
    • static-module: 作为模块的静态代码,不包含反射功能

-w, --wrap

  • w, --wrap: 指定使用的封装方式。也接受自定义封装的路径。
    • default: 默认封装,支持 CommonJS 和 AMD
    • commonjs: CommonJS 封装
    • amd: AMD 封装
    • es6: ES6 封装(隐含 -es6
    • closure: 向 protobuf.roots 添加闭包,其中 protobuf 是全局变量

完整参数

Translates between file formats and generates static code.

  -t, --target     Specifies the target format. Also accepts a path to require a custom target.

                   json          JSON representation
                   json-module   JSON representation as a module
                   proto2        Protocol Buffers, Version 2
                   proto3        Protocol Buffers, Version 3
                   static        Static code without reflection (non-functional on its own)
                   static-module Static code without reflection as a module

  -p, --path       Adds a directory to the include path.

  -o, --out        Saves to a file instead of writing to stdout.

  --sparse         Exports only those types referenced from a main file (experimental).

  Module targets only:

  -w, --wrap       Specifies the wrapper to use. Also accepts a path to require a custom wrapper.

                   default   Default wrapper supporting both CommonJS and AMD
                   commonjs  CommonJS wrapper
                   amd       AMD wrapper
                   es6       ES6 wrapper (implies --es6)
                   closure   A closure adding to protobuf.roots where protobuf is a global

  -r, --root       Specifies an alternative protobuf.roots name.

  -l, --lint       Linter configuration. Defaults to protobuf.js-compatible rules:

                   eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins

  --es6            Enables ES6 syntax (const/let instead of var)

  Proto sources only:

  --keep-case      Keeps field casing instead of converting to camel case.

  Static targets only:

  --no-create      Does not generate create functions used for reflection compatibility.
  --no-encode      Does not generate encode functions.
  --no-decode      Does not generate decode functions.
  --no-verify      Does not generate verify functions.
  --no-convert     Does not generate convert functions like from/toObject
  • 33
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值