code generator that automatically switches endianness
This commit is contained in:
parent
e603c154b9
commit
5532c4f5a8
1 changed files with 291 additions and 34 deletions
|
|
@ -1,29 +1,19 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Runtime.InteropServices;
|
||||
using EndiannessSourceGenerator;
|
||||
|
||||
namespace DisplayCommands.Internals;
|
||||
|
||||
[StructEndianness(IsLittleEndian = false)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 16, Size = 10)]
|
||||
internal struct HeaderWindow
|
||||
internal partial struct HeaderWindow
|
||||
{
|
||||
public DisplayCommand Command;
|
||||
private ushort _command;
|
||||
|
||||
public ushort PosX;
|
||||
private ushort _posX;
|
||||
|
||||
public ushort PosY;
|
||||
private ushort _posY;
|
||||
|
||||
public ushort Width;
|
||||
private ushort _width;
|
||||
|
||||
public ushort Height;
|
||||
|
||||
public void ChangeToNetworkOrder()
|
||||
{
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
return;
|
||||
Command = (DisplayCommand)BinaryPrimitives.ReverseEndianness((ushort)Command);
|
||||
PosX = BinaryPrimitives.ReverseEndianness(PosX);
|
||||
PosY = BinaryPrimitives.ReverseEndianness(PosY);
|
||||
Width = BinaryPrimitives.ReverseEndianness(Width);
|
||||
Height = BinaryPrimitives.ReverseEndianness(Height);
|
||||
}
|
||||
private ushort _height;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue