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

use []byte or custom type for pubsub Message data #49

Closed
codyoss opened this issue Mar 9, 2021 · 4 comments · Fixed by #58
Closed

use []byte or custom type for pubsub Message data #49

codyoss opened this issue Mar 9, 2021 · 4 comments · Fixed by #58
Assignees
Labels
api: eventarc Issues related to the googleapis/google-cloudevents-go API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@codyoss
Copy link
Member

codyoss commented Mar 9, 2021

Expected Behavior

// Option 1
type Message struct {
	Data        []byte        `json:"data,omitempty"`        // The binary data in the message.
}
// Option 2
type Message struct {
	Data        ByteData        `json:"data,omitempty"`        // The binary data in the message.
}

Actual Behavior

type Message struct {
	Data        *string        `json:"data,omitempty"`        // The binary data in the message.
}

Details

The choice to use a string was also made in our HTTP/REST libraries. We did not respect the ”format”: “byte”. We have an open issue around how it would have been nice to generate these types as []byte.

Option 2 might be nice do you could provide a custom mashaller for the type that auto encodes/decodes base64 values so the user of this library does not have to.

@product-auto-label product-auto-label bot added the api: eventarc Issues related to the googleapis/google-cloudevents-go API. label Mar 9, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 10, 2021
@grant grant self-assigned this Mar 10, 2021
@grant grant added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Mar 11, 2021
@grant
Copy link
Contributor

grant commented Mar 17, 2021

Ideally we modify quicktype to support generating []bytes with a native JSON schema base64 type.

glideapps/quicktype#1317


An alternative would be to look for all the "binaryEncoding": "base64" fields in our schemas and convert the respective golang field types.

@grant grant added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Mar 23, 2021
@grant
Copy link
Contributor

grant commented Mar 24, 2021

The implementation of this will be rather complicated. I'll have to check with @grayside on how we can make this possible.

This is one of the cases where using proto/protoc would be nice instead of jsonschema. Proto generation produces a []byte appropriately. There are some upstream jsonschema & jsonschema tooling fixes we'd need to do to natively generate the same base64 []byte from jsonschema.

Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`

@grant
Copy link
Contributor

grant commented Apr 12, 2021

Here are the instances of protos with bytes:

  • Cloud Build: repeated bytes build_step_outputs
  • Cloud Build: bytes value
  • Cloud Firestore: bytes bytes_value
  • Cloud Pub/Sub: bytes data
  • Cloud Scheduler: bytes custom_data

@grant
Copy link
Contributor

grant commented Apr 13, 2021

Should be fixed with the above PR! :)

@grant grant closed this as completed in #58 Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: eventarc Issues related to the googleapis/google-cloudevents-go API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants