Repository navigation
v1.2.0
This release includes numerous changes and enhancements in several packages herein.
"github.com/jhump/protoreflect/desc"
Additions:
- Added
ImportResolvertype andRegisterImportPathfunctions, 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.FileDescriptordid 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
protoprintpackage 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
IncludeSourceInfofield on theParserto true.
Additions:
-
Added
ParseFilesButDoNotLinkmethod to theParser. This allows a "light weight" parse that simply turns a proto source file into aFileDescriptorProto.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.Messageto/from JSON:- Dynamic messages that represented
google.protobuf.Valueorgoogle.protobuf.ListValuecould 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
EmitDefaultson 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
EmitDefaultson 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.
- If
- Dynamic messages that represented
- The
MergeFrommethod of a dynamic message has a slightly more efficient implementation for merging in unknown extension fields.
Additions:
- A
GetKnownTypemethod was added toKnownTypeRegistry. - Adds a
SetExtensionfunction, which can be used to set extension values using a*desc.FieldDescriptorto 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
MessageAsPTypemethod of the registry, for converting a message descriptor to agoogle.protobuf.Type, would panic with the following error:This is now fixed.reflect: call of reflect.Value.Type on zero Value - Previously,
MessageRegistrycould not resolve types provided by aTypeFetcherunless 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 viaAddMessageorAddEnummethods).