public static void WriteToStream(AowMap map, Stream outStream) { int modID = map.ModID; int mapClassID = map.ClassID; using (MemoryStream dataStream = new MemoryStream()) using (MemoryStream headerStream = new MemoryStream()) { _headerSerializer.Serialize(headerStream, map.PreviewHeader); _mapSerializer.Serialize(dataStream, map); BinaryWriter writer = new BinaryWriter(outStream); writer.Write(_signature1); writer.Write(map.HmSignature); writer.Write((int)0); writer.Write((int)headerStream.Length); writer.Write(modID); writer.Write(mapClassID); headerStream.Position = 0; headerStream.CopyTo(outStream); writer.Write(_signatureCFS); using (ZlibStream zlib = new ZlibStream(outStream, CompressionMode.Compress)) { dataStream.Position = 0; dataStream.CopyTo(zlib); } } }
public void SaveRoundTrips(byte[] saveBytes) { AowMap original = AowMap.FromBytes(saveBytes); AowMap roundTripped = AowMap.FromBytes(original.ToBytes()); roundTripped.Should().BeEquivalentTo(original); }
public AowMap DeserializeMap() { DataStream.Position = 0; AowMap map = _mapSerializer.Deserialize(DataStream); map.ModID = ModID; map.ClassID = MapClassID; return(map); }
public static AowMap ReadMapFromStream(Stream inputStream) { (int modId, int mapClassId, int hmSignature, MemoryStream dataStream) = ReadPreHeaderAndDecompressDataStream(inputStream); AowMap map = _mapSerializer.Deserialize(dataStream); map.ModID = modId; map.ClassID = mapClassId; map.HmSignature = hmSignature; return(map); }
public static MapFormatHelper FromMap(AowMap map) { MapFormatHelper helper = new MapFormatHelper(); helper.ModID = map.ModID; helper.MapClassID = map.ClassID; helper.HeaderStream = new MemoryStream(); _headerSerializer.Serialize(helper.HeaderStream, map.PreviewHeader); helper._dataStream = new Lazy <Stream>(() => new MemoryStream()); _mapSerializer.Serialize(helper.DataStream, map); return(helper); }
public void SaveDataSectionRoundTrips(byte[] saveBytes) { MemoryStream compressedSaveStream = new MemoryStream(saveBytes); byte[] originalDataBytes = MapFormatHelper.ReadPreHeaderAndDecompressDataStream(compressedSaveStream).dataStream.ToArray(); AowMap deserializedMap = AowMap.FromBytes(saveBytes); MemoryStream roundTrippedDataStream = new MemoryStream(); AowSerializer <AowMap> mapSerializer = new AowSerializer <AowMap>(hasRootWrapper: true); mapSerializer.Serialize(roundTrippedDataStream, deserializedMap); byte[] roundTrippedDataBytes = roundTrippedDataStream.ToArray(); try { roundTrippedDataBytes.Should().BeEquivalentTo(originalDataBytes); } catch { MapStructureLogger originalLogger = new MapStructureLogger(); _ = mapSerializer.Deserialize(new MemoryStream(originalDataBytes), originalLogger); MapStructureLogger roundTrippedLogger = new MapStructureLogger(); _ = mapSerializer.Deserialize(new MemoryStream(roundTrippedDataBytes), roundTrippedLogger); roundTrippedLogger.RootNode.Should().BeEquivalentTo ( originalLogger.RootNode, cfg => cfg .WithStrictOrdering() .Excluding((IMemberInfo m) => m.SelectedMemberInfo.Name == nameof(MapStructureLogger.Node.Parent)) .AllowingInfiniteRecursion() ); throw; } }