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

Consider having Fw::Buffer::getSerializeRepr return an object instead of a reference #2714

Open
bocchino opened this issue May 1, 2024 · 1 comment

Comments

@bocchino
Copy link
Collaborator

bocchino commented May 1, 2024

Fw::Buffer::getSerializeRepr currently returns a reference into a serialize buffer stored as a member of Fw::Buffer. There are some issues with this:

  1. When you call getSerializeRepr, you're not sure what state the serialize buffer is in. It depends on what has previously been done with the buffer.
  2. The serialize representation state is reset when the buffer object is serialized and deserialized but otherwise persists. This could be an unexpected behavior.
  3. Performing deserialize operations on the buffer updates the serialize buffer and therefore updates the Fw::Buffer. It would be better for theFw::Buffer to be read-only in this case.

Instead we could have getSerializeRepr return an object, say Fw::ExternalSerializeBufferWithMemberCopy. That way the user would own the serialize representation, and it could be freshly initialized each time it is requested. An argument to getSerializeRepr could specify whether the representation is for serialization (in which case the internal serial pointer should be set to zero) or deserialization (in which case the internal serial pointer should be set to the end of the data). Access to the buffer for deserialization would be read-only.

@LeStarch
Copy link
Collaborator

LeStarch commented May 1, 2024

I like it! Thanks for the write-up @bocchino!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants