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

Add support for event content types #2804

Merged
merged 45 commits into from
Sep 20, 2024
Merged

Add support for event content types #2804

merged 45 commits into from
Sep 20, 2024

Conversation

sergeuz
Copy link
Member

@sergeuz sergeuz commented Jul 23, 2024

Description

This PR extends the Particle.publish() and Particle.subscribe() APIs to support events with non-plain text data. The actual format of the data is determined by its content type:

enum class ContentType {
    TEXT, // text/plain; charset=utf-8
    JPEG, // image/jpeg
    PNG, // image/png
    BINARY // application/octet-stream
};

This PR also includes the changes from #2815.

Example

Publishing binary data:

char buf[] = { 0x00, 0x01, 0x02, 0x04 };
Particle.publish("my_event", buf, sizeof(buf), ContentType::BINARY);

Subscribing to binary events:

void eventHandler(const char* name, const char* data, size_t size, ContentType type) {
    Log.info("Received event: %s; content type: %d; size: %u", name, (int)type, (unsigned)size);
    Log.dump(data, size);
    Log.print("\r\n");
}

void setup() {
    Particle.subscribe("my_event", eventHandler);
    // ...
}

When publishing/subscribing to events with a content type via the HTTP API, the event data is expected to be encoded as a data URI.

References

@sergeuz sergeuz marked this pull request as draft July 23, 2024 16:34
@sergeuz sergeuz marked this pull request as ready for review August 7, 2024 13:55
Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

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

Looks great from my point of view. No additional feedback at this point.

@sergeuz sergeuz changed the base branch from develop to develop-6.x August 20, 2024 12:06
@sergeuz sergeuz changed the base branch from develop-6.x to develop September 18, 2024 14:45
@Kategrode Kategrode added this to the 6.2.0 milestone Sep 20, 2024
@sergeuz sergeuz merged commit df9f9fa into develop Sep 20, 2024
13 checks passed
@sergeuz sergeuz deleted the typed-publish/sc-129495 branch September 20, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants