public override void AddMaps(Dictionary <long, Map> maps) { var batch = new LevelDB.WriteBatch(); foreach (var map in maps) { NbtCompound mapfile = new NbtCompound("map") { new NbtLong("mapId", map.Key), new NbtLong("parentMapId", -1), new NbtList("decorations", NbtTagType.Compound), new NbtByte("fullyExplored", 1), new NbtByte("scale", 4), new NbtByte("dimension", 0), new NbtShort("height", Map.MAP_HEIGHT), new NbtShort("width", Map.MAP_WIDTH), new NbtByte("unlimitedTracking", 0), new NbtInt("xCenter", Int32.MaxValue), new NbtInt("zCenter", Int32.MaxValue), new NbtByte("mapLocked", 1), new NbtByteArray("colors", map.Value.Colors) }; NbtFile file = new NbtFile(mapfile); file.BigEndian = false; byte[] bytes = file.SaveToBuffer(NbtCompression.None); batch.Put(Encoding.Default.GetBytes($"map_{map.Key}"), bytes); } BedrockDB.Write(batch); }
public WriteBatch(LevelDB.DB _db, LevelDB.ReadOptions _snapshot = null) { this.db = _db; this.snapshot = _snapshot; if (this.snapshot == null) { this.snapshot = Helper.CreateSnapshot(db); } this.wb = new LevelDB.WriteBatch(); cache = new System.Collections.Concurrent.ConcurrentDictionary <System.Numerics.BigInteger, byte[]>(); }
static void Test_Bytes() { var dbex = Helper.OpenDB("c:\\testdb"); var read = Helper.CreateSnapshot(dbex); var data = new byte[16]; Random r = new Random(); r.NextBytes(data); var key = new byte[] { 0x01, 0x02 }; var table = Helper.GetTable(dbex, new byte[] { 0x03 }); var table2 = Helper.GetTable(dbex, new byte[] { 0x04 }); var batch = new LevelDB.WriteBatch(); //dbex.BeginBatch(); var item = new Bytes(data); table.PutItem(key, item); r.NextBytes(data); table2.PutItem(key, item); //dbex.WriteBatch(batch); //dbex.EndBatch(); var read2 = Helper.CreateSnapshot(dbex); var get1 = table.GetItem(read2, key) as Bytes; var get2 = table2.GetItem(read2, key) as Bytes; Console.WriteLine("get1=" + Helper.Hex2Str(get1.Value)); Console.WriteLine("get2=" + Helper.Hex2Str(get2.Value)); dbex.Dispose(); }
public void Batch_SetItem(LevelDB.WriteBatch wb, byte[] key, IValue item) { }
public void Batch_PutToDB(LevelDB.WriteBatch batch, LevelDB.DB db, byte[] key) { throw new NotSupportedException(); batch.Put(key, this.Value); }
public void PutItem_Batch(LevelDB.WriteBatch batch, byte[] key, IValue value) { var _key = CalcKey(Helper.tagKey_Item, key); (value as IValueCreator).Batch_PutToDB(batch, this.db, _key); }
public void Batch_DeleteItem(LevelDB.WriteBatch batch, byte[] key) { var _key = CalcKey(Helper.tagKey_Item, key); batch.Delete(_key); }