Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0.0-alpha.1 #801

Merged
merged 1 commit into from
Apr 22, 2024
Merged

Release 2.0.0-alpha.1 #801

merged 1 commit into from
Apr 22, 2024

Conversation

timostamm
Copy link
Member

@timostamm timostamm commented Apr 22, 2024

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 uses classes. Instead, we generate a type and a descriptor for every message, and provide functions to create a new instance, for serialization, and other concerns. Here is a simple example:

import { create, toBinary, fromBinary, fromJsonString } from "@bufbuild/protobuf";
import { UserDesc } from "./gen/user_pb.js";

let user = create(UserDesc, {
  firstName: "Homer",
  lastName: "Simpson",
  active: true,
  locations: ["Springfield"],
  projects: { SPP: "Springfield Power Plant" },
  manager: {
    firstName: "Montgomery",
    lastName: "Burns",
  },
});

const bytes = toBinary(UserDesc, user);
user = fromBinary(UserDesc, bytes);
user = fromJsonString(UserDesc, '{"firstName": "Homer", "lastName": "Simpson"}');

This approach solves several outstanding issues, such as:

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

Please note that this is an alpha release, and APIs might still change. We're also missing documentation yet. But if you want to try it out, we welcome your feedback!

This release is published with the alpha tag. To install the alpha packages, you can run:

npm install @bufbuild/protobuf@alpha @bufbuild/protoc-gen-es@alpha

Contributors

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

@timostamm timostamm merged commit ad1541b into v2 Apr 22, 2024
9 checks passed
@timostamm timostamm deleted the tstamm/release-2.0.0-alpha.1 branch April 22, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants