Protobuf-ES

Protocol Buffers for ECMAScript.

README

Protobuf-ES
===========

A complete implementation of Protocol Buffers in TypeScript,
suitable for web browsers and Node.js.

For example, the following definition:

  1. ```protobuf
  2. message Person {
  3.   string name = 1;
  4.   int32 id = 2;  // Unique ID number for this person.
  5.   string email = 3;
  6. }
  7. ```

Is compiled to an ECMAScript class that can be used like this:

  1. ```typescript
  2. let pete = new Person({
  3.   name: "pete",
  4.   id: 123
  5. });

  6. let bytes = pete.toBinary();
  7. pete = Person.fromBinary(bytes);
  8. pete = Person.fromJsonString('{"name": "pete", "id": 123}');
  9. ```

To learn more, have a look at a complete code example,
the documentation for the generated code,
and the documentation for the runtime API.


How does this compare to protoc's JavaScript generator?


[js_generator.cc](https://github.com/protocolbuffers/protobuf-javascript/blob/main/generator/js_generator.cc)
is rarely updated, and has fallen behind the quickly moving world of JavaScript.

For example:
- it does not support ECMAScript modules
- it cannot generate TypeScript (3rd party plugins are necessary)
- it does not support the canonical JSON format
- it does not carry over comments from your .proto files

Because of this, we want to provide a solid, modern alternative with Protobuf-ES.

The main differences of the generated code:
- we use plain properties for fields, where protoc uses getter and setter methods
- we implement the canonical JSON format
- we generate much smaller bundles
- we rely on standard APIs instead of the Closure Library

See the migration guides for details.


What features are implemented


We implement all proto3 features, including the canonical JSON format.  
We implement all proto2 features, except for extensions and the text format.  
The implementation is covered by the protocol buffers


TypeScript


The minimum version of TypeScript supported by Protobuf-ES is 4.1.2.


Packages


  Provides the code generator plugin protoc-gen-es (source).
  The code it generates depends on @bufbuild/protobuf.
  The runtime library for the code generator plugin protoc-gen-es (source).
  Helps to create your own code generator plugin (source).


Copyright


The code to encode and decode varint is Copyright 2008 Google Inc., licensed
under BSD-3-Clause.  
All other files are licensed under Apache-2.0, see LICENSE.