Exemplo n.º 1
0
        public void DeserializeUndef()
        {
            String s    = "!";
            OSD    llsd = OSDParser.DeserializeLLSDNotation(s);

            Assert.AreEqual(OSDType.Unknown, llsd.Type);
        }
Exemplo n.º 2
0
        public override Session Deserialize(byte[] bytes)
        {
            OSDMap map = (OSDMap)OSDParser.DeserializeLLSDNotation(OpenMetaverse.Utils.BytesToString(bytes));

            this.Name          = map["Name"].AsString();
            this.Host          = map["Host"].AsString();
            this.ResponseBytes = map["ResponseBytes"].AsBinary();
            this.Direction     = (Direction)map["Direction"].AsInteger();
            this.ContentType   = map["ContentType"].AsString();
            this.Protocol      = map["Protocol"].AsString();
            this.Length        = ResponseBytes.Length;

            if (map.ContainsKey("ResponseHeaders"))
            {
                this.ResponseHeaders = new WebHeaderCollection();
                OSDArray responseHeadersArray = (OSDArray)map["ResponseHeaders"];
                for (int i = 0; i < responseHeadersArray.Count; i++)
                {
                    OSDMap rMap = (OSDMap)responseHeadersArray[i];
                    foreach (string key in rMap.Keys)
                    {
                        this.ResponseHeaders.Add(key, rMap[key].AsString());
                    }
                }
            }
            return(this);
        }
Exemplo n.º 3
0
        public void SerializeDate()
        {
            DateTime dtOne     = new DateTime(2005, 8, 10, 11, 23, 4, DateTimeKind.Utc);
            OSD      llsdOne   = OSD.FromDate(dtOne);
            string   sDtOne    = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD      llsdOneDS = OSDParser.DeserializeLLSDNotation(sDtOne);

            Assert.AreEqual(OSDType.Date, llsdOneDS.Type);
            DateTime dtOneDS = llsdOneDS.AsDate();

            Assert.AreEqual(dtOne, dtOneDS.ToUniversalTime());

            DateTime dtTwo     = new DateTime(2010, 10, 11, 23, 00, 10, 100, DateTimeKind.Utc);
            OSD      llsdTwo   = OSD.FromDate(dtTwo);
            string   sDtTwo    = OSDParser.SerializeLLSDNotation(llsdTwo);
            OSD      llsdTwoDS = OSDParser.DeserializeLLSDNotation(sDtTwo);

            Assert.AreEqual(OSDType.Date, llsdTwoDS.Type);
            DateTime dtTwoDS = llsdTwoDS.AsDate();

            Assert.AreEqual(dtTwo, dtTwoDS.ToUniversalTime());

            // check if a *local* time can be serialized and deserialized
            DateTime dtThree              = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local);
            OSD      llsdDateThree        = OSD.FromDate(dtThree);
            string   sDateThreeSerialized = OSDParser.SerializeLLSDNotation(llsdDateThree);
            OSD      llsdDateThreeDS      = OSDParser.DeserializeLLSDNotation(sDateThreeSerialized);

            Assert.AreEqual(OSDType.Date, llsdDateThreeDS.Type);
            Assert.AreEqual(dtThree, llsdDateThreeDS.AsDate());
        }
Exemplo n.º 4
0
        public void DeserializeReal()
        {
            String realOne = "r1123412345.465711";
            OSD    llsdOne = OSDParser.DeserializeLLSDNotation(realOne);

            Assert.AreEqual(OSDType.Real, llsdOne.Type);
            Assert.AreEqual(1123412345.465711d, llsdOne.AsReal());

            String realTwo = "r-11234684.923411";
            OSD    llsdTwo = OSDParser.DeserializeLLSDNotation(realTwo);

            Assert.AreEqual(OSDType.Real, llsdTwo.Type);
            Assert.AreEqual(-11234684.923411d, llsdTwo.AsReal());

            String realThree = "r1";
            OSD    llsdThree = OSDParser.DeserializeLLSDNotation(realThree);

            Assert.AreEqual(OSDType.Real, llsdThree.Type);
            Assert.AreEqual(1d, llsdThree.AsReal());

            String realFour = "r2.0193899999999998204e-06";
            OSD    llsdFour = OSDParser.DeserializeLLSDNotation(realFour);

            Assert.AreEqual(OSDType.Real, llsdFour.Type);
            Assert.AreEqual(2.0193899999999998204e-06d, llsdFour.AsReal());

            String realFive = "r0";
            OSD    llsdFive = OSDParser.DeserializeLLSDNotation(realFive);

            Assert.AreEqual(OSDType.Real, llsdFive.Type);
            Assert.AreEqual(0d, llsdFive.AsReal());
        }
Exemplo n.º 5
0
        public void SerializeMap()
        {
            OSDMap llsdOne   = new OSDMap();
            string sOne      = OSDParser.SerializeLLSDNotation(llsdOne);
            OSDMap llsdOneDS = (OSDMap)OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.Map, llsdOneDS.Type);
            Assert.AreEqual(0, llsdOneDS.Count);

            OSD    llsdTwo   = OSD.FromInteger(123234);
            OSD    llsdThree = OSD.FromString("asedkfjhaqweiurohzasdf");
            OSDMap llsdFour  = new OSDMap();

            llsdFour["test0"] = llsdTwo;
            llsdFour["test1"] = llsdThree;

            llsdOne["test0"] = llsdTwo;
            llsdOne["test1"] = llsdThree;
            llsdOne["test2"] = llsdFour;

            string sFive    = OSDParser.SerializeLLSDNotation(llsdOne);
            OSDMap llsdFive = (OSDMap)OSDParser.DeserializeLLSDNotation(sFive);

            Assert.AreEqual(OSDType.Map, llsdFive.Type);
            Assert.AreEqual(3, llsdFive.Count);
            Assert.AreEqual(OSDType.Integer, llsdFive["test0"].Type);
            Assert.AreEqual(123234, llsdFive["test0"].AsInteger());
            Assert.AreEqual(OSDType.String, llsdFive["test1"].Type);
            Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdFive["test1"].AsString());

            OSDMap llsdSix = (OSDMap)llsdFive["test2"];

            Assert.AreEqual(OSDType.Map, llsdSix.Type);
            Assert.AreEqual(2, llsdSix.Count);
            Assert.AreEqual(OSDType.Integer, llsdSix["test0"].Type);
            Assert.AreEqual(123234, llsdSix["test0"].AsInteger());
            Assert.AreEqual(OSDType.String, llsdSix["test1"].Type);
            Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdSix["test1"].AsString());

            // We test here also for 4byte characters as map keys
            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 llsdSeven = new OSDMap();

            llsdSeven[content] = OSD.FromString(content);
            string sSeven      = OSDParser.SerializeLLSDNotation(llsdSeven);
            OSDMap llsdSevenDS = (OSDMap)OSDParser.DeserializeLLSDNotation(sSeven);

            Assert.AreEqual(OSDType.Map, llsdSevenDS.Type);
            Assert.AreEqual(1, llsdSevenDS.Count);
            Assert.AreEqual(content, llsdSevenDS[content].AsString());
        }
Exemplo n.º 6
0
        public void DeserializeString()
        {
            string sOne    = "''";
            OSD    llsdOne = OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.String, llsdOne.Type);
            Assert.AreEqual("", llsdOne.AsString());

            // This is double escaping. Once for the encoding, and once for csharp.
            string sTwo    = "'test\\'\"test'";
            OSD    llsdTwo = OSDParser.DeserializeLLSDNotation(sTwo);

            Assert.AreEqual(OSDType.String, llsdTwo.Type);
            Assert.AreEqual("test'\"test", llsdTwo.AsString());

            // "test \\lest"
            char[] cThree = { (char)0x27, (char)0x74, (char)0x65, (char)0x73, (char)0x74, (char)0x20, (char)0x5c,
                              (char)0x5c, (char)0x6c, (char)0x65, (char)0x73, (char)0x74, (char)0x27 };
            string sThree = new string(cThree);

            OSD llsdThree = OSDParser.DeserializeLLSDNotation(sThree);

            Assert.AreEqual(OSDType.String, llsdThree.Type);
            Assert.AreEqual("test \\lest", llsdThree.AsString());

            string sFour    = "'aa\t la'";
            OSD    llsdFour = OSDParser.DeserializeLLSDNotation(sFour);

            Assert.AreEqual(OSDType.String, llsdFour.Type);
            Assert.AreEqual("aa\t la", llsdFour.AsString());

            char[] cFive    = { (char)0x27, (char)0x5c, (char)0x5c, (char)0x27 };
            string sFive    = new String(cFive);
            OSD    llsdFive = OSDParser.DeserializeLLSDNotation(sFive);

            Assert.AreEqual(OSDType.String, llsdFive.Type);
            Assert.AreEqual("\\", llsdFive.AsString());


            string sSix    = "s(10)\"1234567890\"";
            OSD    llsdSix = OSDParser.DeserializeLLSDNotation(sSix);

            Assert.AreEqual(OSDType.String, llsdSix.Type);
            Assert.AreEqual("1234567890", llsdSix.AsString());

            string sSeven    = "s(5)\"\\\\\\\\\\\"";
            OSD    llsdSeven = OSDParser.DeserializeLLSDNotation(sSeven);

            Assert.AreEqual(OSDType.String, llsdSeven.Type);
            Assert.AreEqual("\\\\\\\\\\", llsdSeven.AsString());

            string sEight    = "\"aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh\"";
            OSD    llsdEight = OSDParser.DeserializeLLSDNotation(sEight);

            Assert.AreEqual(OSDType.String, llsdEight.Type);
            Assert.AreEqual("aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh", llsdEight.AsString());
        }
Exemplo n.º 7
0
        public void SerializeUndef()
        {
            OSD    llsd = new OSD();
            string s    = OSDParser.SerializeLLSDNotation(llsd);

            OSD llsdDS = OSDParser.DeserializeLLSDNotation(s);

            Assert.AreEqual(OSDType.Unknown, llsdDS.Type);
        }
Exemplo n.º 8
0
        public void DoSomeStringSerializingActionsAndAsserts(string s)
        {
            OSD    llsdOne   = OSD.FromString(s);
            string sOne      = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD    llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.String, llsdOne.Type);
            Assert.AreEqual(s, llsdOneDS.AsString());
        }
Exemplo n.º 9
0
        public void DeserializeRealWorldExamples()
        {
            string realWorldExample = @"
[
  {'destination':'http://secondlife.com'}, 
  {'version':i1}, 
  {
    'agent_id':u3c115e51-04f4-523c-9fa6-98aff1034730, 
    'session_id':u2c585cec-038c-40b0-b42e-a25ebab4d132, 
    'circuit_code':i1075, 
    'first_name':'Phoenix', 
    'last_name':'Linden',
    'position':[r70.9247,r254.378,r38.7304], 
    'look_at':[r-0.043753,r-0.999042,r0], 
    'granters':[ua2e76fcd-9360-4f6d-a924-000000000003],
    'attachment_data':
    [
      {
        'attachment_point':i2,
        'item_id':ud6852c11-a74e-309a-0462-50533f1ef9b3,
        'asset_id':uc69b29b1-8944-58ae-a7c5-2ca7b23e22fb
      },
      {
        'attachment_point':i10, 
        'item_id':uff852c22-a74e-309a-0462-50533f1ef900,
        'asset_id':u5868dd20-c25a-47bd-8b4c-dedc99ef9479
      }
    ]
  }
]";
            // We dont do full testing here. We are fine if a few values are right
            // and the parser doesnt throw an exception
            OSDArray llsdArray = (OSDArray)OSDParser.DeserializeLLSDNotation(realWorldExample);

            Assert.AreEqual(OSDType.Array, llsdArray.Type);
            Assert.AreEqual(3, llsdArray.Count);

            OSDMap llsdMapOne = (OSDMap)llsdArray[0];

            Assert.AreEqual(OSDType.Map, llsdMapOne.Type);
            Assert.AreEqual("http://secondlife.com", llsdMapOne["destination"].AsString());

            OSDMap llsdMapTwo = (OSDMap)llsdArray[1];

            Assert.AreEqual(OSDType.Map, llsdMapTwo.Type);
            Assert.AreEqual(OSDType.Integer, llsdMapTwo["version"].Type);
            Assert.AreEqual(1, llsdMapTwo["version"].AsInteger());

            OSDMap llsdMapThree = (OSDMap)llsdArray[2];

            Assert.AreEqual(OSDType.UUID, llsdMapThree["session_id"].Type);
            Assert.AreEqual("2c585cec-038c-40b0-b42e-a25ebab4d132", llsdMapThree["session_id"].AsString());
            Assert.AreEqual(OSDType.UUID, llsdMapThree["agent_id"].Type);
            Assert.AreEqual("3c115e51-04f4-523c-9fa6-98aff1034730", llsdMapThree["agent_id"].AsString());
        }
Exemplo n.º 10
0
        public void DeserializeDate()
        {
            string sDateOne = "d\"2007-12-31T20:49:10Z\"";
            OSD    llsdOne  = OSDParser.DeserializeLLSDNotation(sDateOne);

            Assert.AreEqual(OSDType.Date, llsdOne.Type);
            DateTime dt   = new DateTime(2007, 12, 31, 20, 49, 10, 0, DateTimeKind.Utc);
            DateTime dtDS = llsdOne.AsDate();

            Assert.AreEqual(dt, dtDS.ToUniversalTime());
        }
Exemplo n.º 11
0
        public void SerializeBinary()
        {
            byte[] binary = { 0x0,  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b,
                              0x0b, 0x0c, 0x0d, 0x0e, 0x0f };

            OSD    llsdBinary        = OSD.FromBinary(binary);
            string sBinarySerialized = OSDParser.SerializeLLSDNotation(llsdBinary);
            OSD    llsdBinaryDS      = OSDParser.DeserializeLLSDNotation(sBinarySerialized);

            Assert.AreEqual(OSDType.Binary, llsdBinaryDS.Type);
            Assert.AreEqual(binary, llsdBinaryDS.AsBinary());
        }
Exemplo n.º 12
0
        public override Session Deserialize(byte[] bytes)
        {
            OSDMap map = (OSDMap)OSDParser.DeserializeLLSDNotation(OpenMetaverse.Utils.BytesToString(bytes));

            this.Host        = map["Host"].AsString();
            this.Direction   = (Direction)map["Direction"].AsInteger();
            this.ContentType = map["ContentType"].AsString();

            byte[] packetData = map["PacketBytes"].AsBinary();
            this.Length = packetData.Length;

            int packetEnd = packetData.Length - 1;

            try
            {
                bool msg_zer = ((packetData[0] & Helpers.MSG_ZEROCODED) != 0);
                bool msg_res = ((packetData[0] & Helpers.MSG_RESENT) != 0);
                bool msg_rel = ((packetData[0] & Helpers.MSG_RELIABLE) != 0);
                bool msg_ack = ((packetData[0] & Helpers.MSG_APPENDED_ACKS) != 0);

                if ((packetData[0] & Helpers.MSG_ZEROCODED) != 0)
                {
                    packetData[0] = 0x00;
                }

                this.Packet = Packet.BuildPacket(packetData, ref packetEnd, null);

                this.Packet.Header.Resent       = msg_res;
                this.Packet.Header.Reliable     = msg_rel;
                this.Packet.Header.Zerocoded    = msg_zer;
                this.Packet.Header.AppendedAcks = msg_ack;

                this.Name = this.Packet.Type.ToString();
            }
            catch (IndexOutOfRangeException ex)
            {
                this.Name = ex.Message;
            }
            catch (MalformedDataException ex)
            {
                this.Name = ex.Message;
                //throw;
            }
            catch (NullReferenceException ex)
            {
                this.Name = ex.Message;
            }

            return(this);
        }
Exemplo n.º 13
0
        public void DeserializeURI()
        {
            string sUriOne = "l\"http://test.com/test test>\\\"/&yes\"";
            OSD    llsdOne = OSDParser.DeserializeLLSDNotation(sUriOne);

            Assert.AreEqual(OSDType.URI, llsdOne.Type);
            Assert.AreEqual("http://test.com/test%20test%3E%22/&yes", llsdOne.AsString());

            string sUriTwo = "l\"test/test/test?test=1&toast=2\"";
            OSD    llsdTwo = OSDParser.DeserializeLLSDNotation(sUriTwo);

            Assert.AreEqual(OSDType.URI, llsdTwo.Type);
            Assert.AreEqual("test/test/test?test=1&toast=2", llsdTwo.AsString());
        }
Exemplo n.º 14
0
        public void DeserializeUUID()
        {
            String uuidOne = "u97f4aeca-88a1-42a1-b385-b97b18abb255";
            OSD    llsdOne = OSDParser.DeserializeLLSDNotation(uuidOne);

            Assert.AreEqual(OSDType.UUID, llsdOne.Type);
            Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOne.AsString());

            String uuidTwo = "u00000000-0000-0000-0000-000000000000";
            OSD    llsdTwo = OSDParser.DeserializeLLSDNotation(uuidTwo);

            Assert.AreEqual(OSDType.UUID, llsdTwo.Type);
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwo.AsString());
        }
Exemplo n.º 15
0
        public override Session Deserialize(byte[] bytes)
        {
            OSDMap map = (OSDMap)OSDParser.DeserializeLLSDNotation(OpenMetaverse.Utils.BytesToString(bytes));

            this.Name        = map["Name"].AsString();
            this.Host        = map["Host"].AsString();
            this.Data        = map["Data"].AsString();
            this.Length      = this.Data.ToString().Length;
            this.Direction   = (Direction)map["Direction"].AsInteger();
            this.ContentType = map["ContentType"].AsString();
            this.Protocol    = map["Protocol"].AsString();

            return(this);
        }
Exemplo n.º 16
0
        public void DeserializeInteger()
        {
            string integerOne = "i12319423";
            OSD    llsdOne    = OSDParser.DeserializeLLSDNotation(integerOne);

            Assert.AreEqual(OSDType.Integer, llsdOne.Type);
            Assert.AreEqual(12319423, llsdOne.AsInteger());

            string integerTwo = "i-489234";
            OSD    llsdTwo    = OSDParser.DeserializeLLSDNotation(integerTwo);

            Assert.AreEqual(OSDType.Integer, llsdTwo.Type);
            Assert.AreEqual(-489234, llsdTwo.AsInteger());
        }
Exemplo n.º 17
0
        public void SerializeFormattedTest()
        {
            // This is not a real test. Instead look at the console.out tab for how formatted notation looks like.
            OSDArray llsdArray = new OSDArray();
            OSD      llsdOne   = OSD.FromInteger(1);
            OSD      llsdTwo   = OSD.FromInteger(1);

            llsdArray.Add(llsdOne);
            llsdArray.Add(llsdTwo);

            string sOne = OSDParser.SerializeLLSDNotationFormatted(llsdArray);

            OSDMap llsdMap   = new OSDMap();
            OSD    llsdThree = OSD.FromInteger(2);

            llsdMap["test1"] = llsdThree;
            OSD llsdFour = OSD.FromInteger(2);

            llsdMap["test2"] = llsdFour;

            llsdArray.Add(llsdMap);

            string sTwo = OSDParser.SerializeLLSDNotationFormatted(llsdArray);

            OSDArray llsdArrayTwo = new OSDArray();
            OSD      llsdFive     = OSD.FromString("asdflkhjasdhj");
            OSD      llsdSix      = OSD.FromString("asdkfhasjkldfghsd");

            llsdArrayTwo.Add(llsdFive);
            llsdArrayTwo.Add(llsdSix);

            llsdMap["test3"] = llsdArrayTwo;

            string sThree = OSDParser.SerializeLLSDNotationFormatted(llsdArray);

            // we also try to parse this... and look a little at the results
            OSDArray llsdSeven = (OSDArray)OSDParser.DeserializeLLSDNotation(sThree);

            Assert.AreEqual(OSDType.Array, llsdSeven.Type);
            Assert.AreEqual(3, llsdSeven.Count);
            Assert.AreEqual(OSDType.Integer, llsdSeven[0].Type);
            Assert.AreEqual(1, llsdSeven[0].AsInteger());
            Assert.AreEqual(OSDType.Integer, llsdSeven[1].Type);
            Assert.AreEqual(1, llsdSeven[1].AsInteger());

            Assert.AreEqual(OSDType.Map, llsdSeven[2].Type);
            // thats enough for now.
        }
Exemplo n.º 18
0
        public void DeserializeArray()
        {
            string   sArrayOne    = "[]";
            OSDArray llsdArrayOne = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayOne);

            Assert.AreEqual(OSDType.Array, llsdArrayOne.Type);
            Assert.AreEqual(0, llsdArrayOne.Count);

            string   sArrayTwo    = "[ i0 ]";
            OSDArray llsdArrayTwo = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayTwo);

            Assert.AreEqual(OSDType.Array, llsdArrayTwo.Type);
            Assert.AreEqual(1, llsdArrayTwo.Count);
            OSDInteger llsdIntOne = (OSDInteger)llsdArrayTwo[0];

            Assert.AreEqual(OSDType.Integer, llsdIntOne.Type);
            Assert.AreEqual(0, llsdIntOne.AsInteger());

            string   sArrayThree    = "[ i0, i1 ]";
            OSDArray llsdArrayThree = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayThree);

            Assert.AreEqual(OSDType.Array, llsdArrayThree.Type);
            Assert.AreEqual(2, llsdArrayThree.Count);
            OSDInteger llsdIntTwo = (OSDInteger)llsdArrayThree[0];

            Assert.AreEqual(OSDType.Integer, llsdIntTwo.Type);
            Assert.AreEqual(0, llsdIntTwo.AsInteger());
            OSDInteger llsdIntThree = (OSDInteger)llsdArrayThree[1];

            Assert.AreEqual(OSDType.Integer, llsdIntThree.Type);
            Assert.AreEqual(1, llsdIntThree.AsInteger());

            string   sArrayFour    = " [ \"testtest\", \"aha\",t,f,i1, r1.2, [ i1] ] ";
            OSDArray llsdArrayFour = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayFour);

            Assert.AreEqual(OSDType.Array, llsdArrayFour.Type);
            Assert.AreEqual(7, llsdArrayFour.Count);
            Assert.AreEqual("testtest", llsdArrayFour[0].AsString());
            Assert.AreEqual("aha", llsdArrayFour[1].AsString());
            Assert.AreEqual(true, llsdArrayFour[2].AsBoolean());
            Assert.AreEqual(false, llsdArrayFour[3].AsBoolean());
            Assert.AreEqual(1, llsdArrayFour[4].AsInteger());
            Assert.AreEqual(1.2d, llsdArrayFour[5].AsReal());
            Assert.AreEqual(OSDType.Array, llsdArrayFour[6].Type);
            OSDArray llsdArrayFive = (OSDArray)llsdArrayFour[6];

            Assert.AreEqual(1, llsdArrayFive[0].AsInteger());
        }
Exemplo n.º 19
0
        public void SerializeUUID()
        {
            OSD    llsdOne   = OSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255"));
            string sOne      = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD    llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.UUID, llsdOneDS.Type);
            Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOneDS.AsString());

            OSD    llsdTwo   = OSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000"));
            string sTwo      = OSDParser.SerializeLLSDNotation(llsdTwo);
            OSD    llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo);

            Assert.AreEqual(OSDType.UUID, llsdTwoDS.Type);
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwoDS.AsString());
        }
Exemplo n.º 20
0
        public void SerializeInteger()
        {
            OSD    llsdOne   = OSD.FromInteger(12319423);
            string sOne      = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD    llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.Integer, llsdOneDS.Type);
            Assert.AreEqual(12319423, llsdOne.AsInteger());

            OSD    llsdTwo   = OSD.FromInteger(-71892034);
            string sTwo      = OSDParser.SerializeLLSDNotation(llsdTwo);
            OSD    llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo);

            Assert.AreEqual(OSDType.Integer, llsdTwoDS.Type);
            Assert.AreEqual(-71892034, llsdTwoDS.AsInteger());
        }
Exemplo n.º 21
0
        public void SerializeBoolean()
        {
            OSD    llsdTrue   = OSD.FromBoolean(true);
            string sTrue      = OSDParser.SerializeLLSDNotation(llsdTrue);
            OSD    llsdTrueDS = OSDParser.DeserializeLLSDNotation(sTrue);

            Assert.AreEqual(OSDType.Boolean, llsdTrueDS.Type);
            Assert.AreEqual(true, llsdTrueDS.AsBoolean());

            OSD    llsdFalse   = OSD.FromBoolean(false);
            string sFalse      = OSDParser.SerializeLLSDNotation(llsdFalse);
            OSD    llsdFalseDS = OSDParser.DeserializeLLSDNotation(sFalse);

            Assert.AreEqual(OSDType.Boolean, llsdFalseDS.Type);
            Assert.AreEqual(false, llsdFalseDS.AsBoolean());
        }
Exemplo n.º 22
0
 public bool DeserializeFromFile(string fileName)
 {
     if (File.Exists(fileName))
     {
         try
         {
             OSDMap map = (OSDMap)OSDParser.DeserializeLLSDNotation(File.ReadAllText(fileName));
             this.Deserialize(map);
             return(true);
         }
         catch (Exception e)
         {
             Console.WriteLine("Exception Deserializing From File: {0} {1}", e.Message, e.StackTrace);
         }
     }
     return(false);
 }
Exemplo n.º 23
0
        public override Session Deserialize(byte[] bytes)
        {
            OSDMap map = (OSDMap)OSDParser.DeserializeLLSDNotation(OpenMetaverse.Utils.BytesToString(bytes));

            this.Host        = map["Host"].AsString();
            this.Direction   = (Direction)map["Direction"].AsInteger();
            this.ContentType = map["ContentType"].AsString();

            byte[] packetData = map["PacketBytes"].AsBinary();
            this.Length = packetData.Length;

            int packetEnd = packetData.Length;

            this.Packet = Packet.BuildPacket(packetData, ref packetEnd, null);
            this.Name   = this.Packet.Type.ToString();
            return(this);
        }
Exemplo n.º 24
0
        public void SerializeURI()
        {
            Uri    uriOne    = new Uri("http://test.org/test test>\\\"/&yes\"", UriKind.RelativeOrAbsolute);
            OSD    llsdOne   = OSD.FromUri(uriOne);
            string sUriOne   = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD    llsdOneDS = OSDParser.DeserializeLLSDNotation(sUriOne);

            Assert.AreEqual(OSDType.URI, llsdOneDS.Type);
            Assert.AreEqual(uriOne, llsdOneDS.AsUri());

            Uri    uriTwo    = new Uri("test/test/near/the/end?test=1", UriKind.RelativeOrAbsolute);
            OSD    llsdTwo   = OSD.FromUri(uriTwo);
            string sUriTwo   = OSDParser.SerializeLLSDNotation(llsdTwo);
            OSD    llsdTwoDS = OSDParser.DeserializeLLSDNotation(sUriTwo);

            Assert.AreEqual(OSDType.URI, llsdTwoDS.Type);
            Assert.AreEqual(uriTwo, llsdTwoDS.AsUri());
        }
Exemplo n.º 25
0
        public void SerializeReal()
        {
            OSD    llsdOne   = OSD.FromReal(12987234.723847d);
            string sOne      = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD    llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.Real, llsdOneDS.Type);
            Assert.AreEqual(12987234.723847d, llsdOneDS.AsReal());

            OSD    llsdTwo   = OSD.FromReal(-32347892.234234d);
            string sTwo      = OSDParser.SerializeLLSDNotation(llsdTwo);
            OSD    llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo);

            Assert.AreEqual(OSDType.Real, llsdTwoDS.Type);
            Assert.AreEqual(-32347892.234234d, llsdTwoDS.AsReal());

            OSD    llsdThree   = OSD.FromReal(Double.MaxValue);
            string sThree      = OSDParser.SerializeLLSDNotation(llsdThree);
            OSD    llsdThreeDS = OSDParser.DeserializeLLSDNotation(sThree);

            Assert.AreEqual(OSDType.Real, llsdThreeDS.Type);
            Assert.AreEqual(Double.MaxValue, llsdThreeDS.AsReal());

            OSD    llsdFour   = OSD.FromReal(Double.MinValue);
            string sFour      = OSDParser.SerializeLLSDNotation(llsdFour);
            OSD    llsdFourDS = OSDParser.DeserializeLLSDNotation(sFour);

            Assert.AreEqual(OSDType.Real, llsdFourDS.Type);
            Assert.AreEqual(Double.MinValue, llsdFourDS.AsReal());

            OSD    llsdFive   = OSD.FromReal(-1.1123123E+50d);
            string sFive      = OSDParser.SerializeLLSDNotation(llsdFive);
            OSD    llsdFiveDS = OSDParser.DeserializeLLSDNotation(sFive);

            Assert.AreEqual(OSDType.Real, llsdFiveDS.Type);
            Assert.AreEqual(-1.1123123E+50d, llsdFiveDS.AsReal());

            OSD    llsdSix   = OSD.FromReal(2.0193899999999998204e-06);
            string sSix      = OSDParser.SerializeLLSDNotation(llsdSix);
            OSD    llsdSixDS = OSDParser.DeserializeLLSDNotation(sSix);

            Assert.AreEqual(OSDType.Real, llsdSixDS.Type);
            Assert.AreEqual(2.0193899999999998204e-06, llsdSixDS.AsReal());
        }
Exemplo n.º 26
0
        public static Vector3 ParseVector3(string key, OSDMap reply)
        {
            OSD osd;

            if (reply.TryGetValue(key, out osd))
            {
                if (osd.Type == OSDType.Array)
                {
                    return(((OSDArray)osd).AsVector3());
                }
                else if (osd.Type == OSDType.String)
                {
                    OSDArray array = (OSDArray)OSDParser.DeserializeLLSDNotation(osd.AsString());
                    return(array.AsVector3());
                }
            }

            return(Vector3.Zero);
        }
Exemplo n.º 27
0
        public void DeserializeMap()
        {
            string sMapOne    = " { } ";
            OSDMap llsdMapOne = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapOne);

            Assert.AreEqual(OSDType.Map, llsdMapOne.Type);
            Assert.AreEqual(0, llsdMapOne.Count);

            string sMapTwo    = " { \"test\":i2 } ";
            OSDMap llsdMapTwo = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapTwo);

            Assert.AreEqual(OSDType.Map, llsdMapTwo.Type);
            Assert.AreEqual(1, llsdMapTwo.Count);
            Assert.AreEqual(OSDType.Integer, llsdMapTwo["test"].Type);
            Assert.AreEqual(2, llsdMapTwo["test"].AsInteger());

            string sMapThree    = " { 'test':\"testtesttest\", 'aha':\"muahahaha\" , \"anywhere\":! } ";
            OSDMap llsdMapThree = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapThree);

            Assert.AreEqual(OSDType.Map, llsdMapThree.Type);
            Assert.AreEqual(3, llsdMapThree.Count);
            Assert.AreEqual(OSDType.String, llsdMapThree["test"].Type);
            Assert.AreEqual("testtesttest", llsdMapThree["test"].AsString());
            Assert.AreEqual(OSDType.String, llsdMapThree["test"].Type);
            Assert.AreEqual("muahahaha", llsdMapThree["aha"].AsString());
            Assert.AreEqual(OSDType.Unknown, llsdMapThree["self"].Type);

            string sMapFour    = " { 'test' : { 'test' : i1, 't0st' : r2.5 }, 'tist' : \"hello world!\", 'tast' : \"last\" } ";
            OSDMap llsdMapFour = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapFour);

            Assert.AreEqual(OSDType.Map, llsdMapFour.Type);
            Assert.AreEqual(3, llsdMapFour.Count);
            Assert.AreEqual("hello world!", llsdMapFour["tist"].AsString());
            Assert.AreEqual("last", llsdMapFour["tast"].AsString());
            OSDMap llsdMapFive = (OSDMap)llsdMapFour["test"];

            Assert.AreEqual(OSDType.Map, llsdMapFive.Type);
            Assert.AreEqual(2, llsdMapFive.Count);
            Assert.AreEqual(OSDType.Integer, llsdMapFive["test"].Type);
            Assert.AreEqual(1, llsdMapFive["test"].AsInteger());
            Assert.AreEqual(OSDType.Real, llsdMapFive["t0st"].Type);
            Assert.AreEqual(2.5d, llsdMapFive["t0st"].AsReal());
        }
Exemplo n.º 28
0
        public void LLSDTerseParsing()
        {
            string testOne   = "[r0.99967899999999998428,r-0.025334599999999998787,r0]";
            string testTwo   = "[[r1,r1,r1],r0]";
            string testThree = "{'region_handle':[r255232, r256512], 'position':[r33.6, r33.71, r43.13], 'look_at':[r34.6, r33.71, r43.13]}";

            OSD obj = OSDParser.DeserializeLLSDNotation(testOne);

            Assert.IsInstanceOf <OSDArray>(obj, "Expected SDArray, got " + obj.GetType().ToString());
            OSDArray array = (OSDArray)obj;

            Assert.IsTrue(array.Count == 3, "Expected three contained objects, got " + array.Count);
            Assert.IsTrue(array[0].AsReal() > 0.9d && array[0].AsReal() < 1.0d, "Unexpected value for first real " + array[0].AsReal());
            Assert.IsTrue(array[1].AsReal() < 0.0d && array[1].AsReal() > -0.03d, "Unexpected value for second real " + array[1].AsReal());
            Assert.IsTrue(array[2].AsReal() == 0.0d, "Unexpected value for third real " + array[2].AsReal());

            obj = OSDParser.DeserializeLLSDNotation(testTwo);
            Assert.IsInstanceOf <OSDArray>(obj, "Expected SDArray, got " + obj.GetType().ToString());
            array = (OSDArray)obj;
            Assert.IsTrue(array.Count == 2, "Expected two contained objects, got " + array.Count);
            Assert.IsTrue(array[1].AsReal() == 0.0d, "Unexpected value for real " + array[1].AsReal());
            obj = array[0];
            Assert.IsInstanceOf <OSDArray>(obj, "Expected ArrayList, got " + obj.GetType().ToString());
            array = (OSDArray)obj;
            Assert.IsTrue(array[0].AsReal() == 1.0d && array[1].AsReal() == 1.0d && array[2].AsReal() == 1.0d,
                          "Unexpected value(s) for nested array: " + array[0].AsReal() + ", " + array[1].AsReal() + ", " +
                          array[2].AsReal());

            obj = OSDParser.DeserializeLLSDNotation(testThree);
            Assert.IsInstanceOf <OSDMap>(obj, "Expected LLSDMap, got " + obj.GetType().ToString());
            OSDMap hashtable = (OSDMap)obj;

            Assert.IsTrue(hashtable.Count == 3, "Expected three contained objects, got " + hashtable.Count);
            Assert.IsInstanceOf <OSDArray>(hashtable["region_handle"]);
            Assert.IsTrue(((OSDArray)hashtable["region_handle"]).Count == 2);
            Assert.IsInstanceOf <OSDArray>(hashtable["position"]);
            Assert.IsTrue(((OSDArray)hashtable["position"]).Count == 3);
            Assert.IsInstanceOf <OSDArray>(hashtable["look_at"]);
            Assert.IsTrue(((OSDArray)hashtable["look_at"]).Count == 3);
        }
Exemplo n.º 29
0
        public void SerializeArray()
        {
            OSDArray llsdOne   = new OSDArray();
            string   sOne      = OSDParser.SerializeLLSDNotation(llsdOne);
            OSDArray llsdOneDS = (OSDArray)OSDParser.DeserializeLLSDNotation(sOne);

            Assert.AreEqual(OSDType.Array, llsdOneDS.Type);
            Assert.AreEqual(0, llsdOneDS.Count);

            OSD      llsdTwo   = OSD.FromInteger(123234);
            OSD      llsdThree = OSD.FromString("asedkfjhaqweiurohzasdf");
            OSDArray llsdFour  = new OSDArray();

            llsdFour.Add(llsdTwo);
            llsdFour.Add(llsdThree);

            llsdOne.Add(llsdTwo);
            llsdOne.Add(llsdThree);
            llsdOne.Add(llsdFour);

            string   sFive    = OSDParser.SerializeLLSDNotation(llsdOne);
            OSDArray llsdFive = (OSDArray)OSDParser.DeserializeLLSDNotation(sFive);

            Assert.AreEqual(OSDType.Array, llsdFive.Type);
            Assert.AreEqual(3, llsdFive.Count);
            Assert.AreEqual(OSDType.Integer, llsdFive[0].Type);
            Assert.AreEqual(123234, llsdFive[0].AsInteger());
            Assert.AreEqual(OSDType.String, llsdFive[1].Type);
            Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdFive[1].AsString());

            OSDArray llsdSix = (OSDArray)llsdFive[2];

            Assert.AreEqual(OSDType.Array, llsdSix.Type);
            Assert.AreEqual(2, llsdSix.Count);
            Assert.AreEqual(OSDType.Integer, llsdSix[0].Type);
            Assert.AreEqual(123234, llsdSix[0].AsInteger());
            Assert.AreEqual(OSDType.String, llsdSix[1].Type);
            Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdSix[1].AsString());
        }
Exemplo n.º 30
0
        public void DeserializeBoolean()
        {
            String t     = "true";
            OSD    llsdT = OSDParser.DeserializeLLSDNotation(t);

            Assert.AreEqual(OSDType.Boolean, llsdT.Type);
            Assert.AreEqual(true, llsdT.AsBoolean());

            String tTwo     = "t";
            OSD    llsdTTwo = OSDParser.DeserializeLLSDNotation(tTwo);

            Assert.AreEqual(OSDType.Boolean, llsdTTwo.Type);
            Assert.AreEqual(true, llsdTTwo.AsBoolean());

            String tThree     = "TRUE";
            OSD    llsdTThree = OSDParser.DeserializeLLSDNotation(tThree);

            Assert.AreEqual(OSDType.Boolean, llsdTThree.Type);
            Assert.AreEqual(true, llsdTThree.AsBoolean());

            String tFour     = "T";
            OSD    llsdTFour = OSDParser.DeserializeLLSDNotation(tFour);

            Assert.AreEqual(OSDType.Boolean, llsdTFour.Type);
            Assert.AreEqual(true, llsdTFour.AsBoolean());

            String tFive     = "1";
            OSD    llsdTFive = OSDParser.DeserializeLLSDNotation(tFive);

            Assert.AreEqual(OSDType.Boolean, llsdTFive.Type);
            Assert.AreEqual(true, llsdTFive.AsBoolean());

            String f     = "false";
            OSD    llsdF = OSDParser.DeserializeLLSDNotation(f);

            Assert.AreEqual(OSDType.Boolean, llsdF.Type);
            Assert.AreEqual(false, llsdF.AsBoolean());

            String fTwo     = "f";
            OSD    llsdFTwo = OSDParser.DeserializeLLSDNotation(fTwo);

            Assert.AreEqual(OSDType.Boolean, llsdFTwo.Type);
            Assert.AreEqual(false, llsdFTwo.AsBoolean());

            String fThree     = "FALSE";
            OSD    llsdFThree = OSDParser.DeserializeLLSDNotation(fThree);

            Assert.AreEqual(OSDType.Boolean, llsdFThree.Type);
            Assert.AreEqual(false, llsdFThree.AsBoolean());

            String fFour     = "F";
            OSD    llsdFFour = OSDParser.DeserializeLLSDNotation(fFour);

            Assert.AreEqual(OSDType.Boolean, llsdFFour.Type);
            Assert.AreEqual(false, llsdFFour.AsBoolean());

            String fFive     = "0";
            OSD    llsdFFive = OSDParser.DeserializeLLSDNotation(fFive);

            Assert.AreEqual(OSDType.Boolean, llsdFFive.Type);
            Assert.AreEqual(false, llsdFFive.AsBoolean());
        }