コード例 #1
0
ファイル: BinaryLLSDTests.cs プロジェクト: hibecki/workb
        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());
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: OSDJson.cs プロジェクト: RavenB/gridsearch
        public static JsonData SerializeJson(OSD osd, bool preserveDefaults)
        {
            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], preserveDefaults));
                    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;

                        if (preserveDefaults)
                            data = SerializeJson(kvp.Value, preserveDefaults);
                        else
                            data = SerializeJsonNoDefaults(kvp.Value);

                        if (data != null)
                            jsonmap[kvp.Key] = data;
                    }
                    return jsonmap;
                case OSDType.Unknown:
                default:
                    return new JsonData(null);
            }
        }
コード例 #4
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());
        }
コード例 #5
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());
        }
コード例 #6
0
 object ParseJsonNode(OSD node)
 {
     if (node.Type == OSDType.Integer)
     {
         return(new LSL_Integer(node.AsInteger()));
     }
     if (node.Type == OSDType.Boolean)
     {
         return(new LSL_Integer(node.AsBoolean() ? 1 : 0));
     }
     if (node.Type == OSDType.Real)
     {
         return(new LSL_Float(node.AsReal()));
     }
     if (node.Type == OSDType.UUID || node.Type == OSDType.String)
     {
         return(new LSL_String(node.AsString()));
     }
     if (node.Type == OSDType.Array)
     {
         LSL_List resp = new LSL_List();
         OSDArray ar   = node as OSDArray;
         foreach (OSD o in ar)
         {
             resp.Add(ParseJsonNode(o));
         }
         return(resp);
     }
     if (node.Type == OSDType.Map)
     {
         LSL_List resp = new LSL_List();
         OSDMap   ar   = node as OSDMap;
         foreach (KeyValuePair <string, OSD> o in ar)
         {
             resp.Add(new LSL_String(o.Key));
             resp.Add(ParseJsonNode(o.Value));
         }
         return(resp);
     }
     throw new Exception(ScriptBaseClass.JSON_INVALID);
 }
コード例 #7
0
ファイル: WorldBuilding.cs プロジェクト: drzo/opensim4opencog
        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;
            }

        }
コード例 #8
0
ファイル: OSSL_Api.cs プロジェクト: nebadon2025/opensimulator
 private Object osdToObject(OSD decoded)
 {
     if ( decoded is OSDString ) {
         return (string) decoded.AsString();
     } else if ( decoded is OSDInteger ) {
         return (int) decoded.AsInteger();
     } else if ( decoded is OSDReal ) {
         return (float) decoded.AsReal();
     } else if ( decoded is OSDBoolean ) {
         return (bool) decoded.AsBoolean();
     } else if ( decoded is OSDMap ) {
         return osdToHashtable((OSDMap) decoded);
     } else if ( decoded is OSDArray ) {
         return osdToArray((OSDArray) decoded);
     } else {
         return null;
     }
 }
コード例 #9
0
ファイル: OSDJson.cs プロジェクト: RavenB/gridsearch
        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;
            }
        }
コード例 #10
0
ファイル: OSDJson.cs プロジェクト: RavenB/gridsearch
 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();
     }
 }
コード例 #11
0
 private object ParseJsonNode(OSD node)
 {
     if (node.Type == OSDType.Integer)
         return new LSL_Integer(node.AsInteger());
     if (node.Type == OSDType.Boolean)
         return new LSL_Integer(node.AsBoolean() ? 1 : 0);
     if (node.Type == OSDType.Real)
         return new LSL_Float(node.AsReal());
     if (node.Type == OSDType.UUID || node.Type == OSDType.String)
         return new LSL_String(node.AsString());
     if (node.Type == OSDType.Array)
     {
         LSL_List resp = new LSL_List();
         OSDArray ar = node as OSDArray;
         foreach (OSD o in ar)
             resp.Add(ParseJsonNode(o));
         return resp;
     }
     if (node.Type == OSDType.Map)
     {
         LSL_List resp = new LSL_List();
         OSDMap ar = node as OSDMap;
         foreach (KeyValuePair<string, OSD> o in ar)
         {
             resp.Add(new LSL_String(o.Key));
             resp.Add(ParseJsonNode(o.Value));
         }
         return resp;
     }
     throw new Exception(ScriptBaseClass.JSON_INVALID);
 }
コード例 #12
0
ファイル: SyncedProperty.cs プロジェクト: yonglehou/DSG
        /// <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;
            }
        }