// 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() { RelativePointer(); Console.WriteLine("PASS relative-pointer"); } private static void RelativePointer() { var layout = new CStruct("struct root { uint8 *target; };", pointerSize: 1); byte[] bytes = [0xEE, 1, 42]; using var stream = new MemoryStream(bytes); stream.Position = 1; StructValue root = layout.Parse(stream, "root", options: new ReadOptions { AddressingMode = PointerAddressingMode.Relative, Origin = 1, MaxPointerDepth = 1, MaxPointerTargetBytes = 1, }); Pointer pointer = root.Get("target"); Equal(1L, pointer.Address); Equal((byte)42, (byte)pointer.Value!); } private static void Equal(T expected, T actual) { if (!EqualityComparer.Default.Equals(expected, actual)) { throw new InvalidOperationException($"Expected '{expected}', received '{actual}'."); } } }