// 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() { FixedText(); Console.WriteLine("PASS fixed-text"); } private static void FixedText() { var layout = new CStruct("struct label { char text[4]; };"); StructValue value = layout.Parse(new byte[] { 0x41, 0x42, 0x43, 0x00 }, "label"); Equal("ABC\0", value.Get("text")); SequenceEqual( [0x58, 0x59, 0x00, 0x00], layout.Serialize("label", new Dictionary { ["text"] = "XY" })); } 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)}."); } } }