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

FR: writeBufferWithLength and readBufferWithLength #36

Open
hpx7 opened this issue Jun 22, 2021 · 1 comment
Open

FR: writeBufferWithLength and readBufferWithLength #36

hpx7 opened this issue Jun 22, 2021 · 1 comment

Comments

@hpx7
Copy link

hpx7 commented Jun 22, 2021

I'm not sure what the best name for it would be, but would be nice to have convenience methods for the following common scenario:

// write
const data = ...
const buf = new SmartBuffer()
  .writeUInt32LE(data.length)
  .writeBuffer(data)
  .toBuffer();

...

// read
const reader = SmartBuffer.from(buf);
const data = reader.readBuffer(reader.readUInt32LE());

This is useful when you're constructing complex messages with multiple buffers inside them.

@soanvig
Copy link

soanvig commented May 6, 2022

Just saw this browsing the issues from curiosity.
I'm not the library author, but I'll leave a comment.

Don't ask to add bloat and dozens of configuration options to libraries. Let's keep them simple, and do one thing, and do it right.

If you need such a feature, extend SmartBuffer, add these two functions, and use your own "wrapper" in the code.

To be honest - I would make use of that feature, so it's nothing personal. I have the exact case in my project. The problem I see is that features are being added and added to libraries, which makes them less maintainable, and actually less usable. If some feature is not a blocker (meaning that something cannot be done with current API), and it's not complex to implement by library user, it should be added only if would be used by majority of the users.

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

2 participants