// Generated from executable documentation examples. Edit the source region, then regenerate. using System; using System.IO; using System.IO.Pipelines; using System.Linq; using System.Buffers; using System.Collections.Generic; using System.Dynamic; using System.Globalization; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using CStructSharp; using CStructSharp.Codecs; using CStructSharp.Diagnostics; using CStructSharp.Introspection; using CStructSharp.Values; internal static partial class Program { public static void Main() { IdentifierOrder(); Console.WriteLine("PASS identifier-order"); } private static void IdentifierOrder() { var layout = new CStruct("struct root { uuid network; guid windows; };", aligned: false); Guid id = Guid.Parse("00112233-4455-6677-8899-aabbccddeeff"); byte[] bytes = layout.Serialize("root", new Dictionary { ["network"] = id, ["windows"] = id }); SequenceEqual(Convert.FromHexString("00112233445566778899AABBCCDDEEFF33221100554477668899AABBCCDDEEFF"), bytes); Equal(id, layout.ReadValue(bytes.AsSpan(), "root.network")); Equal(id, layout.ReadValue(bytes.AsSpan(), "root.windows")); using var stream = new MemoryStream(bytes); Equal(16L, layout.ResolveAddress(stream, "root.windows")); } private static void Equal(T expected, T actual) { if (!EqualityComparer.Default.Equals(expected, actual)) { throw new InvalidOperationException($"Expected '{expected}', received '{actual}'."); } } private static void SequenceEqual(byte[] expected, byte[] actual) { if (!expected.AsSpan().SequenceEqual(actual)) { throw new InvalidOperationException( $"Expected {Convert.ToHexString(expected)}, received {Convert.ToHexString(actual)}."); } } }