public void Reallocate()
        {
            const int initialBufferSize = 8;
            var       initialBuffer     = new Byte[initialBufferSize];

            const int biggerBufferSize = 100;
            var       biggerBuffer     = new byte[biggerBufferSize];

            var reallocableBuffer = new DirectBuffer(initialBuffer,
                                                     (existingSize, requestedSize) =>
            {
                Assert.AreEqual(initialBufferSize, existingSize);
                Assert.AreEqual(16, requestedSize);
                return(biggerBuffer);
            });

            reallocableBuffer.CheckLimit(8);
            reallocableBuffer.Int64PutLittleEndian(0, 1);
            Assert.AreEqual(initialBufferSize, reallocableBuffer.Capacity);

            reallocableBuffer.CheckLimit(16);
            reallocableBuffer.Int64PutLittleEndian(8, 2);
            Assert.AreEqual(biggerBufferSize, reallocableBuffer.Capacity);

            Assert.AreEqual(1, BitConverter.ToInt64(biggerBuffer, 0));
            Assert.AreEqual(2, BitConverter.ToInt64(biggerBuffer, 8));
        }
예제 #2
0
        public int GetMake(byte[] dst, int dstOffset, int length)
        {
            const int sizeOfLengthField = 1;
            int       limit             = Limit;

            _buffer.CheckLimit(limit + sizeOfLengthField);
            int dataLength  = _buffer.Uint8Get(limit);
            int bytesCopied = Math.Min(length, dataLength);

            Limit = limit + sizeOfLengthField + dataLength;
            _buffer.GetBytes(limit + sizeOfLengthField, dst, dstOffset, bytesCopied);

            return(bytesCopied);
        }
예제 #3
0
        public int GetManufacturer(byte[] dst, int dstOffset, int length)
        {
            const int sizeOfLengthField = 4;
            int       limit             = _parentMessage.Limit;

            _buffer.CheckLimit(limit + sizeOfLengthField);
            int dataLength  = (int)_buffer.Uint32GetLittleEndian(limit);
            int bytesCopied = Math.Min(length, dataLength);

            _parentMessage.Limit = limit + sizeOfLengthField + dataLength;
            _buffer.GetBytes(limit + sizeOfLengthField, dst, dstOffset, bytesCopied);

            return(bytesCopied);
        }
        public void ReallocateFailure()
        {
            const int initialBufferSize = 8;
            var       initialBuffer     = new Byte[initialBufferSize];
            var       reallocableBuffer = new DirectBuffer(initialBuffer, (existingSize, requestedSize) =>
            {
                Assert.AreEqual(initialBufferSize, existingSize);
                Assert.AreEqual(16, requestedSize);
                return(null);
            });

            reallocableBuffer.CheckLimit(8);
            reallocableBuffer.Int64PutLittleEndian(0, 1);
            Assert.AreEqual(initialBufferSize, reallocableBuffer.Capacity);
            Assert.ThrowsException <IndexOutOfRangeException>(() => reallocableBuffer.CheckLimit(16));
        }
예제 #5
0
 public int UriLength()
 {
     _buffer.CheckLimit(_parentMessage.Limit + 4);
     return((int)_buffer.Uint32GetLittleEndian(_parentMessage.Limit));
 }
 public void CheckPositionShouldNotThrowWhenPositionIsInRange()
 {
     _directBuffer.CheckLimit(_buffer.Length);
 }
예제 #7
0
 public int DeskIDLength()
 {
     _buffer.CheckLimit(_parentMessage.Limit + 1);
     return((int)_buffer.Uint8Get(_parentMessage.Limit));
 }
예제 #8
0
 public int CredentialsLength()
 {
     _buffer.CheckLimit(_parentMessage.Limit + 1);
     return((int)_buffer.Uint8Get(_parentMessage.Limit));
 }
        public void Reallocate()
        {
            const int initialBufferSize = 8;
            var initialBuffer = new Byte[initialBufferSize];
            
            const int biggerBufferSize = 100;
            var biggerBuffer = new byte[biggerBufferSize];
            
            var reallocableBuffer = new DirectBuffer(initialBuffer, 
                (existingSize, requestedSize) =>
                {
                    Assert.AreEqual(initialBufferSize, existingSize);
                    Assert.AreEqual(16, requestedSize);
                    return biggerBuffer;
                });
            
            reallocableBuffer.CheckLimit(8);
            reallocableBuffer.Int64PutLittleEndian(0, 1);
            Assert.AreEqual(initialBufferSize, reallocableBuffer.Capacity);

            reallocableBuffer.CheckLimit(16);
            reallocableBuffer.Int64PutLittleEndian(8, 2);
            Assert.AreEqual(biggerBufferSize, reallocableBuffer.Capacity);

            Assert.AreEqual(1, BitConverter.ToInt64(biggerBuffer, 0));
            Assert.AreEqual(2, BitConverter.ToInt64(biggerBuffer, 8));
        }
        public void ReallocateFailure()
        {
            const int initialBufferSize = 8;
            var initialBuffer = new Byte[initialBufferSize];
            var reallocableBuffer = new DirectBuffer(initialBuffer, (existingSize, requestedSize) =>
            {
                Assert.AreEqual(initialBufferSize, existingSize);
                Assert.AreEqual(16, requestedSize);
                return null;
            });

            reallocableBuffer.CheckLimit(8);
            reallocableBuffer.Int64PutLittleEndian(0, 1);
            Assert.AreEqual(initialBufferSize, reallocableBuffer.Capacity);
            Assert.Throws<IndexOutOfRangeException>(() => reallocableBuffer.CheckLimit(16));
        }