当前位置: 首页>>代码示例>>C#>>正文


C# IByteBuffer.ReadBytes方法代码示例

本文整理汇总了C#中IByteBuffer.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# IByteBuffer.ReadBytes方法的具体用法?C# IByteBuffer.ReadBytes怎么用?C# IByteBuffer.ReadBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IByteBuffer的用法示例。


在下文中一共展示了IByteBuffer.ReadBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyCompression

        static IByteBuffer ApplyCompression(IByteBuffer buffer, CompressionMode compressionMode)
        {
            try
            {
                using (var outputStream = new MemoryStream())
                {
                    using (var gzipStream = new GZipStream(outputStream, compressionMode, true))
                    {
                        buffer.ReadBytes(gzipStream, buffer.ReadableBytes);
                    }

                    Contract.Assert(outputStream.Length <= int.MaxValue);

                    return Unpooled.WrappedBuffer(outputStream.GetBuffer(), 0, (int)outputStream.Length);
                }
            }
            finally
            {
                ReferenceCountUtil.Release(buffer);
            }
        }
开发者ID:kdotchkoff,项目名称:azure-iot-protocol-gateway,代码行数:21,代码来源:MqttPacketPayloadCompressionHandler.cs

示例2: ReadBytes

 /// <summary>
 /// Read the given amount of bytes into a new {@link ByteBuf} that is allocated from the {@link ByteBufAllocator}.
 /// </summary>
 public static IByteBuffer ReadBytes(IByteBufferAllocator alloc, IByteBuffer buffer, int length)
 {
     bool release = true;
     IByteBuffer dst = alloc.Buffer(length);
     try
     {
         buffer.ReadBytes(dst);
         release = false;
         return dst;
     }
     finally
     {
         if (release)
         {
             dst.Release();
         }
     }
 }
开发者ID:donmikel,项目名称:DotNetty,代码行数:21,代码来源:ByteBufferUtil.cs

示例3: AcceptBytes

            public void AcceptBytes(IByteBuffer input)
            {
                TaskCompletionSource<int> tcs = this.readCompletionSource;
                if (tcs == null)
                {
                    // there is no pending read operation - keep for future
                    this.pendingReadBuffer = input;
                    return;
                }

                ArraySegment<byte> sslBuffer = this.sslOwnedBuffer;

                Contract.Assert(sslBuffer.Array != null);

                int readableBytes = input.ReadableBytes;
                int length = Math.Min(sslBuffer.Count, readableBytes);
                input.ReadBytes(sslBuffer.Array, sslBuffer.Offset, length);
                tcs.TrySetResult(length);
                if (length < readableBytes)
                {
                    // set buffer for consecutive read to use
                    this.pendingReadBuffer = input;
                }

                AsyncCallback callback = this.readCallback;
                if (callback != null)
                {
                    callback(tcs.Task);
                }
            }
开发者ID:dalong123,项目名称:DotNetty,代码行数:30,代码来源:TlsHandler.cs

示例4: WriteBytes

 /// <summary>
 /// Writes bytes.
 /// </summary>
 /// <param name="source">The bytes (in the form of an IByteBuffer).</param>
 /// <exception cref="System.ObjectDisposedException">ByteArrayBuffer</exception>
 /// <exception cref="System.InvalidOperationException">Write operations are not allowed for read only buffers.</exception>
 public void WriteBytes(IByteBuffer source)
 {
     ThrowIfDisposed();
     EnsureIsWritable();
     var count = source.Length;
     EnsureSpaceAvailable(count);
     var savedPosition = source.Position;
     source.Position = 0;
     source.ReadBytes(_bytes, _sliceOffset + _position, count);
     _position += count;
     if (_length < _position)
     {
         _length = _position;
     }
     source.Position = savedPosition;
 }
开发者ID:wireclub,项目名称:mongo-csharp-driver,代码行数:22,代码来源:ByteArrayBuffer.cs

示例5: WriteBytes

        /// <summary>
        /// Writes bytes.
        /// </summary>
        /// <param name="source">The bytes (in the form of an IByteBuffer).</param>
        /// <exception cref="System.ObjectDisposedException">MultiChunkBuffer</exception>
        /// <exception cref="System.InvalidOperationException">The MultiChunkBuffer is read only.</exception>
        public void WriteBytes(IByteBuffer source)
        {
            ThrowIfDisposed();
            EnsureIsWritable();
            EnsureSpaceAvailable(source.Length);

            var savedPosition = source.Position;
            source.Position = 0;

            var chunkIndex = (_sliceOffset + _position) / _chunkSize;
            var chunkOffset = (_sliceOffset + _position) % _chunkSize;
            var remaining = source.Length;
            while (remaining > 0)
            {
                var chunkRemaining = _chunkSize - chunkOffset;
                var bytesToCopy = (remaining < chunkRemaining) ? remaining : chunkRemaining;
                source.ReadBytes(_chunks[chunkIndex].Bytes, chunkOffset, bytesToCopy);
                chunkIndex += 1;
                chunkOffset = 0;
                remaining -= bytesToCopy;
                _position += bytesToCopy;
            }
            if (_length < _position)
            {
                _length = _position;
            }

            source.Position = savedPosition;
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:35,代码来源:MultiChunkBuffer.cs

示例6: ReadString

        /// <summary>
        /// Reads the string from the byte buffer until null terminator.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>System.String.</returns>
        private static string ReadString(IByteBuffer input)
        {
            // Scan buffer for end of string null terminator
            for (var index = input.ReaderIndex; index < input.WriterIndex; index++)
            {
                if (input.GetByte(index) != 0xFF) continue;

                var bytes = XorArray(input.ReadBytes(index - input.ReaderIndex).ToArray());
                return Encoding.ASCII.GetString(bytes);
            }

            return string.Empty;
        }
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:18,代码来源:ByteBlasterProtocolDecoder.cs

示例7: ReadPacketBody

        /// <summary>
        /// Reads the packet body.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="size">The size.</param>
        /// <param name="version">The packet version.</param>
        /// <returns>System.Byte[].</returns>
        private static byte[] ReadPacketBody(IByteBuffer input, int size, byte version)
        {
            var body = XorArray(input.ReadBytes(size).ToArray());

            if (version == 2)
                body = ZLibInflate(body);

            return body;
        }
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:16,代码来源:ByteBlasterProtocolDecoder.cs


注:本文中的IByteBuffer.ReadBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。