From 59c18658cd8b7457408c19d0a3c29ff93d58dd5c Mon Sep 17 00:00:00 2001 From: Yauhen Pahrabniak Date: Tue, 28 May 2024 16:26:00 +0200 Subject: [PATCH] Fixed compilation on linux --- MsgPack/Detail/StringComparisonHelper.cs | 37 +++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/MsgPack/Detail/StringComparisonHelper.cs b/MsgPack/Detail/StringComparisonHelper.cs index 024c7fa..c7cdb95 100644 --- a/MsgPack/Detail/StringComparisonHelper.cs +++ b/MsgPack/Detail/StringComparisonHelper.cs @@ -3,22 +3,25 @@ namespace CitizenFX.MsgPack.Detail { - [StructLayout(LayoutKind.Explicit)] - internal unsafe struct StringComparisonHelper - { - [FieldOffset(0)] public fixed byte u8[8]; - [FieldOffset(0)] public fixed ushort u16[4]; - [FieldOffset(0)] public fixed uint u32[2]; - [FieldOffset(0)] public fixed ulong u64[1]; + [StructLayout(LayoutKind.Explicit)] + internal unsafe struct StringComparisonHelper + { + [FieldOffset(0)] public fixed byte u8[8]; + [FieldOffset(0)] public fixed ushort u16[4]; + [FieldOffset(0)] public fixed uint u32[2]; + [FieldOffset(0)] public fixed ulong u64[1]; - public StringComparisonHelper(string str, int offset = 0) - { - int length = str.Length - offset; - if (length > 8) - length = 8; + public StringComparisonHelper(string str, int offset = 0) + { + fixed (byte* pU8 = u8) + { + int length = str.Length - offset; + if (length > 8) + length = 8; - for (int i = 0; i < length; ++i) - u8[i] = (byte)str[i - offset]; - } - } -} + for (int i = 0; i < length; ++i) + pU8[i] = (byte)str[i + offset]; + } + } + } +} \ No newline at end of file