Example #1
0
        /// <summary>
        /// Creates a new instance from a protocol-buffer stream
        /// </summary>
        /// <param name="type">The type to be created.</param>
        /// <param name="source">The binary stream to apply to the new instance (cannot be null).</param>
        /// <returns>A new, initialized instance.</returns>


        public static object Deserialize(System.Type type, Stream source)
        {
            if (typeof(IParseable).IsAssignableFrom(type))
            {
                ProtoReader reader = null;
                object      obj    = null;
                try
                {
                    reader = ProtoReader.Create(source, RuntimeTypeModel.Default, null, -1);
                    //if (value != null) reader.SetRootObject(value);
                    //object obj = DeserializeCore(reader, type, value, autoCreate);
                    obj = Activator.CreateInstance(type);
                    IParseable objProxy = obj as IParseable;
                    objProxy.Parse(reader);
                    reader.CheckFullyConsumed();
                    return(obj);
                }
                finally
                {
                    ProtoReader.Recycle(reader);
                }

                return(obj);
            }

            UnityEngine.Debug.LogWarning("Old Form Load Table " + type.Name + "!!");
            return(RuntimeTypeModel.Default.Deserialize(source, null, type));
        }
Example #2
0
        public static object ParseEx(System.Type type, Stream source)
        {
            ProtoReader reader = null;
            object      obj    = null;

            try
            {
                reader = ProtoReader.Create(source, RuntimeTypeModel.Default, null, -1);
                //if (value != null) reader.SetRootObject(value);
                //object obj = DeserializeCore(reader, type, value, autoCreate);
                obj = Activator.CreateInstance(type);
                IParseable objProxy = obj as IParseable;
                objProxy.Parse(reader);
                reader.CheckFullyConsumed();
                return(obj);
            }
            finally
            {
                ProtoReader.Recycle(reader);
            }

            return(obj);
        }