Skip to content

Commit eceb608

Browse files
committed
Added TcpClient based on chrome.sockets.tcp.
Improved BytesIO. Improved HttpClient.
1 parent fa4e9d6 commit eceb608

File tree

9 files changed

+656
-17
lines changed

9 files changed

+656
-17
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2008-2015 http://hprose.com
3+
Copyright (c) 2008-2016 http://hprose.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Ma Bingyao <andot@hprose.com>",
33
"name": "hprose-html5",
4-
"version": "2.0.3",
4+
"version": "2.0.4",
55
"description": "Hprose is a High Performance Remote Object Service Engine. It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware.",
66
"keywords": [
77
"hprose",

dist/hprose-html5.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ gulp.task('compress', ['clear'], function() {
2424
'src/ResultMode.js',
2525
'src/Client.js',
2626
'src/HttpClient.js',
27+
'src/TcpClient.js',
2728
'src/WebSocketClient.js',
2829
'src/JSONRPCClientFilter.js',
2930
'src/Loader.js'])

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hprose-html5",
33
"filename": "hprose-html5.js",
4-
"version": "2.0.3",
4+
"version": "2.0.4",
55
"description": "Hprose is a High Performance Remote Object Service Engine. It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.",
66
"homepage": "https://github.com/andot/hprose",
77
"keywords": [

src/BytesIO.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* *
1414
* hprose BytesIO for HTML5. *
1515
* *
16-
* LastModified: Aug 21, 2015 *
16+
* LastModified: Feb 5, 2016 *
1717
* Author: Ma Bingyao <andot@hprose.com> *
1818
* *
1919
\**********************************************************/
@@ -22,6 +22,16 @@
2222
(function (global, undefined) {
2323
'use strict';
2424

25+
var arrayLikeObjectArgumentsEnabled = true;
26+
27+
try {
28+
String.fromCharCode.apply(String, new Uint8Array([1, 2]));
29+
}
30+
catch (e) {
31+
arrayLikeObjectArgumentsEnabled = false;
32+
Object.defineProperty(Array.prototype, 'subarray', { value: Array.prototype.slice });
33+
}
34+
2535
var Future = global.hprose.Future;
2636

2737
var _EMPTY_BYTES = new Uint8Array(0);
@@ -80,7 +90,7 @@
8090
}
8191

8292
function readShortString(bytes, n) {
83-
var charCodes = new Uint16Array(n);
93+
var charCodes = new Array(n);
8494
var i = 0, off = 0;
8595
for (var len = bytes.length; i < n && off < len; i++) {
8696
var unit = bytes[off++];
@@ -138,14 +148,14 @@
138148
}
139149
}
140150
if (i < n) {
141-
charCodes = charCodes.subarray(0, i);
151+
charCodes.length = i;
142152
}
143153
return [String.fromCharCode.apply(String, charCodes), off];
144154
}
145155

146156
function readLongString(bytes, n) {
147157
var buf = [];
148-
var charCodes = new Uint16Array(0xffff);
158+
var charCodes = new Array(0xffff);
149159
var i = 0, off = 0;
150160
for (var len = bytes.length; i < n && off < len; i++) {
151161
var unit = bytes[off++];
@@ -203,13 +213,15 @@
203213
}
204214
if (i >= 65534) {
205215
var size = i + 1;
206-
buf.push(String.fromCharCode.apply(String, charCodes.subarray(0, size)));
216+
charCodes.length = size;
217+
buf.push(String.fromCharCode.apply(String, charCodes));
207218
n -= size;
208219
i = -1;
209220
}
210221
}
211222
if (i > 0) {
212-
buf.push(String.fromCharCode.apply(String, charCodes.subarray(0, i)));
223+
charCodes.length = i;
224+
buf.push(String.fromCharCode.apply(String, charCodes));
213225
}
214226
return [buf.join(''), off];
215227
}
@@ -279,6 +291,15 @@
279291
return [bytes.subarray(0, off), off];
280292
}
281293

294+
function toArray(bytes) {
295+
var n = bytes.length;
296+
var a = new Array(bytes.length);
297+
for (var i = 0; i < n; ++i) {
298+
a[i] = bytes[i];
299+
}
300+
return a;
301+
}
302+
282303
function pow2roundup(x) {
283304
--x;
284305
x |= x >> 1;
@@ -360,6 +381,17 @@
360381
_EMPTY_BYTES :
361382
this._bytes.subarray(0, this._length);
362383
} },
384+
buffer: { get : function() {
385+
if (this._bytes === null) {
386+
return _EMPTY_BYTES.buffer;
387+
}
388+
if (this._bytes.buffer.slice) {
389+
return this._bytes.buffer.slice(0, this._length);
390+
}
391+
var buf = new Uint8Array(this._length);
392+
buf.set(this._bytes.subarray(0, this._length));
393+
return buf.buffer;
394+
} },
363395
mark: { value: function() {
364396
this._wmark = this._length;
365397
this._rmark = this._off;
@@ -555,17 +587,18 @@
555587
}
556588
if (n === 0) return '';
557589
var bytes = this._bytes.subarray(this._off, this._off += n);
590+
var charCodes = (arrayLikeObjectArgumentsEnabled ? bytes : toArray(bytes));
558591
if (n < 100000) {
559-
return String.fromCharCode.apply(String, bytes);
592+
return String.fromCharCode.apply(String, charCodes);
560593
}
561594
var remain = n & 0xffff;
562595
var count = n >> 16;
563596
var a = new Array(remain ? count + 1 : count);
564597
for (var i = 0; i < count; ++i) {
565-
a[i] = String.fromCharCode.apply(String, bytes.subarray(i << 16, (i + 1) << 16));
598+
a[i] = String.fromCharCode.apply(String, charCodes.subarray(i << 16, (i + 1) << 16));
566599
}
567600
if (remain) {
568-
a[count] = String.fromCharCode.apply(String, bytes.subarray(count << 16, n));
601+
a[count] = String.fromCharCode.apply(String, charCodes.subarray(count << 16, n));
569602
}
570603
return a.join('');
571604
} },

src/CopyRight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Hprose for HTML5 v2.0.3
1+
// Hprose for HTML5 v2.0.4
22
// Copyright (c) 2008-2015 http://hprose.com
33
// Hprose is freely distributable under the MIT license.
44
// For all details and documentation:

src/HttpClient.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* *
1313
* hprose http client for HTML5. *
1414
* *
15-
* LastModified: Aug 2, 2015 *
15+
* LastModified: Feb 5, 2016 *
1616
* Author: Ma Bingyao <andot@hprose.com> *
1717
* *
1818
\**********************************************************/
@@ -70,7 +70,9 @@
7070
xhr.send(request.buffer.slice(0, request.length));
7171
}
7272
else {
73-
xhr.send(request.buffer);
73+
var buf = new Uint8Array(request.length);
74+
buf.set(request);
75+
xhr.send(buf.buffer);
7476
}
7577
return xhr;
7678
}

0 commit comments

Comments
 (0)