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.
37 lines
858 B
C#
37 lines
858 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace ScreenLogicConnect.Messages
|
|
{
|
|
public class HLMessageTypeHelper
|
|
{
|
|
public static String extractString(BinaryReader br)
|
|
{
|
|
var len = br.ReadInt32();
|
|
var str = new String(br.ReadChars(len));
|
|
while (len % 4 != 0)
|
|
{
|
|
br.Read();
|
|
len++;
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
public static RgbColor extractColor(BinaryReader br)
|
|
{
|
|
return new RgbColor(
|
|
(byte)(br.ReadInt32() & 0xff),
|
|
(byte)(br.ReadInt32() & 0xff),
|
|
(byte)(br.ReadInt32() & 0xff)
|
|
);
|
|
}
|
|
|
|
public static int alignToNext4Boundary(int val)
|
|
{
|
|
int sub = val % 4;
|
|
return sub == 0 ? 0 : 4 - sub;
|
|
}
|
|
}
|
|
}
|