protobuf-ts

module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: Apache-2.0

README

protobuf-ts

Protobuf and RPC for Node.js and the Web Browser.

For the following .proto file:

syntax = "proto3";

message Person {
    string name = 1;
    uint64 id = 2;
    int32 years = 3;
    optional bytes data = 5;
}

protobuf-ts generates code that can be used like this:

let pete: Person = {
    name: "pete", 
    id: 123n, // it's a bigint
    years: 30
    // data: new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
};

let bytes = Person.toBinary(pete);
pete = Person.fromBinary(bytes);

pete = Person.fromJsonString('{"name":"pete", "id":"123", "years": 30}')
Quickstart
  • grab the msg-readme.proto
  • npm install @protobuf-ts/plugin
  • protoc --plugin node_modules/.bin/protoc-gen-ts --ts_out . msg-readme.proto
  • add the --experimental_allow_proto3_optional flag if your protoc version asks for it
Features

Read the MANUAL to learn more.

Building this project

Building this project requires node (14.5.0), npm, protoc (3.12.3), make, bazel, git.
The entire project can be built by running make.

Directories

Path Synopsis
packages
example-twirp-server/rpc/haberdasher
Package haberdasher is a generated twirp stub package.
Package haberdasher is a generated twirp stub package.

Jump to

Keyboard shortcuts

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