Show More
@@ -2,8 +2,8 | |||||
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 |
|
3 | |||
4 | define([ |
|
4 | define([ | |
5 |
' |
|
5 | 'underscore', | |
6 |
], function ( |
|
6 | ], function (_) { | |
7 | "use strict"; |
|
7 | "use strict"; | |
8 |
|
8 | |||
9 | var _deserialize_array_buffer = function (buf) { |
|
9 | var _deserialize_array_buffer = function (buf) { | |
@@ -16,7 +16,7 define([ | |||||
16 | offsets.push(data.getUint32(i * 4)); |
|
16 | offsets.push(data.getUint32(i * 4)); | |
17 | } |
|
17 | } | |
18 | var json_bytes = new Uint8Array(buf.slice(offsets[0], offsets[1])); |
|
18 | var json_bytes = new Uint8Array(buf.slice(offsets[0], offsets[1])); | |
19 |
var msg = |
|
19 | var msg = JSON.parse( | |
20 | (new TextDecoder('utf8')).decode(json_bytes) |
|
20 | (new TextDecoder('utf8')).decode(json_bytes) | |
21 | ); |
|
21 | ); | |
22 | // the remaining chunks are stored as DataViews in msg.buffers |
|
22 | // the remaining chunks are stored as DataViews in msg.buffers | |
@@ -53,7 +53,7 define([ | |||||
53 | // deserialize a message and pass the unpacked message object to callback |
|
53 | // deserialize a message and pass the unpacked message object to callback | |
54 | if (typeof data === "string") { |
|
54 | if (typeof data === "string") { | |
55 | // text JSON message |
|
55 | // text JSON message | |
56 |
callback( |
|
56 | callback(JSON.parse(data)); | |
57 | } else { |
|
57 | } else { | |
58 | // binary message |
|
58 | // binary message | |
59 | _deserialize_binary(data, callback); |
|
59 | _deserialize_binary(data, callback); | |
@@ -63,10 +63,10 define([ | |||||
63 | var _serialize_binary = function (msg) { |
|
63 | var _serialize_binary = function (msg) { | |
64 | // implement the binary serialization protocol |
|
64 | // implement the binary serialization protocol | |
65 | // serializes JSON message to ArrayBuffer |
|
65 | // serializes JSON message to ArrayBuffer | |
66 |
msg = |
|
66 | msg = _.clone(msg); | |
67 | var offsets = []; |
|
67 | var offsets = []; | |
68 | var buffers = []; |
|
68 | var buffers = []; | |
69 |
|
|
69 | msg.buffers.map(function (buf) { | |
70 | buffers.push(buf); |
|
70 | buffers.push(buf); | |
71 | }); |
|
71 | }); | |
72 | delete msg.buffers; |
|
72 | delete msg.buffers; |
General Comments 0
You need to be logged in to leave comments.
Login now