public static void SendCreateRegionMessage(uint xloc, uint yloc, ushort receiverServerPort, ushort regionServerport) { RegionInfo info = new RegionInfo { ExternalHostName = "localhost", InternalEndPoint = new System.Net.IPEndPoint(new System.Net.IPAddress(2130706433), 9001), HttpPort = regionServerport, OutsideIP = "127.0.0.1", RegionID = UUID.Random(), RegionLocX = xloc, RegionLocY = yloc, }; WebRequest req = HttpWebRequest.Create("http://127.0.0.1:" + receiverServerPort + "/region2/regionup"); req.Headers["authorization"] = Util.GenerateHttpAuthorization("key"); req.Timeout = 10000; req.Method = "POST"; byte[] serRegInfo = OSDParser.SerializeLLSDBinary(info.PackRegionInfoData()); var rs = req.GetRequestStream(); rs.Write(serRegInfo, 0, serRegInfo.Length); rs.Flush(); var response = req.GetResponse(); response.Dispose(); }
public void TestUnauthorized() { RegionInfo info = new RegionInfo { ExternalHostName = "localhost", InternalEndPoint = new System.Net.IPEndPoint(new System.Net.IPAddress(2130706433), 9001), HttpPort = 9000, OutsideIP = "127.0.0.1", RegionID = UUID.Random(), RegionLocX = 1100, RegionLocY = 1000, }; WebRequest req = HttpWebRequest.Create("http://127.0.0.1:9000/region2/regionup"); req.Headers["authorization"] = Util.GenerateHttpAuthorization("BADPASSWORD"); req.Timeout = 10000; req.Method = "POST"; byte[] serRegInfo = OSDParser.SerializeLLSDBinary(info.PackRegionInfoData()); var rs = req.GetRequestStream(); rs.Write(serRegInfo, 0, serRegInfo.Length); rs.Flush(); Assert.Throws <System.Net.WebException>(() => { var response = req.GetResponse(); }); }
public void SerializeArray() { OSDArray llsdEmptyArray = new OSDArray(); byte[] binaryEmptyArraySerialized = OSDParser.SerializeLLSDBinary(llsdEmptyArray); Assert.AreEqual(binaryEmptyArray, binaryEmptyArraySerialized); binaryEmptyArraySerialized = OSDParser.SerializeLLSDBinary(llsdEmptyArray, false); Assert.AreEqual(binaryEmptyArrayValue, binaryEmptyArraySerialized); OSDArray llsdSimpleArray = new OSDArray(); llsdSimpleArray.Add(OSD.FromInteger(0)); byte[] binarySimpleArraySerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArray); Assert.AreEqual(binarySimpleArray, binarySimpleArraySerialized); binarySimpleArraySerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArray, false); Assert.AreEqual(binarySimpleArrayValue, binarySimpleArraySerialized); OSDArray llsdSimpleArrayTwo = new OSDArray(); llsdSimpleArrayTwo.Add(OSD.FromInteger(0)); llsdSimpleArrayTwo.Add(OSD.FromInteger(0)); byte[] binarySimpleArrayTwoSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArrayTwo); Assert.AreEqual(binarySimpleArrayTwo, binarySimpleArrayTwoSerialized); binarySimpleArrayTwoSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArrayTwo, false); Assert.AreEqual(binarySimpleArrayTwoValue, binarySimpleArrayTwoSerialized); }
public void SerializeUndef() { OSD llsdUndef = new OSD(); byte[] binaryUndefSerialized = OSDParser.SerializeLLSDBinary(llsdUndef); Assert.AreEqual(binaryUndef, binaryUndefSerialized); }
/// <summary> /// Saves the estate settings to an archive. /// </summary> /// <param name="writer">Writer.</param> /// <param name="scene">Scene.</param> public void SaveModuleToArchive(TarArchiveWriter writer, IScene scene) { MainConsole.Instance.Debug("[Archive]: Writing estates to archive"); EstateSettings settings = scene.RegionInfo.EstateSettings; if (settings == null) { return; } writer.WriteDir("estatesettings"); writer.WriteFile("estatesettings/" + scene.RegionInfo.RegionName, OSDParser.SerializeLLSDBinary(settings.ToOSD())); MainConsole.Instance.Debug("[Archive]: Finished writing estates to archive"); MainConsole.Instance.Debug("[Archive]: Writing region info to archive"); writer.WriteDir("regioninfo"); RegionInfo regionInfo = scene.RegionInfo; writer.WriteFile("regioninfo/" + scene.RegionInfo.RegionName, OSDParser.SerializeLLSDBinary(regionInfo.PackRegionInfoData())); MainConsole.Instance.Debug("[Archive]: Finished writing region info to archive"); }
public void SerializeDateTime() { DateTime dt = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc); OSD llsdDate = OSD.FromDate(dt); byte[] binaryDateSerialized = OSDParser.SerializeLLSDBinary(llsdDate); Assert.AreEqual(binaryDateTime, binaryDateSerialized); // check if a *local* time can be serialized and deserialized DateTime dtOne = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local); OSD llsdDateOne = OSD.FromDate(dtOne); byte[] binaryDateOneSerialized = OSDParser.SerializeLLSDBinary(llsdDateOne); OSD llsdDateOneDS = OSDParser.DeserializeLLSDBinary(binaryDateOneSerialized); Assert.AreEqual(OSDType.Date, llsdDateOneDS.Type); Assert.AreEqual(dtOne, llsdDateOneDS.AsDate()); DateTime dtTwo = new DateTime(2010, 11, 11, 10, 8, 20, DateTimeKind.Utc); OSD llsdDateTwo = OSD.FromDate(dtTwo); byte[] binaryDateTwoSerialized = OSDParser.SerializeLLSDBinary(llsdDateTwo); OSD llsdDateTwoDS = OSDParser.DeserializeLLSDBinary(binaryDateTwoSerialized); Assert.AreEqual(OSDType.Date, llsdDateOneDS.Type); Assert.AreEqual(dtTwo.ToLocalTime(), llsdDateTwoDS.AsDate()); }
public void SerializeString() { OSD llsdString = OSD.FromString("abcdefghijklmnopqrstuvwxyz01234567890"); byte[] binaryLongStringSerialized = OSDParser.SerializeLLSDBinary(llsdString); Assert.AreEqual(binaryLongString, binaryLongStringSerialized); // A test with some utf8 characters string contentAStringXML = "<x>ƖȔȠȨɆɒ</x>"; byte[] bytes = Encoding.UTF8.GetBytes(contentAStringXML); XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); xtr.Read(); xtr.Read(); string contentAString = xtr.ReadString(); OSD llsdAString = OSD.FromString(contentAString); byte[] binaryAString = OSDParser.SerializeLLSDBinary(llsdAString); OSD llsdAStringDS = OSDParser.DeserializeLLSDBinary(binaryAString); Assert.AreEqual(OSDType.String, llsdAStringDS.Type); Assert.AreEqual(contentAString, llsdAStringDS.AsString()); // we also test for a 4byte character. string xml = "<x>𐄷</x>"; byte[] bytesTwo = Encoding.UTF8.GetBytes(xml); XmlTextReader xtrTwo = new XmlTextReader(new MemoryStream(bytesTwo, false)); xtrTwo.Read(); xtrTwo.Read(); string content = xtrTwo.ReadString(); OSD llsdStringOne = OSD.FromString(content); byte[] binaryAStringOneSerialized = OSDParser.SerializeLLSDBinary(llsdStringOne); OSD llsdStringOneDS = OSDParser.DeserializeLLSDBinary(binaryAStringOneSerialized); Assert.AreEqual(OSDType.String, llsdStringOneDS.Type); Assert.AreEqual(content, llsdStringOneDS.AsString()); }
public void SerializeURI() { OSD llsdUri = OSD.FromUri(new Uri("http://www.testurl.test/")); byte[] binaryURISerialized = OSDParser.SerializeLLSDBinary(llsdUri); Assert.AreEqual(binaryURI, binaryURISerialized); }
void SaveCache(object sync) { WorkPool.QueueUserWorkItem(syncx => { OSDArray namesOSD = new OSDArray(names.Count); lock (names) { foreach (var name in names) { namesOSD.Add(name.Value.GetOSD()); } } OSDMap cache = new OSDMap(1); cache["names"] = namesOSD; byte[] data = OSDParser.SerializeLLSDBinary(cache, false); Logger.DebugLog(string.Format("Caching {0} avatar names to {1}", namesOSD.Count, cacheFileName)); try { File.WriteAllBytes(cacheFileName, data); } catch (Exception ex) { Logger.Log("Failed to save avatar name cache: ", Helpers.LogLevel.Error, client, ex); } }); }
private void SendMessageTo(List <KnownNeighborRegion> neighborSnap, string url, MessageType messageType) { try { List <Task> waitingResults = new List <Task>(); OSDMap regionInfo = _scene.RegionInfo.PackRegionInfoData(); byte[] serializedRegionInfo = OSDParser.SerializeLLSDBinary(regionInfo); foreach (var neighbor in neighborSnap) { var req = (HttpWebRequest)HttpWebRequest.Create(neighbor.RegionInfo.InsecurePublicHTTPServerURI + url); req.Headers["authorization"] = Util.GenerateHttpAuthorization(_gridSendKey); req.Timeout = NEIGHBOR_HANDLER_TIMEOUT; req.ReadWriteTimeout = NEIGHBOR_HANDLER_TIMEOUT; req.Method = "POST"; waitingResults.Add(this.DoRegionAsyncCall(req, neighbor, messageType, serializedRegionInfo)); } Task.WaitAll(waitingResults.ToArray()); } catch (AggregateException e) //we're catching exceptions in the call, so we really should never see this { for (int j = 0; j < e.InnerExceptions.Count; j++) { _log.ErrorFormat("[REGIONMANAGER]: Error thrown from async call: {0}", e); } } catch (Exception e) { _log.ErrorFormat("[REGIONMANAGER]: Error thrown while sending heartbeat: {0}", e); } }
public void BeginGetResponse(OSD data, OSDFormat format, int millisecondsTimeout) { byte[] postData; string contentType; switch (format) { case OSDFormat.Xml: postData = OSDParser.SerializeLLSDXmlBytes(data); contentType = "application/llsd+xml"; break; case OSDFormat.Binary: postData = OSDParser.SerializeLLSDBinary(data); contentType = "application/llsd+binary"; break; case OSDFormat.Json: default: postData = System.Text.Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(data)); contentType = "application/llsd+json"; break; } BeginGetResponse(postData, contentType, millisecondsTimeout); }
public byte[] RenderMaterialsGetCap(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { MainConsole.Instance.Debug("[MaterialsDemoModule]: GET cap handler"); OSDMap resp = new OSDMap(); int matsCount = 0; OSDArray allOsd = new OSDArray(); foreach (KeyValuePair <UUID, OSDMap> kvp in m_knownMaterials) { OSDMap matMap = new OSDMap(); matMap["ID"] = OSD.FromBinary(kvp.Key.GetBytes()); matMap["Material"] = kvp.Value; allOsd.Add(matMap); matsCount++; } resp["Zipped"] = ZCompressOSD(allOsd, false); MainConsole.Instance.Debug("[MaterialsDemoModule]: matsCount: " + matsCount.ToString()); return(OSDParser.SerializeLLSDBinary(resp)); }
public void SerializeReal() { OSD llsdReal = OSD.FromReal(947835.234d); byte[] binaryRealSerialized = OSDParser.SerializeLLSDBinary(llsdReal); Assert.AreEqual(binaryReal, binaryRealSerialized); }
public void SerializeDictionary() { OSDMap llsdEmptyMap = new OSDMap(); byte[] binaryEmptyMapSerialized = OSDParser.SerializeLLSDBinary(llsdEmptyMap); Assert.AreEqual(binaryEmptyMap, binaryEmptyMapSerialized); OSDMap llsdSimpleMap = new OSDMap(); llsdSimpleMap["test"] = OSD.FromInteger(0); byte[] binarySimpleMapSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleMap); Assert.AreEqual(binarySimpleMap, binarySimpleMapSerialized); OSDMap llsdSimpleMapTwo = new OSDMap(); llsdSimpleMapTwo["t0st"] = OSD.FromInteger(241); llsdSimpleMapTwo["tes1"] = OSD.FromString("aha"); llsdSimpleMapTwo["test"] = new OSD(); byte[] binarySimpleMapTwoSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleMapTwo); // We dont compare here to the original serialized value, because, as maps dont preserve order, // the original serialized value is not *exactly* the same. Instead we compare to a deserialized // version created by this deserializer. OSDMap llsdSimpleMapDeserialized = (OSDMap)OSDParser.DeserializeLLSDBinary(binarySimpleMapTwoSerialized); Assert.AreEqual(OSDType.Map, llsdSimpleMapDeserialized.Type); Assert.AreEqual(3, llsdSimpleMapDeserialized.Count); Assert.AreEqual(OSDType.Integer, llsdSimpleMapDeserialized["t0st"].Type); Assert.AreEqual(241, llsdSimpleMapDeserialized["t0st"].AsInteger()); Assert.AreEqual(OSDType.String, llsdSimpleMapDeserialized["tes1"].Type); Assert.AreEqual("aha", llsdSimpleMapDeserialized["tes1"].AsString()); Assert.AreEqual(OSDType.Unknown, llsdSimpleMapDeserialized["test"].Type); // we also test for a 4byte key character. string xml = "<x>𐄷</x>"; byte[] bytes = Encoding.UTF8.GetBytes(xml); XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); xtr.Read(); xtr.Read(); string content = xtr.ReadString(); OSDMap llsdSimpleMapThree = new OSDMap(); OSD llsdSimpleValue = OSD.FromString(content); llsdSimpleMapThree[content] = llsdSimpleValue; Assert.AreEqual(content, llsdSimpleMapThree[content].AsString()); byte[] binarySimpleMapThree = OSDParser.SerializeLLSDBinary(llsdSimpleMapThree); OSDMap llsdSimpleMapThreeDS = (OSDMap)OSDParser.DeserializeLLSDBinary(binarySimpleMapThree); Assert.AreEqual(OSDType.Map, llsdSimpleMapThreeDS.Type); Assert.AreEqual(1, llsdSimpleMapThreeDS.Count); Assert.AreEqual(content, llsdSimpleMapThreeDS[content].AsString()); }
public void SerializeBool() { OSD llsdTrue = OSD.FromBoolean(true); byte[] binaryTrueSerialized = OSDParser.SerializeLLSDBinary(llsdTrue); Assert.AreEqual(binaryTrue, binaryTrueSerialized); OSD llsdFalse = OSD.FromBoolean(false); byte[] binaryFalseSerialized = OSDParser.SerializeLLSDBinary(llsdFalse); Assert.AreEqual(binaryFalse, binaryFalseSerialized); }
public void SerializeLLSDBinary() { byte[] contentBinString = { 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x20, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xa, 0xd }; OSD llsdBinary = OSD.FromBinary(contentBinString); byte[] binaryBinarySerialized = OSDParser.SerializeLLSDBinary(llsdBinary); Assert.AreEqual(binaryBinString, binaryBinarySerialized); }
public void SaveModuleToArchive(TarArchiveWriter writer, IScene scene) { writer.WriteDir("windlight"); foreach (RegionLightShareData lsd in m_WindlightSettings.Values) { OSDMap map = lsd.ToOSD(); writer.WriteFile("windlight/" + lsd.UUID.ToString(), OSDParser.SerializeLLSDBinary(map)); } }
public void SerializeInteger() { OSD llsdZeroInt = OSD.FromInteger(0); byte[] binaryZeroIntSerialized = OSDParser.SerializeLLSDBinary(llsdZeroInt); Assert.AreEqual(binaryZeroInt, binaryZeroIntSerialized); OSD llsdAnInt = OSD.FromInteger(1234843); byte[] binaryAnIntSerialized = OSDParser.SerializeLLSDBinary(llsdAnInt); Assert.AreEqual(binaryAnInt, binaryAnIntSerialized); }
public void SerializeUUID() { OSD llsdAUUID = OSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); byte[] binaryAUUIDSerialized = OSDParser.SerializeLLSDBinary(llsdAUUID); Assert.AreEqual(binaryAUUID, binaryAUUIDSerialized); OSD llsdZeroUUID = OSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000")); byte[] binaryZeroUUIDSerialized = OSDParser.SerializeLLSDBinary(llsdZeroUUID); Assert.AreEqual(binaryZeroUUID, binaryZeroUUIDSerialized); }
/// <summary> /// Compress an OSD. /// </summary> /// <returns>The compressed OSD</returns> /// <param name="inOsd">In osd.</param> /// <param name="useHeader">If set to <c>true</c> use header.</param> public static OSD ZCompressOSD(OSD inOsd, bool useHeader) { OSD osd; using (MemoryStream msSinkCompressed = new MemoryStream()) { using (ZOutputStream zOut = new ZOutputStream(msSinkCompressed, zlibConst.Z_DEFAULT_COMPRESSION)) { CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut); zOut.finish(); osd = OSD.FromBinary(msSinkCompressed.ToArray()); } } return(osd); }
public static byte[] ZCompressOSD(OSD data) { byte[] ret = null; using (MemoryStream outMemoryStream = new MemoryStream()) using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_BEST_COMPRESSION)) using (Stream inMemoryStream = new MemoryStream(OSDParser.SerializeLLSDBinary(data, false))) { CopyStream(inMemoryStream, outZStream); outZStream.finish(); ret = outMemoryStream.ToArray(); } return(ret); }
public static OSD ZCompressOSD(OSD inOsd, bool useHeader) { OSD osd = null; using (MemoryStream msSinkCompressed = new MemoryStream()) { using (ZOutputStream zOut = new ZOutputStream(msSinkCompressed)) { CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut); msSinkCompressed.Seek(0L, SeekOrigin.Begin); osd = OSD.FromBinary(msSinkCompressed.ToArray()); zOut.Close(); } } return(osd); }
public void SerializeNestedComposite() { OSDArray llsdNested = new OSDArray(); OSDMap llsdMap = new OSDMap(); OSDArray llsdArray = new OSDArray(); llsdArray.Add(OSD.FromInteger(1)); llsdArray.Add(OSD.FromInteger(2)); llsdMap["t0st"] = llsdArray; llsdMap["test"] = OSD.FromString("what"); llsdNested.Add(llsdMap); llsdNested.Add(OSD.FromInteger(124)); llsdNested.Add(OSD.FromInteger(987)); byte[] binaryNestedSerialized = OSDParser.SerializeLLSDBinary(llsdNested); // Because maps don't preserve order, we compare here to a deserialized value. OSDArray llsdNestedDeserialized = (OSDArray)OSDParser.DeserializeLLSDBinary(binaryNestedSerialized); Assert.AreEqual(OSDType.Array, llsdNestedDeserialized.Type); Assert.AreEqual(3, llsdNestedDeserialized.Count); OSDMap llsdMapDeserialized = (OSDMap)llsdNestedDeserialized[0]; Assert.AreEqual(OSDType.Map, llsdMapDeserialized.Type); Assert.AreEqual(2, llsdMapDeserialized.Count); Assert.AreEqual(OSDType.Array, llsdMapDeserialized["t0st"].Type); OSDArray llsdNestedArray = (OSDArray)llsdMapDeserialized["t0st"]; Assert.AreEqual(OSDType.Array, llsdNestedArray.Type); Assert.AreEqual(2, llsdNestedArray.Count); Assert.AreEqual(OSDType.Integer, llsdNestedArray[0].Type); Assert.AreEqual(1, llsdNestedArray[0].AsInteger()); Assert.AreEqual(OSDType.Integer, llsdNestedArray[1].Type); Assert.AreEqual(2, llsdNestedArray[1].AsInteger()); Assert.AreEqual(OSDType.String, llsdMapDeserialized["test"].Type); Assert.AreEqual("what", llsdMapDeserialized["test"].AsString()); Assert.AreEqual(OSDType.Integer, llsdNestedDeserialized[1].Type); Assert.AreEqual(124, llsdNestedDeserialized[1].AsInteger()); Assert.AreEqual(OSDType.Integer, llsdNestedDeserialized[2].Type); Assert.AreEqual(987, llsdNestedDeserialized[2].AsInteger()); }
public static OSD ZCompressOSD(OSD inOsd, bool useHeader) { OSD osd = null; using (MemoryStream msSinkCompressed = new MemoryStream()) { using (Ionic.Zlib.ZlibStream zOut = new Ionic.Zlib.ZlibStream(msSinkCompressed, Ionic.Zlib.CompressionMode.Compress, CompressionLevel.BestCompression, true)) { CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut); zOut.Close(); } msSinkCompressed.Seek(0L, SeekOrigin.Begin); osd = OSD.FromBinary(msSinkCompressed.ToArray()); } return(osd); }
public void TestAddRegion() { RegionInfo info = new RegionInfo { ExternalHostName = "localhost", InternalEndPoint = new System.Net.IPEndPoint(new System.Net.IPAddress(2130706433), 9001), HttpPort = 9000, OutsideIP = "127.0.0.1", RegionID = UUID.Random(), RegionLocX = 1100, RegionLocY = 1000, }; WebRequest req = HttpWebRequest.Create("http://127.0.0.1:9000/region2/regionup"); req.Headers["authorization"] = Util.GenerateHttpAuthorization("key"); req.Timeout = 10000; req.Method = "POST"; byte[] serRegInfo = OSDParser.SerializeLLSDBinary(info.PackRegionInfoData()); var rs = req.GetRequestStream(); rs.Write(serRegInfo, 0, serRegInfo.Length); rs.Flush(); var response = req.GetResponse(); Assert.AreEqual(2, response.ContentLength); StreamReader sr = new StreamReader(response.GetResponseStream()); Assert.AreEqual("OK", sr.ReadToEnd()); var neighbors = srm.GetNeighborsSnapshot(); Assert.AreEqual(1, neighbors.Count); CompareObjects.Equals((SimpleRegionInfo)info, neighbors[0].RegionInfo); Assert.AreEqual(1, stateChangeCounts[NeighborStateChangeType.NeighborUp]); stateChangeCounts.Clear(); }
public void SaveModuleToArchive(TarArchiveWriter writer, IScene scene) { m_log.Info("[Archive]: Writing estates to archive"); writer.WriteDir("estate"); EstateSettings settings = scene.RegionInfo.EstateSettings; string xmlData = WebUtils.BuildXmlResponse(settings.ToKeyValuePairs(true)); writer.WriteFile("estate/" + scene.RegionInfo.RegionName, xmlData); m_log.Info("[Archive]: Finished writing estates to archive"); m_log.Info("[Archive]: Writing region info to archive"); writer.WriteDir("regioninfo"); RegionInfo regionInfo = scene.RegionInfo; writer.WriteFile("regioninfo/" + scene.RegionInfo.RegionName, OSDParser.SerializeLLSDBinary(regionInfo.PackRegionInfoData(true))); m_log.Info("[Archive]: Finished writing region info to archive"); }
public static OSD ZCompressOSD(OSD inOsd, bool useHeader) { OSD osd = null; byte[] data = OSDParser.SerializeLLSDBinary(inOsd, useHeader); using (MemoryStream msSinkCompressed = new MemoryStream()) { using (Ionic.Zlib.ZlibStream zOut = new Ionic.Zlib.ZlibStream(msSinkCompressed, Ionic.Zlib.CompressionMode.Compress, CompressionLevel.BestCompression, true)) { zOut.Write(data, 0, data.Length); } msSinkCompressed.Seek(0L, SeekOrigin.Begin); osd = OSD.FromBinary(msSinkCompressed.ToArray()); } return(osd); }
/// <summary> /// Serializes OSD data for http request /// </summary> /// <param name="data"><seealso cref="OSD"/>formatted data for input</param> /// <param name="format">Format to serialize data to</param> /// <param name="serializedData">Output serialized data as byte array</param> /// <param name="contentType">content-type string of serialized data</param> private void serializeData(OSD data, OSDFormat format, out byte[] serializedData, out string contentType) { switch (format) { case OSDFormat.Xml: serializedData = OSDParser.SerializeLLSDXmlBytes(data); contentType = "application/llsd+xml"; break; case OSDFormat.Binary: serializedData = OSDParser.SerializeLLSDBinary(data); contentType = "application/llsd+binary"; break; case OSDFormat.Json: default: serializedData = System.Text.Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(data)); contentType = "application/llsd+json"; break; } }
public void SerializeLongMessage() { // each 80 chars string sOne = "asdklfjasadlfkjaerotiudfgjkhsdklgjhsdklfghasdfklhjasdfkjhasdfkljahsdfjklaasdfkj8"; string sTwo = "asdfkjlaaweoiugsdfjkhsdfg,.mnasdgfkljhrtuiohfglökajsdfoiwghjkdlaaaaseldkfjgheus9"; OSD stringOne = OSD.FromString(sOne); OSD stringTwo = OSD.FromString(sTwo); OSDMap llsdMap = new OSDMap(); llsdMap["testOne"] = stringOne; llsdMap["testTwo"] = stringTwo; llsdMap["testThree"] = stringOne; llsdMap["testFour"] = stringTwo; llsdMap["testFive"] = stringOne; llsdMap["testSix"] = stringTwo; llsdMap["testSeven"] = stringOne; llsdMap["testEight"] = stringTwo; llsdMap["testNine"] = stringOne; llsdMap["testTen"] = stringTwo; byte[] binaryData = OSDParser.SerializeLLSDBinary(llsdMap); OSDMap llsdMapDS = (OSDMap)OSDParser.DeserializeLLSDBinary(binaryData); Assert.AreEqual(OSDType.Map, llsdMapDS.Type); Assert.AreEqual(10, llsdMapDS.Count); Assert.AreEqual(sOne, llsdMapDS["testOne"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testTwo"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testThree"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testFour"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testFive"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testSix"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testSeven"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testEight"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testNine"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testTen"].AsString()); }
public static OSD ZCompressOSD(OSD inOSD, bool useHeader) { byte[] inData = OSDParser.SerializeLLSDBinary(inOSD, useHeader); OSD osd = null; try { using (MemoryStream outMemoryStream = new MemoryStream()) using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_DEFAULT_COMPRESSION)) using (Stream inMemoryStream = new MemoryStream(inData)) { CopyStream(inMemoryStream, outZStream); outZStream.finish(); osd = OSD.FromBinary(outMemoryStream.ToArray()); } } catch (Exception e) { m_log.Debug("[RenderMaterials]: Exception in ZCompressBytesToOSD: " + e.ToString()); } return(osd); }