From 7a9922af27658ac570517df530dd7c2cf6d6dded Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 25 Jun 2008 19:33:19 +0000 Subject: Added support for terrain map to be serialised to xml(as base64 binary). useful for places that the terrain map is needed in a serialised form. Also could add console commands to save and load from files, which should be faster than .raw files (these load/save commands are not included/implemented) Add util functions to compress and uncompress strings. Fixed a couple of modules so they use SceneCommunicationService rather than directly call functions on the CommsManager. --- OpenSim/Framework/Util.cs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'OpenSim/Framework/Util.cs') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 719dda6..a835cec 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -28,6 +28,7 @@ using System; using System.Data; using System.IO; +using System.IO.Compression; using System.Net; using System.Net.Sockets; using System.Reflection; @@ -618,6 +619,47 @@ namespace OpenSim.Framework return ret; } + public static string Compress(string text) + { + byte[] buffer = Encoding.UTF8.GetBytes(text); + MemoryStream memory = new MemoryStream(); + using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true)) + { + compressor.Write(buffer, 0, buffer.Length); + } + + memory.Position = 0; + MemoryStream outStream = new MemoryStream(); + + byte[] compressed = new byte[memory.Length]; + memory.Read(compressed, 0, compressed.Length); + + byte[] compressedBuffer = new byte[compressed.Length + 4]; + System.Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length); + System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4); + return Convert.ToBase64String(compressedBuffer); + } + + public static string Decompress(string compressedText) + { + byte[] compressedBuffer = Convert.FromBase64String(compressedText); + using (MemoryStream memory = new MemoryStream()) + { + int msgLength = BitConverter.ToInt32(compressedBuffer, 0); + memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4); + + byte[] buffer = new byte[msgLength]; + + memory.Position = 0; + using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress)) + { + decompressor.Read(buffer, 0, buffer.Length); + } + + return Encoding.UTF8.GetString(buffer); + } + } + public static string[] ParseStartLocationRequest(string startLocationRequest) { string[] returnstring = new string[4]; -- cgit v1.1