Exemplo n.º 1
0
 public static IPAddress ToIP(OSD osd)
 {
     byte[] binary = osd.AsBinary();
     if (binary != null && binary.Length == 4)
         return new IPAddress(binary);
     else
         return IPAddress.Any;
 }
Exemplo n.º 2
0
 private uint ReadUIntVal(OSD obj)
 {
     byte[] tmp = obj.AsBinary();
     if (BitConverter.IsLittleEndian)
     {
         Array.Reverse(tmp);
     }
     return(Utils.BytesToUInt(tmp));
 }
Exemplo n.º 3
0
 private uint readuintval(OSD obj)
 {
     byte[] tmp = obj.AsBinary();
     if (BitConverter.IsLittleEndian)
     {
         Array.Reverse(tmp);
     }
     return(OpenMetaverse.Utils.BytesToUInt(tmp));
 }
Exemplo n.º 4
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());
 }
        public static object SerializeLisp(OSD osd)
        {
            switch (osd.Type)
            {
            case OSDType.Unknown:
                throw new InvalidCastException();

            case OSDType.Boolean:
                return(osd.AsBoolean());

            case OSDType.Integer:
                return(osd.AsInteger());

            case OSDType.Real:
                return(osd.AsReal());

            case OSDType.String:
                return(osd.AsString());

            case OSDType.Date:
                return(osd.AsDate());

            case OSDType.URI:
                return(osd.AsUri());

            case OSDType.UUID:
                return(osd.AsUUID());

            case OSDType.Binary:
                return(osd.AsBinary());

            case OSDType.Array:
                OSDArray args = (OSDArray)osd;
                Cons     ret  = null;
                for (int i = args.Count - 1; i >= 0; --i)
                {
                    ret = new Cons(args[i], ret);
                }
                return(ret);

            case OSDType.Map:
                Cons   list = null;
                OSDMap map  = (OSDMap)osd;
                foreach (KeyValuePair <string, OSD> kvp in map)
                {
                    Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value)));
                    list = new Cons(kv, list);
                }
                return(Cons.Reverse(list));

            default:
                return(osd);
            }
        }
Exemplo n.º 6
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());
        }
 public static IPAddress ToIP(OSD osd)
 {
     byte[] binary = osd.AsBinary();
     if (binary != null && binary.Length == 4)
     {
         return(new IPAddress(binary));
     }
     else
     {
         return(IPAddress.Any);
     }
 }
Exemplo n.º 8
0
 public static JsonData SerializeJson(OSD osd)
 {
     switch (osd.Type)
     {
         case OSDType.Boolean:
             return new JsonData(osd.AsBoolean());
         case OSDType.Integer:
             return new JsonData(osd.AsInteger());
         case OSDType.Real:
             return new JsonData(osd.AsReal());
         case OSDType.String:
         case OSDType.Date:
         case OSDType.URI:
         case OSDType.UUID:
             return new JsonData(osd.AsString());
         case OSDType.Binary:
             byte[] binary = osd.AsBinary();
             JsonData jsonbinarray = new JsonData();
             jsonbinarray.SetJsonType(JsonType.Array);
             for (int i = 0; i < binary.Length; i++)
                 jsonbinarray.Add(new JsonData(binary[i]));
             return jsonbinarray;
         case OSDType.Array:
             JsonData jsonarray = new JsonData();
             jsonarray.SetJsonType(JsonType.Array);
             OSDArray array = (OSDArray)osd;
             for (int i = 0; i < array.Count; i++)
                 jsonarray.Add(SerializeJson(array[i]));
             return jsonarray;
         case OSDType.Map:
             JsonData jsonmap = new JsonData();
             jsonmap.SetJsonType(JsonType.Object);
             OSDMap map = (OSDMap)osd;
             foreach (KeyValuePair<string, OSD> kvp in map)
                 jsonmap[kvp.Key] = SerializeJson(kvp.Value);
             return jsonmap;
         case OSDType.Unknown:
         default:
             return new JsonData();
     }
 }
Exemplo n.º 9
0
        public static object SerializeLisp(OSD osd)
        {
            switch (osd.Type)
            {
                case OSDType.Unknown:
                    throw new InvalidCastException();
                case OSDType.Boolean:
                    return osd.AsBoolean();
                case OSDType.Integer:
                    return osd.AsInteger();
                case OSDType.Real:
                    return osd.AsReal();
                case OSDType.String:
                    return osd.AsString();
                case OSDType.Date:
                    return osd.AsDate();
                case OSDType.URI:
                    return osd.AsUri();
                case OSDType.UUID:
                    return osd.AsUUID();

                case OSDType.Binary:
                    return osd.AsBinary();
                case OSDType.Array:
                    OSDArray args = (OSDArray) osd;
                    Cons ret = null;
                    for (int i = args.Count - 1; i >= 0; --i)
                    {
                        ret = new Cons(args[i], ret);
                    }
                    return ret;
                case OSDType.Map:
                    Cons list = null;
                    OSDMap map = (OSDMap) osd;
                    foreach (KeyValuePair<string, OSD> kvp in map)
                    {
                        Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value)));
                        list = new Cons(kv,list);
                    }
                    return Cons.Reverse(list);
                default:
                    return osd;
            }

        }
Exemplo n.º 10
0
        private static void SerializeLLSDBinaryElement(MemoryStream stream, OSD osd)
        {
            switch (osd.Type)
            {
                case OSDType.Unknown:
                    stream.WriteByte(undefBinaryValue);
                    break;
                case OSDType.Boolean:
                    stream.Write(osd.AsBinary(), 0, 1);
                    break;
                case OSDType.Integer:
                    stream.WriteByte(integerBinaryMarker);
                    stream.Write(osd.AsBinary(), 0, int32Length);
                    break;
                case OSDType.Real:
                    stream.WriteByte(realBinaryMarker);
                    stream.Write(osd.AsBinary(), 0, doubleLength);
                    break;
                case OSDType.UUID:
                    stream.WriteByte(uuidBinaryMarker);
                    stream.Write(osd.AsBinary(), 0, 16);
                    break;
                case OSDType.String:
                    stream.WriteByte(stringBinaryMarker);
                    byte[] rawString = osd.AsBinary();
                    byte[] stringLengthNetEnd = HostToNetworkIntBytes(rawString.Length);
                    stream.Write(stringLengthNetEnd, 0, int32Length);
                    stream.Write(rawString, 0, rawString.Length);
                    break;
                case OSDType.Binary:
                    stream.WriteByte(binaryBinaryMarker);
                    byte[] rawBinary = osd.AsBinary();
                    byte[] binaryLengthNetEnd = HostToNetworkIntBytes(rawBinary.Length);
                    stream.Write(binaryLengthNetEnd, 0, int32Length);
                    stream.Write(rawBinary, 0, rawBinary.Length);
                    break;
                case OSDType.Date:
                    stream.WriteByte(dateBinaryMarker);
                    stream.Write(osd.AsBinary(), 0, doubleLength);
                    break;
                case OSDType.URI:
                    stream.WriteByte(uriBinaryMarker);
                    byte[] rawURI = osd.AsBinary();
                    byte[] uriLengthNetEnd = HostToNetworkIntBytes(rawURI.Length);
                    stream.Write(uriLengthNetEnd, 0, int32Length);
                    stream.Write(rawURI, 0, rawURI.Length);
                    break;
                case OSDType.Array:
                    SerializeLLSDBinaryArray(stream, (OSDArray)osd);
                    break;
                case OSDType.Map:
                    SerializeLLSDBinaryMap(stream, (OSDMap)osd);
                    break;
                default:
                    throw new OSDException("Binary serialization: Not existing element discovered.");

            }
        }
Exemplo n.º 11
0
        private uint readuintval(OSD obj)
        {
            byte[] tmp = obj.AsBinary();
            if (BitConverter.IsLittleEndian)
                Array.Reverse(tmp);
            return OpenMetaverse.Utils.BytesToUInt(tmp);

        }
Exemplo n.º 12
0
        private static JsonData SerializeJsonNoDefaults(OSD osd)
        {
            switch (osd.Type)
            {
                case OSDType.Boolean:
                    bool b = osd.AsBoolean();
                    if (!b)
                        return null;

                    return new JsonData(b);
                case OSDType.Integer:
                    int v = osd.AsInteger();
                    if (v == 0)
                        return null;

                    return new JsonData(v);
                case OSDType.Real:
                    double d = osd.AsReal();
                    if (d == 0.0d)
                        return null;

                    return new JsonData(d);
                case OSDType.String:
                case OSDType.Date:
                case OSDType.URI:
                    string str = osd.AsString();
                    if (String.IsNullOrEmpty(str))
                        return null;

                    return new JsonData(str);
                case OSDType.UUID:
                    UUID uuid = osd.AsUUID();
                    if (uuid == UUID.Zero)
                        return null;

                    return new JsonData(uuid.ToString());
                case OSDType.Binary:
                    byte[] binary = osd.AsBinary();
                    if (binary == Utils.EmptyBytes)
                        return null;

                    JsonData jsonbinarray = new JsonData();
                    jsonbinarray.SetJsonType(JsonType.Array);
                    for (int i = 0; i < binary.Length; i++)
                        jsonbinarray.Add(new JsonData(binary[i]));
                    return jsonbinarray;
                case OSDType.Array:
                    JsonData jsonarray = new JsonData();
                    jsonarray.SetJsonType(JsonType.Array);
                    OSDArray array = (OSDArray)osd;
                    for (int i = 0; i < array.Count; i++)
                        jsonarray.Add(SerializeJson(array[i]));
                    return jsonarray;
                case OSDType.Map:
                    JsonData jsonmap = new JsonData();
                    jsonmap.SetJsonType(JsonType.Object);
                    OSDMap map = (OSDMap)osd;
                    foreach (KeyValuePair<string, OSD> kvp in map)
                    {
                        JsonData data = SerializeJsonNoDefaults(kvp.Value);
                        if (data != null)
                            jsonmap[kvp.Key] = data;
                    }
                    return jsonmap;
                case OSDType.Unknown:
                default:
                    return null;
            }
        }
Exemplo n.º 13
0
 public static JsonData SerializeJson(OSD osd)
 {
     switch (osd.Type)
     {
         case OSDType.Boolean:
             return new JsonData(osd.AsBoolean());
         case OSDType.Integer:
             return new JsonData(osd.AsInteger());
         case OSDType.Real:
             return new JsonData(osd.AsReal());
         case OSDType.String:
             return new JsonData(osd.AsString());
         case OSDType.Date:
             return new JsonData("date::" + osd.AsString());
         case OSDType.URI:
             return new JsonData("uri::" + osd.AsString());
         case OSDType.UUID:
             return new JsonData("uuid::" + osd.AsString());
         case OSDType.Binary:
             return new JsonData("b64::" + Convert.ToBase64String(osd.AsBinary()));
         case OSDType.Array:
             JsonData jsonarray = new JsonData();
             jsonarray.SetJsonType(JsonType.Array);
             OSDArray array = (OSDArray)osd;
             for (int i = 0; i < array.Count; i++)
                 jsonarray.Add(SerializeJson(array[i]));
             return jsonarray;
         case OSDType.Map:
             JsonData jsonmap = new JsonData();
             jsonmap.SetJsonType(JsonType.Object);
             OSDMap map = (OSDMap)osd;
             foreach (KeyValuePair<string, OSD> kvp in map)
                 jsonmap[kvp.Key] = SerializeJson(kvp.Value);
             return jsonmap;
         case OSDType.Unknown:
         default:
             return new JsonData();
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Set member values by decoding out of propertyData. Should only
        /// be called in initialization time (e.g. from constructor).
        /// </summary>
        /// <param name="propertyData"></param>
        private void FromOSDArray(OSDArray propertyData)
        {
            Property            = (SyncableProperties.Type)(propertyData[0].AsInteger());
            LastUpdateTimeStamp = propertyData[1].AsLong();
            LastUpdateSyncID    = propertyData[2].AsString();

            OSD value = propertyData[3];

            switch (Property)
            {
            ///////////////////////////////////////
            // Complex structure properties
            ///////////////////////////////////////
            case SyncableProperties.Type.AgentCircuitData:
            case SyncableProperties.Type.AvatarAppearance:
                LastUpdateValue = (OSDMap)value;
                break;

            case SyncableProperties.Type.Animations:
                LastUpdateValue = (OSDArray)value;
                break;

            ////////////////////////////
            // Integer/enum type properties
            ////////////////////////////
            case SyncableProperties.Type.CreationDate:              // int
            case SyncableProperties.Type.LinkNum:                   // int
            case SyncableProperties.Type.OwnershipCost:             // int
            case SyncableProperties.Type.SalePrice:                 // int
            case SyncableProperties.Type.ScriptAccessPin:           // int
            case SyncableProperties.Type.AggregateScriptEvents:     // enum
            case SyncableProperties.Type.Flags:                     // enum
            case SyncableProperties.Type.LocalFlags:                // enum
            case SyncableProperties.Type.PresenceType:              // enum
                LastUpdateValue = value.AsInteger();
                break;

            case SyncableProperties.Type.ClickAction:
            case SyncableProperties.Type.Material:
            case SyncableProperties.Type.ObjectSaleType:
                LastUpdateValue = (byte)value.AsInteger();
                break;

            ////////////////////////////
            // Boolean type properties
            ////////////////////////////
            case SyncableProperties.Type.AllowedDrop:
            case SyncableProperties.Type.IsAttachment:
            case SyncableProperties.Type.PassTouches:
            case SyncableProperties.Type.VolumeDetectActive:
            case SyncableProperties.Type.Flying:
            case SyncableProperties.Type.IsColliding:
            case SyncableProperties.Type.CollidingGround:
            case SyncableProperties.Type.Kinematic:
            case SyncableProperties.Type.IsSelected:
            case SyncableProperties.Type.AllowMovement:
                LastUpdateValue = value.AsBoolean();
                break;

            ////////////////////////////
            // Vector3 type properties
            ////////////////////////////
            case SyncableProperties.Type.AngularVelocity:
            case SyncableProperties.Type.AttachedPos:
            case SyncableProperties.Type.GroupPosition:
            case SyncableProperties.Type.OffsetPosition:
            case SyncableProperties.Type.Scale:
            case SyncableProperties.Type.SitTargetPosition:
            case SyncableProperties.Type.SitTargetPositionLL:
            case SyncableProperties.Type.SOP_Acceleration:
            case SyncableProperties.Type.Velocity:
            case SyncableProperties.Type.Force:
            case SyncableProperties.Type.PA_Acceleration:
            case SyncableProperties.Type.PA_Velocity:
            case SyncableProperties.Type.PA_TargetVelocity:
            case SyncableProperties.Type.Position:
            case SyncableProperties.Type.RotationalVelocity:
            case SyncableProperties.Type.Size:
            case SyncableProperties.Type.Torque:
            case SyncableProperties.Type.AbsolutePosition:
                LastUpdateValue = value.AsVector3();
                break;

            ////////////////////////////
            // UUID type properties
            ////////////////////////////
            case SyncableProperties.Type.AttachedAvatar:
            case SyncableProperties.Type.CollisionSound:
            case SyncableProperties.Type.CreatorID:
            case SyncableProperties.Type.FolderID:
            case SyncableProperties.Type.GroupID:
            case SyncableProperties.Type.LastOwnerID:
            case SyncableProperties.Type.OwnerID:
            case SyncableProperties.Type.Sound:
                LastUpdateValue = value.AsUUID();
                break;

            ////////////////////////////
            // UInt type properties
            ////////////////////////////
            case SyncableProperties.Type.LocalId:
            case SyncableProperties.Type.AttachmentPoint:
            case SyncableProperties.Type.BaseMask:
            case SyncableProperties.Type.Category:
            case SyncableProperties.Type.EveryoneMask:
            case SyncableProperties.Type.GroupMask:
            case SyncableProperties.Type.InventorySerial:
            case SyncableProperties.Type.NextOwnerMask:
            case SyncableProperties.Type.OwnerMask:
            case SyncableProperties.Type.AgentControlFlags:
            case SyncableProperties.Type.ParentId:
                LastUpdateValue = value.AsUInteger();
                break;

            ////////////////////////////
            // Float type properties
            ////////////////////////////
            case SyncableProperties.Type.CollisionSoundVolume:
            case SyncableProperties.Type.Buoyancy:
                LastUpdateValue = (float)value.AsReal();
                break;

            ////////////////////////////
            // String type properties
            ////////////////////////////
            case SyncableProperties.Type.Color:
            case SyncableProperties.Type.CreatorData:
            case SyncableProperties.Type.Description:
            case SyncableProperties.Type.MediaUrl:
            case SyncableProperties.Type.Name:
            case SyncableProperties.Type.RealRegion:
            case SyncableProperties.Type.Shape:
            case SyncableProperties.Type.SitName:
            case SyncableProperties.Type.TaskInventory:
            case SyncableProperties.Type.Text:
            case SyncableProperties.Type.TouchName:
                LastUpdateValue = value.AsString();
                break;

            ////////////////////////////
            // byte[] (binary data) type properties
            ////////////////////////////
            case SyncableProperties.Type.ParticleSystem:
            case SyncableProperties.Type.TextureAnimation:
                LastUpdateValue = value.AsBinary();
                break;

            ////////////////////////////
            // Quaternion type properties
            ////////////////////////////
            case SyncableProperties.Type.RotationOffset:
            case SyncableProperties.Type.SitTargetOrientation:
            case SyncableProperties.Type.SitTargetOrientationLL:
            case SyncableProperties.Type.Orientation:
            case SyncableProperties.Type.Rotation:
                LastUpdateValue = value.AsQuaternion();
                break;

            default:
                DebugLog.WarnFormat("[SYNCED PROPERTY] FromOSDArray: No handler for property {0} ", Property);
                break;
            }
        }