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

using System;

namespace Demo
{
    public abstract record Shape
    {
        private Shape() { }
        public sealed record Circle(
            double Radius
        ) : Shape;

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

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

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

        public static Shape UnitCircle()
        {
            FfiBuf _buf = NativeMethods.ShapeUnitCircle();
            try
            {
                return Shape.Decode(new WireReader(_buf));
            }
            finally
            {
                NativeMethods.FreeBuf(_buf);
            }
        }

        public static uint VariantCount()
        {
            return NativeMethods.ShapeVariantCount();
        }

        public double Area()
        {
            using var _wire_self = new WireWriter(this.WireEncodedSize());
            this.WireEncodeTo(_wire_self);
            byte[] _selfBytes = _wire_self.ToArray();
            return NativeMethods.ShapeArea(_selfBytes, (UIntPtr)_selfBytes.Length);
        }

        public string Describe()
        {
            using var _wire_self = new WireWriter(this.WireEncodedSize());
            this.WireEncodeTo(_wire_self);
            byte[] _selfBytes = _wire_self.ToArray();
            FfiBuf _buf = NativeMethods.ShapeDescribe(_selfBytes, (UIntPtr)_selfBytes.Length);
            try
            {
                return new WireReader(_buf).ReadString();
            }
            finally
            {
                NativeMethods.FreeBuf(_buf);
            }
        }
    }
}
