---
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 ComputeError
    {
        private ComputeError() { }
        public sealed record InvalidInput(
            int Value
        ) : ComputeError;
        public sealed record Overflow(
            int Value,
            int Limit
        ) : ComputeError;

        internal static ComputeError Decode(WireReader reader) =>
            reader.ReadI32() switch
            {
                0 => new InvalidInput(
                    reader.ReadI32()
                ),
                1 => new Overflow(
                    reader.ReadI32(),
                    reader.ReadI32()
                ),
                int tag => throw new InvalidOperationException($"Unknown ComputeError tag: {tag}"),
            };

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

        internal void WireEncodeTo(WireWriter wire)
        {
            switch (this)
            {
                case InvalidInput _v:
                    wire.WriteI32(0);
                    wire.WriteI32(_v.Value);
                    break;
                case Overflow _v:
                    wire.WriteI32(1);
                    wire.WriteI32(_v.Value);
                    wire.WriteI32(_v.Limit);
                    break;
            }
        }
    }
    /// <summary>
    /// Thrown by generated wrapper methods when the Rust side returns
    /// a <c>ComputeError</c> as the error. The original value is
    /// exposed through <c>Error</c>; the inherited <c>Message</c>
    /// derives from it (forwarded from a <c>Message</c> field when the
    /// wrapped type has one, otherwise the value's <c>ToString()</c>).
    /// </summary>
    public sealed class ComputeErrorException : Exception
    {
        public ComputeError Error { get; }

        public ComputeErrorException(ComputeError error) : base(error.ToString())
        {
            Error = error;
        }
    }
}
