-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
Added support for constructing from ArrayBuffer and added test that verifies support #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,19 @@ test('new buffer from float64array', function (t) { | |
t.end() | ||
}) | ||
|
||
test('new buffer from ArrayBuffer', function(t) { | ||
if (typeof ArrayBuffer !== 'undefined' && typeof DataView !== 'undefined') { | ||
var b1 = new ArrayBuffer(2) | ||
var dataView = new DataView(b1) | ||
dataView.setInt16(0, 256, true) | ||
var b2 = new B(b1) | ||
t.equal(b1.byteLength, b2.length) | ||
t.equal(b1[0], 0) | ||
t.equal(b1[1], 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indexing into ArrayBuffers doesn't work. It's a bug that it works in node 0.10 and will fail in node 0.12 and browsers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, yeah I only tested this in latest Chrome (works like a charm, can parse and send MQTT over WebSocket) and assumed from the lack of any other accessors this would be the only way to have it work. I can try to change the websocket-stream library to construct an Uint8Array from the ArrayBuffer before wrapping with a Buffer. |
||
} | ||
t.end() | ||
}) | ||
|
||
test('buffer toArrayBuffer()', function (t) { | ||
var data = [1, 2, 3, 4, 5, 6, 7, 8] | ||
if (typeof Uint8Array !== 'undefined') { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually not enough to just set the length correctly.
subject
itself should be wrapped in aUint8Array
so the data can actually be pulled out.