Type system changes // canonical string representation#432
Conversation
Signed-off-by: Clemens Vasters <clemensv@microsoft.com>
Signed-off-by: Clemens Vasters <clemensv@microsoft.com>
Signed-off-by: Clemens Vasters <clemensv@microsoft.com>
| The following abstract data types are available for use in attributes. Each of | ||
| these types MAY be represented differently by different event formats and in | ||
| transport metadata fields. This specification defines a canonical string-encoding | ||
| for each type that MUST be supported by all implementations. |
There was a problem hiding this comment.
Even if that impl only supports transports/formats that don't use the string encoding?
There was a problem hiding this comment.
@duglin Yes, all implementations need to expect a string value to come across the wire where the "native" representation would be a binary-encoded number, for instance. Interop.
| the runtime/language native type that best corresponds to the abstract type. | ||
|
|
||
| For example, the `time` attribute might be represented by the language's native | ||
| *datetime* type in a given implementation, but it MUST be settable providing |
There was a problem hiding this comment.
"MUST be settable"... not sure what this means. Does this mean the SDK's setter MUST accept a "string" value from the user? Or is this more about how there are certain transports that will use the string-encoding and impls that support that transport must be prepared to convert between strings and the native type?
There was a problem hiding this comment.
Oh, the next sentence covers the transport stuff. So I think I'm back to not understanding what the "settable" part means in practice.
There was a problem hiding this comment.
@duglin "settable" means that the implementation MUST ALWAYS allow the app to set a time value via its string representation, either from the SDK side (e.g. you're building a forwarder that maps between transports) or from the wire side, even if the "native" representation of the type isn't string. E.g. set_time(time_t) and set_time(string).
There was a problem hiding this comment.
ok that helps clarify things- thanks.
However, is this out of scope for the spec? Should this be guidance in the sdk doc? I'm not sure the spec, which is just about (mainly) defining the metadata, should get into how the metadata is set/retrieved by the app/user. Especially via a "MUST" - as non-normative guidance I can see though.
|
I believe this proposal means:
For example: the receiver of this CloudEvent would pass along the value of Do I have this right @clemensv ? |
|
@jem in #413 (comment) you said you would prefer to keep the type info in the serialized name of the attribute. Can you elaborate on how this info would be used? In particular in cases where the extension is unknown by both the receiving SDK and app. While I can image some amount of type checking might be done (e.g. it can check that |
|
I'm assuming this would not affect the JSON serialization. A number would still have to be encoded as a JSON number, right? |
Yes.
Yes.
Yes. |
Correct, @timbray. Since people have been objecting to having quotes in HTTP header values when they're strings, I'm now defining CloudEvents as having its own string encoding for its type system, but I deep-link into the JSON spec for Integer and Map and lean on RFC3986 for The net effect of all this is that JSON numbers are still JSON numbers and that maps contained in metadata are still proper JSON, but that all the quotes around strings disappear from CloudEvents headers. The design keeps everything else the same. Also, since I'm allowing each encoding and transport and runtime to use whatever native type system it has, and a Time expression might always be an int64 UNIX epoch while you're in a Java and AMQP world, but since I mandate the ability to convert to/from these well-defined string formats, we can always transcode via string to, say, a C# DateTime Tick, which (surprise!) has a different epoch offset. |
Concrete data types only really matter where the event interfaces with the programming abstraction, and the application will generally have an opinion or expectation about those if it handles them. In a C# producer app, you may set an attribute as DateTime and in the receiving Java consumer app you might want to get that attribute value as a Date, but whether that value traveled as an AMQP timestamp or as an RFC3339 string inside an HTTP header doesn't really matter as long as conversions are defined and those conversions don't cause information loss. |
|
Approved on the 6/6 call |
This amends the type system section such that any type can be represented as a runtime or transport or encoding sees it fit, but that all implementations MUST support a canonical string representation.
Fixes: #396
Fixes: #413
Signed-off-by: Clemens Vasters clemensv@microsoft.com