Converted as much ugly code as I could find into appropriate C#-friendly versions. For example, all the manual ByteHelper stuff, buffer index tracking, etc. are now BinaryWriters/BinaryReaders. Also cleaned up a bunch of getter and setter methods to use C# properties.

There's still more to be done here, but this greatly simplifies the code for reading and comprehension.
This commit is contained in:
2018-03-28 15:28:18 -05:00
parent f893882c4e
commit e524e394c6
16 changed files with 355 additions and 921 deletions

View File

@ -1,5 +1,7 @@
using System;
using ScreenLogicConnect.Messages;
using System.IO;
using System.Net.Sockets;
using System.Text;
namespace ScreenLogicConnect
{
@ -8,7 +10,33 @@ namespace ScreenLogicConnect
public static void SendHLMessage(this NetworkStream stream, Messages.HLMessage msg)
{
var arr = msg.asByteArray();
stream.Write((byte[])(Array)arr, 0, arr.Length);
System.Diagnostics.Debug.WriteLine($" sent {arr.Length}");
stream.Write(arr, 0, arr.Length);
}
public static void WritePrefixLength(this BinaryWriter bw, string val)
{
bw.Write(val.Length);
bw.Write(Encoding.ASCII.GetBytes(val));
bw.Write(new byte[HLMessageTypeHelper.alignToNext4Boundary(val.Length)]);
}
public static void WritePrefixLength(this BinaryWriter bw, byte[] val)
{
bw.Write(val.Length);
bw.Write(val);
}
public static void Write(this BinaryWriter bw, HLTime hlTime)
{
bw.Write(hlTime.year);
bw.Write(hlTime.month);
bw.Write(hlTime.dayOfWeek);
bw.Write(hlTime.day);
bw.Write(hlTime.hour);
bw.Write(hlTime.minute);
bw.Write(hlTime.second);
bw.Write(hlTime.millisecond);
}
}
}