Giter Club home page Giter Club logo

protoc-gen-twirp_javascript's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.