Beispiel #1
0
        public void DeserializeReal()
        {
            OSD llsdReal = OSDParser.DeserializeLLSDBinary(binaryReal);

            Assert.AreEqual(OSDType.Real, llsdReal.Type);
            Assert.AreEqual(947835.234d, llsdReal.AsReal());
        }
Beispiel #2
0
        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 static OSD DecompressMeshOSD(byte[] data)
        {
            OSD decodedOsd = null;

            using (MemoryStream inMs = new MemoryStream(data))
            {
                using (MemoryStream outMs = new MemoryStream())
                {
                    using (DeflateStream decompressionStream = new DeflateStream(inMs, CompressionMode.Decompress))
                    {
                        byte[] readBuffer = new byte[2048];
                        inMs.Read(readBuffer, 0, 2); // skip first 2 bytes in header
                        int readLen = 0;

                        while ((readLen = decompressionStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            outMs.Write(readBuffer, 0, readLen);
                        }

                        outMs.Flush();

                        outMs.Seek(0, SeekOrigin.Begin);

                        byte[] decompressedBuf = outMs.GetBuffer();

                        decodedOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
                    }
                }
            }
            return(decodedOsd);
        }
Beispiel #4
0
        public void DeserializeNestedComposite()
        {
            OSD llsdNested = OSDParser.DeserializeLLSDBinary(binaryNested);
            Assert.AreEqual(OSDType.Array, llsdNested.Type);
            OSDArray llsdArray = (OSDArray)llsdNested;
            Assert.AreEqual(3, llsdArray.Count);

            OSDMap llsdMap = (OSDMap)llsdArray[0];
            Assert.AreEqual(OSDType.Map, llsdMap.Type);
            Assert.AreEqual(2, llsdMap.Count);

            OSDArray llsdNestedArray = (OSDArray)llsdMap["t0st"];
            Assert.AreEqual(OSDType.Array, llsdNestedArray.Type);
            OSDInteger llsdNestedIntOne = (OSDInteger)llsdNestedArray[0];
            Assert.AreEqual(OSDType.Integer, llsdNestedIntOne.Type);
            Assert.AreEqual(1, llsdNestedIntOne.AsInteger());
            OSDInteger llsdNestedIntTwo = (OSDInteger)llsdNestedArray[1];
            Assert.AreEqual(OSDType.Integer, llsdNestedIntTwo.Type);
            Assert.AreEqual(2, llsdNestedIntTwo.AsInteger());

            OSDString llsdString = (OSDString)llsdMap["test"];
            Assert.AreEqual(OSDType.String, llsdString.Type);
            Assert.AreEqual("what", llsdString.AsString());

            OSDInteger llsdIntOne = (OSDInteger)llsdArray[1];
            Assert.AreEqual(OSDType.Integer, llsdIntOne.Type);
            Assert.AreEqual(124, llsdIntOne.AsInteger());
            OSDInteger llsdIntTwo = (OSDInteger)llsdArray[2];
            Assert.AreEqual(OSDType.Integer, llsdIntTwo.Type);
            Assert.AreEqual(987, llsdIntTwo.AsInteger());
        }
Beispiel #5
0
        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>&#x196;&#x214;&#x220;&#x228;&#x246;&#x252;</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>&#x10137;</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());
        }
Beispiel #6
0
 public void DeserializeURI()
 {
     OSD llsdURI = OSDParser.DeserializeLLSDBinary(binaryURI);
     Assert.AreEqual(OSDType.URI, llsdURI.Type);
     Uri uri = new Uri("http://www.testurl.test/");
     Assert.AreEqual(uri, llsdURI.AsUri());
 }
        private static OSD DecodeCompressedOSD(byte[] data, int offset, int size)
        {
            try
            {
                using (MemoryStream inMs = new MemoryStream(data, offset, size))
                {
                    /*
                     * Skipping past the first two bytes, which are part of the zlib specification
                     * (RFC 1950), not the deflate specification (RFC 1951). Those bytes contain
                     * information about the compression method and flags.
                     */
                    int streamType  = inMs.ReadByte();
                    int streamFlags = inMs.ReadByte();

                    using (MemoryStream outMs = new MemoryStream())
                    {
                        using (DeflateStream zOut = new DeflateStream(inMs, CompressionMode.Decompress))
                        {
                            zOut.CopyTo(outMs);
                            byte[] decompressedBuf = outMs.ToArray();
                            return(OSDParser.DeserializeLLSDBinary(decompressedBuf) as OSDArray);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[MESH]: exception decoding OSD: {0}", e);
                return(null);
            }
        }
Beispiel #8
0
        /// <summary>
        /// decompresses a gzipped OSD object
        /// </summary>
        /// <param name="decodedOsd"></param> the OSD object
        /// <param name="meshBytes"></param>
        /// <returns></returns>
        private static OSD DecompressOsd(byte[] meshBytes)
        {
            OSD decodedOsd = null;

            using (MemoryStream inMs = new MemoryStream(meshBytes))
            {
                using (MemoryStream outMs = new MemoryStream())
                {
                    using (ZOutputStream zOut = new ZOutputStream(outMs))
                    {
                        byte[] readBuffer = new byte[2048];
                        int    readLen    = 0;
                        while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            zOut.Write(readBuffer, 0, readLen);
                        }
                        zOut.Flush();
                        outMs.Seek(0, SeekOrigin.Begin);

                        byte[] decompressedBuf = outMs.GetBuffer();

                        decodedOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
                    }
                }
            }
            return(decodedOsd);
        }
 private static OSDMap TryExtractOSDMapFromLLSDBinary(ref long start, byte[] bytes)
 {
     using (MemoryStream data = new MemoryStream(bytes))
     {
         try
         {
             OSD osd = OSDParser.DeserializeLLSDBinary(data);
             if (osd is OSDMap)
             {
                 start = data.Position;
                 return((OSDMap)osd);
             }
             else
             {
                 m_log.Warn("[MESH]: unable to cast mesh asset to OSDMap");
                 return(null);
             }
         }
         catch (Exception e)
         {
             m_log.ErrorFormat("[MESH]: Exception deserializing mesh asset header: {0}", e);
             return(null);
         }
     }
 }
Beispiel #10
0
        /// <summary>
        /// decompresses a gzipped OSD object
        /// </summary>
        /// <param name="decodedOsd"></param> the OSD object
        /// <param name="meshBytes"></param>
        /// <returns></returns>
        private static OSD DecompressOsd(byte[] meshBytes)
        {
            OSD decodedOsd = null;

            using (MemoryStream outMs = new MemoryStream())
            {
                using (MemoryStream inMs = new MemoryStream(meshBytes))
                {
                    using (DeflateStream decompressionStream = new DeflateStream(inMs, CompressionMode.Decompress))
                    {
                        byte[] readBuffer = new byte[8192];
                        inMs.Read(readBuffer, 0, 2); // skip first 2 bytes in header
                        int readLen = 0;

                        while ((readLen = decompressionStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            outMs.Write(readBuffer, 0, readLen);
                        }
                    }
                }
                outMs.Seek(0, SeekOrigin.Begin);
                decodedOsd = OSDParser.DeserializeLLSDBinary(outMs);
            }
            return(decodedOsd);
        }
Beispiel #11
0
        void LoadCachedNames()
        {
            WorkPool.QueueUserWorkItem(syncx =>
            {
                try
                {
                    byte[] data       = File.ReadAllBytes(cacheFileName);
                    OSDMap cache      = (OSDMap)OSDParser.DeserializeLLSDBinary(data);
                    OSDArray namesOSD = (OSDArray)cache["names"];
                    DateTime now      = DateTime.Now;
                    TimeSpan maxAge   = new TimeSpan(48, 0, 0);
                    NameMode mode     = (NameMode)(int)instance.GlobalSettings["display_name_mode"];

                    lock (names)
                    {
                        for (int i = 0; i < namesOSD.Count; i++)
                        {
                            AgentDisplayName name = AgentDisplayName.FromOSD(namesOSD[i]);
                            if (mode == NameMode.Standard || ((now - name.Updated) < maxAge))
                            {
                                names[name.ID] = name;
                            }
                        }
                    }

                    Logger.DebugLog(string.Format("Restored {0} names from the avatar name cache", names.Count));
                }
                catch (Exception ex)
                {
                    Logger.Log("Failed loading cached avatar names: ", Helpers.LogLevel.Warning, client, ex);
                }
            });
        }
Beispiel #12
0
        public void DeserializeArray()
        {
            OSD llsdEmptyArray = OSDParser.DeserializeLLSDBinary(binaryEmptyArray);

            Assert.AreEqual(OSDType.Array, llsdEmptyArray.Type);
            OSDArray llsdEmptyArrayArray = (OSDArray)llsdEmptyArray;

            Assert.AreEqual(0, llsdEmptyArrayArray.Count);


            OSD llsdSimpleArray = OSDParser.DeserializeLLSDBinary(binarySimpleArray);

            Assert.AreEqual(OSDType.Array, llsdSimpleArray.Type);
            OSDArray llsdArray = (OSDArray)llsdSimpleArray;

            Assert.AreEqual(OSDType.Integer, llsdArray[0].Type);
            Assert.AreEqual(0, llsdArray[0].AsInteger());


            OSD llsdSimpleArrayTwo = OSDParser.DeserializeLLSDBinary(binarySimpleArrayTwo);

            Assert.AreEqual(OSDType.Array, llsdSimpleArrayTwo.Type);
            OSDArray llsdArrayTwo = (OSDArray)llsdSimpleArrayTwo;

            Assert.AreEqual(2, llsdArrayTwo.Count);

            Assert.AreEqual(OSDType.Integer, llsdArrayTwo[0].Type);
            Assert.AreEqual(0, llsdArrayTwo[0].AsInteger());
            Assert.AreEqual(OSDType.Integer, llsdArrayTwo[1].Type);
            Assert.AreEqual(0, llsdArrayTwo[1].AsInteger());
        }
Beispiel #13
0
        /// <summary>
        /// Unpacks the message sent from a neighboring region and calls the given handler
        /// </summary>
        /// <param name="request"></param>
        /// <param name="httpResponse"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        private string UnpackMessageAndCallHandler(Stream request, OSHttpResponse httpResponse, Action <SimpleRegionInfo> handler)
        {
            try
            {
                byte[] binaryLLSD;
                using (MemoryStream ms = new MemoryStream())
                {
                    request.CopyTo(ms);
                    binaryLLSD = ms.ToArray();
                }

                OSDMap     regionInfoPackage = (OSDMap)OSDParser.DeserializeLLSDBinary(binaryLLSD);
                RegionInfo regionInfo        = new RegionInfo();
                regionInfo.UnpackRegionInfoData(regionInfoPackage);

                handler(regionInfo);

                httpResponse.StatusCode = 200;
                return("OK");
            }
            catch (Exception e)
            {
                httpResponse.StatusCode = 500;
                return("OnHeartbeatReceived: Error: " + e.ToString());
            }
        }
        /// <summary>
        /// decompresses a gzipped OSD object
        /// </summary>
        /// <param name="meshBytes"></param>
        /// <returns></returns>
        static OSD DecompressOsd(byte [] meshBytes)
        {
            OSD decodedOsd = null;

            using (MemoryStream outMs = new MemoryStream()) {
                using (ZOutputStream zOut = new ZOutputStream(outMs)) {
                    using (Stream inMs = new MemoryStream(meshBytes)) {
                        byte [] readBuffer = new byte [meshBytes.Length];
                        int     readLen;

                        while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            zOut.Write(readBuffer, 0, readLen);
                        }
                        zOut.Flush();
                        zOut.finish();

                        byte [] decompressedBuf = outMs.GetBuffer();  //  ToArray();

                        decodedOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
                    }
                }
            }

            return(decodedOsd);
        }
 /// <summary>
 /// Loads the estate settings from an archive.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="filePath">File path.</param>
 /// <param name="type">Type.</param>
 /// <param name="scene">Scene.</param>
 public void LoadModuleFromArchive(byte[] data, string filePath, TarArchiveReader.TarEntryType type, IScene scene)
 {
     if (filePath.StartsWith("estatesettings/"))
     {
         EstateSettings settings = new EstateSettings();
         settings.FromOSD((OSDMap)OSDParser.DeserializeLLSDBinary(data));
         scene.RegionInfo.EstateSettings = settings;
     }
     else if (filePath.StartsWith("regioninfo/"))
     {
         string m_merge =
             MainConsole.Instance.Prompt(
                 "Should we load the region information from the archive (region name, region position, etc)?",
                 "false");
         RegionInfo settings = new RegionInfo();
         settings.UnpackRegionInfoData((OSDMap)OSDParser.DeserializeLLSDBinary(data));
         if (m_merge == "false")
         {
             //Still load the region settings though
             scene.RegionInfo.RegionSettings = settings.RegionSettings;
             return;
         }
         settings.RegionSettings = scene.RegionInfo.RegionSettings;
         settings.EstateSettings = scene.RegionInfo.EstateSettings;
         scene.RegionInfo        = settings;
     }
 }
Beispiel #16
0
 public void DeserializeDateTime()
 {
     OSD llsdDateTime = OSDParser.DeserializeLLSDBinary(binaryDateTime);
     Assert.AreEqual(OSDType.Date, llsdDateTime.Type);
     DateTime dt = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc);
     DateTime dateLocal = llsdDateTime.AsDate();
     Assert.AreEqual(dt, dateLocal.ToUniversalTime());
 }
Beispiel #17
0
        /// <summary>
        /// Decodes mesh asset. See <see cref="OpenMetaverse.Rendering.FacetedMesh.TryDecodeFromAsset"/>
        /// to furter decode it for rendering</summary>
        /// <returns>true</returns>
        public override bool Decode()
        {
            try
            {
                MeshData = new OSDMap();

                using (MemoryStream data = new MemoryStream(AssetData))
                {
                    OSDMap header = (OSDMap)OSDParser.DeserializeLLSDBinary(data);
                    long   start  = data.Position;

                    foreach (string partName in header.Keys)
                    {
                        if (header[partName].Type != OSDType.Map)
                        {
                            MeshData[partName] = header[partName];
                            continue;
                        }

                        OSDMap partInfo = (OSDMap)header[partName];
                        if (partInfo["offset"] < 0 || partInfo["size"] == 0)
                        {
                            MeshData[partName] = partInfo;
                            continue;
                        }

                        byte[] part = new byte[partInfo["size"]];
                        Buffer.BlockCopy(AssetData, partInfo["offset"] + (int)start, part, 0, part.Length);

                        using (MemoryStream input = new MemoryStream(part))
                        {
                            using (MemoryStream output = new MemoryStream())
                            {
                                using (ZOutputStream zout = new ZOutputStream(output))
                                {
                                    byte[] buffer = new byte[2048];
                                    int    len;
                                    while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
                                    {
                                        zout.Write(buffer, 0, len);
                                    }
                                    zout.Flush();
                                    output.Seek(0, SeekOrigin.Begin);
                                    MeshData[partName] = OSDParser.DeserializeLLSDBinary(output);
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log("Failed to decode mesh asset", Helpers.LogLevel.Error, ex);
                return(false);
            }
        }
Beispiel #18
0
        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>&#x10137;</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());
        }
Beispiel #19
0
 public void DeserializeLLSDBinary()
 {
     OSD llsdBytes = OSDParser.DeserializeLLSDBinary(binaryBinString);
     Assert.AreEqual(OSDType.Binary, llsdBytes.Type);
     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 };
     Assert.AreEqual(contentBinString, llsdBytes.AsBinary());
 }
Beispiel #20
0
        public void DeserializeInteger()
        {
            OSD llsdZeroInteger = OSDParser.DeserializeLLSDBinary(binaryZeroInt);
            Assert.AreEqual(OSDType.Integer, llsdZeroInteger.Type);
            Assert.AreEqual(0, llsdZeroInteger.AsInteger());

            OSD llsdAnInteger = OSDParser.DeserializeLLSDBinary(binaryAnInt);
            Assert.AreEqual(OSDType.Integer, llsdAnInteger.Type);
            Assert.AreEqual(1234843, llsdAnInteger.AsInteger());
        }
Beispiel #21
0
        public void DeserializeBool()
        {
            OSD llsdTrue = OSDParser.DeserializeLLSDBinary(binaryTrue);
            Assert.AreEqual(OSDType.Boolean, llsdTrue.Type);
            Assert.AreEqual(true, llsdTrue.AsBoolean());

            OSD llsdFalse = OSDParser.DeserializeLLSDBinary(binaryFalse);
            Assert.AreEqual(OSDType.Boolean, llsdFalse.Type);
            Assert.AreEqual(false, llsdFalse.AsBoolean());
        }
Beispiel #22
0
 public void LoadModuleFromArchive(byte[] data, string filePath, TarArchiveReader.TarEntryType type, IScene scene)
 {
     if (filePath.StartsWith("windlight/"))
     {
         OSDMap map = (OSDMap)OSDParser.DeserializeLLSDBinary(data);
         RegionLightShareData lsd = new RegionLightShareData();
         lsd.FromOSD(map);
         SaveWindLightSettings(lsd.minEffectiveAltitude, lsd);
     }
 }
Beispiel #23
0
        public void DeserializeUUID()
        {
            OSD llsdAUUID = OSDParser.DeserializeLLSDBinary(binaryAUUID);
            Assert.AreEqual(OSDType.UUID, llsdAUUID.Type);
            Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdAUUID.AsString());

            OSD llsdZeroUUID = OSDParser.DeserializeLLSDBinary(binaryZeroUUID);
            Assert.AreEqual(OSDType.UUID, llsdZeroUUID.Type);
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdZeroUUID.AsString());
        }
Beispiel #24
0
        public void DeserializeString()
        {
            OSD llsdEmptyString = OSDParser.DeserializeLLSDBinary(binaryEmptyString);
            Assert.AreEqual(OSDType.String, llsdEmptyString.Type);
            string contentEmptyString = "";
            Assert.AreEqual(contentEmptyString, llsdEmptyString.AsString());

            OSD llsdLongString = OSDParser.DeserializeLLSDBinary(binaryLongString);
            Assert.AreEqual(OSDType.String, llsdLongString.Type);
            string contentLongString = "abcdefghijklmnopqrstuvwxyz01234567890";
            Assert.AreEqual(contentLongString, llsdLongString.AsString());
        }
Beispiel #25
0
        public static OSD ZDecompressOSD(byte[] data)
        {
            OSD ret;

            using (MemoryStream input = new MemoryStream(data))
                using (MemoryStream output = new MemoryStream())
                    using (ZOutputStream zout = new ZOutputStream(output))
                    {
                        CopyStream(input, zout);
                        zout.finish();
                        output.Seek(0, SeekOrigin.Begin);
                        ret = OSDParser.DeserializeLLSDBinary(output);
                    }

            return(ret);
        }
Beispiel #26
0
        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd = null;

            using (MemoryStream msSinkUnCompressed = new MemoryStream())
            {
                using (Ionic.Zlib.ZlibStream zOut = new Ionic.Zlib.ZlibStream(msSinkUnCompressed, CompressionMode.Decompress, true))
                {
                    zOut.Write(input, 0, input.Length);
                }

                msSinkUnCompressed.Seek(0L, SeekOrigin.Begin);
                osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
            }

            return(osd);
        }
        /// <summary>
        /// Decompress bytes to osd.
        /// </summary>
        /// <returns>The decompressed osd.</returns>
        /// <param name="input">Input.</param>
        public static OSD ZDecompressBytesToOsd(byte [] input)
        {
            OSD osd;

            using (MemoryStream msSinkUnCompressed = new MemoryStream()) {
                using (ZOutputStream zOut = new ZOutputStream(msSinkUnCompressed)) {
                    using (Stream inMs = new MemoryStream(input)) {
                        CopyStream(inMs, zOut);
                        zOut.finish();

                        osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
                    }
                }
            }

            return(osd);
        }
Beispiel #28
0
        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd = null;

            using (MemoryStream msSinkUnCompressed = new MemoryStream())
            {
                using (ZInputStream zOut = new ZInputStream(msSinkUnCompressed))
                {
                    zOut.Read(input, 0, input.Length);
                    msSinkUnCompressed.Seek(0L, SeekOrigin.Begin);
                    osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
                    zOut.Close();
                }
            }

            return(osd);
        }
Beispiel #29
0
        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());
        }
Beispiel #30
0
        /// <summary>
        /// Decodes mesh asset.
        /// <returns>OSDMap of all of the submeshes in the mesh. The value of the submesh name
        /// is the uncompressed data for that mesh.
        /// The OSDMap is made up of the asset_header section (which includes a lot of stuff)
        /// plus each of the submeshes unpacked into compressed byte arrays.
        /// </returns>
        public OSDMap UnpackMesh(byte[] assetData)
        {
            OSDMap meshData = new OSDMap();

            try
            {
                using (MemoryStream data = new MemoryStream(assetData))
                {
                    OSDMap header = (OSDMap)OSDParser.DeserializeLLSDBinary(data);
                    meshData["asset_header"] = header;
                    long start = data.Position;

                    foreach (string partName in header.Keys)
                    {
                        if (header[partName].Type != OSDType.Map)
                        {
                            meshData[partName] = header[partName];
                            continue;
                        }

                        OSDMap partInfo = (OSDMap)header[partName];
                        if (partInfo["offset"] < 0 || partInfo["size"] == 0)
                        {
                            meshData[partName] = partInfo;
                            continue;
                        }

                        byte[] part = new byte[partInfo["size"]];
                        Buffer.BlockCopy(assetData, partInfo["offset"] + (int)start, part, 0, part.Length);
                        meshData[partName] = part;
                        // meshData[partName] = Helpers.ZDecompressOSD(part);   // Do decompression at unpack time
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Failed to decode mesh asset", Helpers.LogLevel.Error, ex);
                meshData = null;
            }
            return(meshData);
        }