-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdb.go
1090 lines (939 loc) · 21.5 KB
/
rdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
// Parser RDB file per spec: https://github.com/sripathikrishnan/redis-rdb-tools/wiki/Redis-RDB-Dump-File-Format
import (
"bufio"
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
"strconv"
"time"
)
const (
rdbOpAux = 0xFA
rdbOpResizeDB = 0xFB
rdbOpDB = 0xFE
rdbOpExpirySec = 0xFD
rdbOpExpiryMSec = 0xFC
rdbOpEOF = 0xFF
rdbLen6Bit = 0x0
rdbLen14bit = 0x1
rdbLen32Bit = 0x2
rdbLenEnc = 0x3
Type32Bit = 0x80
Type64Bit = 0x81
rdbOpString = 0x00
rdbOpList = 0x01
rdbOpSet = 0x02
rdbOpZset = 0x03
rdbOpHash = 0x04
rdbOpZset2 = 0x05
rdbOpModule2 = 0x07
rdbOpZipmap = 0x09
rdbOpZiplist = 0x0a
rdbOpIntset = 0x0b
rdbOpSortedSet = 0x0c
rdbOpHashmap = 0x0d
rdbOpListQuicklist = 0x0e
rdbOpStreamListpacks = 0x0f
RdbModuleOpcodeEOF = 0
RdbModuleOpcodeSInt = 1
RdbModuleOpcodeUInt = 2
RdbModuleOpcodeFloat = 3
RdbModuleOpcodeDouble = 4
RdbModuleOpcodeString = 5
)
var (
rdbSignature = []byte{0x52, 0x45, 0x44, 0x49, 0x53}
restoreCommand = "RESTORE"
currentTimestamp = uint64(0)
)
var (
// ErrWrongSignature is returned when RDB signature can't be parsed
ErrWrongSignature = errors.New("rdb: wrong signature")
// ErrVersionUnsupported is returned when RDB version is too high (can't parse)
ErrVersionUnsupported = errors.New("rdb: version unsupported")
// ErrUnsupportedOp is returned when unsupported operation is encountered in RDB
ErrUnsupportedOp = errors.New("rdb: unsupported opcode")
// ErrUnsupportedStringEnc is returned when unsupported string encoding is encountered in RDB
ErrUnsupportedStringEnc = errors.New("rdb: unsupported string encoding")
)
type RedisCommand struct {
Command []string
BulkSize int64
}
// Parser holds internal state of RDB parser while running
type Parser struct {
reader *bufio.Reader
output chan *RedisCommand
length int64
hash uint64
rawData []byte
key string
expiry uint64
counter *uint64
rdbVersion int
rdbVersion16bit []byte
valueState state
currentOp byte
}
type state func(parser *Parser) (nextstate state, err error)
// ParseRDB parsers RDB file which is read from reader, sending chunks of data through output channel
// length is original length of RDB file
func ParseRDB(reader *bufio.Reader, output chan *RedisCommand, counter *uint64) (err error) {
currentTimestamp = uint64(time.Now().Unix())
go cron()
parser := &Parser{
reader: reader,
output: output,
counter: counter,
}
state := stateMagic
for state != nil {
state, err = state(parser)
if err != nil {
return
}
}
return nil
}
func cron() {
ticker := time.NewTicker(time.Second * 1)
for {
select {
case <-ticker.C:
currentTimestamp = uint64(time.Now().Unix())
}
}
}
// Read exactly n bytes
func (parser *Parser) safeRead(n uint64) (result []byte, err error) {
result = make([]byte, n)
_, err = io.ReadFull(parser.reader, result)
return
}
// Accumulate some data that might be either parsered out or passed through
func (parser *Parser) commandWrite(save bool, data []byte) {
if !save {
return
}
if parser.rawData == nil {
parser.rawData = make([]byte, len(data), 4096)
copy(parser.rawData, data)
} else {
parser.rawData = append(parser.rawData, data...)
}
}
func (parser *Parser) appendVersion() {
parser.rawData = append(parser.rawData, parser.rdbVersion16bit...)
}
func (parser *Parser) buildCRCData() {
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, CRC64Update(0, parser.rawData))
parser.rawData = append(parser.rawData, buf...)
}
func toHex(data []byte) string {
// result := ""
result := "\""
for _, b := range data {
result = result + fmt.Sprintf("\\x%02x", b)
}
result += "\""
// result := fmt.Sprintf("%x", data)
return result
}
// Discard or keep saved data
func (parser *Parser) keep() {
parser.appendVersion()
parser.buildCRCData()
var cmd *RedisCommand
if Replace {
cmd = &RedisCommand{
Command: []string{
restoreCommand,
parser.key,
fmt.Sprint(parser.expiry),
string(parser.rawData),
"REPLACE",
},
}
} else {
cmd = &RedisCommand{
Command: []string{
restoreCommand,
parser.key,
fmt.Sprint(parser.expiry),
string(parser.rawData),
},
}
}
if !SkipRDB {
parser.output <- cmd
if parser.counter != nil {
(*parser.counter)++
}
}
parser.rawData = []byte{}
parser.expiry = 0
}
// Read length encoded prefix
func (parser *Parser) readLength(save bool) (length uint64, encoding int8, err error) {
prefix, err := parser.reader.ReadByte()
if err != nil {
return 0, 0, err
}
parser.commandWrite(save, []byte{prefix})
kind := (prefix & 0xC0) >> 6
switch kind {
case rdbLen6Bit: // 0x00
length = uint64(prefix & 0x3F)
return length, -1, nil
case rdbLen14bit: // 0x01
data, err := parser.reader.ReadByte()
if err != nil {
return 0, 0, err
}
parser.commandWrite(save, []byte{data})
length = ((uint64(prefix) & 0x3F) << 8) | uint64(data)
return length, -1, nil
case rdbLen32Bit: // 0x10
if prefix == Type32Bit {
data, err := parser.safeRead(4)
if err != nil {
return 0, 0, err
}
parser.commandWrite(save, data)
length = uint64(binary.BigEndian.Uint32(data))
return length, -1, nil
} else if prefix == Type64Bit {
data, err := parser.safeRead(8)
if err != nil {
return 0, 0, err
}
parser.commandWrite(save, data)
length = binary.BigEndian.Uint64(data)
return length, -1, nil
}
case rdbLenEnc: // wtf
encoding = int8(prefix & 0x3F)
return 0, encoding, nil
}
panic("never reached")
}
// read string from RDB, only uncompressed version is supported
func (parser *Parser) readString(save bool) (string, error) {
var result string
length, encoding, err := parser.readLength(false)
if err != nil {
return "", err
}
switch encoding {
// length-prefixed string
case -1:
data, err := parser.safeRead(length)
if err != nil {
return "", err
}
parser.commandWrite(save, data)
result = string(data)
// integer as string
case 0, 1, 2:
data, err := parser.safeRead(1 << uint8(encoding))
if err != nil {
return "", err
}
parser.commandWrite(save, data)
var num uint32
if encoding == 0 {
num = uint32(data[0])
} else if encoding == 1 {
num = uint32(data[0]) | (uint32(data[1]) << 8)
} else if encoding == 2 {
num = uint32(data[0]) | (uint32(data[1]) << 8) | (uint32(data[2]) << 16) | (uint32(data[3]) << 24)
}
result = fmt.Sprintf("%d", num)
// compressed string
case 3:
clength, _, err := parser.readLength(save)
if err != nil {
return "", err
}
length, _, err := parser.readLength(save)
if err != nil {
return "", err
}
data, err := parser.safeRead(clength)
if err != nil {
return "", err
}
parser.commandWrite(save, data)
result = string(lzfDecompressNew(data, int(clength), int(length)))
default:
return "", ErrUnsupportedStringEnc
}
return result, nil
}
// skip (copy) string from RDB
func (parser *Parser) copyString(save bool) error {
length, encoding, err := parser.readLength(save)
if err != nil {
return err
}
switch encoding {
// length-prefixed string
case -1:
data, err := parser.safeRead(length)
if err != nil {
return err
}
parser.commandWrite(save, data)
// integer as string
case 0, 1, 2:
data, err := parser.safeRead(1 << uint8(encoding))
if err != nil {
return err
}
parser.commandWrite(save, data)
// compressed string
case 3:
clength, _, err := parser.readLength(save)
if err != nil {
return err
}
_, _, err = parser.readLength(save)
if err != nil {
return err
}
data, err := parser.safeRead(clength)
if err != nil {
return err
}
parser.commandWrite(save, data)
default:
return ErrUnsupportedStringEnc
}
return nil
}
// read RDB magic header
func stateMagic(parser *Parser) (state, error) {
signature, err := parser.safeRead(5)
if err != nil {
return nil, err
}
if bytes.Compare(signature, rdbSignature) != 0 {
return nil, ErrWrongSignature
}
versionRaw, err := parser.safeRead(4)
if err != nil {
return nil, err
}
version, err := strconv.Atoi(string(versionRaw))
if err != nil {
return nil, ErrWrongSignature
}
if version > 9 {
return nil, ErrVersionUnsupported
}
parser.rdbVersion = version
parser.rdbVersion16bit = make([]byte, 2)
binary.LittleEndian.PutUint16(parser.rdbVersion16bit, uint16(version))
return stateOp, nil
}
// main selector of operations
func stateOp(parser *Parser) (state, error) {
op, err := parser.reader.ReadByte()
if err != nil {
return nil, err
}
parser.currentOp = op
if parser.currentOp != rdbOpDB && parser.currentOp != rdbOpExpirySec && parser.currentOp != rdbOpExpiryMSec &&
parser.currentOp != rdbOpAux && parser.currentOp != rdbOpResizeDB {
parser.commandWrite(true, []byte{op})
}
switch op {
case rdbOpDB:
return stateDB, nil
case rdbOpExpirySec:
return stateExpirySec, nil
case rdbOpExpiryMSec:
return stateExpiryMSec, nil
case rdbOpString, rdbOpZipmap, rdbOpIntset, rdbOpZiplist, rdbOpSortedSet, rdbOpHashmap:
parser.valueState = stateCopyString
return stateKey, nil
case rdbOpList, rdbOpSet:
parser.valueState = stateCopySetOrList
return stateKey, nil
case rdbOpZset:
parser.valueState = stateCopyZset
return stateKey, nil
case rdbOpZset2:
parser.valueState = stateCopyZset2
return stateKey, nil
case rdbOpHash:
parser.valueState = stateCopyHash
return stateKey, nil
case rdbOpModule2:
parser.valueState = stateCopyModule2
return stateKey, nil
case rdbOpAux:
return stateAux, nil
case rdbOpResizeDB:
return stateResizeDB, nil
case rdbOpListQuicklist:
parser.valueState = stateCopyQuicklist
return stateKey, nil
case rdbOpStreamListpacks:
parser.valueState = stateCopyListpacks
return stateKey, nil
case rdbOpEOF:
if parser.rdbVersion > 4 {
return stateCRC64, nil
}
return statePadding, nil
default:
return nil, ErrUnsupportedOp
}
}
func stateResizeDB(parser *Parser) (state, error) {
dbSize, _, err := parser.readLength(false)
if err != nil {
return nil, err
}
expireSize, _, err := parser.readLength(false)
if err != nil {
return nil, err
}
nouse(dbSize, expireSize)
// pp.Printf("dbsize %s expireSize %s\n", int(dbSize), int(expireSize))
return stateOp, nil
}
func stateAux(parser *Parser) (state, error) {
key, err := parser.readString(false)
if err != nil {
return nil, err
}
value, err := parser.readString(false)
if err != nil {
return nil, err
}
// pp.Println(key, value)
nouse(key, value)
return stateOp, nil
}
// DB index operation
func stateDB(parser *Parser) (state, error) {
_, _, err := parser.readLength(false) // skip 0x00
if err != nil {
return nil, err
}
return stateOp, nil
}
func stateExpirySec(parser *Parser) (state, error) {
expiry, err := parser.safeRead(4)
if err != nil {
return nil, err
}
fd := binary.LittleEndian.Uint64(expiry)
timeGap := fd - currentTimestamp
if timeGap < 0 {
parser.expiry = 1
} else {
parser.expiry = timeGap * 1000
}
return stateOp, nil
}
func stateExpiryMSec(parser *Parser) (state, error) {
expiry, err := parser.safeRead(8)
if err != nil {
return nil, err
}
fc := binary.LittleEndian.Uint64(expiry)
timeGap := fc - currentTimestamp*1000
if fc < currentTimestamp*1000 {
parser.expiry = 1
} else {
parser.expiry = timeGap
}
return stateOp, nil
}
// read key
func stateKey(parser *Parser) (state, error) {
key, err := parser.readString(false)
if err != nil {
return nil, err
}
parser.key = key
return parser.valueState, nil
}
// skip over string
func stateCopyString(parser *Parser) (state, error) {
err := parser.copyString(true)
if err != nil {
return nil, err
}
parser.keep()
return stateOp, nil
}
// skip over set or list
func stateCopySetOrList(parser *Parser) (state, error) {
length, _, err := parser.readLength(true)
if err != nil {
return nil, err
}
var i uint64
for i = 0; i < length; i++ {
// list element
err = parser.copyString(true)
if err != nil {
return nil, err
}
}
parser.keep()
return stateOp, nil
}
// skip over hash
func stateCopyHash(parser *Parser) (state, error) {
length, _, err := parser.readLength(true)
if err != nil {
return nil, err
}
var i uint64
for i = 0; i < length; i++ {
// key
err = parser.copyString(true)
if err != nil {
return nil, err
}
// value
err = parser.copyString(true)
if err != nil {
return nil, err
}
}
parser.keep()
return stateOp, nil
}
// skip over zset
func stateCopyZset(parser *Parser) (state, error) {
length, _, err := parser.readLength(true)
if err != nil {
return nil, err
}
var i uint64
for i = 0; i < length; i++ {
err = parser.copyString(true)
if err != nil {
return nil, err
}
dlen, err := parser.reader.ReadByte()
if err != nil {
return nil, err
}
parser.commandWrite(true, []byte{dlen})
if dlen < 0xFD {
double, err := parser.safeRead(uint64(dlen))
if err != nil {
return nil, err
}
parser.commandWrite(true, double)
}
}
parser.keep()
return stateOp, nil
}
// skip over zset
func stateCopyZset2(parser *Parser) (state, error) {
length, _, err := parser.readLength(true)
if err != nil {
return nil, err
}
var i uint64
for i = 0; i < length; i++ {
err = parser.copyString(true)
if err != nil {
return nil, err
}
scoreBytes, err := parser.safeRead(uint64(8))
if err != nil {
return nil, err
}
// score double
score := math.Float64frombits(binary.LittleEndian.Uint64(scoreBytes))
nouse(score)
}
parser.keep()
return stateOp, nil
}
func stateCopyQuicklist(parser *Parser) (state, error) {
listLen, _, err := parser.readLength(true)
if err != nil {
return nil, err
}
for i := uint64(0); i < listLen; i++ {
err = parser.copyString(true)
if err != nil {
return nil, err
}
}
parser.keep()
return stateOp, nil
}
func stateCopyListpacks(parser *Parser) (state, error) {
return nil, errors.New("not imp")
}
// re-calculate crc64
func stateCRC64(parser *Parser) (state, error) {
_, err := parser.safeRead(8)
if err != nil {
return nil, err
}
return statePadding, nil
}
// pad RDB with 0xFF up to original length
func statePadding(parser *Parser) (state, error) {
return nil, nil
}
func (parser *Parser) readUnsigned(save bool) (uint64, error) {
val, _, err := parser.readLength(save)
if err != nil {
return 0, err
} else if val != RdbModuleOpcodeUInt {
return 0, errors.New(fmt.Sprintf("illegal RdbModuleOpcodeUInt %d,expect:%d", val, RdbModuleOpcodeUInt))
}
value, _, err := parser.readLength(save)
if err != nil {
return 0, err
}
// pp.Printf("type %d value %s\n", opcode, int(value))
return value, nil
}
// 为了存2个数值,在一起是uint,为了防止超范围;共用体底层还是uint64
func (parser *Parser) readSigned(save bool) (uint64, error) {
val, _, err := parser.readLength(save)
if err != nil {
return 0, err
} else if val != RdbModuleOpcodeUInt {
return 0, errors.New(fmt.Sprintf("illegal RdbModuleOpcodeSInt %d,expect:%d", val, RdbModuleOpcodeUInt))
}
value, _, err := parser.readLength(save)
if err != nil {
return 0, err
}
// pp.Printf("type %d value %s\n", opcode, int(value))
return value, nil
}
func (parser *Parser) readDouble(save bool) (uint32, error) {
val, _, err := parser.readLength(save)
if err != nil {
return 0, err
} else if val != RdbModuleOpcodeDouble {
return 0, errors.New(fmt.Sprintf("illegal RdbModuleOpcodeDouble %d,expect:%d", val, RdbModuleOpcodeDouble))
}
scoreBytes, err := parser.safeRead(uint64(8))
if err != nil {
return 0, err
}
parser.commandWrite(true, scoreBytes)
// score
math.Float64frombits(binary.LittleEndian.Uint64(scoreBytes))
return 0, nil
}
func (parser *Parser) readStringBuffer(save bool) (uint32, error) {
val, _, err := parser.readLength(save)
if err != nil {
return 0, err
} else if val != RdbModuleOpcodeString {
return 0, errors.New(fmt.Sprintf("illegal RdbModuleOpcodeString %d,expect:%d", val, RdbModuleOpcodeString))
}
err = parser.copyString(save)
if err != nil {
return 0, err
}
// pp.Printf("type %d value %s\n", opcode, int(value))
return 0, nil
}
func stateCopyModule2(parser *Parser) (state, error) {
length, _, err := parser.readLength(true)
if err != nil {
return nil, err
}
// todo 改成 switch
if length == 3465209449566631940 {
// bloomFilter
return stateCopyBloomFilter(parser)
} else if length == 3465209449562641412 {
// cuckooFilter
return stateCopyCuckooFilter(parser)
} else if length == 5659418315958718464 {
return stateCopyTopk(parser)
} else if length == 5490471757281169408 {
return stateCopyTDigest(parser)
} else if length == 631811237999480832 {
return stateCopyCMS(parser)
} else {
fmt.Println(length)
return nil, errors.New("目前只支持布隆过滤器模块")
}
}
func stateCopyBloomFilter(parser *Parser) (state, error) {
// size
_, err := parser.readUnsigned(true)
if err != nil {
return nil, err
}
// nfilters
nfilters, err := parser.readUnsigned(true)
if err != nil {
return nil, err
}
// options
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// growth
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
numFilters := int(nfilters)
i := 0
for i < numFilters {
i += 1
// entries
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// error
_, err = parser.readDouble(true)
if err != nil {
return nil, err
}
// hashes
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// bpe
_, err = parser.readDouble(true)
if err != nil {
return nil, err
}
// bits
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// n2
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// string buffer
_, err = parser.readStringBuffer(true)
if err != nil {
return nil, err
}
// size
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
}
return stateRdbModuleEOF(parser)
}
func stateCopyCuckooFilter(parser *Parser) (state, error) {
numFilters, err := parser.readUnsigned(true)
if err != nil {
return nil, err
}
// numBuckets
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// numItems
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// numDeletes
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// bucketSize
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// maxIterations
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// expansion
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
i := uint64(0)
for i < numFilters {
i++
// filters[i].numBuckets
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// string buffer
_, err = parser.readStringBuffer(true)
if err != nil {
return nil, err
}
}
return stateRdbModuleEOF(parser)
}
func stateCopyTopk(parser *Parser) (state, error) {
// k
k, err := parser.readUnsigned(true)
if err != nil {
return nil, err
}
// width
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// depth
_, err = parser.readUnsigned(true)
if err != nil {
return nil, err
}
// decay
_, err = parser.readDouble(true)
if err != nil {
return nil, err
}
// Bucket
_, err = parser.readStringBuffer(true)
if err != nil {
return nil, err
}
// HeapBucket
_, err = parser.readStringBuffer(true)
if err != nil {
return nil, err
}
i := uint64(0)
for i < k {
i += 1
// k
_, err = parser.readStringBuffer(true)
if err != nil {
return nil, err
}
}
return stateRdbModuleEOF(parser)
}
func stateCopyTDigest(parser *Parser) (state, error) {
// compression
_, err := parser.readDouble(true)
if err != nil {
return nil, err
}
// min
_, err = parser.readDouble(true)
if err != nil {
return nil, err
}
// max
_, err = parser.readDouble(true)
if err != nil {
return nil, err