Skip to content

v1.22.0

Compare
Choose a tag to compare
@dsnet dsnet released this 04 May 19:22

Overview

This release adds support for the experimental proto3 optional semantics coming in the v3.12.0 release of the protobuf language, adjusts the API to ease migration from the old module to the new module, and fixes some minor bugs.

Notable changes

New features:

  • CL/230698: all: implement support for proto3 optional semantics
  • CL/229157: proto: add RangeExtensions and adjust HasExtension and GetExtension

Minor changes:

  • CL/228837: all: consistently treat nil message interface as an empty read-only message
  • CL/228838: proto: never return nil []byte from Marshal when successful
  • CL/229558: all: improve extension validation
  • CL/229277: internal/impl: inline coderInfoFields for better cache locality

Bug fixes:

  • CL/229278: internal/impl: fix off-by-one error in message initialization

Proto3 optional semantics

Protocol buffers in v3.12.0 is gaining experimental support to represent true presence for scalars in the proto3 syntax. By default, scalars in proto3 lack presence, so users are unable to distinguish between an unpopulated field and whether the zero value was explicitly stored into that field. With this new language feature, users can explicitly specify the optional keyword for scalars to indicate that presence information should be preserved for that field.

This release adds support to the generator and the runtime for this feature. Generation of proto3 optional fields are represented as pointers to scalar types (similar to proto2 optional scalars).

Adjustments to ease migration

A few minor changes were made to the API to unify the behavior between the old github.com/golang/protobuf module and the new google.golang.org/protobuf module. This should aid users migrating from the former to the latter.

Changes:

  • Adjusted all functions to treat a nil proto.Message as an untyped, read-only, empty message and provide sensible results given that semantic.
  • Adjusted proto.HasExtension to always report false if the extension descriptor does not extend the parent message (as opposed to panicking previously).
  • Added proto.RangeExtensions as a replacement for the legacy proto.ClearAllExtensions and proto.ExtensionDescs functions.
  • Fixed protoreflect.ExtensionType.IsValidInterface to never panic and properly report whether the given value is of the right type.

Upcoming breakage changes

There are no new upcoming breaking changes to announce in this release.

As a reminder, the following have already been announced and may take effect in the near future: