Skip to content

v1.8.0

Choose a tag to compare

@jhump jhump released this 07 Dec 16:34
8269465

This release contains some additions to the protoparse package, including a new protoparse/ast sub-package. It also contains numerous bug fixes.

NOTE: The Go module for this repo now requires v1.4.2 (or higher) of the protobuf runtime packages in "github.com/golang/protobuf". While that is only a minor version bump from previous versions of this module (e.g. last release required at least v1.3.1), it is a non-trivial change. Version 1.4, while intended to be backwards compatible with v1.3, introduced a significant number of changes in order to be interoperable with the new API in "google.golang.org/protobuf".

"github.com/jhump/protoreflect/codec"

Changes/fixes:

  • When serializing messages deterministically, if a message contained a map type that had messages as values, these nested value messages could be serialized non-deterministically. This is now fixed.

"github.com/jhump/protoreflect/desc/builder"

Changes/fixes:

  • When a file builder included references to multiple other descriptors or builders with the same file name, it would produce an invalid descriptor that tried to import the same file name multiple times. Now, implicit dependencies are permitted to have duplicates as long as their descriptor protos are equal (according to protobuf message equality). Otherwise, when duplicates are detected, a better error message is returned.
  • When a message included a mix of fields with explicit tags and fields without tags (i.e. tags that get auto-assigned when the message is built), an "index out of bounds" panic could occur. This has been corrected.

"github.com/jhump/protoreflect/desc/protoparse"

Additions:

  • Adds a field named LookupImportProto to protoparse.Parser. This behaves similarly to the existing LookupImport field, except it can return a descriptor proto, instead of a fully-linked descriptor.
  • Adds a new method named ParseToAST to protoparse.Parser. This is similar to the ParseFilesButDoNotLink method except that it returns an AST that represents the source file, instead of returning a descriptor proto.

Changes/fixes:

  • Fixes a panic when parsing a file that does not contain legal protobuf source. In some cases, the file's AST could be left incomplete when parsing encountered syntax errors, which then caused a nil-dereference panic. This is corrected and a syntax error will be reported instead.
  • Fixes a panic when a custom option value includes message literals for a map type but do not contain both key and value fields. Now these fields default to zero values for the respective type instead of causing a nil-dereference panic.
  • Parsing a file that contained a BOM (byte order mark) would result in a syntax error. Source files are required to be UTF-8, but even the UTF-8 mark (0xEF 0xBB 0xBF) would be rejected. This has been fixed, and files with a UTF-8 BOM are accepted. Other BOM, for alternate UTF encodings, are not accepted.

"github.com/jhump/protoreflect/desc/protoparse/ast"

This is a brand new package which provides a model of the abstract syntax tree for protobuf source files. The AST includes much more information than descriptor protos, so they can be used for a greater variety of source tooling such as formatters and static analyzers.

The key abstraction is the ast.Node interface, which represents a node in the tree. A valid source file is an *ast.FileNode, which is the root of the tree. Many node types correspond to elements of descriptor protos, but the AST includes more information, including source information for everything in the file, including all comments (regardless of their location) and all punctuation.

"github.com/jhump/protoreflect/desc/protoprint"

Changes/fixes:

  • When printing a file that used public or weak imports, the resulting output would be missing the "public" or "weak" keyword. This could cause subsequent parse/compile operations with these outputs to fail unexpectedly. This has been corrected.

"github.com/jhump/protoreflect/dynamic/msgregistry"

Changes/fixes:

  • The Resolve method of the *MessageRegistry type would cause a nil-dereference panic if given an unknown message type. It now returns an error instead.