35 lines
984 B
C#
35 lines
984 B
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Meum.Core.Messages;
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct DataMessageHeader
|
|
{
|
|
// 0xb65d6d - meum in 6-bit ascii encoding
|
|
// 02 - DataMessageHeader
|
|
private const uint correct_magic = 0xb65d6d02;
|
|
|
|
/// warning: check with <see cref="ThrowIfInvalid"/>
|
|
public uint magic;
|
|
/// warning: can be any int
|
|
public MessageTypeCode type_code;
|
|
/// warning: check with <see cref="ThrowIfInvalid"/>
|
|
public int data_size;
|
|
|
|
|
|
public DataMessageHeader(MessageTypeCode t, int size)
|
|
{
|
|
magic = correct_magic;
|
|
type_code = t;
|
|
data_size = size;
|
|
}
|
|
|
|
public void ThrowIfInvalid()
|
|
{
|
|
if(magic != correct_magic)
|
|
throw new Exception($"Invalid DataMessageHeader magic: {magic}");
|
|
if(data_size < 1)
|
|
throw new Exception($"Invalid DataMessageHeader data size: {data_size}");
|
|
}
|
|
}
|