public void SerializeDeserialize() { var collection = new MetaCollection <int>(0); var size = 1024; for (uint i = 0; i < size; i++) { collection[i] = (int)(i * 2); } using (var stream = new MemoryStream()) { collection.Serialize(stream); stream.Seek(0, SeekOrigin.Begin); collection = MetaCollection.Deserialize(stream, null) as MetaCollection <int>; } for (uint i = 0; i < size; i++) { Assert.AreEqual(i * 2, collection[i]); } }
/// <summary> /// Deserializes a db. /// </summary> public static MetaCollectionDb Deserialize(Stream stream, ArrayProfile profile = null) { var version = stream.ReadByte(); if (version != 1) { if (version != 1) { throw new Exception(string.Format("Cannot deserialize meta-data db: Invalid version #: {0}, upgrade Itinero.", version)); } } var collections = new Dictionary <string, MetaCollection>(); var count = stream.ReadByte(); for (var i = 0; i < count; i++) { var name = stream.ReadWithSizeString(); var collection = MetaCollection.Deserialize(stream, profile); collections[name] = collection; } return(new MetaCollectionDb(collections)); }