-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Recognize the AllowPartial flag when parsing Any #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ func (d decoder) unmarshalAny(m protoreflect.Message) error { | |
// Use another decoder to parse the unread bytes for @type field. This | ||
// avoids advancing a read from current decoder because the current JSON | ||
// object may contain the fields of the embedded type. | ||
dec := decoder{d.Clone(), UnmarshalOptions{RecursionLimit: d.opts.RecursionLimit}} | ||
dec := decoder{d.Clone(), UnmarshalOptions{RecursionLimit: d.opts.RecursionLimit, AllowPartial: d.opts.AllowPartial}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I should also plumb through DiscardUnknown (or maybe all the options?). Those are the two options that cloud.google.com/go passes today: e.g. https://github.com/googleapis/google-cloud-go/blob/b23a08492a7724ce6f1f95395b7f71feb9b3de66/ai/generativelanguage/apiv1beta/generative_client.go#L600 |
||
tok, err := findTypeURL(dec) | ||
switch err { | ||
case errEmptyObject: | ||
|
@@ -348,7 +348,9 @@ func (d decoder) unmarshalAnyValue(unmarshal unmarshalFunc, m protoreflect.Messa | |
switch tok.Kind() { | ||
case json.ObjectClose: | ||
if !found { | ||
return d.newError(tok.Pos(), `missing "value" field`) | ||
if !d.opts.AllowPartial { | ||
return d.newError(tok.Pos(), `missing "value" field`) | ||
} | ||
} | ||
return nil | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function wrapping is unnecessary. Since the function doesn’t do anything other than return an
anypb.Any
composite literal.