-
Notifications
You must be signed in to change notification settings - Fork 513
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
Encode/decode event data as a Variant #2815
Encode/decode event data as a Variant #2815
Conversation
8c218ac
to
f3f9e48
Compare
*/ | ||
char* data() { | ||
return d_.data(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original Buffer
implementation that we used internally exposed its data as char*
so I did the same here to reduce changes in unrelated parts of Device OS that use this class. The Wiring library tends to use uint8_t*
for binary data though so I'm wondering if it would be better to use that type instead.
ca470ea
to
c2cd5aa
Compare
863993c
to
5288bca
Compare
53057dc
to
ac3ea97
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Note: This PR is targeting typed-publish/sc-129495 for review purposes.
Description
This PR introduces the following changes:
Buffer
class to a public API.Variant
to supportBuffer
as one of its alternative types.Particle.publish()
to support publishing event data as a variant.Particle.subscribe()
to support a new callback type that takes event data as a variant.Buffer
is a general purpose class for storing arbitrary data in a dynamically allocated buffer. Note that one implication of supporting it as one of theVariant
's alternative types is that it makes it possible to store binary data in a ledger so this PR enables that as well.When an event is published as a variant, it's serialized as CBOR on the wire. The server then converts it to JSON and forwards it to the subscribers. In the opposite direction, from the server to device, a conversion to CBOR is performed if necessary (see the examples below).
Examples
Sending event data as a variant:
Subscribing via the CLI:
Receiving event data as a variant:
When sending an event to the device, the content type of the event data can be arbitrary. On the wire, the data is converted to a CBOR which is then parsed by Device OS as a variant:
Device output: