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

ByteBuffer::__construct() behaviour is always surprising to one use case or the other #13

Open
dktapps opened this issue Jan 29, 2024 · 0 comments

Comments

@dktapps
Copy link
Member

dktapps commented Jan 29, 2024

If the caller wants to read a ByteBuffer for reading, the offset should be 0, so that the bytes can be read from the beginning.
If the caller wants to write a ByteBuffer, the offset should be placed at the end of the input data, as if writeByteArray() was used.

Possible solutions:

  • Make the offset parameter mandatory
  • Make a parameter that indicates whether the offset should be at the beginning or the end (slightly easier to use than a mandatory offset parameter)
  • Make the constructor private and have ::reader() and ::writer() static factory functions
  • Split ByteBuffer into a ByteBufferReader and ByteBufferWriter
  • Separate read offset and write offset (effectively what BinaryStream was implicitly doing)
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

No branches or pull requests

1 participant