示例#1
0
        public static byte[] SerializeObject <T>(T value, MessagePackFormatterOptions options)
        {
            var hGBytes = BytesPool.Rent();

            SerializeObject(value, hGBytes, options);

            var ret = hGBytes.ToArray();

            BytesPool.Return(hGBytes);

            return(ret);
        }
示例#2
0
        SerializeAsync <T>(T value, Stream stream)
        {
            var hGBytes = BytesPool.Rent();

            Serialize(value, hGBytes);

            var bytes = hGBytes.ToArray();

            BytesPool.Return(hGBytes);

            await stream.WriteAsync(bytes, 0, bytes.Length);
        }
示例#3
0
        public static byte[] SerializeObject <T>(T value)
        {
            var hGBytes = BytesPool.Rent();

            SerializeObject(value, hGBytes);

            var ret = hGBytes.ToArray();

            BytesPool.Return(hGBytes);

            return(ret);
        }
示例#4
0
        SerializeObjectAsync <T>(T value, Stream stream, MessagePackFormatterOptions options)
        {
            var hGBytes = BytesPool.Rent();

            SerializeObject(value, hGBytes, options);

            var bytes = hGBytes.ToArray();

            BytesPool.Return(hGBytes);

            await stream.WriteAsync(bytes, 0, bytes.Length);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="componentOrder">The component order.</param>
        /// <param name="padding">The number of bytes to pad each row.</param>
        public PixelArea(int width, int height, ComponentOrder componentOrder, int padding)
        {
            this.Width          = width;
            this.Height         = height;
            this.ComponentOrder = componentOrder;
            this.RowStride      = (width * GetComponentCount(componentOrder)) + padding;
            this.Length         = this.RowStride * height;
            this.Bytes          = BytesPool.Rent(this.Length);
            this.isBufferRented = true;
            this.pixelsHandle   = GCHandle.Alloc(this.Bytes, GCHandleType.Pinned);

            // TODO: Why is Resharper warning us about an impure method call?
            this.dataPointer = this.pixelsHandle.AddrOfPinnedObject();
            this.PixelBase   = (byte *)this.dataPointer.ToPointer();
        }
示例#6
0
        public static void SerializeObject <T>(T value, Stream stream, MessagePackFormatterOptions options)
        {
            var hGBytes = BytesPool.Rent();

            if ((options & ReferenceSerializerOptions) != 0)
            {
                SerializeObject <T, MessagePackSerializeModes.ReferenceMode>(value, hGBytes, options);
            }
            else
            {
                SerializeObject <T, MessagePackSerializeModes.StandardMode>(value, hGBytes, options);
            }

            hGBytes.WriteTo(stream);

            BytesPool.Return(hGBytes);
        }
示例#7
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);
        }
示例#8
0
        /// <summary>
        /// 异步将 HGlobalCache 中的内容写入到流中。
        /// </summary>
        /// <param name="hGCache">HGlobalCache</param>
        /// <param name="stream">流</param>
        /// <param name="encoding">编码</param>
        public static async Task WriteToAsync(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);
            }

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

            await hGBytes.WriteToAsync(stream);

            BytesPool.Return(hGBytes);
        }