// 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() { InspectRanges(); Console.WriteLine("PASS inspect-ranges"); } private static void InspectRanges() { var layout = new CStruct("struct sample { uint8 tag; uint16 value; };"); using var stream = new MemoryStream([0xA1, 0x34, 0x12]); (StructValue result, IReadOnlyList ranges) = layout.ParseWithDebug(stream, "sample"); Equal((byte)0xA1, result.Get("tag")); True(ranges.Any(item => item.Start == 1 && item.End == 3), "Value range was not reported."); stream.Position = 0; Equal(1L, layout.ResolveAddress(stream, "sample.value")); Equal(0L, stream.Position); } private static void Equal(T expected, T actual) { if (!EqualityComparer.Default.Equals(expected, actual)) { throw new InvalidOperationException($"Expected '{expected}', received '{actual}'."); } } private static void True(bool condition, string message) { if (!condition) { throw new InvalidOperationException(message); } } }