System.Net.WebSockets.WebSocketBuffer.IsNativeBuffer C# (CSharp) Method

IsNativeBuffer() private method

private IsNativeBuffer ( IntPtr pBuffer, uint bufferSize ) : bool
pBuffer IntPtr
bufferSize uint
return bool
        private bool IsNativeBuffer(IntPtr pBuffer, uint bufferSize)
        {
            Debug.Assert(pBuffer != IntPtr.Zero, "'pBuffer' MUST NOT be NULL.");
            Debug.Assert(bufferSize <= GetMaxBufferSize(),
                "'bufferSize' MUST NOT be bigger than 'm_ReceiveBufferSize' and 'm_SendBufferSize'.");

            long nativeBufferStartAddress = pBuffer.ToInt64();
            long nativeBufferEndAddress = bufferSize + nativeBufferStartAddress;

            Debug.Assert(Marshal.UnsafeAddrOfPinnedArrayElement(_internalBuffer.Array, _internalBuffer.Offset).ToInt64() == _startAddress,
                "'m_InternalBuffer.Array' MUST be pinned for the whole lifetime of a WebSocket.");

            if (nativeBufferStartAddress >= _startAddress &&
                nativeBufferStartAddress <= _endAddress &&
                nativeBufferEndAddress >= _startAddress &&
                nativeBufferEndAddress <= _endAddress)
            {
                return true;
            }

            return false;
        }