Innovenergy_trunk/csharp/Lib/Protocols/DBus/Transport/DBusBufferReader.cs

39 lines
1.0 KiB
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
using InnovEnergy.Lib.Protocols.DBus.WireFormat;
namespace InnovEnergy.Lib.Protocols.DBus.Transport;
using Buffer = ArraySegment<Byte>;
internal class DBusBufferReader : DBusReader
{
private Int32 _Position;
private Buffer Buffer { get; }
public override Int32 BytesRead => _Position;
public DBusBufferReader(Buffer buffer, Boolean swapEndian) : base(swapEndian) => Buffer = buffer;
public override Byte ReadByte()
{
return Buffer[_Position++];
}
public override Buffer ReadSegment(Int32 size)
{
var segment = Buffer.Slice(_Position, size);
// DEBUG
// var s = new System.Diagnostics.StackTrace();
// var frames = s.GetFrames();
// var meth = frames
// .Select(f => f.GetMethod()!.Name)
// .FirstOrDefault(n => !n.Contains("AlignedSpan") && !n.Contains("ReadSegment"));
//
// Console.WriteLine(meth ?? "");
// Console.WriteLine(segment.ToHexView2());
_Position += size;
return segment;
}
}