Exemple #1
0
 public void OnReadAll(IDataWriter <int> dataWriter)
 {
     for (int i = 0; i < dbDataReader.FieldCount; i++)
     {
         ValueInterface.WriteValue(dataWriter[i], dbDataReader[i]);
     }
 }
Exemple #2
0
        public void XObjectTest()
        {
            var rw = XObjectRW.Create <ObjectTester>();

            AreEqual(rw.Content, null);

            AreEqual(rw.Count, 2);

            AreEqual(rw.ContentType, typeof(ObjectTester));

            rw.Initialize();

            AreNotEqual(rw.Content, null);

            AreEqual(((ObjectTester)rw.Content).Id, 0);
            AreEqual(((ObjectTester)rw.Content).Name, null);

            rw["@id"].WriteInt32(123);
            rw["@name"].WriteString("Dogwei");

            AreEqual(((ObjectTester)rw.Content).Id, 123);
            AreEqual(((ObjectTester)rw.Content).Name, "Dogwei");

            AreEqual(rw["@id"].ReadInt32(), 123);
            AreEqual(rw["@name"].ReadString(), "Dogwei");

            IsTrue(
                ValueInterface <Dictionary <string, object> > .ReadValue(ValueCopyer.ValueOf(rw)) is Dictionary <string, object> dic &&
                dic.Count == 2 &&
                (int)dic["@id"] == 123 &&
                (string)dic["@name"] == "Dogwei"
                );
        }
 public static object DeserializeObject(string text, Type type)
 {
     fixed(char *chars = text)
     {
         return(ValueInterface.GetInterface(type).Read(new JsonDeserializer(chars, 0, text.Length)));
     }
 }
Exemple #4
0
        public FSharpOption <T> ReadValue(IValueReader valueReader)
        {
            if (default(T) != null)
            {
                var obj = NullableInterface.Read(valueReader);

                if (obj is null)
                {
                    return(FSharpOption <T> .None);
                }

                return((T)obj);
            }
            else
            {
                var val = ValueInterface <T> .ReadValue(valueReader);

                if (val == null)
                {
                    return(FSharpOption <T> .None);
                }

                return(val);
            }
        }
Exemple #5
0
 public static object DeserializeObject(string text, Type type, JsonFormatterOptions options = JsonFormatterOptions.Default)
 {
     fixed(char *chars = text)
     {
         return(ValueInterface.GetInterface(type).ReadValue(new JsonDeserializer(chars, 0, text.Length, options)));
     }
 }
Exemple #6
0
        public byte[] ReadBinary()
        {
            var length = TryReadBinaryHead();

            if (length >= 0)
            {
                var result = new byte[length];

                ReadBinary(ref result[0], length);

                return(result);
            }

            if (TryReadNull())
            {
                return(null);
            }

            if (IsArrayHead())
            {
                return(ValueInterface <byte[]> .ReadValue(this));
            }

            return((byte[])Convert.ChangeType(DirectRead(), typeof(byte[])));
        }
Exemple #7
0
 static FSharpOptionInterface()
 {
     if (default(T) != null)
     {
         NullableInterface = ValueInterface.GetInterface(typeof(Nullable <>).MakeGenericType(typeof(T)));
     }
 }
Exemple #8
0
        public void ReadMap <TKey>(IDataWriter <TKey> mapWriter)
        {
            var length = TryReadMapHead();

            if (length >= 0)
            {
                mapWriter.Initialize(length);

                for (int i = 0; i < length; i++)
                {
                    mapWriter.OnWriteValue(ValueInterface <TKey> .ReadValue(this), this);
                }

                return;
            }

            if (TryReadNull())
            {
                return;
            }

            if (IsArrayHead())
            {
                ReadArray(mapWriter.As <int>());

                return;
            }

            throw new InvalidOperationException("The msgpack node is not a map.");
        }
Exemple #9
0
 public void OnReadAll(IDataWriter <string> dataWriter)
 {
     for (int i = 0; i < dbDataReader.FieldCount; i++)
     {
         ValueInterface.WriteValue(dataWriter[dbDataReader.GetName(i)], dbDataReader[i]);
     }
 }
Exemple #10
0
        public void ReaderTest()
        {
            var hGCache = new HGlobalCache <char>();

            JsonFormatter.SerializeObject(new object[] { 123, "Dogwei", true, null, new { Id = 123 } }, hGCache);

            var jsonReader = JsonFormatter.CreateJsonReader(hGCache);

            AreEqual(jsonReader.GetToken(), JsonToken.Array);
            AreEqual(jsonReader.TryReadBeginArray(), true);

            AreEqual(jsonReader.TryReadEndArray(), false);
            AreEqual(jsonReader.GetToken(), JsonToken.Number);
            AreEqual(jsonReader.ReadInt32(), 123);

            AreEqual(jsonReader.TryReadEndArray(), false);
            AreEqual(jsonReader.GetToken(), JsonToken.String);
            AreEqual(jsonReader.ReadString(), "Dogwei");

            AreEqual(jsonReader.TryReadEndArray(), false);
            AreEqual(jsonReader.GetToken(), JsonToken.Boolean);
            AreEqual(jsonReader.ReadBoolean(), true);

            AreEqual(jsonReader.TryReadEndArray(), false);
            AreEqual(jsonReader.GetToken(), JsonToken.Null);
            AreEqual(jsonReader.DirectRead(), null);

            AreEqual(jsonReader.TryReadEndArray(), false);
            AreEqual(jsonReader.GetToken(), JsonToken.Object);
            AreEqual(JsonFormatter.SerializeObject(ValueInterface <Dictionary <string, object> > .ReadValue(jsonReader)), "{\"Id\":123}");

            AreEqual(jsonReader.TryReadEndArray(), true);
            AreEqual(jsonReader.GetToken(), JsonToken.End);
        }
        public static object DeserializeObject(char *chars, int length, Type type, JsonFormatterOptions options)
        {
            if ((options & JsonFormatterOptions.MultiReferencingReference) != 0)
            {
                var jsonDeserializer = new JsonReferenceDeserializer(chars, length);

                var result = ValueInterface.GetInterface(type).Read(jsonDeserializer);

                if (jsonDeserializer.references.Count != 0)
                {
                    ReferenceInfo.ProcessReference(result, jsonDeserializer.references);

                    if (jsonDeserializer.updateBase)
                    {
                        result = RWHelper.GetContent <object>(jsonDeserializer.writer);

                        result = Convert.ChangeType(result, type);
                    }
                }

                return(result);
            }

            return(DeserializeObject(chars, length, type));
        }
Exemple #12
0
 public object Deserialize(string text, Type type)
 {
     fixed(char *chars = text)
     {
         return(ValueInterface.GetInterface(type).ReadValue(new JsonDeserializer(chars, 0, text.Length, Options)));
     }
 }
Exemple #13
0
        internal static object ReadArray(IValueReader valueReader, Type type)
        {
            var items = ValueInterface.ReadValue(valueReader, GetArrayValueType(type));

            Underlying.GetMethodTablePointer(items) = TypeHelper.GetMethodTablePointer(type);

            return(items);
        }
Exemple #14
0
        public static void SerializeObject <T>(T value, HGlobalCache <char> hGCache)
        {
            var jsonSerializer = new JsonSerializer <JsonSerializeModes.SimpleMode>(hGCache, DefaultMaxDepth);

            ValueInterface <T> .WriteValue(jsonSerializer, value);

            jsonSerializer.Flush();
        }
Exemple #15
0
        internal static void WriteArray(IValueWriter valueWriter, object value, Type type)
        {
            var items = Underlying.As <Array>(value).Clone();

            Underlying.GetMethodTablePointer(items) = TypeHelper.GetMethodTablePointer(GetArrayValueType(type));

            ValueInterface.WriteValue(valueWriter, items);
        }
        public static void SerializeObject <T>(T value, HGlobalCache <byte> hGCache)
        {
            var messagePackSerializer = new MessagePackSerializer <MessagePackSerializeModes.StandardMode>(hGCache, DefaultMaxDepth);

            ValueInterface <T> .WriteValue(messagePackSerializer, value);

            messagePackSerializer.Flush();
        }
Exemple #17
0
        public IValueWriter this[TKey key]
        {
            get
            {
                ValueInterface <TKey> .WriteValue(serializer, key);

                return(serializer);
            }
        }
Exemple #18
0
        public T?ReadNullable <T>() where T : struct
        {
            if ((RandomInstance.Next() & 3) == 3)
            {
                return(null);
            }

            return(ValueInterface <T> .ReadValue(this));
        }
        private protected override void InitializeByRef(PropertyInfo propertyInfo, XBindingFlags flags)
        {
            base.InitializeByRef(propertyInfo, flags);

            _get = null;
            _set = null;

            @interface = ValueInterface.GetInterface(propertyInfo.PropertyType.GetElementType());
        }
Exemple #20
0
        public T?ReadNullable <T>() where T : struct
        {
            if (TryReadNull())
            {
                return(null);
            }

            return(ValueInterface <T> .ReadValue(this));
        }
        public void OnReadValue(object obj, IValueWriter valueWriter)
        {
            Assert(CanRead, "get");

            var value = _get(ref GetRef(obj));

            Console.WriteLine(value);

            ValueInterface <TValue> .WriteValue(valueWriter, value);
        }
        object Deserialize <TMode>(byte *bytes, int length, Type type, MessagePackFormatterOptions options) where TMode : struct
        {
            var deserializer = new MessagePackDeserializer <TMode>(this, bytes, length, MaxDepth, options);

            if (typeof(TMode) == typeof(MessagePackDeserializeModes.ReferenceMode))
            {
                deserializer.InitReferences();
            }

            return(ValueInterface.GetInterface(type).Read(deserializer));
        }
        public TwoDimensionaArrayTest()
        {
            var random = new RandomDataReader()
            {
                MinArraySize = 10, MaxArraySize = 1000
            };

            data = ValueInterface <int[, ]> .ReadValue(random);

            json = JsonConvert.SerializeObject(data);
        }
Exemple #24
0
 public void WriteValue(IValueWriter valueWriter, T?value)
 {
     if (value is null)
     {
         valueWriter.DirectWrite(null);
     }
     else
     {
         ValueInterface <T> .WriteValue(valueWriter, value.Value);
     }
 }
        static T DeserializeObject <T, TMode>(byte *bytes, int length, MessagePackFormatterOptions options) where TMode : struct
        {
            var deserializer = new MessagePackDeserializer <TMode>(bytes, length, DefaultMaxDepth, options);

            if (typeof(TMode) == typeof(MessagePackDeserializeModes.ReferenceMode))
            {
                deserializer.InitReferences();
            }

            return(ValueInterface <T> .ReadValue(deserializer));
        }
 public object DirectRead()
 {
     try
     {
         return(ValueInterface.GetInterface(ReadType()).Read(this));
     }
     catch
     {
         return(null);
     }
 }
        public void Serialize <T>(T value, HGlobalCache <char> hGCache)
        {
            var options = Options;

            if ((options & ReferenceOptions) != 0)
            {
                var jsonSerializer = new JsonSerializer <JsonSerializeModes.ReferenceMode>(options, hGCache, MaxDepth)
                {
                    jsonFormatter = this,
                    References    = new JsonReferenceWriter()
                };

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.IndentedChars  = IndentedChars;
                    jsonSerializer.LineBreakChars = LineBreakChars;
                    jsonSerializer.MiddleChars    = MiddleChars;
                }

                ValueInterface <T> .WriteValue(jsonSerializer, value);

                jsonSerializer.Flush();
            }
            else if ((options & ComplexOptions) != 0)
            {
                var jsonSerializer = new JsonSerializer <JsonSerializeModes.ComplexMode>(options, hGCache, MaxDepth)
                {
                    jsonFormatter = this
                };

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.IndentedChars  = IndentedChars;
                    jsonSerializer.LineBreakChars = LineBreakChars;
                    jsonSerializer.MiddleChars    = MiddleChars;
                }

                ValueInterface <T> .WriteValue(jsonSerializer, value);

                jsonSerializer.Flush();
            }
            else
            {
                var jsonSerializer = new JsonSerializer <JsonSerializeModes.SimpleMode>(options, hGCache, MaxDepth)
                {
                    jsonFormatter = this
                };

                ValueInterface <T> .WriteValue(jsonSerializer, value);

                jsonSerializer.Flush();
            }
        }
        public static string SerializeObject <T>(T value)
        {
            using (var jsonSerializer = new JsonDefaultSerializer(DefaultMaxDepth))
            {
                ValueInterface <T> .WriteValue(jsonSerializer, value);

                return(new string(
                           jsonSerializer.hGlobal.GetPointer(),
                           0,
                           jsonSerializer.StringLength));
            }
        }
        public static string SerializeObject <T>(T value, JsonFormatterOptions options)
        {
            using (var jsonSerializer = CreateJsonSerializer(options))
            {
                ValueInterface <T> .WriteValue((IValueWriter)jsonSerializer, value);

                return(new string(
                           jsonSerializer.hGlobal.GetPointer(),
                           0,
                           jsonSerializer.StringLength));
            }
        }
        public static void SerializeObject <T>(T value, TextWriter textWriter, JsonFormatterOptions options)
        {
            using (var jsonSerializer = CreateJsonSerializer(options))
            {
                ValueInterface <T> .WriteValue((IValueWriter)jsonSerializer, value);

                VersionDifferences.WriteChars(
                    textWriter,
                    jsonSerializer.hGlobal.GetPointer(),
                    jsonSerializer.StringLength);
            }
        }
Exemple #31
0
        ///<summary>
        ///Called when the owner is registered
        ///</summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            //todo: perform initialization for the component

            //todo: look up interfaces exposed by other components
            //E.g.,
            //_theirInterface =
            //     Owner.Components.GetInterface<ValueInterface<float>>(
            //         "float", "their interface name");

            //activate tick callback for this component.
            ProcessList.Instance.AddTickCallback(Owner, this);

            if (null != _monitoredObject as T2DSpawnObject)
            {
                string name;
                if (_monitoredObject.Name.EndsWith("Template") ||
                    _monitoredObject.Name.EndsWith("template"))
                {
                    name =
                        _monitoredObject.Name.Substring(
                            0, _monitoredObject.Name.Length - 8);
                }
                else
                {
                    name = _monitoredObject.Name + "Instance";
                }
                _monitoredObject =
                    TorqueObjectDatabase.Instance.FindObject<T2DStaticSprite>(name);
            }

            if ((_monitoredObject != null) && (_monitoredInterfaceName != null))
            {
                _monitoredInterface =
                    _monitoredObject.Components.GetInterface<ValueInterface<float>>(
                        "float", _monitoredInterfaceName);
            }

            //create a camera for the compass
            T2DSceneCamera defaultCamera =
                TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
            if (defaultCamera != null)
            {
                T2DSceneCamera instrumentCam =
                    (T2DSceneCamera)defaultCamera.Clone();
                instrumentCam.Name = "InstrumentCam";
                TorqueObjectType instrument =
                    TorqueObjectDatabase.Instance.GetObjectType("instrument");

                instrumentCam.CenterPosition = CameraCenter;
                instrumentCam.Extent = CameraExtent;

                TorqueObjectDatabase.Instance.Register(instrumentCam);

                //display the instrument camera on screen
                GUIControlStyle instrumentStyle = new GUIControlStyle();
                GUISceneview instrumentView = new GUISceneview();
                instrumentView.Name = "InstrumentView";
                instrumentView.Style = instrumentStyle;
                instrumentView.Camera = instrumentCam;

                //only render objects of type "instrument"
                instrumentView.RenderMask = instrument;
                instrumentView.Visible = true;
                instrumentView.Folder =
                    TorqueObjectDatabase.Instance.FindObject<GUISceneview>("DefaultSceneView");
                instrumentView.Position = ViewPosition;
                instrumentView.Size = ViewSize;
            }

            return true;
        }
        /// <summary>
        /// Called when the owner is registered
        /// </summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            // todo: perform initialization for the component

            // todo: look up interfaces exposed by other components
            // E.g.,
            // _theirInterface =
            //      Owner.Components.GetInterface<ValueInterface<float>>(
            //          "float", "their interface name");

            // activate tick callback for this component.
            ProcessList.Instance.AddTickCallback(Owner, this);

            _maxForwardSpeed =
                Owner.Components.GetInterface<ValueInterface<float>>(
                    "float", "maxForwardSpeed");
            _maxReverseSpeed =
                Owner.Components.GetInterface<ValueInterface<float>>(
                    "float", "maxReverseSpeed");
            _maxBrakingDeceleration =
                Owner.Components.GetInterface<ValueInterface<float>>(
                    "float", "maxBrakingDeceleration");

            return true;
        }
 /// <summary>
 /// Get interfaces for position and rotation of named link point, if link point exists.
 /// </summary>
 /// <param name="name">Name of link point to query.</param>
 /// <param name="position">TorqueInterface for link point position.</param>
 /// <param name="rotation">TorqueInterface for link point rotation.</param>
 /// <returns>True if link point exists.</returns>
 public bool GetLinkPoint(string name, out ValueInterface<Vector2> position, out ValueInterface<float> rotation)
 {
     Assert.Fatal(name != null && name != String.Empty, "link points must have a name");
     SList<LinkPoint> walk = _linkPoints;
     while (walk != null)
     {
         if (walk.Val.Name == name)
         {
             position = walk.Val.Position;
             rotation = walk.Val.Rotation;
             return true;
         }
         walk = walk.Next;
     }
     position = null;
     rotation = null;
     return false;
 }