WriteDBHeader write db index and resize db into rdb file
(dbIndex uint, keyCount, ttlCount uint64)
| 203 | |
| 204 | // WriteDBHeader write db index and resize db into rdb file |
| 205 | func (enc *Encoder) WriteDBHeader(dbIndex uint, keyCount, ttlCount uint64) error { |
| 206 | if !enc.validateStateChange(writtenDBHeaderState) { |
| 207 | return fmt.Errorf("cannot writing db header at state: %s", enc.state) |
| 208 | } |
| 209 | if _, ok := enc.existDB[dbIndex]; ok { |
| 210 | return fmt.Errorf("db %d existed", dbIndex) |
| 211 | } |
| 212 | enc.existDB[dbIndex] = struct{}{} |
| 213 | err := enc.write([]byte{opCodeSelectDB}) |
| 214 | if err != nil { |
| 215 | return err |
| 216 | } |
| 217 | err = enc.writeLength(uint64(dbIndex)) |
| 218 | if err != nil { |
| 219 | return err |
| 220 | } |
| 221 | err = enc.write([]byte{opCodeResizeDB}) |
| 222 | if err != nil { |
| 223 | return err |
| 224 | } |
| 225 | err = enc.writeLength(keyCount) |
| 226 | if err != nil { |
| 227 | return err |
| 228 | } |
| 229 | err = enc.writeLength(ttlCount) |
| 230 | if err != nil { |
| 231 | return err |
| 232 | } |
| 233 | enc.state = writtenDBHeaderState |
| 234 | return nil |
| 235 | } |
| 236 | |
| 237 | // WriteEnd writes EOF and crc sum |
| 238 | func (enc *Encoder) WriteEnd() error { |