Skip to content

Commit

Permalink
Fix up JSON type mappings (#496)
Browse files Browse the repository at this point in the history
* Fix up JSON type mappings

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Fix type mapping for AMQP

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Add `data` to AMQP.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Add payload data to amqp-format.md

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>

* Update AMQP data encoding per discussion in #492

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>
  • Loading branch information
evankanderson authored and Doug Davis committed Sep 12, 2019
1 parent be24089 commit d7ae79c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
46 changes: 29 additions & 17 deletions amqp-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Abstract

The AMQP Format for CloudEvents defines how event attributes are expressed in
the [AMQP 1.0 Type System][type-system].
The AMQP Format for CloudEvents defines how event attributes and payload data
are expressed in the [AMQP 1.0 Type System][type-system].

## Status of this document

Expand All @@ -13,7 +13,8 @@ This document is a working draft.

1. [Introduction](#1-introduction)
2. [Attributes](#2-attributes)
3. [References](#3-references)
3. [Data](#3-data)
4. [References](#4-references)

## 1. Introduction

Expand Down Expand Up @@ -55,13 +56,13 @@ exceptions noted below.

| CloudEvents | AMQP |
| ------------- | --------------------------- |
| String | [string][amqp-string] |
| Boolean | [boolean][amqp-boolean] |
| Integer | [long][amqp-long] |
| String | [string][amqp-string] |
| Binary | [binary][amqp-binary] |
| URI | [string][amqp-string] |
| URI-reference | [string][amqp-string] |
| Timestamp | [timestamp][amqp-timestamp] |
| Any | See 2.3. |

A CloudEvents AMQP format implementation MUST allow for attribute values to be
convertible from/to their canonical CloudEvents string representation. For
Expand All @@ -88,14 +89,21 @@ any revision of such a specification, MUST also define explicit mapping rules
for all other event formats that are part of the CloudEvents core at the time of
the submission or revision.

### 2.3. Mapping Any-typed Attributes
## 3. Data

Before encoding, the AMQP serializer MUST first determine the runtime data type
of the data content. This may be determined by examining the data for characters
outside the UTF-8 range or by consulting the `datacontenttype` attribute.

If the implementation determines that the type of the data is binary, the value
MUST be stored in the payload as a single [AMQP data][amqp-data] section.

`Any`-typed CloudEvents values can either hold a `String`, or a `Binary` value,
or a `Map`. `Map` entry values are also `Any` typed. AMQP's type system natively
represents dynamic typing in its [type system encoding][type-system-encoding],
and therefore immediately allows for the required variant type representation.
For other types (non-binary data without a `datacontenttype` attribute), the
implementation MUST translate the data value into an [AMQP type
system][type-system] value and the value MUST be stored in an [AMQP
value][amqp-value] section.

## 3. References
## 4. References

- [RFC2046][rfc2046] Multipurpose Internet Mail Extensions (MIME) Part Two:
Media Types
Expand All @@ -109,21 +117,25 @@ and therefore immediately allows for the required variant type representation.
https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html
[type-system-encoding]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#section-encodings
[amqp-string]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-string
[amqp-boolean]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-boolean
[amqp-long]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-long
[amqp-string]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-string
[amqp-binary]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-binary
[amqp-timestamp]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-timestamp
[amqp-map]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#type-map
[amqp-describedtype]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-types-v1.0-os.html#doc-idp38080
[amqp-data]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-data
[amqp-value]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-value
[rfc2046]: https://tools.ietf.org/html/rfc2046
[rfc2119]: https://tools.ietf.org/html/rfc2119
[rfc4627]: https://tools.ietf.org/html/rfc4627
[rfc4648]: https://tools.ietf.org/html/rfc4648
[rfc6839]: https://tools.ietf.org/html/rfc6839#section-3.1
[rfc8259]: https://tools.ietf.org/html/rfc8259
[oasis-amqp-1.0]:
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-overview-v1.0-os.html
5 changes: 3 additions & 2 deletions json-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ with exceptions noted below.

| CloudEvents | JSON |
| ------------- | -------------------------------------------------------------- |
| String | [string][json-string] |
| Boolean | [boolean][json-bool]
| Integer | [number][json-number], only the `int` component is permitted |
| String | [string][json-string] |
| Binary | [string][json-string], [Base64-encoded][base64] binary |
| URI | [string][json-string] following [RFC 3986][rfc3986] |
| URI-reference | [string][json-string] following [RFC 3986][rfc3986] |
| Timestamp | [string][json-string] following [RFC 3339][rfc3339] (ISO 8601) |
| Any | [JSON value][json-value] |

Extension specifications MAY define diverging mapping rules for the values of
attributes they define.
Expand Down Expand Up @@ -297,6 +297,7 @@ also valid in a request):
https://www.iana.org/assignments/media-types/application/geo+json-seq
[json-object]: https://tools.ietf.org/html/rfc7159#section-4
[json-seq]: https://www.iana.org/assignments/media-types/application/json-seq
[json-bool]: https://tools.ietf.org/html/rfc7159#section-3
[json-number]: https://tools.ietf.org/html/rfc7159#section-6
[json-string]: https://tools.ietf.org/html/rfc7159#section-7
[json-value]: https://tools.ietf.org/html/rfc7159#section-3
Expand Down

0 comments on commit d7ae79c

Please sign in to comment.