Skip to content

Instantly share code, notes, and snippets.

@disc99
Last active November 4, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disc99/0d55512403fac872f58566f72c0df0b6 to your computer and use it in GitHub Desktop.
Save disc99/0d55512403fac872f58566f72c0df0b6 to your computer and use it in GitHub Desktop.

Examples

Java

protoc -I=$SRC_DIR \
  --java_out=$DST_DIR \
  $SRC_DIR/HelloService.proto

gRPC-Web (Using protoc-gen-grpc-web plugin)

protoc -I=$SRC_DIR \
  --js_out=import_style=commonjs:$OUT_DIR \
  --grpc-web_out=import_style=commonjs,mode=grpcwebtext:$OUT_DIR \
  echo.proto

Import Style

  • import_style=closure: The default generated code has Closure goog.require() import style.
  • import_style=commonjs: The CommonJS style require() is also supported.
  • import_style=commonjs+dts: (Experimental) In addition to above, a .d.ts typings file will also be generated for the protobuf messages and service stub.
  • import_style=typescript: (Experimental) The service stub will be generated in TypeScript.

Wire Format Mode

  • mode=grpcwebtext: The default generated code sends the payload in the grpc-web-text format. Content-type: application/grpc-web-text Payload are base64-encoded. Both unary and server streaming calls are supported.
  • mode=grpcweb: A binary protobuf format is also supported. Content-type: application/grpc-web+proto Payload are in the binary protobuf format. Only unary calls are supported for now.

Tips

プラグインの仕組み

image

プラグインの命名規則

プラグインファイル名: protoc-gen-{name} 呼び出し方: --{name}_out=...

プラグインの引数の見方

コマンド: protoc --foo_out=arg1=aaaaaa,arg2,arg3=cccccc:DIR input.proto 引数: ':'までが引数となる。この場合'arg1=aaaaaa,arg2,arg3=cccccc'がプラグインへの引数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment