node-struct icon indicating copy to clipboard operation
node-struct copied to clipboard

Null-terminated string

Open majimboo opened this issue 11 years ago • 5 comments

No Null-terminating string support?

majimboo avatar Jul 01 '14 12:07 majimboo

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

xdenser avatar Jul 01 '14 18:07 xdenser

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?

majimboo avatar Jul 01 '14 18:07 majimboo

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

xdenser avatar Jul 01 '14 18:07 xdenser

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

majimboo avatar Jul 02 '14 00:07 majimboo

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

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

svaygame avatar Jan 23 '17 09:01 svaygame