-
-
Save slaskis/0a1e7479ec9ddaaf2caf to your computer and use it in GitHub Desktop.
Node 0.9.7 endianness error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test Endian</title> | |
</head> | |
<body> | |
<script src='test-endian.js'></script> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var msg = new ArrayBuffer(4) | |
, dat = new DataView(msg); | |
dat.setUint8(0,1) | |
dat.setUint8(1,2) | |
dat.setUint8(2,3) | |
dat.setUint8(3,4) | |
// add msg seq & length | |
var cmd = new Uint8Array(3+msg.byteLength) | |
, dat = new DataView(cmd.buffer); | |
dat.setUint16(0,1); | |
dat.setUint8(2,msg.byteLength); | |
cmd.set(new Uint8Array(msg),3); | |
// build packet | |
var pkt = new Uint8Array(2+cmd.byteLength); | |
var dat = new DataView(pkt.buffer); | |
dat.setUint16(0,0) | |
pkt.set(cmd,2) | |
var dest = new DataView(pkt.buffer) | |
console.log('should equal 0:',dest.getUint16(0)) | |
console.log('should equal 1:',dest.getUint16(2)) // fails on node 0.9.7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment