Skip to content

Conversation

@saulecabrera
Copy link
Contributor

This patch fixes how the encoding codec is handled across the entire codebase.

Prior to this commit, support for codecs other than JSON was incomplete, mainly since the code assumed that all function output must be valid JSON.

Proper handling of codecs involves:

  • Validating JSON as the canonical input to function runner.
  • Encoding from JSON to a given codec if needed
  • Encoding to JSON from the function's output if needed and ensuring to keep save any encoding errors when needed.

In order to achieve proper codec handling, I opted to encapsulate the details related to input and output bytes in a container (BytesContainer), which can either hold input or output bytes, and similarly perform all the byte-level operations needed for reporting, such as calculating the length, presenting a human-readable representation, etc.

This commit also adds the proper tests for each codec.

This patch fixes how the encoding codec is handled across the entire
codebase.

Prior to this commit, support for codecs other than JSON was
incomplete, mainly since the code assumed that all function output must be valid .

Proper handling of codecs involves:

* Validating JSON as the canonical input to function runner.
* Encoding from JSON to a given codec if needed
* Encoding to JSON from the function's output if needed and ensuring to
keep save any encoding errors when needed.

In order to achieve proper codec handling, I opted to encapsulate
the details related to input and output bytes in a container
(`BytesContainer`), which can either hold input or output bytes, and
simiarly perform all the byte-level operations needed for reporting,
such as calculating the length, presenting a human-readable
representation, etc.

This commit also adds the proper tests for each codec.
src/lib.rs Outdated
/// JSON input.
Json,
/// Raw input, no validation, passed as-is.
#[default]
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have expected Json to be the default based on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the same as echo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

edition = "2021"

[dependencies]
rmpv = "1.3.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I wanted to decode in this test, but forgot about it. I've updated the test to do the decoding.

Copy link
Contributor

@lopert lopert left a comment

Choose a reason for hiding this comment

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

I've been tophatting this by stacking my branch on top of it and using the new provider that needs messagepack. 👍 #463

@saulecabrera saulecabrera mentioned this pull request Apr 25, 2025
Co-authored-by: Alex Bradley <alexandre.bradley@shopify.com>
@saulecabrera saulecabrera merged commit 7926a44 into Shopify:main Apr 25, 2025
5 checks passed
@saulecabrera saulecabrera deleted the fix-codec-handling branch April 25, 2025 13:09
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.

3 participants