Exemple #1
0
        /// <summary>Creates a new big-endian buffer which wraps the specified array. A modification on the
        /// specified array's content will be visible to the returned buffer.</summary>
        public static IByteBuffer WrappedBuffer(byte[] array)
        {
            if (array is null)
            {
                return(Empty);
            }

            return(0u >= (uint)array.Length ? Empty :
                   PlatformDependent.DirectBufferPreferred
                    ? ArrayPooledUnsafeDirectByteBuffer.NewInstance(Allocator, DefaultArrayPool, array, array.Length, array.Length)
                    : (IByteBuffer)ArrayPooledHeapByteBuffer.NewInstance(Allocator, DefaultArrayPool, array, array.Length, array.Length));
        }
Exemple #2
0
        /// <summary>Creates a new big-endian buffer which wraps the sub-region of the specified array. A
        /// modification on the specified array's content will be visible to the returned buffer.</summary>
        public static IByteBuffer WrappedBuffer(byte[] array, int offset, int length)
        {
            if (array is null || 0u >= (uint)length)
            {
                return(Empty);
            }
            if (MathUtil.IsOutOfBounds(offset, length, array.Length))
            {
                ThrowHelper.ThrowIndexOutOfRangeException_Index(offset, length, array.Length);
            }

            if (0u >= (uint)offset)
            {
                return(PlatformDependent.DirectBufferPreferred
                     ? ArrayPooledUnsafeDirectByteBuffer.NewInstance(Allocator, DefaultArrayPool, array, length, array.Length)
                     : (IByteBuffer)ArrayPooledHeapByteBuffer.NewInstance(Allocator, DefaultArrayPool, array, length, array.Length));
            }

            return(WrappedBuffer(array).Slice(offset, length));
        }