Skip to content

v1.5.0

Choose a tag to compare

@jhump jhump released this 08 Aug 15:54
c67d679

This release contains bug fixes and new features/APIs.

This release also fixes the repo's go.mod file to be compatible with Go 1.13.

"github.com/jhump/protoreflect/codec"

Additions:

  • This is a new package. It provides a Buffer type that provides API for interacting with the protobuf binary format. This makes it easy to write programs that can dynamically emit or consume a stream of protobuf-encoded data.

"github.com/jhump/protoreflect/desc"

Additions:

  • Added a new CreateFileDescriptorsFromSet function. This is a convenience method around CreateFileDescriptors when the source of descriptors is a *FileDescriptorSet.

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

Changes/fixes:

  • When custom options were used, BuilderOptions had to be used with a custom extension registry, or else those custom options would not make it into the built descriptor. Now, the custom option can be defined in the file being built or in any of its dependencies, and they will successfully be interpreted and retained. This means that BuilderOptions.Extensions should no longer be needed in most cases.
  • Added new methods to FileBuilder: AddDependency and AddImportedDependency, which allow explicitly adding imports to the file. These can be used during building to resolve custom options.
  • When using FromFile to convert and existing file descriptor into a builder and then building the result, the output descriptor would strip unused imports from the file. This is no longer the case, so that some imports that are only used to define custom options can be retained and custom options correctly interpreted.

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

Additions:

  • A new ErrorReporter type and eponymous name on the Parser struct have been added. When the field is unset, the behavior matches previous versions. When set, the reporter will be called for each error encountered, and parsing may continue, allowing a single parse invocation to report many errors instead of failing after the first one.
  • A new ErrorWithPos interface is provided to represent an error that includes source position. The type of errors returned by the parser were previously unspecified, but were often instances of the concrete exported type *ErrorWithSourcePos. Code that inspected errors and attempted type assertions to this type should instead type assert to this new interface as errors returned by the parser in the future may not be of this concrete type, but may still contain source position information.

Changes/fixes:

  • When generating source code info for a descriptor, no entry was created for allow_alias options for enums. This is fixed.
  • When generating source code info, an option with a boolean value could be missing its trailing comment. This is fixed.
  • If multiple goroutines were invoking protoparse and the files being compiled used the package's copy of standard imports (such as google/protobuf/timestamp.proto et al), when the race detector was enabled, it was possible for it to be tripped. The race should be harmless in practice since the writes that trigger the race are actually no-ops, so it is mainly an issue when running tests with the race detector enabled. This has been fixed: concurrent invocations of protoparse no longer share a copy of these standard imports. Instead, they are cloned for each invocation to use safely.
  • When generating source code info, the output is now significantly closer to that of protoc. Here are the most significant variances that were addressed:
    • The order of source code location entries in the resulting descriptor now matches protoc's order.
    • Updated the way source info was generated for group and map fields to address small discrepancies with protoc.
    • This package now correctly handles extension blocks and preserves comments for them, the same way that protoc generates source info for extension blocks.
    • Fixed generation of source locations for "intermediate" paths to match behavior of protoc. For example, protoc emits multiple entries for the path option (without an index), one for each actual option declared in the file. This package now does the same.
    • Updated computation of "column" in source locations to account for tab stabs. This mirrors protoc's logic, which assumes that tab stops are 8 characters apart.
  • This package now accepts an empty file, just as protoc does. Instead of returning an error, it will return an empty descriptor.
  • The UninterpretedOptions fields in options messages of descriptors produced by this package will now be nil when all options are interpreted. Previously, the field was set to an empty slice, which caused confusing/noisy output if the descriptor were then marshaled to JSON via the golang.org/protobuf/jsonpb package.

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

Changes/fixes:

  • The default ordering of a descriptor, when no source info is available, has changed slightly. Previously, options would appear before package and import statements. Now options appear after package and import statements. If source info is available, elements will still retain their ordering per the source info.
  • It was previously possible, when not explicitly sorting elements and when a file descriptor had source info present, for elements to be printed in non-deterministic order. In this mode, the printer uses relative order based on source info to sort elements. But, if source info had ambiguous entries (e.g. more than one entry that matched a printed element), the entry in source info that was used relied on map iteration order. This has been fixed and output is deterministic, even in cases such as this.
  • Previously, trying to print a descriptor that had an extension whose type was a group (vs. a message) would result in a type conversion panic. This has been fixed.
  • Previously, if a descriptor included source code info and it indicated that a set of extensions for the same extendee were defined in multiple extension blocks, this would not be preserved. Instead, all extensions for the same extendee were grouped into a single extension block when the descriptor was printed. Also, comments (leading and trailing) for the extension block were not included in the printed output. This has been corrected. Printing such a descriptor will group extensions correctly into blocks as well as include any comments.

"github.com/jhump/protoreflect/dynamic"

Changes/fixes:

  • When unmarshaling a dynamic message from a slice of bytes, in the protobuf binary format, if the data contained an illegal size prefix for bytes, string, and nested message values, the operation could result in an "index out of bounds" panic. This has been fixed and an error will be correctly reported instead.