@nxtedition/deepstream.io-client-js 31.0.3 → 31.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@ import * as C from '../constants/constants.js'
|
|
|
2
2
|
import varint from 'varint'
|
|
3
3
|
|
|
4
4
|
const SEP = C.MESSAGE_PART_SEPERATOR
|
|
5
|
-
const MAX_MESSAGE_SIZE = 1024 * 1024
|
|
6
5
|
|
|
7
6
|
let poolBuf
|
|
8
7
|
let poolPos = 0
|
|
8
|
+
let poolSize = 1024 * 1024
|
|
9
9
|
|
|
10
10
|
export function getMsg(topic, action, data, binary) {
|
|
11
11
|
if (data && !(data instanceof Array)) {
|
|
@@ -14,6 +14,7 @@ export function getMsg(topic, action, data, binary) {
|
|
|
14
14
|
|
|
15
15
|
if (binary) {
|
|
16
16
|
let headerSize = 0
|
|
17
|
+
let estimatedSize = 0
|
|
17
18
|
|
|
18
19
|
// Estimate headerSize
|
|
19
20
|
if (data) {
|
|
@@ -22,14 +23,18 @@ export function getMsg(topic, action, data, binary) {
|
|
|
22
23
|
if (typeof data[n] !== 'string') {
|
|
23
24
|
throw new Error(`invalid data[${n}]`)
|
|
24
25
|
}
|
|
26
|
+
estimatedSize += data[n].length + 1 // +1 for the separator
|
|
25
27
|
headerSize += varint.encodingLength(data[n].length)
|
|
26
28
|
}
|
|
27
|
-
// Allow for some multi chars here and there...
|
|
29
|
+
// Allow extra space for some multi chars here and there...
|
|
28
30
|
headerSize += 2
|
|
31
|
+
|
|
32
|
+
estimatedSize += headerSize + topic.length + action.length + 2 // +2 for the topic and action separators
|
|
33
|
+
estimatedSize += 32 // Allow for some extra space
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
if (!poolBuf || poolBuf.byteLength - poolPos <
|
|
32
|
-
poolBuf = Buffer.allocUnsafeSlow(
|
|
36
|
+
if (!poolBuf || poolBuf.byteLength - poolPos < estimatedSize) {
|
|
37
|
+
poolBuf = Buffer.allocUnsafeSlow(poolSize)
|
|
33
38
|
poolPos = 0
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -73,6 +78,13 @@ export function getMsg(topic, action, data, binary) {
|
|
|
73
78
|
const len = poolBuf.write(data[i], dataPos)
|
|
74
79
|
dataPos += len
|
|
75
80
|
|
|
81
|
+
if (dataPos >= poolPos + poolBuf.byteLength) {
|
|
82
|
+
poolSize *= poolPos === 0 ? 2 : 1
|
|
83
|
+
poolBuf = null
|
|
84
|
+
poolPos = 0
|
|
85
|
+
return getMsg(topic, action, data, binary)
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
if (headerSize > 0) {
|
|
77
89
|
const encodingLength = varint.encodingLength(len + 1)
|
|
78
90
|
if (headerPos + encodingLength > dataStart) {
|