Add server implementation

This commit is contained in:
Christian Kratky
2017-03-26 21:48:50 +02:00
parent 18538ebbb9
commit ee25228c0b
110 changed files with 2164 additions and 496 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;
}
}
}