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

Fixed-length types not encoding as expected #33

Open
pmarrapese opened this issue Jul 23, 2019 · 0 comments
Open

Fixed-length types not encoding as expected #33

pmarrapese opened this issue Jul 23, 2019 · 0 comments

Comments

@pmarrapese
Copy link

Version: 1.0.0
Issue: I'm using restructure to unpack/pack objects for use in a binary protocol. Given "C-like structures" are a supported feature, I expected the "encode" function to align fields based on the spec provided.

If the spec states a string is 10 bytes long, shouldn't a 3-byte string be null-padded when encoded?

For example:

let stream = new r.EncodeStream();
stream.on('data', console.log);

let encoder = new r.Struct({
  foo: new r.Buffer(10),
  bar: new r.String(10)
});

encoder.encode(stream, {
  foo: Buffer.from('foo'),
  bar: 'bar'
});
stream.end();

Expected:

<Buffer 66 6f 6f 00 00 00 00 00 00 00>
<Buffer 62 61 72 00 00 00 00 00 00 00>

Actual:

<Buffer 66 6f 6f>
<Buffer 62 61 72>
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