/// <summary>
///
/// </summary>
/// <param name="count"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public BitWriter2 WriteBits(int count, uint value)
{
if (count > _leftBits)
{
var bits1 = _leftBits;
var bits2 = count - _leftBits;
WriteBits(bits1, value >> (count - bits1));
WriteBits(bits2, value);
return(this);
}
if (LSB)
{
_currentValue |= (value & BitUtils.CreateMask(count)) << (CurrentBits);
}
else
{
_currentValue |= (value & BitUtils.CreateMask(count)) << (_leftBits - count);
}
_leftBits -= count;
if (_leftBits != 0)
{
return(this);
}
//Console.WriteLine("Writting: {0:X" + (ByteCapacity * 2) + "}", CurrentValue);
switch (_byteCapacity)
{
case 1:
Stream.WriteByte((byte)_currentValue);
break;
case 2:
Stream.WriteStruct((ushort)_currentValue);
break;
case 4:
// ReSharper disable once RedundantCast
Stream.WriteStruct((uint)_currentValue);
break;
default:
throw(new InvalidOperationException());
}
ResetValue();
return(this);
}