You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A more-fundamental approach that absolves the need for per-type read/write functions whilst being less verbose, enables direct data-to-constructor without modification of types, providing more versatility and reducing the exposed surface area that users could introduce bugs in their code.
Valid. In current runtime the tail is sunk and doesn't raise an error; if changed, lots of data would be written unintentionally to the buffer, with OOBs being the following consequence. I'll seek to update this.
Some current thoughts I have:
An overload where buffer.write*(buffer: buffer, index: number, value: {number}) is a current thought as the value type changes distinctly, and this pattern isn't depended on as it currently errors in runtime.
This feels particularly nasty, and I can only imagine the performance implications are not great. Not being able to do this with buffer.read* feels like a dead end.
Adding separately named functions to the buffer library, such as buffer.pack* and buffer.unpack* to better-define intent. This could allow retaining the current RFC where ...number and count are used, whilst replacing read*/write* with pack*/unpack*.
This does add bloat to the library and it would have to be warranted by how compelling the use-cases are.
It would still be less verbose, provide more versatility, and reduce the exposed surface area for bugs in user code.
Edit: I have decided to go with buffer.pack*/buffer.unpack* with my latest revision.
I don't know how feasible it would be implementation wise, however an interesting alternative to consider would be having pack/unpack accept the respective function that you'd normally use to read/write the type: buffer.unpack(buffer.readf32, offset, count) buffer.pack(buffer.writef32, offset, ...)
and so on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rendered
A more-fundamental approach that absolves the need for per-type read/write functions whilst being less verbose, enables direct data-to-constructor without modification of types, providing more versatility and reducing the exposed surface area that users could introduce bugs in their code.