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

Support content types following structured syntax suffixes #1007

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

dan-j
Copy link
Contributor

@dan-j dan-j commented Jan 19, 2024

See #990, this adds support for encoding/decoding cloudevent data which is defined by a content-type following the Structured Syntax Suffixes standard.

This enables the encoding/decoding of custom content types which use the +json or +xml suffix to indicate that their encoding is JSON or XML respectively. Users can also add their own suffixes to the registry in a similar fashion to how datacodec.AddDecoder() and dataodec.AddEncoder() work, but via the AddStructuredSuffixDecoder and AddStructuredSuffixEncoder functions.

Fixes #990

@dan-j dan-j force-pushed the 990-structured-syntax-suffix branch from 2617113 to d6764a3 Compare January 19, 2024 23:25
@duglin duglin force-pushed the 990-structured-syntax-suffix branch from d6764a3 to bc1a952 Compare January 30, 2024 14:32
Copy link
Contributor

@duglin duglin left a comment

Choose a reason for hiding this comment

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

@duglin duglin force-pushed the 990-structured-syntax-suffix branch from bc1a952 to 595c306 Compare January 31, 2024 15:30
@duglin duglin force-pushed the 990-structured-syntax-suffix branch from 595c306 to 410c767 Compare February 12, 2024 14:27
@yanmxa
Copy link
Contributor

yanmxa commented Mar 13, 2024

Hi @dan-j @duglin !
I'm a little bit confused by the naming AddStructuredSuffixDecoder or AddStructuredSuffixEncoder with the structured(or binary) mode based on the content-type format.

So what's the relationship between the AddStructuredSuffixDecoder and the structured mode? It seems they are describing two kinds of different things, if so, I suggest using another name that won't cause any ambiguity to register the encoder and decoder.

Thanks!

@dan-j
Copy link
Contributor Author

dan-j commented Mar 13, 2024

Hi @yanmxa, the datacodec package isn't concerned with how an event is encoded (whether structured/binary mode), which is what I think you're referring to?

The datacodec package is concerned with marshalling/unmarshalling an event's data attribute, and is determined by the event's datacontenttype attribute. So for example if you have a cloudevent.Event where datacontenttype=application/vnd.github+json like so, it would use the github.com/cloudevents/sdk-go/v2/event/datacodec/json package to unmarshal.

var e cloudevent.Event

var target MyStruct
_ = e.DataAs(&target)

"Structure Syntax Suffix" is the formal name for this technique, as documented here: https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xhtml. We could rename the functions AddStructuredSyntaxSuffixEncoder/Decoder but I feel this wouldn't really help the confusion, it's just a longer name.

I've also tried to explain this in the GoDoc for the functions, if you have a way to better word this then I'm happy for some feedback.

@yanmxa
Copy link
Contributor

yanmxa commented Mar 14, 2024

Hi @yanmxa, the datacodec package isn't concerned with how an event is encoded (whether structured/binary mode), which is what I think you're referring to?

The datacodec package is concerned with marshalling/unmarshalling an event's data attribute, and is determined by the event's datacontenttype attribute. So for example if you have a cloudevent.Event where datacontenttype=application/vnd.github+json like so, it would use the github.com/cloudevents/sdk-go/v2/event/datacodec/json package to unmarshal.

var e cloudevent.Event

var target MyStruct
_ = e.DataAs(&target)

"Structure Syntax Suffix" is the formal name for this technique, as documented here: https://www.iana.org/assignments/media-type-structured-suffix/media-type-structured-suffix.xhtml. We could rename the functions AddStructuredSyntaxSuffixEncoder/Decoder but I feel this wouldn't really help the confusion, it's just a longer name.

I've also tried to explain this in the GoDoc for the functions, if you have a way to better word this then I'm happy for some feedback.

Since "Structure Syntax Suffix" is a conventional formal name for it. Using any other name seems to break the original meaning, and I agree with you that we can clarify it in the comments on the methods.

@dan-j Thanks for your clarification!

This enables the encoding/decoding of custom content types which
use the `+json` or `+xml` suffix to indicate that their encoding
is JSON or XML respectively. Users can also add their own suffixes
to the registry in a similar fashion to how `datacodec.AddDecoder()`
and `dataodec.AddEncoder()` work, but via the `AddStructuredSuffixDecoder`
and `AddStructuredSuffixEncoder` functions.

Signed-off-by: dan-j <[email protected]>
@dan-j dan-j force-pushed the 990-structured-syntax-suffix branch from 030c702 to c68ed0e Compare April 18, 2024 10:07
@dan-j dan-j enabled auto-merge April 18, 2024 10:12
@dan-j dan-j merged commit 6408c01 into cloudevents:main Apr 18, 2024
9 checks passed
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.

Support structured syntax suffixes for custom content types
3 participants