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

Convert WordArrays to ArrayBuffers when msgpack-encoding #143

Merged
merged 2 commits into from
Sep 30, 2015

Conversation

SimonWoolf
Copy link
Member

Fixes #142, and makes msgpack more efficient when used with encryption, as encrypted binary data is encoded as binary data rather than as arrays of ints.

The actual bit-packing code already existed in the 3.x development branch of the google code project, but the version on github (which is what's packaged on npm) was forked from the 3.1.2 release, which doesn't have it. For simplicity I just copied & pasted the relevant code into bufferutils.

@paddybyers
Copy link
Member

makes msgpack more efficient

err .. makes it interoperable, because sending a map would never work except for other browser clients.

var uint8View = new Uint8Array(arrayBuffer);

for (var i = 0; i < buf.sigBytes; i++) {
uint8View[i] = (buf.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still isn't great efficiency-wise, because we should be writing words into a unit32View, but we can leave this and file a lower-priority issue to improve it unless you want to do it now anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is definitely not worth optimising now, let's please land this as it works and performance of this obscure requirement for now is not a high priority

@mattheworiordan
Copy link
Member

Nice work

paddybyers added a commit that referenced this pull request Sep 30, 2015
Convert WordArrays to ArrayBuffers when msgpack-encoding
@paddybyers paddybyers merged commit 7f14700 into master Sep 30, 2015
@SimonWoolf SimonWoolf deleted the msgpack-wordarray-1 branch October 6, 2015 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants