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

Byte order neutrality #8

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

Byte order neutrality #8

wants to merge 1 commit into from

Conversation

jacopodl
Copy link

@jacopodl jacopodl commented Dec 21, 2023

Hi, in this PR I removed Uint32Array and replaced it with DataView.

Unfortunately Uint32Array serializes and deserializes data using the byte order of your platform. If the platform sending/receiving the data differs in byte order, the data cannot be read/written correctly.

DataView (in this case) will always and only use the big endian order, guaranteeing compatibility on the various platforms.

@allevo
Copy link
Collaborator

allevo commented Mar 13, 2024

Hi!
Thanks for your contribution. Anyway, this PR introduce a 5% of performance penalty.
I'm ok to support this feature differently, for instance adapt the implementation based on the endness.
So if the server returns a content type with this information, the client can adapt the byte interpretation accordingly. So, I support we can enhance seqproto during the deserialization phase where I can pass the type of the endness.
If the client has the same configuration, it is ok the deserialize it directly, otherwise we can use the "slow" implementation with DataView.
In this way, there's not pay any penalties if the the client and the server agree (the case is the server side).

WDYT?

@jacopodl
Copy link
Author

Hi!

It's an interesting idea, but handling endianness manually might not be practical. Instead, we could consider adding a "magic_number" to determine the endianness. One possible solution could be initializing "seqproto" using the first incoming bytes (the "magic_number") to determine how to proceed.

We could follow this approach:

  • When the first serialization function is called (regardless of which one it is, e.g.: serializeNumber, serializeUInt32), the "magic_number" is added before the serialized data. Subsequently, the next call to the serialization functions continues as usual.
  • For the deserializer: the first called function expects to find the "magic_number" as the first thing with which to initialize "seqproto". It then proceeds with deserializing the data as usual.

WDYT?

@allevo
Copy link
Collaborator

allevo commented Apr 28, 2024

If we go in this direction, it is a breaking change. While we can change the method signatures, I prefer to keep the dump created compatible (i.e., allow the developer to turn off this option).
So, we can use a createSer and createDes parameter to specify if the dump should contain that initial byte.
createSer({ something: true }) and createDes({ something: true }).
WDYT?

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.

2 participants