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

Implement Alignment Support for Custom Extensions in Encoder/Decoder #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EddiG
Copy link

@EddiG EddiG commented Aug 23, 2024

This update introduces a solution to handle data alignment in custom extensions, ensuring that encoded data is aligned in memory according to specified requirements. The main benefit of this approach is enabling zero-copy deserialization, which significantly enhances performance when working with data types like Float32Array that have strict alignment needs.

Key Steps:

  1. Alignment Handling in Encoding:

    • In the Encoder class, the code checks if an alignment requirement (align) is specified for the extension before encoding it.
    • The necessary padding is calculated to align the data properly in memory. Padding bytes (0xc1, known as noop bytes) are inserted before the extension type to ensure the data starts at an aligned memory position.
  2. Padding Skipping in Decoding:

    • The Decoder class is enhanced to recognize and skip padding bytes (0xc1) when decoding an extension. This ensures the actual extension type is correctly identified, regardless of any alignment padding added during encoding.
  3. Storing Alignment Information:

    • The ExtensionCodec class is modified to store the alignment requirement for each registered extension. This alignment information is utilized during encoding to ensure that data is correctly aligned in memory.
  4. Modification of the ExtData Class:

    • The ExtData class is extended to include an optional align property. This property stores the alignment requirement for each extension, allowing the encoder to handle data alignment appropriately.

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.

1 participant