static AmqpConnectionFrameWriter()
        {
            var v = Encoding.ASCII.GetBytes("AMQP");

            GreetingPayload = new byte[8];
            // Buffer.BlockCopy(v, 0, GreetingPayload, 0, v.Length);
            BufferUtil.FastCopy(GreetingPayload, 0, v, 0, v.Length);
            GreetingPayload[4] = 0;
            GreetingPayload[5] = 0;             // major
            GreetingPayload[6] = 9;             // minor
            GreetingPayload[7] = 1;             // revision
        }
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (_buffer == null)
            {
                _buffer = _pool.Rent(_arraySize);
            }
            BufferUtil.FastCopy(_buffer, _position, buffer, offset, count);
//			if (count <= 8)
//			{
//				int byteCount = count;
//				while (--byteCount >= 0)
//					_buffer[_position + byteCount] = buffer[offset + byteCount];
//			}
//			else
//			{
//				// TODO: better/faster option?
//				Buffer.BlockCopy(buffer, offset, _buffer, _position, count);
//			}
            _position += count;
        }
Esempio n. 3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("MemoryStream2");
            }

            int toCopy = _buffer.Length - _position;

            if (toCopy > count)
            {
                toCopy = count;
            }
            if (toCopy <= 0)
            {
                return(0);
            }

            BufferUtil.FastCopy(buffer, offset, _buffer, _position, toCopy);

//			if (toCopy <= 8)
//			{
//				int bCount = toCopy;
//				while (--bCount >= 0)
//				{
//					buffer[offset + bCount] = _buffer[_position + bCount];
//				}
//			}
//			else
//			{
//				Buffer.BlockCopy(_buffer, _position, buffer, offset, toCopy);
//			}
            _position += toCopy;

            return(toCopy);
        }
Esempio n. 4
0
 public override BaseLightStream CloneStream(int bodySize)
 {
     return(new MemoryStream2(BufferUtil.Copy(this, bodySize)));
 }