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 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); }
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)); }
public int UriLength() { _buffer.CheckLimit(_parentMessage.Limit + 4); return((int)_buffer.Uint32GetLittleEndian(_parentMessage.Limit)); }
public void CheckPositionShouldNotThrowWhenPositionIsInRange() { _directBuffer.CheckLimit(_buffer.Length); }
public int DeskIDLength() { _buffer.CheckLimit(_parentMessage.Limit + 1); return((int)_buffer.Uint8Get(_parentMessage.Limit)); }
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)); }