Skip to content
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

gRPC: Unwrap structpb data value properly #488

Closed
wants to merge 1 commit into from

Conversation

SmartArray
Copy link

This PR fixes the issue seen in #418.

At least this is something we can build on. But support for recursive objects, lists and nullValues needs to be added before we can merge this in master.

Missing: recursive objects and lists (arrays)
notification.Data[k] = x.NumberValue
} else if x, ok := v.GetKind().(*structpb.Value_BoolValue); ok {
notification.Data[k] = x.BoolValue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about other types:list, null, struct? may be add some logging for else cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why the PR is on hold. I am no expert in Go, which is why I need help from you.
NullValue and ListValue might be easy. However, structs seem to be difficult for me.

@dhax
Copy link

dhax commented Jun 10, 2020

Hi, looks like there will be new AsMap() function available with the next protobuf release solving this problem:

package structpb
func NewStruct(map[string]interface{}) (*Struct, error)
*func (Struct) AsMap() map[string]interface{}
func (*Struct) MarshalJSON() ([]byte, error)
func (*Struct) UnmarshalJSON(b []byte) error

Found in this issue golang/protobuf#370 linking to the commit https://go-review.googlesource.com/c/protobuf/+/225298/

also for sake of completeness, here is an example how it could have been done with above approach:
https://github.com/googleapis/google-cloud-go/blob/master/internal/protostruct/protostruct.go

@slimus
Copy link
Contributor

slimus commented Oct 26, 2021

@SmartArray thank you for your fix! I created new PR #638 with AsMap() function

@slimus
Copy link
Contributor

slimus commented Oct 26, 2021

@appleboy let's close this PR. And can you please review my #638 PR?

@appleboy appleboy force-pushed the master branch 2 times, most recently from 60a7a68 to 2c29b4b Compare June 30, 2022 15:02
@appleboy appleboy closed this Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants