Пример #1
0
        private void InternalExpand(int expandMinSize)
        {
            if (hGlobal.Count == HGlobalCache <char> .MaxSize && textWriter != null && offset != 0)
            {
                VersionDifferences.WriteChars(textWriter, hGlobal.GetPointer(), offset);

                offset = 0;

                Expand(expandMinSize);
            }
            else
            {
                hGlobal.Expand(expandMinSize);
            }
        }
Пример #2
0
        /// <summary>
        /// 将 Stream 的内容缓存到 HGlobalCache 中。
        /// </summary>
        /// <param name="hGCache">HGlobalCache</param>
        /// <param name="stream">Stream</param>
        /// <param name="encoding">编码</param>
        /// <returns>返回缓冲的长度</returns>
        public static void ReadFrom(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding)
        {
            var hGBytes = BytesPool.Rent();

            hGBytes.ReadFrom(stream);

            var maxCharsCount = encoding.GetMaxCharCount(hGBytes.Count);

            if (maxCharsCount >= hGCache.Capacity)
            {
                hGCache.Expand(maxCharsCount);
            }

            hGCache.Count = encoding.GetChars(
                hGBytes.GetPointer(),
                hGBytes.Count,
                hGCache.GetPointer(),
                hGCache.Capacity);

            BytesPool.Return(hGBytes);
        }
Пример #3
0
        /// <summary>
        /// 将 HGlobalCache 中的内容写入到流中。
        /// </summary>
        /// <param name="hGCache">HGlobalCache</param>
        /// <param name="stream">流</param>
        /// <param name="encoding">编码</param>
        public static void WriteTo(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding)
        {
            var hGBytes = BytesPool.Rent();

            var maxBytesCount = encoding.GetMaxByteCount(hGCache.Count);

            if (maxBytesCount > hGBytes.Capacity)
            {
                hGBytes.Expand(maxBytesCount - hGBytes.Capacity);
            }

            hGBytes.Count = encoding.GetBytes(
                hGCache.GetPointer(),
                hGCache.Count,
                hGBytes.GetPointer(),
                hGBytes.Capacity);

            hGBytes.WriteTo(stream);

            BytesPool.Return(hGBytes);
        }
Пример #4
0
        /// <summary>
        /// 异步将 Stream 的内容缓存到 HGlobalCache 中。
        /// </summary>
        /// <param name="hGCache">HGlobalCache</param>
        /// <param name="stream">Stream</param>
        /// <param name="encoding">编码</param>
        /// <returns>返回缓冲的长度</returns>
        public static async Task ReadFromAsync(this HGlobalCache <char> hGCache, Stream stream, Encoding encoding)
        {
            var hGBytes = BytesPool.Rent();

            await hGBytes.ReadFromAsync(stream);

            var maxCharsCount = encoding.GetMaxCharCount(hGBytes.Count);

            if (maxCharsCount > hGCache.Capacity)
            {
                hGCache.Expand(maxCharsCount - hGCache.Capacity);
            }

            unsafe
            {
                hGCache.Count = encoding.GetChars(
                    hGBytes.GetPointer(),
                    hGBytes.Count,
                    hGCache.GetPointer(),
                    hGCache.Capacity);
            }

            BytesPool.Return(hGBytes);
        }
Пример #5
0
 /// <summary>
 /// 将 JSON 字符串反序列化到指定的数据写入器中。
 /// </summary>
 /// <param name="hGCache">JSON 字符串缓存</param>
 /// <param name="dataWriter">数据写入器</param>
 public void DeserializeTo(HGlobalCache <char> hGCache, IDataWriter dataWriter)
 {
     DeserializeTo(hGCache.GetPointer(), hGCache.Count, dataWriter);
 }
Пример #6
0
 public object Deserialize(HGlobalCache <char> hGCache, Type type)
 {
     return(Deserialize(hGCache.GetPointer(), hGCache.Count, type));
 }
Пример #7
0
 public T Deserialize <T>(HGlobalCache <char> hGCache)
 {
     return(Deserialize <T>(hGCache.GetPointer(), hGCache.Count));
 }
Пример #8
0
        public void WriteDateTime(DateTime value)
        {
            WriteValueBefore();

            Expand(32);

            Append(FixString);

            offset += DateTimeHelper.ToISOString(value, HGCache.GetPointer() + offset);

            Append(FixString);

            AppendValueAfter();
        }
Пример #9
0
 public static IJsonReader CreateJsonReader(HGlobalCache <char> hGCache)
 {
     return(CreateJsonReader(hGCache.GetPointer(), hGCache.Count));
 }
Пример #10
0
 public static object DeserializeObject(HGlobalCache <char> hGCache, Type type, JsonFormatterOptions options)
 {
     return(DeserializeObject(hGCache.GetPointer(), hGCache.Count, type, options));
 }
Пример #11
0
 public static T DeserializeObject <T>(HGlobalCache <char> hGCache, JsonFormatterOptions options)
 {
     return(DeserializeObject <T>(hGCache.GetPointer(), hGCache.Count, options));
 }