Show More
@@ -54,7 +54,7 b' def serialize_binary_message(msg):' | |||
|
54 | 54 | offsets = [4 * (nbufs + 1)] |
|
55 | 55 | for buf in buffers[:-1]: |
|
56 | 56 | offsets.append(offsets[-1] + len(buf)) |
|
57 |
offsets_buf = struct.pack('!' + ' |
|
|
57 | offsets_buf = struct.pack('!' + 'I' * (nbufs + 1), nbufs, *offsets) | |
|
58 | 58 | buffers.insert(0, offsets_buf) |
|
59 | 59 | return b''.join(buffers) |
|
60 | 60 | |
@@ -75,7 +75,7 b' def deserialize_binary_message(bmsg):' | |||
|
75 | 75 | message dictionary |
|
76 | 76 | """ |
|
77 | 77 | nbufs = struct.unpack('!i', bmsg[:4])[0] |
|
78 |
offsets = list(struct.unpack('!' + ' |
|
|
78 | offsets = list(struct.unpack('!' + 'I' * nbufs, bmsg[4:4*(nbufs+1)])) | |
|
79 | 79 | offsets.append(None) |
|
80 | 80 | bufs = [] |
|
81 | 81 | for start, stop in zip(offsets[:-1], offsets[1:]): |
@@ -9,11 +9,11 b' define([' | |||
|
9 | 9 | var _deserialize_array_buffer = function (buf) { |
|
10 | 10 | var data = new DataView(buf); |
|
11 | 11 | // read the header: 1 + nbufs 32b integers |
|
12 |
var nbufs = data.get |
|
|
12 | var nbufs = data.getUint32(0); | |
|
13 | 13 | var offsets = []; |
|
14 | 14 | var i; |
|
15 | 15 | for (i = 1; i <= nbufs; i++) { |
|
16 |
offsets.push(data.get |
|
|
16 | offsets.push(data.getUint32(i * 4)); | |
|
17 | 17 | } |
|
18 | 18 | var json_bytes = new Uint8Array(buf.slice(offsets[0], offsets[1])); |
|
19 | 19 | var msg = $.parseJSON( |
@@ -81,13 +81,13 b' define([' | |||
|
81 | 81 | var msg_buf = new Uint8Array( |
|
82 | 82 | offsets[offsets.length-1] + buffers[buffers.length-1].byteLength |
|
83 | 83 | ); |
|
84 |
// use DataView.set |
|
|
84 | // use DataView.setUint32 for network byte-order | |
|
85 | 85 | var view = new DataView(msg_buf.buffer); |
|
86 | 86 | // write nbufs to first 4 bytes |
|
87 |
view.set |
|
|
87 | view.setUint32(0, nbufs); | |
|
88 | 88 | // write offsets to next 4 * nbufs bytes |
|
89 | 89 | for (i = 0; i < offsets.length; i++) { |
|
90 |
view.set |
|
|
90 | view.setUint32(4 * (i+1), offsets[i]); | |
|
91 | 91 | } |
|
92 | 92 | // write all the buffers at their respective offsets |
|
93 | 93 | for (i = 0; i < buffers.length; i++) { |
General Comments 0
You need to be logged in to leave comments.
Login now