コード例 #1
0
        protected override bool ParsePayload(byte[] buffer, ref int offset, ref int count)
        {
            // got everything, do not do a temp copy.
            if (_receiveOffset == 0 && count >= _receivePayloadLength)
            {
                Payload = new DotNetType(Encoding.ASCII.GetString(buffer, offset, _receivePayloadLength));
                offset += _receivePayloadLength;
                count -= _receivePayloadLength;
                return true;
            }

            var bytesToCopy = Math.Min(count, _receiveBytesLeft);
            Buffer.BlockCopy(buffer, offset, _receiveBuffer, _receiveOffset, bytesToCopy);
            _receiveOffset += bytesToCopy;
            _receiveBytesLeft -= bytesToCopy;
            offset += bytesToCopy;
            count -= bytesToCopy;
            return _receiveBytesLeft == 0;
        }
コード例 #2
0
        protected override bool ParsePayload(byte[] buffer, ref int offset, ref int count)
        {
            // got everything, do not do a temp copy.
            if (_receiveOffset == 0 && count >= _receivePayloadLength)
            {
                Payload = new DotNetType(Encoding.ASCII.GetString(buffer, offset, _receivePayloadLength));
                offset += _receivePayloadLength;
                count  -= _receivePayloadLength;
                return(true);
            }

            var bytesToCopy = Math.Min(count, _receiveBytesLeft);

            Buffer.BlockCopy(buffer, offset, _receiveBuffer, _receiveOffset, bytesToCopy);
            _receiveOffset    += bytesToCopy;
            _receiveBytesLeft -= bytesToCopy;
            offset            += bytesToCopy;
            count             -= bytesToCopy;
            return(_receiveBytesLeft == 0);
        }