public async Task SaveUpkFile(DomainHeader Header, string Filename) { if (Header == null) { return; } foreach (DomainExportTableEntry export in Header.ExportTable.Where(export => export.DomainObject == null)) { await export.ParseDomainObject(Header, false, false); } FileStream stream = new FileStream(Filename, FileMode.Create); int headerSize = Header.GetBuilderSize(); ByteArrayWriter writer = ByteArrayWriter.CreateNew(headerSize); await Header.WriteBuffer(writer, 0); await stream.WriteAsync(writer.GetBytes(), 0, headerSize); foreach (DomainExportTableEntry export in Header.ExportTable) { ByteArrayWriter objectWriter = await export.WriteObjectBuffer(); await stream.WriteAsync(objectWriter.GetBytes(), 0, objectWriter.Index); } await stream.FlushAsync(); stream.Close(); }
public void GetBytes_AfterCreate(bool alwaysCopyInputData) { IByteArrayWriter writer = new ByteArrayWriter(alwaysCopyInputData); byte[] output = writer.GetBytes(); Assert.AreEqual(0, output.Length); }
public void GetBytes_AfterWrite1ByteWithoutOffsetCount() { IByteArrayWriter writer = new ByteArrayWriter(true); writer.WriteBytes(30); byte[] output = writer.GetBytes(); Assert.AreEqual(1, output.Length); Assert.AreEqual(30, output[0]); }
public void GetBytes_AfterWrite2Bytes3Offset(bool alwaysCopyInputData) { byte[] data = new byte[] { 1, 2, 3, 4, 5 }; IByteArrayWriter writer = new ByteArrayWriter(alwaysCopyInputData); writer.WriteBytes(data, 3, 2); byte[] output = writer.GetBytes(); Assert.AreEqual(2, output.Length); Assert.AreEqual(4, output[0]); Assert.AreEqual(5, output[1]); }
public void WriteGetBytes_4BytesWithoutOffsetCount() { IByteArrayWriter writer = new ByteArrayWriter(true); writer.WriteBytes(10, 20, 30, 40); byte[] output = writer.GetBytes(); Assert.AreEqual(4, output.Length); Assert.AreEqual(10, output[0]); Assert.AreEqual(20, output[1]); Assert.AreEqual(30, output[2]); Assert.AreEqual(40, output[3]); }