---
source: boltffi_bindgen/src/render/csharp/templates.rs
assertion_line: 1075
expression: template.render().unwrap()
---
// <auto-generated>
// This file was generated by BoltFFI. Do not edit.
// </auto-generated>
#nullable enable

using System;

namespace Demo
{
    /// <summary>
    /// A 2D shape.
    /// </summary>
    public abstract record Shape
    {
        private Shape() { }
        /// <summary>
        /// A round shape.
        /// </summary>
        /// <param name="Radius">Distance from the center.</param>
        public sealed record Circle(
            double Radius
        ) : Shape;
        /// <summary>
        /// A degenerate point.
        /// </summary>
        public sealed record Point() : Shape;

        internal static Shape Decode(WireReader reader) =>
            reader.ReadI32() switch
            {
                0 => new Circle(
                    reader.ReadF64()
                ),
                1 => new Point(),
                int tag => throw new InvalidOperationException($"Unknown Shape tag: {tag}"),
            };

        internal int WireEncodedSize() => 4 + this switch
        {
            Circle _v => 8,
            Point => 0,
            _ => throw new InvalidOperationException($"Unknown Shape variant"),
        };

        internal void WireEncodeTo(WireWriter wire)
        {
            switch (this)
            {
                case Circle _v:
                    wire.WriteI32(0);
                    wire.WriteF64(_v.Radius);
                    break;
                case Point:
                    wire.WriteI32(1);
                    break;
            }
        }
    }
}
