Exemple #1
0
 /// <summary>
 /// Asserts that the contents of the SDBinary match the values and length
 /// of the supplied byte array
 /// </summary>
 /// <param name="inBinary"></param>
 /// <param name="inExpected"></param>
 private void TestBinary(OSDBinary inBinary, byte[] inExpected)
 {
     byte[] binary = inBinary.AsBinary();
     Assert.AreEqual(inExpected.Length, binary.Length);
     for (int i = 0; i < inExpected.Length; i++)
     {
         if (inExpected[i] != binary[i])
         {
             Assert.Fail("Expected " + inExpected[i].ToString() + " at position " + i.ToString() +
                         " but saw " + binary[i].ToString());
         }
     }
 }
Exemple #2
0
        public void DeserializeBinary()
        {
            OSD       theSD      = null;
            OSDArray  array      = null;
            OSDBinary tempBinary = null;

            String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
            <llsd>
                <array>
                    <binary encoding='base64'>cmFuZG9t</binary>
                    <binary>dGhlIHF1aWNrIGJyb3duIGZveA==</binary>
                    <binary/>
                </array>
            </llsd>";

            //Deserialize the string
            byte[] bytes = Encoding.UTF8.GetBytes(testSD);
            theSD = OSDParser.DeserializeLLSDXml(bytes);

            Assert.IsTrue(theSD is OSDArray);
            array = (OSDArray)theSD;

            Assert.AreEqual(OSDType.Binary, array[0].Type);
            tempBinary = (OSDBinary)array[0];
            byte[] testData1 = { 114, 97, 110, 100, 111, 109 };
            TestBinary(tempBinary, testData1);

            Assert.AreEqual(OSDType.Binary, array[1].Type);
            tempBinary = (OSDBinary)array[1];
            byte[] testData2 = { 116, 104, 101,  32, 113, 117, 105, 99, 107, 32, 98,
                                 114, 111, 119, 110,  32, 102, 111, 120 };
            TestBinary(tempBinary, testData2);

            Assert.AreEqual(OSDType.Binary, array[1].Type);
            tempBinary = (OSDBinary)array[2];
            Assert.AreEqual(0, tempBinary.AsBinary().Length);
        }
 /// <summary>
 /// Asserts that the contents of the SDBinary match the values and length
 /// of the supplied byte array
 /// </summary>
 /// <param name="inBinary"></param>
 /// <param name="inExpected"></param>
 private void TestBinary(OSDBinary inBinary, byte[] inExpected)
 {
     byte[] binary = inBinary.AsBinary();
     Assert.AreEqual(inExpected.Length, binary.Length);
     for (int i = 0; i < inExpected.Length; i++)
     {
         if (inExpected[i] != binary[i])
         {
             Assert.Fail("Expected " + inExpected[i].ToString() + " at position " + i.ToString() +
                 " but saw " + binary[i].ToString());
         }
     }
 }
Exemple #4
0
        //The input, two ODSMaps, are assumed to be packed by AvatarAppearance.Pack(),
        //that is, they each have the fields:
        //serial
        //height
        //wearables
        //textures
        //visualparams
        //attachments
        private bool PropertyValueEquals_AvatarAppearance(OSDMap sceneValue, OSDMap syncValue)
        {
            if (sceneValue.ContainsKey("serial") && syncValue.ContainsKey("serial"))
            {
                if (!sceneValue["serial"].AsInteger().Equals(syncValue["serial"].AsInteger()))
                {
                    return(false);
                }
            }

            if (sceneValue.ContainsKey("height") && syncValue.ContainsKey("height"))
            {
                if (!sceneValue["height"].AsReal().Equals(syncValue["height"].AsReal()))
                {
                    return(false);
                }
            }

            if (sceneValue.ContainsKey("wearables") && syncValue.ContainsKey("wearables"))
            {
                OSDArray sceneWears = (OSDArray)sceneValue["wearables"];
                OSDArray syncWears  = (OSDArray)syncValue["wearables"];

                if (sceneWears.Count != syncWears.Count)
                {
                    return(false);
                }

                if (!sceneWears.ToString().Equals(syncWears.ToString()))
                {
                    return(false);
                }
            }

            if (sceneValue.ContainsKey("textures") && syncValue.ContainsKey("textures"))
            {
                OSDArray sceneTextures = (OSDArray)sceneValue["textures"];
                OSDArray syncTextures  = (OSDArray)syncValue["textures"];

                if (sceneTextures.Count != syncTextures.Count)
                {
                    return(false);
                }

                if (!sceneTextures.ToString().Equals(syncTextures.ToString()))
                {
                    return(false);
                }
            }

            if (sceneValue.ContainsKey("visualparams") && syncValue.ContainsKey("visualparams"))
            {
                OSDBinary sceneTextures = (OSDBinary)sceneValue["visualparams"];
                OSDBinary syncTextures  = (OSDBinary)syncValue["visualparams"];

                byte[] sceneBytes = sceneTextures.AsBinary();
                byte[] syncBytes  = syncTextures.AsBinary();
                if (sceneBytes.Length != syncBytes.Length)
                {
                    return(false);
                }
                for (int i = 0; i < sceneBytes.Length; i++)
                {
                    if (!sceneBytes[i].Equals(syncBytes[i]))
                    {
                        return(false);
                    }
                }
            }

            if (sceneValue.ContainsKey("attachments") && syncValue.ContainsKey("attachments"))
            {
                OSDArray sceneAttachs = (OSDArray)sceneValue["attachments"];
                OSDArray syncAttachs  = (OSDArray)syncValue["attachments"];

                if (sceneAttachs.Count != syncAttachs.Count)
                {
                    return(false);
                }

                if (!sceneAttachs.ToString().Equals(syncAttachs.ToString()))
                {
                    return(false);
                }
            }

            return(true);
        }