Show More
@@ -75,15 +75,17 b' define([' | |||
|
75 | 75 | msg = _.clone(msg); |
|
76 | 76 | var offsets = []; |
|
77 | 77 | var buffers = []; |
|
78 | msg.buffers.map(function (buf) { | |
|
79 | buffers.push(buf); | |
|
80 | }); | |
|
78 | var i; | |
|
79 | for (i = 0; i < msg.buffers.length; i++) { | |
|
80 | // msg.buffers elements could be either views or ArrayBuffers | |
|
81 | // buffers elements are ArrayBuffers | |
|
82 | buffers.push(msg.buffers[i].buffer || msg.buffers[i]) | |
|
83 | } | |
|
81 | 84 | delete msg.buffers; |
|
82 | 85 | var json_utf8 = (new TextEncoder('utf8')).encode(JSON.stringify(msg)); |
|
83 | 86 | buffers.unshift(json_utf8); |
|
84 | 87 | var nbufs = buffers.length; |
|
85 | 88 | offsets.push(4 * (nbufs + 1)); |
|
86 | var i; | |
|
87 | 89 | for (i = 0; i + 1 < buffers.length; i++) { |
|
88 | 90 | offsets.push(offsets[offsets.length-1] + buffers[i].byteLength); |
|
89 | 91 | } |
@@ -100,7 +102,7 b' define([' | |||
|
100 | 102 | } |
|
101 | 103 | // write all the buffers at their respective offsets |
|
102 | 104 | for (i = 0; i < buffers.length; i++) { |
|
103 |
msg_buf.set(new Uint8Array(buffers[i] |
|
|
105 | msg_buf.set(new Uint8Array(buffers[i]), offsets[i]); | |
|
104 | 106 | } |
|
105 | 107 | |
|
106 | 108 | // return raw ArrayBuffer |
General Comments 0
You need to be logged in to leave comments.
Login now