Skip to content

v2.0.0

Compare
Choose a tag to compare
@timostamm timostamm released this 30 Jul 16:12
· 16 commits to main since this release
76cbbc1

What's new in version 2

To support Protobuf editions, we have to make breaking changes that also affect users of proto2 and proto3. This prompted us to make more extensive changes that take feedback from version 1 into account:

We no longer use classes. Instead, we generate a schema object and a type for every message. To create a new instance, to serialize, and for other concerns, we provide functions. Here is a simple example:

import { create, toBinary } from "@bufbuild/protobuf";
import { UserSchema } from "./gen/example_pb";

let user = create(UserSchema, {
  firstName: "Homer",
  lastName: "Simpson",
  active: true,
});

const bytes = toBinary(UserSchema, user);

If you use proto3, messages are now plain objects. Files with proto2 and editions use the prototype chain to track field presence.

This approach solves several outstanding issues, such as:

  • #397 Provide custom options at runtime
  • #551 Generated types allow assigning wrong message type if it is a superset of the target type
  • #414 Improvements for proto2 required
  • #738 type-save full enum value names
  • #928 Better interop with 3rd party frameworks requiring plain objects
  • #508 JSON types

Tip

Take a look at the upgrade guide to learn more.

Note

Connect-ES does not support version 2 yet. We will update it shortly.

Contributors

Thanks to @srikrsna-buf for his contributions to v2!