##// END OF EJS Templates
use TextEncoding for string<->ArrayBuffer...
MinRK -
Show More
@@ -5,10 +5,10 b' define(['
5 5 'base/js/namespace',
6 6 'jquery',
7 7 'base/js/utils',
8 'services/kernels/js/comm',
9 'widgets/js/init',
10 './serialize'
11 ], function(IPython, $, utils, comm, widgetmanager, serialize) {
8 './comm',
9 './serialize',
10 'widgets/js/init'
11 ], function(IPython, $, utils, comm, serialize, widgetmanager) {
12 12 "use strict";
13 13
14 14 /**
@@ -3,7 +3,6 b''
3 3
4 4 define([
5 5 'jquery',
6 'components/utf8/utf8'
7 6 ], function ($, utf8) {
8 7 "use strict";
9 8
@@ -16,14 +15,9 b' define(['
16 15 for (i = 1; i <= nbufs; i++) {
17 16 offsets.push(data.getInt32(i * 4));
18 17 }
19 // have to convert array to string for utf8.js
20 var bytestring = String.fromCharCode.apply(null,
21 new Uint8Array(buf.slice(offsets[0], offsets[1]))
22 );
18 var json_bytes = new Uint8Array(buf.slice(offsets[0], offsets[1]));
23 19 var msg = $.parseJSON(
24 utf8.decode(
25 bytestring
26 )
20 (new TextDecoder('utf8')).decode(json_bytes)
27 21 );
28 22 // the remaining chunks are stored as DataViews in msg.buffers
29 23 msg.buffers = [];
@@ -66,16 +60,6 b' define(['
66 60 }
67 61 };
68 62
69 var _bytes2buf = function (bytestring) {
70 // convert bytestring to UInt8Array
71 var nbytes = bytestring.length;
72 var buf = new Uint8Array(nbytes);
73 for (var i = 0; i < nbytes; i++) {
74 buf[i] = bytestring.charCodeAt(i);
75 }
76 return buf;
77 };
78
79 63 var _serialize_binary = function (msg) {
80 64 // implement the binary serialization protocol
81 65 // serializes JSON message to ArrayBuffer
@@ -83,7 +67,7 b' define(['
83 67 var offsets = [];
84 68 var buffers = msg.buffers;
85 69 delete msg.buffers;
86 var json_utf8 = _bytes2buf(utf8.encode(JSON.stringify(msg)));
70 var json_utf8 = (new TextEncoder('utf8')).encode(JSON.stringify(msg));
87 71 buffers.unshift(json_utf8);
88 72 var nbufs = buffers.length;
89 73 offsets.push(4 * (nbufs + 1));
@@ -112,7 +96,6 b' define(['
112 96 };
113 97
114 98 var serialize = function (msg) {
115 console.log(msg.buffers, msg.buffers.length);
116 99 if (msg.buffers && msg.buffers.length) {
117 100 return _serialize_binary(msg);
118 101 } else {
@@ -311,6 +311,7 b' class="notebook_app"'
311 311 {% block script %}
312 312 {{super()}}
313 313
314 <script src="{{ static_url("components/text-encoding/lib/encoding.js") }}" charset="utf-8"></script>
314 315
315 316 <script src="{{ static_url("notebook/js/main.js") }}" charset="utf-8"></script>
316 317
General Comments 0
You need to be logged in to leave comments. Login now