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