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); } }
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; } }
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; } }
/// <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; } }