public static UnmanagedMemory ZibCompress(byte[] input) { using (var ms = new TraderMemoryStream(500 * 1024)) { using (var zs = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, true)) { zs.Write(input, 0, input.Length); } return ms.Buffer; } }
public static UnmanagedMemory ToPointer(this DataSet dataset) { if (dataset == null) { return null; } using (var ms = new TraderMemoryStream(CAPACITY)) { using (TextWriter tw = new StreamWriter(ms)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet)); xmlSerializer.Serialize(tw, dataset); return ms.Buffer; } } }
public static string ToXml(this DataSet dataset) { if (dataset == null) { return String.Empty; } using (var ms = new TraderMemoryStream(CAPACITY)) { using (TextWriter tw = new StreamWriter(ms)) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet)); xmlSerializer.Serialize(tw, dataset); string xml = PacketConstants.ContentEncoding.GetString(ms.ToArray()); ms.Buffer.Dispose(); return xml; } } }