/// <summary> /// Does the v2 deserialization. /// </summary> /// <param name="stream"></param> /// <param name="lazy"></param> /// <param name="vehicles"></param> /// <returns></returns> protected override IBasicRouterDataSource <CHEdgeData> DoDeserialize( LimitedStream stream, bool lazy, IEnumerable <string> vehicles) { var intBytes = new byte[4]; stream.Read(intBytes, 0, 4); int startOfBlocks = BitConverter.ToInt32(intBytes, 0); stream.Read(intBytes, 0, 4); int startOfTags = BitConverter.ToInt32(intBytes, 0); stream.Read(intBytes, 0, 4); int sizeRegionIndex = BitConverter.ToInt32(intBytes, 0); // deserialize regions index. var chVertexRegionIndex = (CHVertexRegionIndex)_runtimeTypeModel.Deserialize( new CappedStream(stream, stream.Position, sizeRegionIndex), null, typeof(CHVertexRegionIndex)); // deserialize blocks index. stream.Seek(startOfBlocks, SeekOrigin.Begin); stream.Read(intBytes, 0, 4); int sizeBlockIndex = BitConverter.ToInt32(intBytes, 0); var chBlockIndex = (CHBlockIndex)_runtimeTypeModel.Deserialize( new CappedStream(stream, stream.Position, sizeBlockIndex), null, typeof(CHBlockIndex)); // deserialize tags. stream.Seek(startOfTags, SeekOrigin.Begin); ITagsCollectionIndexReadonly tagsIndex = TagIndexSerializer.DeserializeBlocks(stream); return(new v2.CHEdgeDataDataSource(stream, this, vehicles, sizeRegionIndex + 12, chVertexRegionIndex, _regionZoom, startOfBlocks + sizeBlockIndex + 4, chBlockIndex, (uint)_blockVertexSize, tagsIndex)); }
/// <summary> /// Executes the tests. /// </summary> public static void Test() { TagsTableCollectionIndex index = new TagsTableCollectionIndex(); // first fill the index. ITagCollectionIndexTests.FillIndex(index, 100000); // serialize the index. FileInfo testFile = new FileInfo(@"test.file"); testFile.Delete(); Stream writeStream = testFile.OpenWrite(); OsmSharp.Logging.Log.TraceEvent("Blocked", OsmSharp.Logging.TraceEventType.Information, "Serializing blocked file...."); TagIndexSerializer.SerializeBlocks(writeStream, index, 100); writeStream.Flush(); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("Blocked", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testFile.Length / 1024)); // deserialize the index. Stream readStream = testFile.OpenRead(); ITagsCollectionIndexReadonly readOnlyIndex = TagIndexSerializer.DeserializeBlocks(readStream); // test access. OsmSharp.Logging.Log.TraceEvent("Blocked", OsmSharp.Logging.TraceEventType.Information, "Started testing random access...."); ITagCollectionIndexTests.TestRandomAccess("Blocked", readOnlyIndex, 1000); readStream.Dispose(); testFile.Delete(); }
/// <summary> /// Serialize/deserialize index. /// </summary> /// <param name="index"></param> /// <param name="blockSize"></param> /// <param name="position"></param> /// <returns></returns> private ITagsCollectionIndexReadonly SerializeDeserializeBlock(ITagsCollectionIndex index, uint blockSize, int position) { MemoryStream stream = new MemoryStream(); stream.Seek(position, SeekOrigin.Begin); TagIndexSerializer.SerializeBlocks(stream, index, blockSize); stream.Seek(position, SeekOrigin.Begin); return(TagIndexSerializer.DeserializeBlocks(stream)); }