Skip to content

Commit c1f23b6

Browse files
committed
fix: rm fast header
1 parent 50a4395 commit c1f23b6

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"invariant": "^2.2.4",
4141
"lodash.clonedeep": "^4.5.0",
4242
"utf-8-validate": "^6.0.4",
43-
"varint": "^6.0.0",
4443
"ws": "^8.18.0",
4544
"xuid": "^4.1.3",
4645
"xxhash-wasm": "^1.0.2"

src/message/message-builder.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as C from '../constants/constants.js'
22
import * as utils from '../utils/utils.js'
3-
import varint from 'varint'
43

54
const poolEncoder = new globalThis.TextEncoder()
65

@@ -9,14 +8,12 @@ const maxMessageSize = 1024 * 1024
98
const poolSize = maxMessageSize * 8
109

1110
let poolBuffer
12-
let poolView
1311
let poolOffset
1412

1513
function reallocPool() {
1614
poolBuffer = utils.isNode
1715
? globalThis.Buffer.allocUnsafe(poolSize)
1816
: new Uint8Array(new ArrayBuffer(poolSize))
19-
poolView = new DataView(poolBuffer.buffer)
2017
poolOffset = 0
2118
}
2219

@@ -50,14 +47,6 @@ export function getMsg(topic, action, data) {
5047

5148
const start = poolOffset
5249

53-
const headerSize = 8
54-
for (let n = 0; n < headerSize; n++) {
55-
poolBuffer[poolOffset++] = 0
56-
}
57-
58-
let headerPos = start
59-
poolBuffer[headerPos++] = 128 + headerSize
60-
6150
poolBuffer[poolOffset++] = topic.charCodeAt(0)
6251
poolBuffer[poolOffset++] = 31
6352
for (let n = 0; n < action.length; n++) {
@@ -67,30 +56,18 @@ export function getMsg(topic, action, data) {
6756
if (data) {
6857
for (let i = 0; i < data.length; i++) {
6958
const type = typeof data[i]
70-
let len
7159
if (data[i] == null) {
7260
poolBuffer[poolOffset++] = 31
73-
len = 0
61+
poolOffset += 0
7462
} else if (type === 'object') {
7563
poolBuffer[poolOffset++] = 31
76-
len = writeString(poolBuffer, JSON.stringify(data[i]), poolOffset)
77-
} else if (type === 'bigint') {
78-
poolBuffer[poolOffset++] = 31
79-
poolView.setBigUint64(poolOffset, data[i], false)
80-
len = 8
64+
poolOffset += writeString(poolBuffer, JSON.stringify(data[i]), poolOffset)
8165
} else if (type === 'string') {
8266
poolBuffer[poolOffset++] = 31
83-
len = writeString(poolBuffer, data[i], poolOffset)
67+
poolOffset += writeString(poolBuffer, data[i], poolOffset)
8468
} else {
8569
throw new Error('invalid data')
8670
}
87-
poolOffset += len
88-
89-
varint.encode(len + 1, poolBuffer, headerPos)
90-
headerPos += varint.encode.bytes
91-
if (headerPos - start >= headerSize) {
92-
throw new Error('header too large')
93-
}
9471

9572
if (poolOffset >= poolSize) {
9673
throw new Error('message too large')

0 commit comments

Comments
 (0)