---
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;
        public sealed record Rectangle(
            double Width,
            double Height
        ) : Shape;
        public sealed record Point() : Shape;

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

        internal int WireEncodedSize() => 4 + this switch
        {
            Circle _v => 8,
            Rectangle _v => 8 + 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 Rectangle _v:
                    wire.WriteI32(1);
                    wire.WriteF64(_v.Width);
                    wire.WriteF64(_v.Height);
                    break;
                case Point:
                    wire.WriteI32(2);
                    break;
            }
        }
    }
}
