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

Usage question. #4

Closed
Pappa opened this issue Apr 15, 2013 · 2 comments
Closed

Usage question. #4

Pappa opened this issue Apr 15, 2013 · 2 comments

Comments

@Pappa
Copy link

Pappa commented Apr 15, 2013

Hi. I'm a little unsure if I'm using this correctly. My code:

var struct = require('struct').Struct().word64Ube('connection_id').word32Ube('action').word32Ube('transaction_id');

struct.allocate();

struct.set("connection_id", 0x41727101980);
struct.set("action", 0);
struct.set("transaction_id", 84548454);

var buf = struct.buffer();

and then passing the buffer on to a dgram client. Is this correct usage?

@xdenser
Copy link
Owner

xdenser commented Apr 15, 2013

Yes. You may also get fields property from struct and access fiedls directly. Like:
,,,
var fields = struct.fields;
fields.connection_id = 0x41727101980;
fields.action = 0;
fiedls.transaction_id = 84548454;

Also please note that for 64 bit integers JavaScript has a limit of precision for conversion from|to Number value as 2^53. So maybe it is worth to represent 64bit fields as two 32 bit.

@Pappa
Copy link
Author

Pappa commented Apr 16, 2013

Thank you xdenser. 👍

@Pappa Pappa closed this as completed Apr 16, 2013
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