func (ts *Ts) GetDBKeys(db *db.DB) ds.List { list := ds.NewList() for key, _ := range db.Data { list.Put(ds.CreateObject([]byte(key), ds.BIN, ts.TsId)) } for key, _ := range ts.magicDB { list.Put(ds.CreateObject([]byte(key), ds.BIN, ts.TsId)) } return list }
func (ts *Ts) SetDBKey(db *db.DB, t uint8, key []byte, value []byte) { var err error tsr := NewTsRecord(AddDbKey) if origObj := db.GetDbObj(key); origObj != nil { log.Println("SetDBKey() origObj:", origObj) tsr.Position = ts.tsLog.Put(db, origObj.GetObjectType(), key, origObj.GetBuffer()) if tsr.Position == nil { log.Panicln(err) } } tsr.Key = key tsr.Dbptr = db ts.AddTsRecord(tsr) ts.setMagicDb(key, ds.CreateObject(value, t, ts.TsId)) }
// |keylen|key|vallen|value| func (db *DB) LoadDbObjFromReader(reader io.Reader, objtype uint8) error { var ( argsN uint16 i uint16 keylen uint64 vallen uint64 ) err := binary.Read(reader, binary.BigEndian, &argsN) if err != nil { return err } if argsN%2 != 0 { return errors.New("argsN fail!") } for i = 0; i < argsN; i++ { err = binary.Read(reader, binary.BigEndian, &keylen) if err != nil { return err } keybuf := make([]byte, keylen) _, err = reader.Read(keybuf) if err != nil { return err } i++ err = binary.Read(reader, binary.BigEndian, &vallen) if err != nil { return err } valbuf := make([]byte, vallen) _, err = reader.Read(valbuf) if err != nil { return err } i++ db.Data[string(keybuf)] = ds.CreateObject(valbuf, objtype, 0) } log.Println(db.Data) return nil }