Skip to content

v1.2.0

Choose a tag to compare

@jhump jhump released this 07 Mar 17:23
8bfeffd

This release includes numerous changes and enhancements in several packages herein.

"github.com/jhump/protoreflect/desc"

Additions:

  • Added ImportResolver type and RegisterImportPath functions, to aid with working around known link errors that can happen due to the way that generated code registers file descriptors in the proto runtime.

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

Changes/Fixes:

  • Previously, custom options were not examined. The result was that the built *desc.FileDescriptor did not have dependencies that properly reflected the true transitive closure of the descriptors therein.

    While this was not usually a problem when using the built descriptors, trying to use them with the protoprint package would fail to print these custom options (since they could not be resolved from the file's imports). This is now fixed.

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

Changes/Fixes:

  • Fixed issue where source info was not properly defined in parsed descriptors, even after setting the IncludeSourceInfo field on the Parser to true.

Additions:

  • Added ParseFilesButDoNotLink method to the Parser. This allows a "light weight" parse that simply turns a proto source file into a FileDescriptorProto.

    Note that since linking is skipped, many aspects of the file cannot be checked and some properties in the resulting descriptor will be wrong. For example, options cannot be interpreted, type references will be left as they are in source (e.g. unqualified), and fields with enum types will actually indicate they their type is message (the only way to distinguish an enum field from a message field is during linking, to examine whether the referenced element is an enum or a message).

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

Changes/Fixes:

  • Several fixes in marshaling/unmarshaling *dynamic.Message to/from JSON:
    • Dynamic messages that represented google.protobuf.Value or google.protobuf.ListValue could not be correctly unmarshalled from "null" or "[]" JSON, respectively. This is now fixed.
    • One-of fields in proto3 syntax files were not always correctly marshalled:
      • If EmitDefaults on the marshaler was true, the code would incorrectly include all of the oneof fields in the resulting JSON, each showing their default value. This makes it impossible for unmarshalling code to know which field was actually supposed to be set.
      • If EmitDefaults on the marshaler was false, but the oneof field had its default/zero value, it would be incorrectly excluded from the resulting JSON. This makes it impossible for unmarshalling code to know which field was supposed to be set.
  • The MergeFrom method of a dynamic message has a slightly more efficient implementation for merging in unknown extension fields.

Additions:

  • A GetKnownType method was added to KnownTypeRegistry.
  • Adds a SetExtension function, which can be used to set extension values using a *desc.FieldDescriptor to describe the extension and can be used to set extension fields on either dynamic messages or generated message structs.

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

Changes/Fixes:

  • The MessageAsPType method of the registry, for converting a message descriptor to a google.protobuf.Type, would panic with the following error:
    reflect: call of reflect.Value.Type on zero Value
    
    This is now fixed.
  • Previously, MessageRegistry could not resolve types provided by a TypeFetcher unless that fetcher could provide the entire transitive closure for the type. Now, such types can be resolved as long as the type's dependencies are known to the registry (e.g. explicitly added via AddMessage or AddEnum methods).