public static DataBaseSizeCommand ReadResponse(BinaryReader reader) { return(new DataBaseSizeCommand() { DataBaseSize = (long)CountCompression.Deserialize(reader) }); }
public void Load(WTree tree, BinaryReader reader) { int count = (int)CountCompression.Deserialize(reader); Capacity = count; NodeType nodeType = (NodeType)reader.ReadByte(); for (int i = 0; i < count; i++) { //read fullKey var locator = tree.DeserializeLocator(reader); var key = locator.KeyPersist.Read(reader); var fullKey = new FullKey(locator, key); //read branch info long nodeID = reader.ReadInt64(); NodeState nodeState = (NodeState)reader.ReadInt32(); Branch branch = new Branch(tree, nodeType, nodeID); branch.NodeState = nodeState; branch.Cache.Load(tree, reader); Add(new KeyValuePair <FullKey, Branch>(fullKey, branch)); } }
public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream); if (reader.ReadByte() != VERSION) { throw new Exception("Invalid LeafNode version."); } long id = (long)CountCompression.Deserialize(reader); if (id != Branch.NodeHandle) { throw new Exception("Wtree logical error."); } int count = (int)CountCompression.Deserialize(reader); for (int i = 0; i < count; i++) { Locator path = Branch.Tree.DeserializeLocator(reader); IOrderedSet <IData, IData> data = path.OrderedSetPersist.Read(reader); Container[path] = data; RecordCount += data.Count; } IsModified = false; }
public void Store(WTree tree, BinaryWriter writer) { CountCompression.Serialize(writer, checked ((ulong)Count)); Debug.Assert(Count > 0); writer.Write((byte)this[0].Value.NodeType); for (int i = 0; i < Count; i++) { var kv = this[i]; FullKey fullkey = kv.Key; Branch branch = kv.Value; //lock (branch) //{ //} //write locator tree.SerializeLocator(writer, fullkey.Locator); fullkey.Locator.KeyPersist.Write(writer, fullkey.Key); //write branch info writer.Write(branch.NodeHandle); writer.Write((int)branch.NodeState); branch.Cache.Store(tree, writer); } }
public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream); int version = (int)CountCompression.Deserialize(reader); switch (version) { case 1: { long id = (long)CountCompression.Deserialize(reader); if (id != Branch.NodeHandle) { throw new Exception("Wtree logical error."); } HaveChildrenForMaintenance = reader.ReadBoolean(); Branches.Load(Branch.Tree, reader); RebuildOptimizator(); } break; default: throw new NotSupportedException(string.Format("Inernal node version {0}", version)); } IsModified = false; }
public static ObtainHandleCommand ReadResponse(BinaryReader reader) { return(new ObtainHandleCommand() { Handle = (long)CountCompression.Deserialize(reader) }); }
public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream); int version = (int)CountCompression.Deserialize(reader); switch (version) { case 1: { long id = (long)CountCompression.Deserialize(reader); if (id != Branch.NodeHandle) { throw new Exception("Wtree logical error."); } int count = (int)CountCompression.Deserialize(reader); for (int i = 0; i < count; i++) { ILocator path = Branch.Tree.Deserialize(reader); IDataContainer data = path.PersistDataContainer.Read(reader); Container[path] = data; FillPercentage += data.FillPercentage; } } break; default: throw new NotSupportedException(string.Format("Leaf node version {0}", version)); } IsModified = false; }
public static HandleExistCommand ReadRequest(BinaryReader reader) { return(new HandleExistCommand() { Handle = (long)CountCompression.Deserialize(reader) }); }
public static ReadCommand ReadResponse(BinaryReader reader) { return(new ReadCommand() { Buffer = reader.ReadBytes((int)CountCompression.Deserialize(reader)) }); }
public static GetTagCommand ReadResponse(BinaryReader reader) { return(new GetTagCommand() { Tag = reader.ReadBoolean() ? reader.ReadBytes((int)CountCompression.Deserialize(reader)) : null }); }
private void LoadExampleSingleSlot(BinaryReader reader, Action <int, IData> values, int count) { byte[] buffer = reader.ReadBytes((int)CountCompression.Deserialize(reader)); //String using (MemoryStream ms = new MemoryStream(buffer)) ((IIndexerPersist <string>)Persists[0]).Load(new BinaryReader(ms), (idx, value) => { values(idx, new Data <string>(value)); }, count); }
public static Locator Deserialize(BinaryReader reader) { if (reader.ReadByte() != VERSION) { throw new Exception("Invalid Locator version."); } long id = reader.ReadInt64(); if (id == Locator.MIN.ID) { return(Locator.MIN); } bool isDeleted = reader.ReadBoolean(); string name = reader.ReadString(); int structureType = reader.ReadByte(); //data types DataType keyDataType = DataType.Deserialize(reader); DataType recordDataType = DataType.Deserialize(reader); //types string sKeyType = reader.ReadString(); Type keyType = (sKeyType != "") ? TypeCache.GetType(sKeyType) : DataTypeUtils.BuildType(keyDataType); string sRecordType = reader.ReadString(); Type recordType = (sRecordType != "") ? TypeCache.GetType(sRecordType) : DataTypeUtils.BuildType(recordDataType); //key & record members var keyMembers = ReadMembers(reader); var recordMembers = ReadMembers(reader); //create time DateTime createTime = new DateTime(reader.ReadInt64()); DateTime modifiedTime = new DateTime(reader.ReadInt64()); DateTime accessTime = new DateTime(reader.ReadInt64()); //tag byte[] tag = reader.ReadBoolean() ? reader.ReadBytes((int)CountCompression.Deserialize(reader)) : null; var locator = new Locator(id, name, structureType, keyDataType, recordDataType, keyType, recordType); locator.IsDeleted = isDeleted; locator.keyMembers = keyMembers; locator.recordMembers = recordMembers; locator.CreateTime = createTime; locator.ModifiedTime = modifiedTime; locator.AccessTime = accessTime; locator.Tag = tag; return(locator); }
public static void WriteResponse(BinaryWriter writer, byte[] tag) { writer.Write(tag != null); if (tag != null) { CountCompression.Serialize(writer, (ulong)tag.Length); writer.Write(tag, 0, tag.Length); } }
public void Load(BinaryReader reader, Action <int, byte[]> values, int count) { if (reader.ReadByte() != VERSION) { throw new Exception("Invalid ByteArrayIndexerPersist version."); } int index = 0; byte format = reader.ReadByte(); if (format == 1) { if (count == 0) { return; } int c = reader.ReadInt32(); int length = reader.ReadInt32(); if (length < 0) { for (int i = 0; i < c; i++) { values(index++, null); } } else { for (int i = 0; i < c; i++) { values(index++, reader.ReadBytes(length)); } } if (index == count) { return; } } for (int i = index; i < count; i++) { int length = (int)CountCompression.Deserialize(reader); if (length == 0) { values(i, null); } else { values(i, reader.ReadBytes(length - 1)); } } }
private void StoreExampleSingleSlot(BinaryWriter writer, Func <int, IData> values, int count) { //String using (MemoryStream ms = new MemoryStream()) { ((IIndexerPersist <String>)Persists[0]).Store(new BinaryWriter(ms), (idx) => { return(((Data <string>)values(idx)).Slot0); }, count); CountCompression.Serialize(writer, checked ((ulong)ms.Length)); writer.Write(ms.GetBuffer(), 0, (int)ms.Length); } }
public void Load(BinaryReader reader, Action <int, long> values, int count) { long factor = (long)CountCompression.Deserialize(reader); List <long> rawValues = (List <long>)DeltaCompression.CoreDecompress(reader); for (int i = 0; i < count; i++) { values(i, factor * rawValues[i]); } }
public static void WriteRequest(BinaryWriter writer, byte[] tag) { writer.Write((byte)RemoteHeapCommandCodes.SetTag); writer.Write(tag != null); if (tag != null) { CountCompression.Serialize(writer, (ulong)tag.Length); writer.Write(tag, 0, tag.Length); } }
public void Load(BinaryReader reader, Action <int, long> values, int count) { if (reader.ReadByte() != VERSION) { throw new Exception("Invalid Int64IndexerPersist version."); } long factor = (long)CountCompression.Deserialize(reader); DeltaCompression.Decompress(reader, (idx, val) => values(idx, factor * val), count); }
public static void WriteRequest(BinaryWriter writer, long handle, int index, int count, byte[] buffer) { writer.Write((byte)RemoteHeapCommandCodes.WriteCommand); CountCompression.Serialize(writer, (ulong)handle); CountCompression.Serialize(writer, (ulong)index); CountCompression.Serialize(writer, (ulong)count); CountCompression.Serialize(writer, (ulong)(count + index)); writer.Write(buffer, 0, index + count); }
public static WriteCommand ReadRequest(BinaryReader reader) { return(new WriteCommand() { Handle = (long)CountCompression.Deserialize(reader), Index = (int)CountCompression.Deserialize(reader), Count = (int)CountCompression.Deserialize(reader), Buffer = reader.ReadBytes((int)CountCompression.Deserialize(reader)) }); }
public IDataContainer Read(BinaryReader reader) { int count = (int)CountCompression.Deserialize(reader); bool isOrdered = reader.ReadBoolean(); IData[] keys = new IData[count]; IData[] records = new IData[count]; Action[] actions = new Action[2]; byte[][] buffers = new byte[2][]; for (int i = 0; i < buffers.Length; i++) { buffers[i] = reader.ReadBytes((int)CountCompression.Deserialize(reader)); } actions[0] = () => { using (MemoryStream ms = new MemoryStream(buffers[0])) keyIndexerPersist.Load(new BinaryReader(ms), (idx, value) => { keys[idx] = value; }, count); }; actions[1] = () => { using (MemoryStream ms = new MemoryStream(buffers[1])) recordIndexerPersist.Load(new BinaryReader(ms), (idx, value) => { records[idx] = value; }, count); }; Parallel.Invoke(actions); var data = Locator.CreateDataContainer(); var set = (IOrderedSet <IData, IData>)data; if (!isOrdered) { for (int i = 0; i < count; i++) { set.Add(keys[i], records[i]); } } else { KeyValuePair <IData, IData>[] orderedArray = new KeyValuePair <IData, IData> [count]; for (int i = 0; i < orderedArray.Length; i++) { orderedArray[i] = new KeyValuePair <IData, IData>(keys[i], records[i]); } set.AddOrdered(orderedArray, 0, orderedArray.Length); } return(data); }
public override void Store(Stream stream) { BinaryWriter writer = new BinaryWriter(stream); writer.Write(VERSION); CountCompression.Serialize(writer, checked ((ulong)Branch.NodeHandle)); writer.Write(HaveChildrenForMaintenance); Branches.Store(Branch.Tree, writer); IsModified = false; }
private void WriteVertical(BinaryWriter writer, IOrderedSet <IData, IData> data) { KeyValuePair <IData, IData>[] rows; bool isInternallyOrdered; lock (data) { isInternallyOrdered = data.IsInternallyOrdered; rows = new KeyValuePair <IData, IData> [data.Count]; int index = 0; foreach (var kv in data.InternalEnumerate()) { rows[index++] = kv; } CountCompression.Serialize(writer, checked ((ulong)rows.Length)); writer.Write(data.IsInternallyOrdered); } Action[] actions = new Action[2]; MemoryStream[] streams = new MemoryStream[2]; actions[0] = () => { streams[0] = new MemoryStream(); keyIndexerPersist.Store(new BinaryWriter(streams[0]), (idx) => { return(rows[idx].Key); }, rows.Length); }; actions[1] = () => { streams[1] = new MemoryStream(); recordIndexerPersist.Store(new BinaryWriter(streams[1]), (idx) => { return(rows[idx].Value); }, rows.Length); }; Parallel.Invoke(actions); foreach (var stream in streams) { using (stream) { CountCompression.Serialize(writer, checked ((ulong)stream.Length)); writer.Write(stream.GetBuffer(), 0, (int)stream.Length); } } }
public override void Store(Stream stream) { BinaryWriter writer = new BinaryWriter(stream); CountCompression.Serialize(writer, 1); //structure version CountCompression.Serialize(writer, checked ((ulong)Branch.NodeHandle)); CountCompression.Serialize(writer, checked ((ulong)Container.Count)); foreach (var kv in Container) { Branch.Tree.Serialize(writer, kv.Key); kv.Key.PersistDataContainer.Write(writer, kv.Value); } IsModified = false; }
public override void Store(Stream stream) { BinaryWriter writer = new BinaryWriter(stream); writer.Write(VERSION); CountCompression.Serialize(writer, checked ((ulong)Branch.NodeHandle)); CountCompression.Serialize(writer, checked ((ulong)Container.Count)); foreach (var kv in Container) { Branch.Tree.SerializeLocator(writer, kv.Key); kv.Key.OrderedSetPersist.Write(writer, kv.Value); } IsModified = false; }
private StorageEngineGetEnumeratorCommand ReadStorageEngineGetEnumeratorCommand(BinaryReader reader) { bool isListNull = reader.ReadBoolean(); List <IDescriptor> descriptions = new List <IDescriptor>(); if (!isListNull) { int listCount = (int)CountCompression.Deserialize(reader); for (int i = 0; i < listCount; i++) { descriptions.Add((Descriptor)DeserializeDescriptor(reader)); } } return(new StorageEngineGetEnumeratorCommand(descriptions)); }
private void InternalSerialize(BinaryWriter writer) { //StructureType writer.Write(checked ((byte)StructureType)); if (Object.ReferenceEquals(this, Locator.MIN)) { return; } //descriptor descriptor.Serialize(writer); //Items CountCompression.Serialize(writer, checked ((ulong)Path.Length)); for (int i = 0; i < Path.Length; i++) { writer.Write(Path[i]); } }
private void LoadExample(BinaryReader reader, Action <int, IData> values, int count) { Data <int, string, double>[] array = new Data <int, string, double> [count]; for (int i = 0; i < count; i++) { var data = new Data <int, string, double>(); array[i] = data; values(i, data); } Action[] actions = new Action[DataType.TypesCount]; byte[][] buffers = new byte[DataType.TypesCount][]; for (int i = 0; i < DataType.TypesCount; i++) { buffers[i] = reader.ReadBytes((int)CountCompression.Deserialize(reader)); } //Int32 actions[0] = () => { using (MemoryStream ms = new MemoryStream(buffers[0])) ((IIndexerPersist <Int32>)Persists[0]).Load(new BinaryReader(ms), (idx, value) => { array[idx].Slot0 = value; }, count); }; //String actions[1] = () => { using (MemoryStream ms = new MemoryStream(buffers[1])) ((IIndexerPersist <String>)Persists[0]).Load(new BinaryReader(ms), (idx, value) => { array[idx].Slot1 = value; }, count); }; //Double actions[2] = () => { using (MemoryStream ms = new MemoryStream(buffers[2])) ((IIndexerPersist <Double>)Persists[0]).Load(new BinaryReader(ms), (idx, value) => { array[idx].Slot2 = value; }, count); }; Parallel.Invoke(actions); }
private void WriteStorageEngineGetEnumeratorCommand(BinaryWriter writer, ICommand command) { var cmd = (StorageEngineGetEnumeratorCommand)command; if (cmd.Descriptions == null) { writer.Write(true); } else { writer.Write(false); int listCount = cmd.Descriptions.Count; CountCompression.Serialize(writer, (ulong)listCount); for (int i = 0; i < listCount; i++) { SerializeDescriptor(writer, cmd.Descriptions[i]); } } }
public static Locator Deserialize(BinaryReader reader) { //StructureType int structureType = reader.ReadByte(); if (structureType == Locator.MIN.StructureType) { return(Locator.MIN); } //descriptor var descriptor = StructureDescriptor.Deserialize(reader); //Items string[] items = new string[CountCompression.Deserialize(reader)]; for (int i = 0; i < items.Length; i++) { items[i] = reader.ReadString(); } return(new Locator(structureType, descriptor, items)); }