40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
|
using InnovEnergy.Lib.Protocols.DBus.Protocol.Header;
|
||
|
using InnovEnergy.Lib.Protocols.DBus.Transport;
|
||
|
|
||
|
namespace InnovEnergy.Lib.Protocols.DBus.WireFormat;
|
||
|
|
||
|
internal class DBusSocketReader : DBusReader
|
||
|
{
|
||
|
private BufferedSocketReader BufferedSocketReader { get; }
|
||
|
|
||
|
public override Int32 BytesRead => BufferedSocketReader.BytesRead;
|
||
|
|
||
|
public DBusSocketReader(BufferedSocketReader bufferedSocketReader, Boolean swapEndian) : base(swapEndian)
|
||
|
{
|
||
|
BufferedSocketReader = bufferedSocketReader;
|
||
|
}
|
||
|
|
||
|
public DBusSocketReader(BufferedSocketReader bufferedSocketReader) :
|
||
|
this(bufferedSocketReader, MessageStart(bufferedSocketReader))
|
||
|
{
|
||
|
}
|
||
|
|
||
|
private static Boolean MessageStart(BufferedSocketReader socketReader)
|
||
|
{
|
||
|
Endian PeekEndian() => (Endian) socketReader.PeekByte();
|
||
|
|
||
|
while (PeekEndian() is not (Endian.Little or Endian.Big))
|
||
|
{
|
||
|
socketReader.ReadByte();
|
||
|
}
|
||
|
|
||
|
socketReader.Reset();
|
||
|
|
||
|
return PeekEndian() != Env.Endianness;
|
||
|
}
|
||
|
|
||
|
public override Byte ReadByte() => BufferedSocketReader.ReadByte();
|
||
|
|
||
|
public override ArraySegment<Byte> ReadSegment(Int32 size) => BufferedSocketReader.ReadSegment(size);
|
||
|
|
||
|
}
|