Initial commit.

This commit is contained in:
Christian Kratky
2017-03-19 18:41:29 +01:00
parent bc50796f9d
commit 9b720d2325
70 changed files with 3487 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
using System;
namespace MQTTnet.Core.Serializer
{
public class ByteReader
{
private int _index;
private readonly int _byte;
public ByteReader(byte @byte)
{
_byte = @byte;
}
public bool Read()
{
if (_index >= 8)
{
throw new InvalidOperationException("End of the byte reached.");
}
var result = ((1 << _index) & _byte) > 0;
_index++;
return result;
}
public byte Read(int count)
{
var result = 0;
for (var i = 0; i < count; i++)
{
if (Read())
{
result |= 1 << i;
}
}
return (byte)result;
}
}
}