Created
July 26, 2012 18:08
-
-
Save tJener/3183572 to your computer and use it in GitHub Desktop.
Network serialization
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
// Store number in Float64Array. | |
var arr = new Float64Array([ 15.290663048624992 ]); | |
// View the underlying ArrayBuffer as unsigned bytes. | |
var bytes = new Uint8Array( arr.buffer ); | |
// Serialize to a string. Pay attention to endian in production code. | |
var str = [].map.call( bytes, function( byte ) { | |
return String.fromCharCode( byte ); | |
}).join(''); | |
// Or more bluntly put: | |
// var str = String.fromCharCode( | |
// bytes[0], bytes[1], bytes[2], bytes[3], | |
// bytes[4], bytes[5], bytes[6], bytes[7] | |
// ); | |
str.length; // 8 |
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 arr = new Float64Array([15.290663048624992]); | |
// { '0': 15.290663048624992, | |
// buffer: | |
// { '0': 0, | |
// '1': 0, | |
// '2': 128, | |
// '3': 201, | |
// '4': 209, | |
// '5': 148, | |
// '6': 46, | |
// '7': 64, | |
// byteLength: 8 }, | |
// BYTES_PER_ELEMENT: 8, | |
// length: 1, | |
// set: [Function: set], | |
// slice: [Function: slice], | |
// byteOffset: 0, | |
// byteLength: 8, | |
// subarray: [Function: subarray] } |
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
[15.290663048624992,2.0000000004989023,-24.90756910131313,0.12015604357058937,0.32514392007855847,-0.8798439564294107,0.32514392007855847] |
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
"?¾Âål6@.ÑÉ\u0000\u0000?ÔÏ(qÎÂé@\u0000\u0000\u0000\u0000\u0011$d¿ì'®NRzÀ8èVrÙ\u0000\u0000?ÔÏ(qÎÂé" |
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 transform = { | |
origin: { | |
x: 15.290663048624992, | |
y: 2.0000000004989023, | |
z: -24.90756910131313 | |
}, | |
rotation: { | |
w: 0.12015604357058937, | |
x: 0.32514392007855847, | |
y: -0.8798439564294107, | |
z: 0.32514392007855847 | |
} | |
}; |
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
{"origin":{"x":15.290663048624992,"y":2.0000000004989023,"z":-24.90756910131313},"rotation":{"w":0.12015604357058937,"x":0.32514392007855847,"y":-0.8798439564294107,"z":0.32514392007855847}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment