コード例 #1
0
        private static void EnsureWritableIntStatusShouldFailButNotThrow0(bool force)
        {
            var buf      = Unpooled.Buffer(1);
            var readOnly = buf.AsReadOnly();
            int result   = readOnly.EnsureWritable(1, force);

            Assert.Equal(1, result);
            Assert.False(ByteBufferUtil.EnsureWritableSuccess(result));
            readOnly.Release();
        }
コード例 #2
0
            private static bool AttemptCopyToCumulation(IByteBuffer cumulation, IByteBuffer next, int wrapDataSize)
            {
                int inReadableBytes    = next.ReadableBytes;
                int cumulationCapacity = cumulation.Capacity;

                if (wrapDataSize - cumulation.ReadableBytes >= inReadableBytes &&
                    // Avoid using the same buffer if next's data would make cumulation exceed the wrapDataSize.
                    // Only copy if there is enough space available and the capacity is large enough, and attempt to
                    // resize if the capacity is small.
                    ((cumulation.IsWritable(inReadableBytes) && cumulationCapacity >= wrapDataSize) ||
                     (cumulationCapacity < wrapDataSize && ByteBufferUtil.EnsureWritableSuccess(cumulation.EnsureWritable(inReadableBytes, false)))))
                {
                    cumulation.WriteBytes(next);
                    next.Release();
                    return(true);
                }
                return(false);
            }