Exemplo n.º 1
0
        public T ReadValue(IValueReader valueReader)
        {
            if (valueReader is ISingleThreadOptimize)
            {
                var current_cache = thread_cache;

                if (current_cache == null)
                {
                    InitializeInstance(ref current_cache);
                }

                if (current_cache.IsUsed)
                {
                    goto Default;
                }

                current_cache.IsUsed = true;

                current_cache.Instance.content = default;

                ReadValue(valueReader, current_cache.Instance);

                current_cache.IsUsed = false;

                return(current_cache.Instance.content);
            }

Default:

            var fastObjectRW = FastObjectRW <T> .Create();

            ReadValue(valueReader, fastObjectRW);

            return(fastObjectRW.content);
        }
Exemplo n.º 2
0
            /// <summary>
            /// 初始化值暂存器。
            /// </summary>
            /// <param name="dataRW">数据读写器</param>
            /// <param name="key">键</param>
            internal FastFieldRW(FastObjectRW <T> dataRW, long key)
            {
                this.dataRW = dataRW;
                this.key    = key;

                valueCopyer = new ValueCopyer();
            }
Exemplo n.º 3
0
        public T ReadValue(IValueReader valueReader)
        {
            var fastObjectRW = FastObjectRW <T> .Create();

            valueReader.ReadObject(fastObjectRW);

            return(fastObjectRW.Content);
        }
Exemplo n.º 4
0
        public T ReadValue(IValueReader valueReader)
        {
            var writer = FastObjectRW <T> .Create();

            valueReader.ReadObject(writer);

            return(writer.Content);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 使用 <see cref="FastObjectRW{T}"/> 往值写入器中写入一个对象。
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="valueWriter">值写入器</param>
        /// <param name="obj">对象</param>
        public static void FastWriteObject <T>(this IValueWriter valueWriter, T obj)
        {
            var rw = FastObjectRW <T> .Create();

            rw.content = obj;

            valueWriter.WriteObject(rw);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 使用 <see cref="FastObjectRW{T}"/> 从值读取器中读取一个对象。
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="valueReader">值读取器</param>
        /// <returns>返回一个对象</returns>
        public static T FastReadObject <T>(this IValueReader valueReader)
        {
            var rw = FastObjectRW <T> .Create();

            valueReader.ReadObject(rw);

            return(rw.content);
        }
Exemplo n.º 7
0
        public void InitializeInstance(ref InternalInstance <FastObjectRW <T> > current_cache)
        {
            current_cache = new InternalInstance <FastObjectRW <T> >
            {
                Instance = FastObjectRW <T> .Create()
            };

            thread_cache = current_cache;
        }
Exemplo n.º 8
0
 public void ReadValue(IValueReader valueReader, FastObjectRW <T> fastObjectRW)
 {
     if (valueReader is IId64Filler <char> id64Filler)
     {
         id64Filler.FillValue(fastObjectRW);
     }
     else
     {
         valueReader.ReadObject(fastObjectRW);
     }
 }
Exemplo n.º 9
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckChildrenInstance && Int64TypeHandle != (long)TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            if (valueWriter is ISingleThreadOptimize)
            {
                var current_cache = thread_cache;

                if (current_cache == null)
                {
                    InitializeInstance(ref current_cache);
                }

                if (current_cache.IsUsed)
                {
                    goto Default;
                }

                current_cache.IsUsed = true;

                current_cache.Instance.Initialize(value);

                valueWriter.WriteObject(current_cache.Instance);

                current_cache.IsUsed = false;

                return;
            }

Default:

            var fastObjectRW = FastObjectRW <T> .Create();

            fastObjectRW.Initialize(value);

            valueWriter.WriteObject(fastObjectRW);
        }
Exemplo n.º 10
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckChildrenInstance && Int64TypeHandle != (long)TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            var fastObjectRW = FastObjectRW <T> .Create();

            fastObjectRW.Initialize(value);

            valueWriter.WriteObject(fastObjectRW);
        }
Exemplo n.º 11
0
        public void WriteValue(IValueWriter valueWriter, T value)
        {
            if (value == null)
            {
                valueWriter.DirectWrite(null);

                return;
            }

            /* 父类引用,子类实例时使用 Type 获取写入器。 */
            if (CheckDerivedInstance && TypeHandle != TypeHelper.GetTypeHandle(value))
            {
                ValueInterface.GetInterface(value).Write(valueWriter, value);

                return;
            }

            var reader = FastObjectRW <T> .Create();

            reader.Initialize(value);

            valueWriter.WriteObject(reader);
        }