protoc-gen-twirp_javascript

command module
v0.0.0-...-63287b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

README

protoc-gen-twirp_javascript

A protoc plugin that generates Protobuf.js service implementations for Twirp.

This plugin supports the following Protobuf.js output formats:

  1. JSON descriptors, which rely on reflection
  2. Static JavaScript modules

See Protobuf.js documentation for more details about those formats.

Parameters

This plugin has two parameters, explained below. Bold values are the defaults.

Name Description Values
pbjs_format Output format of the file generated by pbjs
  • json
  • static-module
twirp_version Version of the Twirp protocol specification to use.
  • v6
  • v5

Usage

The plugin generates code with import paths that expect files generated by pbjs to be in the same directory as the plugin output file(s), with the same name as the source .proto file.

With JSON descriptors

Consider the following directory structure:

.
├── foo
│   ├── bar.proto           # Source Protobuf file
│   └── bar.json            # JSON descriptors that correspond to the Protobuf file, generated by Protobuf.js
└── ...

To generate the RPC client:

$ protoc --proto_path=. --twirp_javascript_output=pbjs_format=json:. ./foo/bar.proto

Result:

.
├── foo
│   ├── bar.json
│   ├── bar.proto
│   └── bar.twirp.js        # Plugin output file
└── ...

A few things to note:

  • Contrary to the JSON file generated by pbjs, the source .proto is not directly used by the generated RPC client. This is a plugin limitation, as Protobuf.js itself supports loading of .proto files. Support may be added at a later point.
  • The JSON file is only used at runtime and the plugin does not need it to generate the RPC client. That property can be taken advantage of when protoc output directory layout is not known in advance: first invoke protoc-gen-twirp_javascript, and then pbjs with the now known target directory.
With static modules

Almost all of the information in the JSON descriptors section also applies here. .json extension is replaced by .pb.js.

To generate the RPC client:

$ protoc --proto_path=. --twirp_javascript_output=pbjs_format=static-module:. ./foo/bar.proto

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL