Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mqtt-client
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
mqtt-client
Commits
58088be2
Commit
58088be2
authored
Jun 08, 2022
by
邓晓峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复format function undefined
parent
019c4945
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
100 deletions
+103
-100
utils.js
es/utils.js
+50
-49
utils.js
lib/utils.js
+52
-50
Client.js
src/Client.js
+1
-1
No files found.
es/utils.js
View file @
58088be2
import
_typeof
from
"@babel/runtime/helpers/esm/typeof"
;
import
_typeof
from
"@babel/runtime/helpers/esm/typeof"
;
import
{
ERROR
,
MESSAGE_TYPE
}
from
'./consts'
;
import
{
ERROR
,
MESSAGE_TYPE
}
from
'./consts'
;
import
Message
from
'./Message'
;
import
Message
from
'./Message'
;
import
WireMessage
from
'./WireMessage'
;
/* eslint-disable */
/* eslint-disable */
/**
/**
...
@@ -20,10 +21,10 @@ export var validate = function validate(obj, keys) {
...
@@ -20,10 +21,10 @@ export var validate = function validate(obj, keys) {
if
(
keys
.
hasOwnProperty
(
key
))
{
if
(
keys
.
hasOwnProperty
(
key
))
{
if
(
_typeof
(
obj
[
key
])
!==
keys
[
key
])
throw
new
Error
(
format
(
ERROR
.
INVALID_TYPE
,
[
_typeof
(
obj
[
key
]),
key
]));
if
(
_typeof
(
obj
[
key
])
!==
keys
[
key
])
throw
new
Error
(
format
(
ERROR
.
INVALID_TYPE
,
[
_typeof
(
obj
[
key
]),
key
]));
}
else
{
}
else
{
var
errorStr
=
"Unknown property, "
+
key
+
". Valid properties are:"
;
var
errorStr
=
'Unknown property, '
+
key
+
'. Valid properties are:'
;
for
(
var
validKey
in
keys
)
{
for
(
var
validKey
in
keys
)
{
if
(
keys
.
hasOwnProperty
(
validKey
))
errorStr
=
errorStr
+
" "
+
validKey
;
if
(
keys
.
hasOwnProperty
(
validKey
))
errorStr
=
errorStr
+
' '
+
validKey
;
}
}
throw
new
Error
(
errorStr
);
throw
new
Error
(
errorStr
);
...
@@ -32,12 +33,12 @@ export var validate = function validate(obj, keys) {
...
@@ -32,12 +33,12 @@ export var validate = function validate(obj, keys) {
}
}
};
};
/**
/**
* Format an error message text.
* Format an error message text.
* @private
* @private
* @param {error} ERROR value above.
* @param {error} ERROR value above.
* @param {substitutions} [array] substituted into the text.
* @param {substitutions} [array] substituted into the text.
* @return the text with the substitutions made.
* @return the text with the substitutions made.
*/
*/
export
var
format
=
function
format
(
error
,
substitutions
)
{
export
var
format
=
function
format
(
error
,
substitutions
)
{
var
text
=
error
.
text
;
var
text
=
error
.
text
;
...
@@ -46,7 +47,7 @@ export var format = function format(error, substitutions) {
...
@@ -46,7 +47,7 @@ export var format = function format(error, substitutions) {
var
field
,
start
;
var
field
,
start
;
for
(
var
i
=
0
;
i
<
substitutions
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
substitutions
.
length
;
i
++
)
{
field
=
"{"
+
i
+
"}"
;
field
=
'{'
+
i
+
'}'
;
start
=
text
.
indexOf
(
field
);
start
=
text
.
indexOf
(
field
);
if
(
start
>
0
)
{
if
(
start
>
0
)
{
...
@@ -76,7 +77,7 @@ export function decodeMessage(input, pos) {
...
@@ -76,7 +77,7 @@ export function decodeMessage(input, pos) {
}
}
digit
=
input
[
pos
++
];
digit
=
input
[
pos
++
];
remLength
+=
(
digit
&
0x7
F
)
*
multiplier
;
remLength
+=
(
digit
&
0x7
f
)
*
multiplier
;
multiplier
*=
128
;
multiplier
*=
128
;
}
while
((
digit
&
0x80
)
!==
0
);
}
while
((
digit
&
0x80
)
!==
0
);
...
@@ -151,9 +152,9 @@ export function readUint16(buffer, offset) {
...
@@ -151,9 +152,9 @@ export function readUint16(buffer, offset) {
return
256
*
buffer
[
offset
]
+
buffer
[
offset
+
1
];
return
256
*
buffer
[
offset
]
+
buffer
[
offset
+
1
];
}
}
/**
/**
* Encodes an MQTT Multi-Byte Integer
* Encodes an MQTT Multi-Byte Integer
* @private
* @private
*/
*/
export
function
encodeMBI
(
number
)
{
export
function
encodeMBI
(
number
)
{
var
output
=
new
Array
(
1
);
var
output
=
new
Array
(
1
);
...
@@ -173,9 +174,9 @@ export function encodeMBI(number) {
...
@@ -173,9 +174,9 @@ export function encodeMBI(number) {
return
output
;
return
output
;
}
}
/**
/**
* Takes a String and calculates its length in bytes when encoded in UTF8.
* Takes a String and calculates its length in bytes when encoded in UTF8.
* @private
* @private
*/
*/
export
function
UTF8Length
(
input
)
{
export
function
UTF8Length
(
input
)
{
var
output
=
0
;
var
output
=
0
;
...
@@ -183,23 +184,23 @@ export function UTF8Length(input) {
...
@@ -183,23 +184,23 @@ export function UTF8Length(input) {
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
var
charCode
=
input
.
charCodeAt
(
i
);
var
charCode
=
input
.
charCodeAt
(
i
);
if
(
charCode
>
0x7
FF
)
{
if
(
charCode
>
0x7
ff
)
{
// Surrogate pair means its a 4 byte character
// Surrogate pair means its a 4 byte character
if
(
0x
D800
<=
charCode
&&
charCode
<=
0xDBFF
)
{
if
(
0x
d800
<=
charCode
&&
charCode
<=
0xdbff
)
{
i
++
;
i
++
;
output
++
;
output
++
;
}
}
output
+=
3
;
output
+=
3
;
}
else
if
(
charCode
>
0x7
F
)
output
+=
2
;
else
output
++
;
}
else
if
(
charCode
>
0x7
f
)
output
+=
2
;
else
output
++
;
}
}
return
output
;
return
output
;
}
}
/**
/**
* Takes a String and writes it into an array as UTF8 encoded bytes.
* Takes a String and writes it into an array as UTF8 encoded bytes.
* @private
* @private
*/
*/
export
function
stringToUTF8
(
input
,
output
,
start
)
{
export
function
stringToUTF8
(
input
,
output
,
start
)
{
var
pos
=
start
;
var
pos
=
start
;
...
@@ -207,37 +208,37 @@ export function stringToUTF8(input, output, start) {
...
@@ -207,37 +208,37 @@ export function stringToUTF8(input, output, start) {
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
var
charCode
=
input
.
charCodeAt
(
i
);
// Check for a surrogate pair.
var
charCode
=
input
.
charCodeAt
(
i
);
// Check for a surrogate pair.
if
(
0x
D800
<=
charCode
&&
charCode
<=
0xDBFF
)
{
if
(
0x
d800
<=
charCode
&&
charCode
<=
0xdbff
)
{
var
lowCharCode
=
input
.
charCodeAt
(
++
i
);
var
lowCharCode
=
input
.
charCodeAt
(
++
i
);
if
(
isNaN
(
lowCharCode
))
{
if
(
isNaN
(
lowCharCode
))
{
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UNICODE
,
[
charCode
,
lowCharCode
]));
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UNICODE
,
[
charCode
,
lowCharCode
]));
}
}
charCode
=
(
charCode
-
0x
D800
<<
10
)
+
(
lowCharCode
-
0xDC
00
)
+
0x10000
;
charCode
=
(
charCode
-
0x
d800
<<
10
)
+
(
lowCharCode
-
0xdc
00
)
+
0x10000
;
}
}
if
(
charCode
<=
0x7
F
)
{
if
(
charCode
<=
0x7
f
)
{
output
[
pos
++
]
=
charCode
;
output
[
pos
++
]
=
charCode
;
}
else
if
(
charCode
<=
0x7
FF
)
{
}
else
if
(
charCode
<=
0x7
ff
)
{
output
[
pos
++
]
=
charCode
>>
6
&
0x1
F
|
0xC
0
;
output
[
pos
++
]
=
charCode
>>
6
&
0x1
f
|
0xc
0
;
output
[
pos
++
]
=
charCode
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
f
|
0x80
;
}
else
if
(
charCode
<=
0x
FFFF
)
{
}
else
if
(
charCode
<=
0x
ffff
)
{
output
[
pos
++
]
=
charCode
>>
12
&
0x0
F
|
0xE
0
;
output
[
pos
++
]
=
charCode
>>
12
&
0x0
f
|
0xe
0
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
f
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
f
|
0x80
;
}
else
{
}
else
{
output
[
pos
++
]
=
charCode
>>
18
&
0x07
|
0x
F
0
;
output
[
pos
++
]
=
charCode
>>
18
&
0x07
|
0x
f
0
;
output
[
pos
++
]
=
charCode
>>
12
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
>>
12
&
0x3
f
|
0x80
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
f
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
f
|
0x80
;
}
}
}
}
return
output
;
return
output
;
}
}
export
function
parseUTF8
(
input
,
offset
,
length
)
{
export
function
parseUTF8
(
input
,
offset
,
length
)
{
var
output
=
""
;
var
output
=
''
;
var
utf16
;
var
utf16
;
var
pos
=
offset
;
var
pos
=
offset
;
...
@@ -245,28 +246,28 @@ export function parseUTF8(input, offset, length) {
...
@@ -245,28 +246,28 @@ export function parseUTF8(input, offset, length) {
var
byte1
=
input
[
pos
++
];
var
byte1
=
input
[
pos
++
];
if
(
byte1
<
128
)
utf16
=
byte1
;
else
{
if
(
byte1
<
128
)
utf16
=
byte1
;
else
{
var
byte2
=
input
[
pos
++
]
-
128
;
var
byte2
=
input
[
pos
++
]
-
128
;
if
(
byte2
<
0
)
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
""
]));
if
(
byte2
<
0
)
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
''
]));
if
(
byte1
<
0x
E
0
)
// 2 byte character
if
(
byte1
<
0x
e
0
)
// 2 byte character
utf16
=
64
*
(
byte1
-
0x
C
0
)
+
byte2
;
else
{
utf16
=
64
*
(
byte1
-
0x
c
0
)
+
byte2
;
else
{
var
byte3
=
input
[
pos
++
]
-
128
;
var
byte3
=
input
[
pos
++
]
-
128
;
if
(
byte3
<
0
)
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
)]));
if
(
byte3
<
0
)
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
)]));
if
(
byte1
<
0x
F
0
)
// 3 byte character
if
(
byte1
<
0x
f
0
)
// 3 byte character
utf16
=
4096
*
(
byte1
-
0x
E
0
)
+
64
*
byte2
+
byte3
;
else
{
utf16
=
4096
*
(
byte1
-
0x
e
0
)
+
64
*
byte2
+
byte3
;
else
{
var
byte4
=
input
[
pos
++
]
-
128
;
var
byte4
=
input
[
pos
++
]
-
128
;
if
(
byte4
<
0
)
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
if
(
byte4
<
0
)
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
if
(
byte1
<
0x
F
8
)
// 4 byte character
if
(
byte1
<
0x
f
8
)
// 4 byte character
utf16
=
262144
*
(
byte1
-
0x
F0
)
+
4096
*
byte2
+
64
*
byte3
+
byte4
;
else
// longer encodings are not supported
utf16
=
262144
*
(
byte1
-
0x
f0
)
+
4096
*
byte2
+
64
*
byte3
+
byte4
;
// longer encodings are not supported
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
else
throw
new
Error
(
format
(
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
}
}
}
}
}
}
if
(
utf16
>
0x
FFFF
)
// 4 byte character - express as a surrogate pair
if
(
utf16
>
0x
ffff
)
{
{
// 4 byte character - express as a surrogate pair
utf16
-=
0x10000
;
utf16
-=
0x10000
;
output
+=
String
.
fromCharCode
(
0xD
800
+
(
utf16
>>
10
));
// lead character
output
+=
String
.
fromCharCode
(
0xd
800
+
(
utf16
>>
10
));
// lead character
utf16
=
0xDC00
+
(
utf16
&
0x3FF
);
// trail character
utf16
=
0xdc00
+
(
utf16
&
0x3ff
);
// trail character
}
}
output
+=
String
.
fromCharCode
(
utf16
);
output
+=
String
.
fromCharCode
(
utf16
);
...
...
lib/utils.js
View file @
58088be2
...
@@ -21,6 +21,8 @@ var _consts = require("./consts");
...
@@ -21,6 +21,8 @@ var _consts = require("./consts");
var
_Message
=
_interopRequireDefault
(
require
(
"./Message"
));
var
_Message
=
_interopRequireDefault
(
require
(
"./Message"
));
var
_WireMessage
=
_interopRequireDefault
(
require
(
"./WireMessage"
));
/* eslint-disable */
/* eslint-disable */
/**
/**
...
@@ -39,10 +41,10 @@ var validate = function validate(obj, keys) {
...
@@ -39,10 +41,10 @@ var validate = function validate(obj, keys) {
if
(
keys
.
hasOwnProperty
(
key
))
{
if
(
keys
.
hasOwnProperty
(
key
))
{
if
((
0
,
_typeof2
.
default
)(
obj
[
key
])
!==
keys
[
key
])
throw
new
Error
(
format
(
_consts
.
ERROR
.
INVALID_TYPE
,
[(
0
,
_typeof2
.
default
)(
obj
[
key
]),
key
]));
if
((
0
,
_typeof2
.
default
)(
obj
[
key
])
!==
keys
[
key
])
throw
new
Error
(
format
(
_consts
.
ERROR
.
INVALID_TYPE
,
[(
0
,
_typeof2
.
default
)(
obj
[
key
]),
key
]));
}
else
{
}
else
{
var
errorStr
=
"Unknown property, "
+
key
+
". Valid properties are:"
;
var
errorStr
=
'Unknown property, '
+
key
+
'. Valid properties are:'
;
for
(
var
validKey
in
keys
)
{
for
(
var
validKey
in
keys
)
{
if
(
keys
.
hasOwnProperty
(
validKey
))
errorStr
=
errorStr
+
" "
+
validKey
;
if
(
keys
.
hasOwnProperty
(
validKey
))
errorStr
=
errorStr
+
' '
+
validKey
;
}
}
throw
new
Error
(
errorStr
);
throw
new
Error
(
errorStr
);
...
@@ -51,12 +53,12 @@ var validate = function validate(obj, keys) {
...
@@ -51,12 +53,12 @@ var validate = function validate(obj, keys) {
}
}
};
};
/**
/**
* Format an error message text.
* Format an error message text.
* @private
* @private
* @param {error} ERROR value above.
* @param {error} ERROR value above.
* @param {substitutions} [array] substituted into the text.
* @param {substitutions} [array] substituted into the text.
* @return the text with the substitutions made.
* @return the text with the substitutions made.
*/
*/
exports
.
validate
=
validate
;
exports
.
validate
=
validate
;
...
@@ -68,7 +70,7 @@ var format = function format(error, substitutions) {
...
@@ -68,7 +70,7 @@ var format = function format(error, substitutions) {
var
field
,
start
;
var
field
,
start
;
for
(
var
i
=
0
;
i
<
substitutions
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
substitutions
.
length
;
i
++
)
{
field
=
"{"
+
i
+
"}"
;
field
=
'{'
+
i
+
'}'
;
start
=
text
.
indexOf
(
field
);
start
=
text
.
indexOf
(
field
);
if
(
start
>
0
)
{
if
(
start
>
0
)
{
...
@@ -101,7 +103,7 @@ function decodeMessage(input, pos) {
...
@@ -101,7 +103,7 @@ function decodeMessage(input, pos) {
}
}
digit
=
input
[
pos
++
];
digit
=
input
[
pos
++
];
remLength
+=
(
digit
&
0x7
F
)
*
multiplier
;
remLength
+=
(
digit
&
0x7
f
)
*
multiplier
;
multiplier
*=
128
;
multiplier
*=
128
;
}
while
((
digit
&
0x80
)
!==
0
);
}
while
((
digit
&
0x80
)
!==
0
);
...
@@ -111,7 +113,7 @@ function decodeMessage(input, pos) {
...
@@ -111,7 +113,7 @@ function decodeMessage(input, pos) {
return
[
null
,
startingPos
];
return
[
null
,
startingPos
];
}
}
var
wireMessage
=
new
WireMessage
(
type
);
var
wireMessage
=
new
_WireMessage
.
default
(
type
);
switch
(
type
)
{
switch
(
type
)
{
case
_consts
.
MESSAGE_TYPE
.
CONNACK
:
case
_consts
.
MESSAGE_TYPE
.
CONNACK
:
...
@@ -179,9 +181,9 @@ function readUint16(buffer, offset) {
...
@@ -179,9 +181,9 @@ function readUint16(buffer, offset) {
return
256
*
buffer
[
offset
]
+
buffer
[
offset
+
1
];
return
256
*
buffer
[
offset
]
+
buffer
[
offset
+
1
];
}
}
/**
/**
* Encodes an MQTT Multi-Byte Integer
* Encodes an MQTT Multi-Byte Integer
* @private
* @private
*/
*/
function
encodeMBI
(
number
)
{
function
encodeMBI
(
number
)
{
...
@@ -202,9 +204,9 @@ function encodeMBI(number) {
...
@@ -202,9 +204,9 @@ function encodeMBI(number) {
return
output
;
return
output
;
}
}
/**
/**
* Takes a String and calculates its length in bytes when encoded in UTF8.
* Takes a String and calculates its length in bytes when encoded in UTF8.
* @private
* @private
*/
*/
function
UTF8Length
(
input
)
{
function
UTF8Length
(
input
)
{
...
@@ -213,23 +215,23 @@ function UTF8Length(input) {
...
@@ -213,23 +215,23 @@ function UTF8Length(input) {
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
var
charCode
=
input
.
charCodeAt
(
i
);
var
charCode
=
input
.
charCodeAt
(
i
);
if
(
charCode
>
0x7
FF
)
{
if
(
charCode
>
0x7
ff
)
{
// Surrogate pair means its a 4 byte character
// Surrogate pair means its a 4 byte character
if
(
0x
D800
<=
charCode
&&
charCode
<=
0xDBFF
)
{
if
(
0x
d800
<=
charCode
&&
charCode
<=
0xdbff
)
{
i
++
;
i
++
;
output
++
;
output
++
;
}
}
output
+=
3
;
output
+=
3
;
}
else
if
(
charCode
>
0x7
F
)
output
+=
2
;
else
output
++
;
}
else
if
(
charCode
>
0x7
f
)
output
+=
2
;
else
output
++
;
}
}
return
output
;
return
output
;
}
}
/**
/**
* Takes a String and writes it into an array as UTF8 encoded bytes.
* Takes a String and writes it into an array as UTF8 encoded bytes.
* @private
* @private
*/
*/
function
stringToUTF8
(
input
,
output
,
start
)
{
function
stringToUTF8
(
input
,
output
,
start
)
{
...
@@ -238,30 +240,30 @@ function stringToUTF8(input, output, start) {
...
@@ -238,30 +240,30 @@ function stringToUTF8(input, output, start) {
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
input
.
length
;
i
++
)
{
var
charCode
=
input
.
charCodeAt
(
i
);
// Check for a surrogate pair.
var
charCode
=
input
.
charCodeAt
(
i
);
// Check for a surrogate pair.
if
(
0x
D800
<=
charCode
&&
charCode
<=
0xDBFF
)
{
if
(
0x
d800
<=
charCode
&&
charCode
<=
0xdbff
)
{
var
lowCharCode
=
input
.
charCodeAt
(
++
i
);
var
lowCharCode
=
input
.
charCodeAt
(
++
i
);
if
(
isNaN
(
lowCharCode
))
{
if
(
isNaN
(
lowCharCode
))
{
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UNICODE
,
[
charCode
,
lowCharCode
]));
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UNICODE
,
[
charCode
,
lowCharCode
]));
}
}
charCode
=
(
charCode
-
0x
D800
<<
10
)
+
(
lowCharCode
-
0xDC
00
)
+
0x10000
;
charCode
=
(
charCode
-
0x
d800
<<
10
)
+
(
lowCharCode
-
0xdc
00
)
+
0x10000
;
}
}
if
(
charCode
<=
0x7
F
)
{
if
(
charCode
<=
0x7
f
)
{
output
[
pos
++
]
=
charCode
;
output
[
pos
++
]
=
charCode
;
}
else
if
(
charCode
<=
0x7
FF
)
{
}
else
if
(
charCode
<=
0x7
ff
)
{
output
[
pos
++
]
=
charCode
>>
6
&
0x1
F
|
0xC
0
;
output
[
pos
++
]
=
charCode
>>
6
&
0x1
f
|
0xc
0
;
output
[
pos
++
]
=
charCode
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
f
|
0x80
;
}
else
if
(
charCode
<=
0x
FFFF
)
{
}
else
if
(
charCode
<=
0x
ffff
)
{
output
[
pos
++
]
=
charCode
>>
12
&
0x0
F
|
0xE
0
;
output
[
pos
++
]
=
charCode
>>
12
&
0x0
f
|
0xe
0
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
f
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
f
|
0x80
;
}
else
{
}
else
{
output
[
pos
++
]
=
charCode
>>
18
&
0x07
|
0x
F
0
;
output
[
pos
++
]
=
charCode
>>
18
&
0x07
|
0x
f
0
;
output
[
pos
++
]
=
charCode
>>
12
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
>>
12
&
0x3
f
|
0x80
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
>>
6
&
0x3
f
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
F
|
0x80
;
output
[
pos
++
]
=
charCode
&
0x3
f
|
0x80
;
}
}
}
}
...
@@ -269,7 +271,7 @@ function stringToUTF8(input, output, start) {
...
@@ -269,7 +271,7 @@ function stringToUTF8(input, output, start) {
}
}
function
parseUTF8
(
input
,
offset
,
length
)
{
function
parseUTF8
(
input
,
offset
,
length
)
{
var
output
=
""
;
var
output
=
''
;
var
utf16
;
var
utf16
;
var
pos
=
offset
;
var
pos
=
offset
;
...
@@ -277,28 +279,28 @@ function parseUTF8(input, offset, length) {
...
@@ -277,28 +279,28 @@ function parseUTF8(input, offset, length) {
var
byte1
=
input
[
pos
++
];
var
byte1
=
input
[
pos
++
];
if
(
byte1
<
128
)
utf16
=
byte1
;
else
{
if
(
byte1
<
128
)
utf16
=
byte1
;
else
{
var
byte2
=
input
[
pos
++
]
-
128
;
var
byte2
=
input
[
pos
++
]
-
128
;
if
(
byte2
<
0
)
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
""
]));
if
(
byte2
<
0
)
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
''
]));
if
(
byte1
<
0x
E
0
)
// 2 byte character
if
(
byte1
<
0x
e
0
)
// 2 byte character
utf16
=
64
*
(
byte1
-
0x
C
0
)
+
byte2
;
else
{
utf16
=
64
*
(
byte1
-
0x
c
0
)
+
byte2
;
else
{
var
byte3
=
input
[
pos
++
]
-
128
;
var
byte3
=
input
[
pos
++
]
-
128
;
if
(
byte3
<
0
)
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
)]));
if
(
byte3
<
0
)
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
)]));
if
(
byte1
<
0x
F
0
)
// 3 byte character
if
(
byte1
<
0x
f
0
)
// 3 byte character
utf16
=
4096
*
(
byte1
-
0x
E
0
)
+
64
*
byte2
+
byte3
;
else
{
utf16
=
4096
*
(
byte1
-
0x
e
0
)
+
64
*
byte2
+
byte3
;
else
{
var
byte4
=
input
[
pos
++
]
-
128
;
var
byte4
=
input
[
pos
++
]
-
128
;
if
(
byte4
<
0
)
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
if
(
byte4
<
0
)
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
if
(
byte1
<
0x
F
8
)
// 4 byte character
if
(
byte1
<
0x
f
8
)
// 4 byte character
utf16
=
262144
*
(
byte1
-
0x
F0
)
+
4096
*
byte2
+
64
*
byte3
+
byte4
;
else
// longer encodings are not supported
utf16
=
262144
*
(
byte1
-
0x
f0
)
+
4096
*
byte2
+
64
*
byte3
+
byte4
;
// longer encodings are not supported
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
else
throw
new
Error
(
format
(
_consts
.
ERROR
.
MALFORMED_UTF
,
[
byte1
.
toString
(
16
),
byte2
.
toString
(
16
),
byte3
.
toString
(
16
),
byte4
.
toString
(
16
)]));
}
}
}
}
}
}
if
(
utf16
>
0x
FFFF
)
// 4 byte character - express as a surrogate pair
if
(
utf16
>
0x
ffff
)
{
{
// 4 byte character - express as a surrogate pair
utf16
-=
0x10000
;
utf16
-=
0x10000
;
output
+=
String
.
fromCharCode
(
0xD
800
+
(
utf16
>>
10
));
// lead character
output
+=
String
.
fromCharCode
(
0xd
800
+
(
utf16
>>
10
));
// lead character
utf16
=
0xDC00
+
(
utf16
&
0x3FF
);
// trail character
utf16
=
0xdc00
+
(
utf16
&
0x3ff
);
// trail character
}
}
output
+=
String
.
fromCharCode
(
utf16
);
output
+=
String
.
fromCharCode
(
utf16
);
...
...
src/Client.js
View file @
58088be2
import
ClientImplementation
from
'./ClientImplementation'
;
import
ClientImplementation
from
'./ClientImplementation'
;
import
{
ERROR
}
from
'./consts'
;
import
{
ERROR
}
from
'./consts'
;
import
{
validate
}
from
'./utils'
;
import
{
validate
,
format
}
from
'./utils'
;
/* eslint-disable */
/* eslint-disable */
const
Client
=
function
(
host
,
port
,
path
,
clientId
)
{
const
Client
=
function
(
host
,
port
,
path
,
clientId
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment