---
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;
using System.Text;

namespace Demo
{
    public readonly record struct AppError(
        int Code,
        string Message
    )
    {
        internal static AppError Decode(WireReader reader) =>
            new AppError(
                reader.ReadI32(),
                reader.ReadString()
            );

        internal int WireEncodedSize() =>
            4 +
            (4 + Encoding.UTF8.GetByteCount(this.Message));

        internal void WireEncodeTo(WireWriter wire)
        {
            wire.WriteI32(this.Code);
            wire.WriteString(this.Message);
        }
    }
    /// <summary>
    /// Thrown by generated wrapper methods when the Rust side returns
    /// a <c>AppError</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 AppErrorException : Exception
    {
        public AppError Error { get; }

        public AppErrorException(AppError error) : base(error.Message)
        {
            Error = error;
        }
    }
}
