public void SerializeDateTime() { DateTime dt = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc); LLSD llsdDate = LLSD.FromDate(dt); byte[] binaryDateSerialized = LLSDParser.SerializeBinary(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); LLSD llsdDateOne = LLSD.FromDate(dtOne); byte[] binaryDateOneSerialized = LLSDParser.SerializeBinary(llsdDateOne); LLSD llsdDateOneDS = LLSDParser.DeserializeBinary(binaryDateOneSerialized); Assert.AreEqual(LLSDType.Date, llsdDateOneDS.Type); Assert.AreEqual(dtOne, llsdDateOneDS.AsDate()); DateTime dtTwo = new DateTime(2010, 11, 11, 10, 8, 20, DateTimeKind.Utc); LLSD llsdDateTwo = LLSD.FromDate(dtTwo); byte[] binaryDateTwoSerialized = LLSDParser.SerializeBinary(llsdDateTwo); LLSD llsdDateTwoDS = LLSDParser.DeserializeBinary(binaryDateTwoSerialized); Assert.AreEqual(LLSDType.Date, llsdDateOneDS.Type); Assert.AreEqual(dtTwo.ToLocalTime(), llsdDateTwoDS.AsDate()); }
public void SerializeReal() { LLSD llsdReal = LLSD.FromReal(947835.234d); byte[] binaryRealSerialized = LLSDParser.SerializeBinary(llsdReal); Assert.AreEqual(binaryReal, binaryRealSerialized); }
public void SerializeURI() { LLSD llsdUri = LLSD.FromUri(new Uri("http://www.testurl.test/")); byte[] binaryURISerialized = LLSDParser.SerializeBinary(llsdUri); Assert.AreEqual(binaryURI, binaryURISerialized); }
public void SerializeUndef() { LLSD llsdUndef = new LLSD(); byte[] binaryUndefSerialized = LLSDParser.SerializeBinary(llsdUndef); Assert.AreEqual(binaryUndef, binaryUndefSerialized); }
public void SerializeDictionary() { LLSDMap llsdEmptyMap = new LLSDMap(); byte[] binaryEmptyMapSerialized = LLSDParser.SerializeBinary(llsdEmptyMap); Assert.AreEqual(binaryEmptyMap, binaryEmptyMapSerialized); LLSDMap llsdSimpleMap = new LLSDMap(); llsdSimpleMap["test"] = LLSD.FromInteger(0); byte[] binarySimpleMapSerialized = LLSDParser.SerializeBinary(llsdSimpleMap); Assert.AreEqual(binarySimpleMap, binarySimpleMapSerialized); LLSDMap llsdSimpleMapTwo = new LLSDMap(); llsdSimpleMapTwo["t0st"] = LLSD.FromInteger(241); llsdSimpleMapTwo["tes1"] = LLSD.FromString("aha"); llsdSimpleMapTwo["test"] = new LLSD(); byte[] binarySimpleMapTwoSerialized = LLSDParser.SerializeBinary(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. LLSDMap llsdSimpleMapDeserialized = (LLSDMap)LLSDParser.DeserializeBinary(binarySimpleMapTwoSerialized); Assert.AreEqual(LLSDType.Map, llsdSimpleMapDeserialized.Type); Assert.AreEqual(3, llsdSimpleMapDeserialized.Count); Assert.AreEqual(LLSDType.Integer, llsdSimpleMapDeserialized["t0st"].Type); Assert.AreEqual(241, llsdSimpleMapDeserialized["t0st"].AsInteger()); Assert.AreEqual(LLSDType.String, llsdSimpleMapDeserialized["tes1"].Type); Assert.AreEqual("aha", llsdSimpleMapDeserialized["tes1"].AsString()); Assert.AreEqual(LLSDType.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(); LLSDMap llsdSimpleMapThree = new LLSDMap(); LLSD llsdSimpleValue = LLSD.FromString(content); llsdSimpleMapThree[content] = llsdSimpleValue; Assert.AreEqual(content, llsdSimpleMapThree[content].AsString()); byte[] binarySimpleMapThree = LLSDParser.SerializeBinary(llsdSimpleMapThree); LLSDMap llsdSimpleMapThreeDS = (LLSDMap)LLSDParser.DeserializeBinary(binarySimpleMapThree); Assert.AreEqual(LLSDType.Map, llsdSimpleMapThreeDS.Type); Assert.AreEqual(1, llsdSimpleMapThreeDS.Count); Assert.AreEqual(content, llsdSimpleMapThreeDS[content].AsString()); }
public void SerializeBinary() { 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 }; LLSD llsdBinary = LLSD.FromBinary(contentBinString); byte[] binaryBinarySerialized = LLSDParser.SerializeBinary(llsdBinary); Assert.AreEqual(binaryBinString, binaryBinarySerialized); }
public void SerializeUUID() { LLSD llsdAUUID = LLSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); byte[] binaryAUUIDSerialized = LLSDParser.SerializeBinary(llsdAUUID); Assert.AreEqual(binaryAUUID, binaryAUUIDSerialized); LLSD llsdZeroUUID = LLSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000")); byte[] binaryZeroUUIDSerialized = LLSDParser.SerializeBinary(llsdZeroUUID); Assert.AreEqual(binaryZeroUUID, binaryZeroUUIDSerialized); }
public void SerializeInteger() { LLSD llsdZeroInt = LLSD.FromInteger(0); byte[] binaryZeroIntSerialized = LLSDParser.SerializeBinary(llsdZeroInt); Assert.AreEqual(binaryZeroInt, binaryZeroIntSerialized); LLSD llsdAnInt = LLSD.FromInteger(1234843); byte[] binaryAnIntSerialized = LLSDParser.SerializeBinary(llsdAnInt); Assert.AreEqual(binaryAnInt, binaryAnIntSerialized); }
public void SerializeBool() { LLSD llsdTrue = LLSD.FromBoolean(true); byte[] binaryTrueSerialized = LLSDParser.SerializeBinary(llsdTrue); Assert.AreEqual(binaryTrue, binaryTrueSerialized); LLSD llsdFalse = LLSD.FromBoolean(false); byte[] binaryFalseSerialized = LLSDParser.SerializeBinary(llsdFalse); Assert.AreEqual(binaryFalse, binaryFalseSerialized); }
public void SerializeNestedComposite() { LLSDArray llsdNested = new LLSDArray(); LLSDMap llsdMap = new LLSDMap(); LLSDArray llsdArray = new LLSDArray(); llsdArray.Add(LLSD.FromInteger(1)); llsdArray.Add(LLSD.FromInteger(2)); llsdMap["t0st"] = llsdArray; llsdMap["test"] = LLSD.FromString("what"); llsdNested.Add(llsdMap); llsdNested.Add(LLSD.FromInteger(124)); llsdNested.Add(LLSD.FromInteger(987)); byte[] binaryNestedSerialized = LLSDParser.SerializeBinary(llsdNested); // Because maps don't preserve order, we compare here to a deserialized value. LLSDArray llsdNestedDeserialized = (LLSDArray)LLSDParser.DeserializeBinary(binaryNestedSerialized); Assert.AreEqual(LLSDType.Array, llsdNestedDeserialized.Type); Assert.AreEqual(3, llsdNestedDeserialized.Count); LLSDMap llsdMapDeserialized = (LLSDMap)llsdNestedDeserialized[0]; Assert.AreEqual(LLSDType.Map, llsdMapDeserialized.Type); Assert.AreEqual(2, llsdMapDeserialized.Count); Assert.AreEqual(LLSDType.Array, llsdMapDeserialized["t0st"].Type); LLSDArray llsdNestedArray = (LLSDArray)llsdMapDeserialized["t0st"]; Assert.AreEqual(LLSDType.Array, llsdNestedArray.Type); Assert.AreEqual(2, llsdNestedArray.Count); Assert.AreEqual(LLSDType.Integer, llsdNestedArray[0].Type); Assert.AreEqual(1, llsdNestedArray[0].AsInteger()); Assert.AreEqual(LLSDType.Integer, llsdNestedArray[1].Type); Assert.AreEqual(2, llsdNestedArray[1].AsInteger()); Assert.AreEqual(LLSDType.String, llsdMapDeserialized["test"].Type); Assert.AreEqual("what", llsdMapDeserialized["test"].AsString()); Assert.AreEqual(LLSDType.Integer, llsdNestedDeserialized[1].Type); Assert.AreEqual(124, llsdNestedDeserialized[1].AsInteger()); Assert.AreEqual(LLSDType.Integer, llsdNestedDeserialized[2].Type); Assert.AreEqual(987, llsdNestedDeserialized[2].AsInteger()); }
public void SerializeString() { LLSD llsdString = LLSD.FromString("abcdefghijklmnopqrstuvwxyz01234567890"); byte[] binaryLongStringSerialized = LLSDParser.SerializeBinary(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(); LLSD llsdAString = LLSD.FromString(contentAString); byte[] binaryAString = LLSDParser.SerializeBinary(llsdAString); LLSD llsdAStringDS = LLSDParser.DeserializeBinary(binaryAString); Assert.AreEqual(LLSDType.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(); LLSD llsdStringOne = LLSD.FromString(content); byte[] binaryAStringOneSerialized = LLSDParser.SerializeBinary(llsdStringOne); LLSD llsdStringOneDS = LLSDParser.DeserializeBinary(binaryAStringOneSerialized); Assert.AreEqual(LLSDType.String, llsdStringOneDS.Type); Assert.AreEqual(content, llsdStringOneDS.AsString()); }
public void SerializeArray() { LLSDArray llsdEmptyArray = new LLSDArray(); byte[] binaryEmptyArraySerialized = LLSDParser.SerializeBinary(llsdEmptyArray); Assert.AreEqual(binaryEmptyArray, binaryEmptyArraySerialized); LLSDArray llsdSimpleArray = new LLSDArray(); llsdSimpleArray.Add(LLSD.FromInteger(0)); byte[] binarySimpleArraySerialized = LLSDParser.SerializeBinary(llsdSimpleArray); Assert.AreEqual(binarySimpleArray, binarySimpleArraySerialized); LLSDArray llsdSimpleArrayTwo = new LLSDArray(); llsdSimpleArrayTwo.Add(LLSD.FromInteger(0)); llsdSimpleArrayTwo.Add(LLSD.FromInteger(0)); byte[] binarySimpleArrayTwoSerialized = LLSDParser.SerializeBinary(llsdSimpleArrayTwo); Assert.AreEqual(binarySimpleArrayTwo, binarySimpleArrayTwoSerialized); }
public void SerializeLongMessage() { // each 80 chars string sOne = "asdklfjasadlfkjaerotiudfgjkhsdklgjhsdklfghasdfklhjasdfkjhasdfkljahsdfjklaasdfkj8"; string sTwo = "asdfkjlaaweoiugsdfjkhsdfg,.mnasdgfkljhrtuiohfglökajsdfoiwghjkdlaaaaseldkfjgheus9"; LLSD stringOne = LLSD.FromString(sOne); LLSD stringTwo = LLSD.FromString(sTwo); LLSDMap llsdMap = new LLSDMap(); 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 = LLSDParser.SerializeBinary(llsdMap); LLSDMap llsdMapDS = (LLSDMap)LLSDParser.DeserializeBinary(binaryData); Assert.AreEqual(LLSDType.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 byte[] ToBinary(Packet packet) { return(LLSDParser.SerializeBinary(ToLLSD(packet))); }