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

Null-terminated string #15

Open
majimboo opened this issue Jul 1, 2014 · 5 comments
Open

Null-terminated string #15

majimboo opened this issue Jul 1, 2014 · 5 comments

Comments

@majimboo
Copy link

majimboo commented Jul 1, 2014

No Null-terminating string support?

@xdenser
Copy link
Owner

xdenser commented Jul 1, 2014

Any problems with null-terminated strings?
chars field should work

@majimboo
Copy link
Author

majimboo commented Jul 1, 2014

Hmmm, I thought it was not supported, how would be the syntax on that?

For example I have a null terminated string on a buffer, or a string that is fixed on an actual length no null terminators? How would both work?

@xdenser
Copy link
Owner

xdenser commented Jul 1, 2014

see source - it uses standard NodeJS Buffer.toString Method and slices string to zero character.

https://github.com/xdenser/node-struct/blob/master/index.js#L92

@majimboo
Copy link
Author

majimboo commented Jul 2, 2014

So it uses null to terminate the string but if it won't find the null terminator it will use the full length?

@svaygame
Copy link

wrong:
p.buf.fill(0, (offset + val.length), length);

correct:
p.buf.fill(0, (offset + val.length), (offset + length) );

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

3 participants