@@ -6,9 +6,11 @@ class Framer {
6
6
constructor ( client ) {
7
7
// Encoding
8
8
this . packets = [ ]
9
+ this . batchHeader = client . batchHeader
9
10
this . compressor = client . compressionAlgorithm || 'none'
10
11
this . compressionLevel = client . compressionLevel
11
12
this . compressionThreshold = client . compressionThreshold
13
+ this . compressionHeader = client . compressionHeader || 0
12
14
this . writeCompressor = client . features . compressorInHeader && client . compressionReady
13
15
}
14
16
@@ -38,7 +40,7 @@ class Framer {
38
40
39
41
static decode ( client , buf ) {
40
42
// Read header
41
- if ( buf [ 0 ] !== 0xfe ) throw Error ( ' bad batch packet header ' + buf [ 0 ] )
43
+ if ( this . batchHeader && buf [ 0 ] !== this . batchHeader ) throw Error ( ` bad batch packet header, received: ${ buf [ 0 ] } , expected: ${ this . batchHeader } ` )
42
44
const buffer = buf . slice ( 1 )
43
45
// Decompress
44
46
let decompressed
@@ -58,9 +60,10 @@ class Framer {
58
60
59
61
encode ( ) {
60
62
const buf = Buffer . concat ( this . packets )
61
- const compressed = ( buf . length > this . compressionThreshold ) ? this . compress ( buf ) : buf
62
- const header = this . writeCompressor ? [ 0xfe , 0 ] : [ 0xfe ]
63
- return Buffer . concat ( [ Buffer . from ( header ) , compressed ] )
63
+ const shouldCompress = buf . length > this . compressionThreshold
64
+ const header = this . batchHeader ? [ this . batchHeader ] : [ ]
65
+ if ( this . writeCompressor ) header . push ( shouldCompress ? this . compressionHeader : 255 )
66
+ return Buffer . concat ( [ Buffer . from ( header ) , shouldCompress ? this . compress ( buf ) : buf ] )
64
67
}
65
68
66
69
addEncodedPacket ( chunk ) {
0 commit comments