---
source: crates/cli/tests/codegen.rs
expression: outfiles
---
"AddPlayerReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class AddPlayer : IReducerArgs
{
string IReducerArgs.ReducerName => "add_player";
public string Name = "";
}
}
'''
"AddPrivateReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class AddPrivate : IReducerArgs
{
string IReducerArgs.ReducerName => "add_private";
public string Name = "";
}
}
'''
"Baz.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class Baz
{
[DataMember(Name = "field")]
public string Field;
public Baz(
string Field
)
{
this.Field = Field;
}
public Baz()
{
this.Field = "";
}
}
}
'''
"DeletePlayerReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class DeletePlayer : IReducerArgs
{
string IReducerArgs.ReducerName => "delete_player";
public ulong Id;
}
}
'''
"DeletePlayersByNameReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class DeletePlayersByName : IReducerArgs
{
string IReducerArgs.ReducerName => "delete_players_by_name";
public string Name = "";
}
}
'''
"Foobar.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial record Foobar : SpacetimeDB.TaggedEnum<(
SpacetimeDB.Baz Baz,
SpacetimeDB.Unit Bar,
uint Har
)>;
}
'''
"HasSpecialStuff.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class HasSpecialStuff : IDatabaseRow
{
[DataMember(Name = "identity")]
public SpacetimeDB.Identity Identity;
[DataMember(Name = "address")]
public SpacetimeDB.Address Address;
public HasSpecialStuff(
SpacetimeDB.Identity Identity,
SpacetimeDB.Address Address
)
{
this.Identity = Identity;
this.Address = Address;
}
public HasSpecialStuff()
{
this.Identity = new();
this.Address = new();
}
}
}
'''
"NamespaceTestC.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
public partial class Namespace
{
public partial class Types
{
[SpacetimeDB.Type]
public enum TestC
{
Foo,
Bar,
}
}
}
}
'''
"NamespaceTestF.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
public partial class Namespace
{
public partial class Types
{
[SpacetimeDB.Type]
public partial record TestF : SpacetimeDB.TaggedEnum<(
SpacetimeDB.Unit Foo,
SpacetimeDB.Unit Bar,
string Baz
)>;
}
}
}
'''
"PkMultiIdentity.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class PkMultiIdentity : IDatabaseRow
{
[DataMember(Name = "id")]
public uint Id;
[DataMember(Name = "other")]
public uint Other;
public PkMultiIdentity(
uint Id,
uint Other
)
{
this.Id = Id;
this.Other = Other;
}
public PkMultiIdentity()
{
}
}
}
'''
"Points.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class Point : IDatabaseRow
{
[DataMember(Name = "x")]
public long X;
[DataMember(Name = "y")]
public long Y;
public Point(
long X,
long Y
)
{
this.X = X;
this.Y = Y;
}
public Point()
{
}
}
}
'''
"Private.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class Private : IDatabaseRow
{
[DataMember(Name = "name")]
public string Name;
public Private(
string Name
)
{
this.Name = Name;
}
public Private()
{
this.Name = "";
}
}
}
'''
"QueryPrivateReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class QueryPrivate : IReducerArgs
{
string IReducerArgs.ReducerName => "query_private";
}
}
'''
"RepeatingTestArg.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class RepeatingTestArg : IDatabaseRow
{
[DataMember(Name = "prev_time")]
public ulong PrevTime;
[DataMember(Name = "scheduled_id")]
public ulong ScheduledId;
[DataMember(Name = "scheduled_at")]
public SpacetimeDB.ScheduleAt ScheduledAt;
public RepeatingTestArg(
ulong PrevTime,
ulong ScheduledId,
SpacetimeDB.ScheduleAt ScheduledAt
)
{
this.PrevTime = PrevTime;
this.ScheduledId = ScheduledId;
this.ScheduledAt = ScheduledAt;
}
public RepeatingTestArg()
{
this.ScheduledAt = null!;
}
}
}
'''
"RepeatingTestReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class RepeatingTest : IReducerArgs
{
string IReducerArgs.ReducerName => "repeating_test";
public SpacetimeDB.RepeatingTestArg Arg = new();
}
}
'''
"TestA.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class TestA : IDatabaseRow
{
[DataMember(Name = "x")]
public uint X;
[DataMember(Name = "y")]
public uint Y;
[DataMember(Name = "z")]
public string Z;
public TestA(
uint X,
uint Y,
string Z
)
{
this.X = X;
this.Y = Y;
this.Z = Z;
}
public TestA()
{
this.Z = "";
}
}
}
'''
"TestB.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class TestB
{
[DataMember(Name = "foo")]
public string Foo;
public TestB(
string Foo
)
{
this.Foo = Foo;
}
public TestB()
{
this.Foo = "";
}
}
}
'''
"TestD.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class TestD : IDatabaseRow
{
[DataMember(Name = "test_c")]
public SpacetimeDB.Namespace.Types.TestC? TestC;
public TestD(
SpacetimeDB.Namespace.Types.TestC? TestC
)
{
this.TestC = TestC;
}
public TestD()
{
}
}
}
'''
"TestE.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class TestE : IDatabaseRow
{
[DataMember(Name = "id")]
public ulong Id;
[DataMember(Name = "name")]
public string Name;
public TestE(
ulong Id,
string Name
)
{
this.Id = Id;
this.Name = Name;
}
public TestE()
{
this.Name = "";
}
}
}
'''
"TestF.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
[DataContract]
public partial class TestFoobar : IDatabaseRow
{
[DataMember(Name = "field")]
public SpacetimeDB.Foobar Field;
public TestFoobar(
SpacetimeDB.Foobar Field
)
{
this.Field = Field;
}
public TestFoobar()
{
this.Field = null!;
}
}
}
'''
"TestReducer.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
namespace SpacetimeDB
{
[SpacetimeDB.Type]
public partial class Test : IReducerArgs
{
string IReducerArgs.ReducerName => "test";
public SpacetimeDB.TestA Arg = new();
public SpacetimeDB.TestB Arg2 = new();
public SpacetimeDB.Namespace.Types.TestC Arg3;
public SpacetimeDB.Namespace.TestF Arg4 = null!;
}
}
'''
"_Globals/SpacetimeDBClient.cs" = '''
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN RUST INSTEAD.
// <auto-generated />
#nullable enable
using System;
using SpacetimeDB.ClientApi;
using System.Collections.Generic;
namespace SpacetimeDB
{
public sealed class RemoteTables
{
public class HasSpecialStuffHandle : RemoteTableHandle<EventContext, HasSpecialStuff>
{
internal HasSpecialStuffHandle()
{
}
}
public readonly HasSpecialStuffHandle HasSpecialStuff = new();
public class PkMultiIdentityHandle : RemoteTableHandle<EventContext, PkMultiIdentity>
{
private static Dictionary<uint, PkMultiIdentity> Id_Index = new(16);
private static Dictionary<uint, PkMultiIdentity> Other_Index = new(16);
public override void InternalInvokeValueInserted(IDatabaseRow row)
{
var value = (PkMultiIdentity)row;
Id_Index[value.Id] = value;
Other_Index[value.Other] = value;
}
public override void InternalInvokeValueDeleted(IDatabaseRow row)
{
Id_Index.Remove(((PkMultiIdentity)row).Id);
Other_Index.Remove(((PkMultiIdentity)row).Other);
}
public readonly ref struct IdUniqueIndex
{
public PkMultiIdentity? Find(uint value)
{
Id_Index.TryGetValue(value, out var r);
return r;
}
}
public IdUniqueIndex Id => new();
public readonly ref struct OtherUniqueIndex
{
public PkMultiIdentity? Find(uint value)
{
Other_Index.TryGetValue(value, out var r);
return r;
}
}
public OtherUniqueIndex Other => new();
internal PkMultiIdentityHandle()
{
}
public override object GetPrimaryKey(IDatabaseRow row) => ((PkMultiIdentity)row).Id;
}
public readonly PkMultiIdentityHandle PkMultiIdentity = new();
public class PointsHandle : RemoteTableHandle<EventContext, Point>
{
public class XYIndex
{
PointsHandle Handle;
internal XYIndex(PointsHandle handle) => Handle = handle;
public IEnumerable<Point> Filter(long value) =>
Handle.Query(x => x.X == value);
}
public XYIndex XY { get; init; }
internal PointsHandle()
{
XY = new(this);
}
}
public readonly PointsHandle Points = new();
public class PrivateHandle : RemoteTableHandle<EventContext, Private>
{
internal PrivateHandle()
{
}
}
public readonly PrivateHandle Private = new();
public class RepeatingTestArgHandle : RemoteTableHandle<EventContext, RepeatingTestArg>
{
private static Dictionary<ulong, RepeatingTestArg> ScheduledId_Index = new(16);
public override void InternalInvokeValueInserted(IDatabaseRow row)
{
var value = (RepeatingTestArg)row;
ScheduledId_Index[value.ScheduledId] = value;
}
public override void InternalInvokeValueDeleted(IDatabaseRow row)
{
ScheduledId_Index.Remove(((RepeatingTestArg)row).ScheduledId);
}
public readonly ref struct ScheduledIdUniqueIndex
{
public RepeatingTestArg? Find(ulong value)
{
ScheduledId_Index.TryGetValue(value, out var r);
return r;
}
}
public ScheduledIdUniqueIndex ScheduledId => new();
internal RepeatingTestArgHandle()
{
}
public override object GetPrimaryKey(IDatabaseRow row) => ((RepeatingTestArg)row).ScheduledId;
}
public readonly RepeatingTestArgHandle RepeatingTestArg = new();
public class TestAHandle : RemoteTableHandle<EventContext, TestA>
{
public class XIndex
{
TestAHandle Handle;
internal XIndex(TestAHandle handle) => Handle = handle;
public IEnumerable<TestA> Filter(uint value) =>
Handle.Query(x => x.X == value);
}
public XIndex X { get; init; }
internal TestAHandle()
{
X = new(this);
}
}
public readonly TestAHandle TestA = new();
public class TestDHandle : RemoteTableHandle<EventContext, TestD>
{
internal TestDHandle()
{
}
}
public readonly TestDHandle TestD = new();
public class TestEHandle : RemoteTableHandle<EventContext, TestE>
{
private static Dictionary<ulong, TestE> Id_Index = new(16);
public override void InternalInvokeValueInserted(IDatabaseRow row)
{
var value = (TestE)row;
Id_Index[value.Id] = value;
}
public override void InternalInvokeValueDeleted(IDatabaseRow row)
{
Id_Index.Remove(((TestE)row).Id);
}
public readonly ref struct IdUniqueIndex
{
public TestE? Find(ulong value)
{
Id_Index.TryGetValue(value, out var r);
return r;
}
}
public IdUniqueIndex Id => new();
public class NameIndex
{
TestEHandle Handle;
internal NameIndex(TestEHandle handle) => Handle = handle;
public IEnumerable<TestE> Filter(string value) =>
Handle.Query(x => x.Name == value);
}
public NameIndex Name { get; init; }
internal TestEHandle()
{
Name = new(this);
}
public override object GetPrimaryKey(IDatabaseRow row) => ((TestE)row).Id;
}
public readonly TestEHandle TestE = new();
public class TestFHandle : RemoteTableHandle<EventContext, TestFoobar>
{
internal TestFHandle()
{
}
}
public readonly TestFHandle TestF = new();
}
public sealed class RemoteReducers : RemoteBase<DbConnection>
{
internal RemoteReducers(DbConnection conn) : base(conn) {}
public delegate void AddPlayerHandler(EventContext ctx, string name);
public event AddPlayerHandler? OnAddPlayer;
public void AddPlayer(string name)
{
conn.InternalCallReducer(new AddPlayer { Name = name });
}
public bool InvokeAddPlayer(EventContext ctx, AddPlayer args)
{
if (OnAddPlayer == null) return false;
OnAddPlayer(
ctx,
args.Name
);
return true;
}
public delegate void AddPrivateHandler(EventContext ctx, string name);
public event AddPrivateHandler? OnAddPrivate;
public void AddPrivate(string name)
{
conn.InternalCallReducer(new AddPrivate { Name = name });
}
public bool InvokeAddPrivate(EventContext ctx, AddPrivate args)
{
if (OnAddPrivate == null) return false;
OnAddPrivate(
ctx,
args.Name
);
return true;
}
public delegate void DeletePlayerHandler(EventContext ctx, ulong id);
public event DeletePlayerHandler? OnDeletePlayer;
public void DeletePlayer(ulong id)
{
conn.InternalCallReducer(new DeletePlayer { Id = id });
}
public bool InvokeDeletePlayer(EventContext ctx, DeletePlayer args)
{
if (OnDeletePlayer == null) return false;
OnDeletePlayer(
ctx,
args.Id
);
return true;
}
public delegate void DeletePlayersByNameHandler(EventContext ctx, string name);
public event DeletePlayersByNameHandler? OnDeletePlayersByName;
public void DeletePlayersByName(string name)
{
conn.InternalCallReducer(new DeletePlayersByName { Name = name });
}
public bool InvokeDeletePlayersByName(EventContext ctx, DeletePlayersByName args)
{
if (OnDeletePlayersByName == null) return false;
OnDeletePlayersByName(
ctx,
args.Name
);
return true;
}
public delegate void QueryPrivateHandler(EventContext ctx);
public event QueryPrivateHandler? OnQueryPrivate;
public void QueryPrivate()
{
conn.InternalCallReducer(new QueryPrivate { });
}
public bool InvokeQueryPrivate(EventContext ctx, QueryPrivate args)
{
if (OnQueryPrivate == null) return false;
OnQueryPrivate(
ctx
);
return true;
}
public delegate void RepeatingTestHandler(EventContext ctx, SpacetimeDB.RepeatingTestArg arg);
public event RepeatingTestHandler? OnRepeatingTest;
public void RepeatingTest(SpacetimeDB.RepeatingTestArg arg)
{
conn.InternalCallReducer(new RepeatingTest { Arg = arg });
}
public bool InvokeRepeatingTest(EventContext ctx, RepeatingTest args)
{
if (OnRepeatingTest == null) return false;
OnRepeatingTest(
ctx,
args.Arg
);
return true;
}
public delegate void TestHandler(EventContext ctx, SpacetimeDB.TestA arg, SpacetimeDB.TestB arg2, SpacetimeDB.Namespace.Types.TestC arg3, SpacetimeDB.Namespace.TestF arg4);
public event TestHandler? OnTest;
public void Test(SpacetimeDB.TestA arg, SpacetimeDB.TestB arg2, SpacetimeDB.Namespace.Types.TestC arg3, SpacetimeDB.Namespace.TestF arg4)
{
conn.InternalCallReducer(new Test { Arg = arg, Arg2 = arg2, Arg3 = arg3, Arg4 = arg4 });
}
public bool InvokeTest(EventContext ctx, Test args)
{
if (OnTest == null) return false;
OnTest(
ctx,
args.Arg,
args.Arg2,
args.Arg3,
args.Arg4
);
return true;
}
}
public partial record EventContext : DbContext<RemoteTables>, IEventContext
{
public readonly RemoteReducers Reducers;
public readonly Event<Reducer> Event;
internal EventContext(DbConnection conn, Event<Reducer> reducerEvent) : base(conn.Db)
{
Reducers = conn.Reducers;
Event = reducerEvent;
}
}
[Type]
public partial record Reducer : TaggedEnum<(
AddPlayer AddPlayer,
AddPrivate AddPrivate,
DeletePlayer DeletePlayer,
DeletePlayersByName DeletePlayersByName,
QueryPrivate QueryPrivate,
RepeatingTest RepeatingTest,
Test Test,
Unit StdbNone,
Unit StdbIdentityConnected,
Unit StdbIdentityDisconnected
)>;
public class DbConnection : DbConnectionBase<DbConnection, Reducer>
{
public readonly RemoteTables Db = new();
public readonly RemoteReducers Reducers;
public DbConnection()
{
Reducers = new(this);
clientDB.AddTable<HasSpecialStuff>("has_special_stuff", Db.HasSpecialStuff);
clientDB.AddTable<PkMultiIdentity>("pk_multi_identity", Db.PkMultiIdentity);
clientDB.AddTable<Point>("points", Db.Points);
clientDB.AddTable<Private>("private", Db.Private);
clientDB.AddTable<RepeatingTestArg>("repeating_test_arg", Db.RepeatingTestArg);
clientDB.AddTable<TestA>("test_a", Db.TestA);
clientDB.AddTable<TestD>("test_d", Db.TestD);
clientDB.AddTable<TestE>("test_e", Db.TestE);
clientDB.AddTable<TestFoobar>("test_f", Db.TestF);
}
protected override Reducer ToReducer(TransactionUpdate update)
{
var encodedArgs = update.ReducerCall.Args;
return update.ReducerCall.ReducerName switch {
"add_player" => new Reducer.AddPlayer(BSATNHelpers.Decode<AddPlayer>(encodedArgs)),
"add_private" => new Reducer.AddPrivate(BSATNHelpers.Decode<AddPrivate>(encodedArgs)),
"delete_player" => new Reducer.DeletePlayer(BSATNHelpers.Decode<DeletePlayer>(encodedArgs)),
"delete_players_by_name" => new Reducer.DeletePlayersByName(BSATNHelpers.Decode<DeletePlayersByName>(encodedArgs)),
"query_private" => new Reducer.QueryPrivate(BSATNHelpers.Decode<QueryPrivate>(encodedArgs)),
"repeating_test" => new Reducer.RepeatingTest(BSATNHelpers.Decode<RepeatingTest>(encodedArgs)),
"test" => new Reducer.Test(BSATNHelpers.Decode<Test>(encodedArgs)),
"<none>" => new Reducer.StdbNone(default),
"__identity_connected__" => new Reducer.StdbIdentityConnected(default),
"__identity_disconnected__" => new Reducer.StdbIdentityDisconnected(default),
"" => new Reducer.StdbNone(default),
var reducer => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
};
}
protected override IEventContext ToEventContext(Event<Reducer> reducerEvent) =>
new EventContext(this, reducerEvent);
protected override bool Dispatch(IEventContext context, Reducer reducer)
{
var eventContext = (EventContext)context;
return reducer switch {
Reducer.AddPlayer(var args) => Reducers.InvokeAddPlayer(eventContext, args),
Reducer.AddPrivate(var args) => Reducers.InvokeAddPrivate(eventContext, args),
Reducer.DeletePlayer(var args) => Reducers.InvokeDeletePlayer(eventContext, args),
Reducer.DeletePlayersByName(var args) => Reducers.InvokeDeletePlayersByName(eventContext, args),
Reducer.QueryPrivate(var args) => Reducers.InvokeQueryPrivate(eventContext, args),
Reducer.RepeatingTest(var args) => Reducers.InvokeRepeatingTest(eventContext, args),
Reducer.Test(var args) => Reducers.InvokeTest(eventContext, args),
Reducer.StdbNone or
Reducer.StdbIdentityConnected or
Reducer.StdbIdentityDisconnected => true,
_ => throw new ArgumentOutOfRangeException("Reducer", $"Unknown reducer {reducer}")
};
}
public SubscriptionBuilder<EventContext> SubscriptionBuilder() => new(this);
}
}
'''