diff --git a/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj b/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj index cb369cc..0b26467 100644 --- a/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj +++ b/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj @@ -1,7 +1,7 @@  - net471 + netcoreapp2.1;net471 false diff --git a/Capnp.Net.Runtime.Tests/Dtbdct.cs b/Capnp.Net.Runtime.Tests/Dtbdct.cs new file mode 100644 index 0000000..75d2a93 --- /dev/null +++ b/Capnp.Net.Runtime.Tests/Dtbdct.cs @@ -0,0 +1,96 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Capnp.Net.Runtime.Tests +{ + [TestClass] + [TestCategory("Coverage")] + public class Dtbdct: TestBase + { + [TestMethod] + public void Embargo() + { + NewDtbdctTestbed().RunTest(Testsuite.Embargo); + } + + [TestMethod] + public void EmbargoError() + { + NewDtbdctTestbed().RunTest(Testsuite.EmbargoError); + } + + [TestMethod] + public void EmbargoNull() + { + NewDtbdctTestbed().RunTest(Testsuite.EmbargoNull); + } + + [TestMethod] + public void CallBrokenPromise() + { + NewDtbdctTestbed().RunTest(Testsuite.CallBrokenPromise); + } + + [TestMethod] + public void TailCall() + { + NewDtbdctTestbed().RunTest(Testsuite.TailCall); + } + + [TestMethod] + public void SendTwice() + { + NewDtbdctTestbed().RunTest(Testsuite.SendTwice); + } + + [TestMethod] + public void Cancel() + { + NewDtbdctTestbed().RunTest(Testsuite.Cancel); + } + + [TestMethod] + public void RetainAndRelease() + { + NewDtbdctTestbed().RunTest(Testsuite.RetainAndRelease); + } + + [TestMethod] + public void PromiseResolve() + { + NewDtbdctTestbed().RunTest(Testsuite.PromiseResolve); + } + + [TestMethod] + public void Cancelation() + { + NewDtbdctTestbed().RunTest(Testsuite.Cancelation); + } + + [TestMethod] + public void ReleaseOnCancel() + { + NewDtbdctTestbed().RunTest(Testsuite.ReleaseOnCancel); + } + + [TestMethod] + public void Release() + { + NewDtbdctTestbed().RunTest(Testsuite.Release); + } + + [TestMethod] + public void Pipeline() + { + NewDtbdctTestbed().RunTest(Testsuite.Pipeline); + } + + [TestMethod] + public void Basic() + { + NewDtbdctTestbed().RunTest(Testsuite.Basic); + } + } +} diff --git a/Capnp.Net.Runtime.Tests/Interception.cs b/Capnp.Net.Runtime.Tests/Interception.cs index ac0ea63..3008723 100644 --- a/Capnp.Net.Runtime.Tests/Interception.cs +++ b/Capnp.Net.Runtime.Tests/Interception.cs @@ -78,13 +78,13 @@ namespace Capnp.Net.Runtime.Tests Assert.IsTrue(fcc.Wait(MediumNonDbgTimeout)); var cc = fcc.Result; - var pr = new Capnproto_test.Capnp.Test.TestInterface.Params_foo.READER(cc.InArgs); + var pr = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo.READER(cc.InArgs); Assert.AreEqual(123u, pr.I); cc.ForwardToBob(); Assert.IsTrue(policy.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout)); - var rr = new Capnproto_test.Capnp.Test.TestInterface.Result_foo.READER(cc.OutArgs); + var rr = new Capnproto_test.Capnp.Test.TestInterface.Result_Foo.READER(cc.OutArgs); Assert.AreEqual("foo", rr.X); cc.ReturnToAlice(); @@ -117,11 +117,11 @@ namespace Capnp.Net.Runtime.Tests Assert.AreEqual(InterceptionState.RequestedFromAlice, cc.State); - var pr = new Capnproto_test.Capnp.Test.TestInterface.Params_foo.READER(cc.InArgs); + var pr = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo.READER(cc.InArgs); Assert.AreEqual(321u, pr.I); Assert.AreEqual(false, pr.J); - var pw = cc.InArgs.Rewrap(); + var pw = cc.InArgs.Rewrap(); pw.I = 123u; pw.J = true; @@ -133,12 +133,12 @@ namespace Capnp.Net.Runtime.Tests Assert.IsTrue(cc.State == InterceptionState.ForwardedToBob || rx.IsCompleted); Assert.IsTrue(rx.Wait(MediumNonDbgTimeout)); - var rr = new Capnproto_test.Capnp.Test.TestInterface.Result_foo.READER(cc.OutArgs); + var rr = new Capnproto_test.Capnp.Test.TestInterface.Result_Foo.READER(cc.OutArgs); Assert.AreEqual("foo", rr.X); Assert.IsFalse(request1.IsCompleted); - var rw = ((DynamicSerializerState)cc.OutArgs).Rewrap(); + var rw = ((DynamicSerializerState)cc.OutArgs).Rewrap(); rw.X = "bar"; cc.OutArgs = rw; @@ -174,7 +174,7 @@ namespace Capnp.Net.Runtime.Tests Assert.IsTrue(policy.Calls.TryReceive(out var cc)); Assert.IsFalse(request1.IsCompleted); - var rw = SerializerState.CreateForRpc(); + var rw = SerializerState.CreateForRpc(); rw.X = "bar"; cc.OutArgs = rw; diff --git a/Capnp.Net.Runtime.Tests/LocalRpc.cs b/Capnp.Net.Runtime.Tests/LocalRpc.cs index 232313b..fd4f87b 100644 --- a/Capnp.Net.Runtime.Tests/LocalRpc.cs +++ b/Capnp.Net.Runtime.Tests/LocalRpc.cs @@ -20,12 +20,14 @@ namespace Capnp.Net.Runtime.Tests var tcs = new TaskCompletionSource(); var impl = new TestPipelineImpl2(tcs.Task); var bproxy = BareProxy.FromImpl(impl); - var proxy = bproxy.Cast(true); - var cap = proxy.GetCap(0, null).OutBox_Cap(); - var foo = cap.Foo(123, true); - tcs.SetResult(0); - Assert.IsTrue(foo.Wait(TestBase.MediumNonDbgTimeout)); - Assert.AreEqual("bar", foo.Result); + using (var proxy = bproxy.Cast(true)) + using (var cap = proxy.GetCap(0, null).OutBox_Cap()) + { + var foo = cap.Foo(123, true); + tcs.SetResult(0); + Assert.IsTrue(foo.Wait(TestBase.MediumNonDbgTimeout)); + Assert.AreEqual("bar", foo.Result); + } } } } diff --git a/Capnp.Net.Runtime.Tests/TestCapImplementations.cs b/Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs similarity index 98% rename from Capnp.Net.Runtime.Tests/TestCapImplementations.cs rename to Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs index 44cfde2..34fd9fe 100644 --- a/Capnp.Net.Runtime.Tests/TestCapImplementations.cs +++ b/Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs @@ -574,18 +574,17 @@ namespace Capnp.Net.Runtime.Tests.GenImpls class TestCallOrderImpl : ITestCallOrder { readonly object _lock = new object(); + uint _counter; ILogger Logger { get; } = Logging.CreateLogger(); - public uint Count { get; set; } - public uint? CountToDispose { get; set; } public void Dispose() { lock (_lock) - { - Assert.IsTrue(!CountToDispose.HasValue || Count == CountToDispose, "Must not dispose at this point"); + { + Assert.IsTrue(!CountToDispose.HasValue || _counter == CountToDispose, $"Must not dispose at this point: {_counter} {Thread.CurrentThread.Name}"); } } @@ -593,7 +592,18 @@ namespace Capnp.Net.Runtime.Tests.GenImpls { lock (_lock) { - return Task.FromResult(Count++); + return Task.FromResult(_counter++); + } + } + + public uint Count + { + get + { + lock (_lock) + { + return _counter; + } } } } @@ -749,7 +759,7 @@ namespace Capnp.Net.Runtime.Tests.GenImpls public Task GetHeld(CancellationToken cancellationToken_) { Interlocked.Increment(ref _counters.CallCount); - return Task.FromResult(ClientToHold); + return Task.FromResult(Proxy.Share(ClientToHold)); } public Task GetNull(CancellationToken cancellationToken_) diff --git a/Capnp.Net.Runtime.Tests/test.cs b/Capnp.Net.Runtime.Tests/Mock/test.cs similarity index 89% rename from Capnp.Net.Runtime.Tests/test.cs rename to Capnp.Net.Runtime.Tests/Mock/test.cs index db23211..f7930f2 100644 --- a/Capnp.Net.Runtime.Tests/test.cs +++ b/Capnp.Net.Runtime.Tests/Mock/test.cs @@ -56,7 +56,7 @@ namespace Capnproto_test.Capnp.Test Float64List = reader.Float64List; TextList = reader.TextList; DataList = reader.DataList; - StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + StructList = reader.StructList?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); EnumList = reader.EnumList; InterfaceList = reader.InterfaceList; applyDefaults(); @@ -321,7 +321,7 @@ namespace Capnproto_test.Capnp.Test public ulong UInt64Field => ctx.ReadDataULong(192UL, 0UL); public float Float32Field => ctx.ReadDataFloat(256UL, 0F); public double Float64Field => ctx.ReadDataDouble(320UL, 0); - public string TextField => ctx.ReadText(0, ""); + public string TextField => ctx.ReadText(0, null); public IReadOnlyList DataField => ctx.ReadList(1).CastByte(); public Capnproto_test.Capnp.Test.TestAllTypes.READER StructField => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); public Capnproto_test.Capnp.Test.TestEnum EnumField => (Capnproto_test.Capnp.Test.TestEnum)ctx.ReadDataUShort(288UL, (ushort)0); @@ -419,8 +419,8 @@ namespace Capnproto_test.Capnp.Test public string TextField { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public ListOfPrimitivesSerializer DataField @@ -581,7 +581,7 @@ namespace Capnproto_test.Capnp.Test Float64List = reader.Float64List; TextList = reader.TextList; DataList = reader.DataList; - StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + StructList = reader.StructList?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); EnumList = reader.EnumList; InterfaceList = reader.InterfaceList; applyDefaults(); @@ -1284,7 +1284,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); AnyStructField = CapnpSerializable.Create(reader.AnyStructField); - AnyListField = reader.AnyListField.ToReadOnlyList(_ => (object)_); + AnyListField = reader.AnyListField?.ToReadOnlyList(_ => (object)_); CapabilityField = reader.CapabilityField; applyDefaults(); } @@ -1472,15 +1472,15 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string Qux => ctx.ReadText(0, ""); - public string Grault => ctx.ReadText(1, ""); - public string Bar => ctx.ReadText(2, ""); - public string Foo => ctx.ReadText(3, ""); - public string Corge => ctx.ReadText(4, ""); - public string Waldo => ctx.ReadText(5, ""); - public string Quux => ctx.ReadText(6, ""); - public string Garply => ctx.ReadText(7, ""); - public string Baz => ctx.ReadText(8, ""); + public string Qux => ctx.ReadText(0, null); + public string Grault => ctx.ReadText(1, null); + public string Bar => ctx.ReadText(2, null); + public string Foo => ctx.ReadText(3, null); + public string Corge => ctx.ReadText(4, null); + public string Waldo => ctx.ReadText(5, null); + public string Quux => ctx.ReadText(6, null); + public string Garply => ctx.ReadText(7, null); + public string Baz => ctx.ReadText(8, null); } public class WRITER : SerializerState @@ -1492,56 +1492,56 @@ namespace Capnproto_test.Capnp.Test public string Qux { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public string Grault { - get => this.ReadText(1, ""); - set => this.WriteText(1, value, ""); + get => this.ReadText(1, null); + set => this.WriteText(1, value, null); } public string Bar { - get => this.ReadText(2, ""); - set => this.WriteText(2, value, ""); + get => this.ReadText(2, null); + set => this.WriteText(2, value, null); } public string Foo { - get => this.ReadText(3, ""); - set => this.WriteText(3, value, ""); + get => this.ReadText(3, null); + set => this.WriteText(3, value, null); } public string Corge { - get => this.ReadText(4, ""); - set => this.WriteText(4, value, ""); + get => this.ReadText(4, null); + set => this.WriteText(4, value, null); } public string Waldo { - get => this.ReadText(5, ""); - set => this.WriteText(5, value, ""); + get => this.ReadText(5, null); + set => this.WriteText(5, value, null); } public string Quux { - get => this.ReadText(6, ""); - set => this.WriteText(6, value, ""); + get => this.ReadText(6, null); + set => this.WriteText(6, value, null); } public string Garply { - get => this.ReadText(7, ""); - set => this.WriteText(7, value, ""); + get => this.ReadText(7, null); + set => this.WriteText(7, value, null); } public string Baz { - get => this.ReadText(8, ""); - set => this.WriteText(8, value, ""); + get => this.ReadText(8, null); + set => this.WriteText(8, value, null); } } } @@ -1553,10 +1553,10 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Union0 = CapnpSerializable.Create(reader.Union0); - Union1 = CapnpSerializable.Create(reader.Union1); - Union2 = CapnpSerializable.Create(reader.Union2); - Union3 = CapnpSerializable.Create(reader.Union3); + Union0 = CapnpSerializable.Create(reader.Union0); + Union1 = CapnpSerializable.Create(reader.Union1); + Union2 = CapnpSerializable.Create(reader.Union2); + Union3 = CapnpSerializable.Create(reader.Union3); Bit0 = reader.Bit0; Bit2 = reader.Bit2; Bit3 = reader.Bit3; @@ -1593,25 +1593,25 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestUnion.@union0 Union0 + public Capnproto_test.Capnp.Test.TestUnion.union0 Union0 { get; set; } - public Capnproto_test.Capnp.Test.TestUnion.@union1 Union1 + public Capnproto_test.Capnp.Test.TestUnion.union1 Union1 { get; set; } - public Capnproto_test.Capnp.Test.TestUnion.@union2 Union2 + public Capnproto_test.Capnp.Test.TestUnion.union2 Union2 { get; set; } - public Capnproto_test.Capnp.Test.TestUnion.@union3 Union3 + public Capnproto_test.Capnp.Test.TestUnion.union3 Union3 { get; set; @@ -1676,10 +1676,10 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @union0.READER Union0 => new @union0.READER(ctx); - public @union1.READER Union1 => new @union1.READER(ctx); - public @union2.READER Union2 => new @union2.READER(ctx); - public @union3.READER Union3 => new @union3.READER(ctx); + public union0.READER Union0 => new union0.READER(ctx); + public union1.READER Union1 => new union1.READER(ctx); + public union2.READER Union2 => new union2.READER(ctx); + public union3.READER Union3 => new union3.READER(ctx); public bool Bit0 => ctx.ReadDataBool(128UL, false); public bool Bit2 => ctx.ReadDataBool(130UL, false); public bool Bit3 => ctx.ReadDataBool(131UL, false); @@ -1697,24 +1697,24 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(8, 2); } - public @union0.WRITER Union0 + public union0.WRITER Union0 { - get => Rewrap<@union0.WRITER>(); + get => Rewrap(); } - public @union1.WRITER Union1 + public union1.WRITER Union1 { - get => Rewrap<@union1.WRITER>(); + get => Rewrap(); } - public @union2.WRITER Union2 + public union2.WRITER Union2 { - get => Rewrap<@union2.WRITER>(); + get => Rewrap(); } - public @union3.WRITER Union3 + public union3.WRITER Union3 { - get => Rewrap<@union3.WRITER>(); + get => Rewrap(); } public bool Bit0 @@ -1767,7 +1767,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfc76a82eecb7a718UL)] - public class @union0 : ICapnpSerializable + public class union0 : ICapnpSerializable { public const UInt64 typeId = 0xfc76a82eecb7a718UL; public enum WHICH : ushort @@ -2091,13 +2091,13 @@ namespace Capnproto_test.Capnp.Test public short U0f0s16 => which == WHICH.U0f0s16 ? ctx.ReadDataShort(64UL, (short)0) : default; public int U0f0s32 => which == WHICH.U0f0s32 ? ctx.ReadDataInt(64UL, 0) : default; public long U0f0s64 => which == WHICH.U0f0s64 ? ctx.ReadDataLong(64UL, 0L) : default; - public string U0f0sp => which == WHICH.U0f0sp ? ctx.ReadText(0, "") : default; + public string U0f0sp => which == WHICH.U0f0sp ? ctx.ReadText(0, null) : default; public bool U0f1s1 => which == WHICH.U0f1s1 ? ctx.ReadDataBool(64UL, false) : default; public sbyte U0f1s8 => which == WHICH.U0f1s8 ? ctx.ReadDataSByte(64UL, (sbyte)0) : default; public short U0f1s16 => which == WHICH.U0f1s16 ? ctx.ReadDataShort(64UL, (short)0) : default; public int U0f1s32 => which == WHICH.U0f1s32 ? ctx.ReadDataInt(64UL, 0) : default; public long U0f1s64 => which == WHICH.U0f1s64 ? ctx.ReadDataLong(64UL, 0L) : default; - public string U0f1sp => which == WHICH.U0f1sp ? ctx.ReadText(0, "") : default; + public string U0f1sp => which == WHICH.U0f1sp ? ctx.ReadText(0, null) : default; } public class WRITER : SerializerState @@ -2144,8 +2144,8 @@ namespace Capnproto_test.Capnp.Test public string U0f0sp { - get => which == WHICH.U0f0sp ? this.ReadText(0, "") : default; - set => this.WriteText(0, value, ""); + get => which == WHICH.U0f0sp ? this.ReadText(0, null) : default; + set => this.WriteText(0, value, null); } public bool U0f1s1 @@ -2180,14 +2180,14 @@ namespace Capnproto_test.Capnp.Test public string U0f1sp { - get => which == WHICH.U0f1sp ? this.ReadText(0, "") : default; - set => this.WriteText(0, value, ""); + get => which == WHICH.U0f1sp ? this.ReadText(0, null) : default; + set => this.WriteText(0, value, null); } } } [TypeId(0xee0a6b99b7dc7ab2UL)] - public class @union1 : ICapnpSerializable + public class union1 : ICapnpSerializable { public const UInt64 typeId = 0xee0a6b99b7dc7ab2UL; public enum WHICH : ushort @@ -2636,14 +2636,14 @@ namespace Capnproto_test.Capnp.Test public int U1f1s32 => which == WHICH.U1f1s32 ? ctx.ReadDataInt(160UL, 0) : default; public long U1f0s64 => which == WHICH.U1f0s64 ? ctx.ReadDataLong(192UL, 0L) : default; public long U1f1s64 => which == WHICH.U1f1s64 ? ctx.ReadDataLong(192UL, 0L) : default; - public string U1f0sp => which == WHICH.U1f0sp ? ctx.ReadText(1, "") : default; - public string U1f1sp => which == WHICH.U1f1sp ? ctx.ReadText(1, "") : default; + public string U1f0sp => which == WHICH.U1f0sp ? ctx.ReadText(1, null) : default; + public string U1f1sp => which == WHICH.U1f1sp ? ctx.ReadText(1, null) : default; public bool U1f2s1 => which == WHICH.U1f2s1 ? ctx.ReadDataBool(129UL, false) : default; public sbyte U1f2s8 => which == WHICH.U1f2s8 ? ctx.ReadDataSByte(136UL, (sbyte)0) : default; public short U1f2s16 => which == WHICH.U1f2s16 ? ctx.ReadDataShort(144UL, (short)0) : default; public int U1f2s32 => which == WHICH.U1f2s32 ? ctx.ReadDataInt(160UL, 0) : default; public long U1f2s64 => which == WHICH.U1f2s64 ? ctx.ReadDataLong(192UL, 0L) : default; - public string U1f2sp => which == WHICH.U1f2sp ? ctx.ReadText(1, "") : default; + public string U1f2sp => which == WHICH.U1f2sp ? ctx.ReadText(1, null) : default; } public class WRITER : SerializerState @@ -2720,14 +2720,14 @@ namespace Capnproto_test.Capnp.Test public string U1f0sp { - get => which == WHICH.U1f0sp ? this.ReadText(1, "") : default; - set => this.WriteText(1, value, ""); + get => which == WHICH.U1f0sp ? this.ReadText(1, null) : default; + set => this.WriteText(1, value, null); } public string U1f1sp { - get => which == WHICH.U1f1sp ? this.ReadText(1, "") : default; - set => this.WriteText(1, value, ""); + get => which == WHICH.U1f1sp ? this.ReadText(1, null) : default; + set => this.WriteText(1, value, null); } public bool U1f2s1 @@ -2762,14 +2762,14 @@ namespace Capnproto_test.Capnp.Test public string U1f2sp { - get => which == WHICH.U1f2sp ? this.ReadText(1, "") : default; - set => this.WriteText(1, value, ""); + get => which == WHICH.U1f2sp ? this.ReadText(1, null) : default; + set => this.WriteText(1, value, null); } } } [TypeId(0xafc5fd419f0d66d4UL)] - public class @union2 : ICapnpSerializable + public class union2 : ICapnpSerializable { public const UInt64 typeId = 0xafc5fd419f0d66d4UL; public enum WHICH : ushort @@ -2984,7 +2984,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa2fb022ec7f30053UL)] - public class @union3 : ICapnpSerializable + public class union3 : ICapnpSerializable { public const UInt64 typeId = 0xa2fb022ec7f30053UL; public enum WHICH : ushort @@ -3328,11 +3328,11 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); - public string Before => ctx.ReadText(0, ""); + public string Before => ctx.ReadText(0, null); public ushort Foo => which == WHICH.Foo ? ctx.ReadDataUShort(0UL, (ushort)0) : default; public ushort Middle => ctx.ReadDataUShort(16UL, (ushort)0); public uint Bar => which == WHICH.Bar ? ctx.ReadDataUInt(64UL, 0U) : default; - public string After => ctx.ReadText(1, ""); + public string After => ctx.ReadText(1, null); } public class WRITER : SerializerState @@ -3350,8 +3350,8 @@ namespace Capnproto_test.Capnp.Test public string Before { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public ushort Foo @@ -3374,8 +3374,8 @@ namespace Capnproto_test.Capnp.Test public string After { - get => this.ReadText(1, ""); - set => this.WriteText(1, value, ""); + get => this.ReadText(1, null); + set => this.WriteText(1, value, null); } } } @@ -3387,7 +3387,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Outer = CapnpSerializable.Create(reader.Outer); + Outer = CapnpSerializable.Create(reader.Outer); applyDefaults(); } @@ -3405,7 +3405,7 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestUnionInUnion.@outer Outer + public Capnproto_test.Capnp.Test.TestUnionInUnion.outer Outer { get; set; @@ -3422,7 +3422,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @outer.READER Outer => new @outer.READER(ctx); + public outer.READER Outer => new outer.READER(ctx); } public class WRITER : SerializerState @@ -3432,14 +3432,14 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(2, 0); } - public @outer.WRITER Outer + public outer.WRITER Outer { - get => Rewrap<@outer.WRITER>(); + get => Rewrap(); } } [TypeId(0xd005f6c63707670cUL)] - public class @outer : ICapnpSerializable + public class outer : ICapnpSerializable { public const UInt64 typeId = 0xd005f6c63707670cUL; public enum WHICH : ushort @@ -3455,7 +3455,7 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.Inner: - Inner = CapnpSerializable.Create(reader.Inner); + Inner = CapnpSerializable.Create(reader.Inner); break; case WHICH.Baz: Baz = reader.Baz; @@ -3510,9 +3510,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestUnionInUnion.@outer.@inner Inner + public Capnproto_test.Capnp.Test.TestUnionInUnion.outer.inner Inner { - get => _which == WHICH.Inner ? (Capnproto_test.Capnp.Test.TestUnionInUnion.@outer.@inner)_content : null; + get => _which == WHICH.Inner ? (Capnproto_test.Capnp.Test.TestUnionInUnion.outer.inner)_content : null; set { _which = WHICH.Inner; @@ -3542,7 +3542,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); - public @inner.READER Inner => which == WHICH.Inner ? new @inner.READER(ctx) : default; + public inner.READER Inner => which == WHICH.Inner ? new inner.READER(ctx) : default; public int Baz => which == WHICH.Baz ? ctx.ReadDataInt(0UL, 0) : default; } @@ -3558,9 +3558,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(64U, (ushort)value, (ushort)0); } - public @inner.WRITER Inner + public inner.WRITER Inner { - get => which == WHICH.Inner ? Rewrap<@inner.WRITER>() : default; + get => which == WHICH.Inner ? Rewrap() : default; } public int Baz @@ -3571,7 +3571,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xff9ce111c6f8e5dbUL)] - public class @inner : ICapnpSerializable + public class inner : ICapnpSerializable { public const UInt64 typeId = 0xff9ce111c6f8e5dbUL; public enum WHICH : ushort @@ -3713,7 +3713,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Groups = CapnpSerializable.Create(reader.Groups); + Groups = CapnpSerializable.Create(reader.Groups); applyDefaults(); } @@ -3731,7 +3731,7 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestGroups.@groups Groups + public Capnproto_test.Capnp.Test.TestGroups.groups Groups { get; set; @@ -3748,7 +3748,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @groups.READER Groups => new @groups.READER(ctx); + public groups.READER Groups => new groups.READER(ctx); } public class WRITER : SerializerState @@ -3758,14 +3758,14 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(2, 2); } - public @groups.WRITER Groups + public groups.WRITER Groups { - get => Rewrap<@groups.WRITER>(); + get => Rewrap(); } } [TypeId(0xe22ae74ff9113268UL)] - public class @groups : ICapnpSerializable + public class groups : ICapnpSerializable { public const UInt64 typeId = 0xe22ae74ff9113268UL; public enum WHICH : ushort @@ -3782,13 +3782,13 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.Foo: - Foo = CapnpSerializable.Create(reader.Foo); + Foo = CapnpSerializable.Create(reader.Foo); break; case WHICH.Baz: - Baz = CapnpSerializable.Create(reader.Baz); + Baz = CapnpSerializable.Create(reader.Baz); break; case WHICH.Bar: - Bar = CapnpSerializable.Create(reader.Bar); + Bar = CapnpSerializable.Create(reader.Bar); break; } @@ -3846,9 +3846,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestGroups.@groups.@foo Foo + public Capnproto_test.Capnp.Test.TestGroups.groups.foo Foo { - get => _which == WHICH.Foo ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@foo)_content : null; + get => _which == WHICH.Foo ? (Capnproto_test.Capnp.Test.TestGroups.groups.foo)_content : null; set { _which = WHICH.Foo; @@ -3856,9 +3856,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestGroups.@groups.@baz Baz + public Capnproto_test.Capnp.Test.TestGroups.groups.baz Baz { - get => _which == WHICH.Baz ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@baz)_content : null; + get => _which == WHICH.Baz ? (Capnproto_test.Capnp.Test.TestGroups.groups.baz)_content : null; set { _which = WHICH.Baz; @@ -3866,9 +3866,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestGroups.@groups.@bar Bar + public Capnproto_test.Capnp.Test.TestGroups.groups.bar Bar { - get => _which == WHICH.Bar ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@bar)_content : null; + get => _which == WHICH.Bar ? (Capnproto_test.Capnp.Test.TestGroups.groups.bar)_content : null; set { _which = WHICH.Bar; @@ -3888,9 +3888,9 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); - public @foo.READER Foo => which == WHICH.Foo ? new @foo.READER(ctx) : default; - public @baz.READER Baz => which == WHICH.Baz ? new @baz.READER(ctx) : default; - public @bar.READER Bar => which == WHICH.Bar ? new @bar.READER(ctx) : default; + public foo.READER Foo => which == WHICH.Foo ? new foo.READER(ctx) : default; + public baz.READER Baz => which == WHICH.Baz ? new baz.READER(ctx) : default; + public bar.READER Bar => which == WHICH.Bar ? new bar.READER(ctx) : default; } public class WRITER : SerializerState @@ -3905,24 +3905,24 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(32U, (ushort)value, (ushort)0); } - public @foo.WRITER Foo + public foo.WRITER Foo { - get => which == WHICH.Foo ? Rewrap<@foo.WRITER>() : default; + get => which == WHICH.Foo ? Rewrap() : default; } - public @baz.WRITER Baz + public baz.WRITER Baz { - get => which == WHICH.Baz ? Rewrap<@baz.WRITER>() : default; + get => which == WHICH.Baz ? Rewrap() : default; } - public @bar.WRITER Bar + public bar.WRITER Bar { - get => which == WHICH.Bar ? Rewrap<@bar.WRITER>() : default; + get => which == WHICH.Bar ? Rewrap() : default; } } [TypeId(0xf5fcba89c0c1196fUL)] - public class @foo : ICapnpSerializable + public class foo : ICapnpSerializable { public const UInt64 typeId = 0xf5fcba89c0c1196fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -3981,7 +3981,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public int Corge => ctx.ReadDataInt(0UL, 0); public long Grault => ctx.ReadDataLong(64UL, 0L); - public string Garply => ctx.ReadText(0, ""); + public string Garply => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -4004,14 +4004,14 @@ namespace Capnproto_test.Capnp.Test public string Garply { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0xf0fa30304066a4b3UL)] - public class @baz : ICapnpSerializable + public class baz : ICapnpSerializable { public const UInt64 typeId = 0xf0fa30304066a4b3UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4069,8 +4069,8 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public int Corge => ctx.ReadDataInt(0UL, 0); - public string Grault => ctx.ReadText(0, ""); - public string Garply => ctx.ReadText(1, ""); + public string Grault => ctx.ReadText(0, null); + public string Garply => ctx.ReadText(1, null); } public class WRITER : SerializerState @@ -4087,20 +4087,20 @@ namespace Capnproto_test.Capnp.Test public string Grault { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public string Garply { - get => this.ReadText(1, ""); - set => this.WriteText(1, value, ""); + get => this.ReadText(1, null); + set => this.WriteText(1, value, null); } } } [TypeId(0xb727c0d0091a001dUL)] - public class @bar : ICapnpSerializable + public class bar : ICapnpSerializable { public const UInt64 typeId = 0xb727c0d0091a001dUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4158,7 +4158,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public int Corge => ctx.ReadDataInt(0UL, 0); - public string Grault => ctx.ReadText(0, ""); + public string Grault => ctx.ReadText(0, null); public long Garply => ctx.ReadDataLong(64UL, 0L); } @@ -4176,8 +4176,8 @@ namespace Capnproto_test.Capnp.Test public string Grault { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public long Garply @@ -4197,8 +4197,8 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Group1 = CapnpSerializable.Create(reader.Group1); - Group2 = CapnpSerializable.Create(reader.Group2); + Group1 = CapnpSerializable.Create(reader.Group1); + Group2 = CapnpSerializable.Create(reader.Group2); applyDefaults(); } @@ -4217,13 +4217,13 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1 Group1 + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group1 Group1 { get; set; } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2 Group2 + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group2 Group2 { get; set; @@ -4240,8 +4240,8 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @group1.READER Group1 => new @group1.READER(ctx); - public @group2.READER Group2 => new @group2.READER(ctx); + public group1.READER Group1 => new group1.READER(ctx); + public group2.READER Group2 => new group2.READER(ctx); } public class WRITER : SerializerState @@ -4251,19 +4251,19 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(6, 6); } - public @group1.WRITER Group1 + public group1.WRITER Group1 { - get => Rewrap<@group1.WRITER>(); + get => Rewrap(); } - public @group2.WRITER Group2 + public group2.WRITER Group2 { - get => Rewrap<@group2.WRITER>(); + get => Rewrap(); } } [TypeId(0xc7485a3516c7d3c8UL)] - public class @group1 : ICapnpSerializable + public class group1 : ICapnpSerializable { public const UInt64 typeId = 0xc7485a3516c7d3c8UL; public enum WHICH : ushort @@ -4283,7 +4283,7 @@ namespace Capnproto_test.Capnp.Test Qux = reader.Qux; break; case WHICH.Corge: - Corge = CapnpSerializable.Create(reader.Corge); + Corge = CapnpSerializable.Create(reader.Corge); break; case WHICH.Fred: Fred = reader.Fred; @@ -4373,9 +4373,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1.@corge Corge + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group1.corge Corge { - get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1.@corge)_content : null; + get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.group1.corge)_content : null; set { _which = WHICH.Corge; @@ -4414,9 +4414,9 @@ namespace Capnproto_test.Capnp.Test public uint Foo => ctx.ReadDataUInt(0UL, 0U); public ulong Bar => ctx.ReadDataULong(64UL, 0UL); public ushort Qux => which == WHICH.Qux ? ctx.ReadDataUShort(192UL, (ushort)0) : default; - public @corge.READER Corge => which == WHICH.Corge ? new @corge.READER(ctx) : default; - public string Waldo => ctx.ReadText(0, ""); - public string Fred => which == WHICH.Fred ? ctx.ReadText(2, "") : default; + public corge.READER Corge => which == WHICH.Corge ? new corge.READER(ctx) : default; + public string Waldo => ctx.ReadText(0, null); + public string Fred => which == WHICH.Fred ? ctx.ReadText(2, null) : default; } public class WRITER : SerializerState @@ -4449,26 +4449,26 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(192UL, value, (ushort)0); } - public @corge.WRITER Corge + public corge.WRITER Corge { - get => which == WHICH.Corge ? Rewrap<@corge.WRITER>() : default; + get => which == WHICH.Corge ? Rewrap() : default; } public string Waldo { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public string Fred { - get => which == WHICH.Fred ? this.ReadText(2, "") : default; - set => this.WriteText(2, value, ""); + get => which == WHICH.Fred ? this.ReadText(2, null) : default; + set => this.WriteText(2, value, null); } } [TypeId(0xdb0afd413f4a313aUL)] - public class @corge : ICapnpSerializable + public class corge : ICapnpSerializable { public const UInt64 typeId = 0xdb0afd413f4a313aUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4535,8 +4535,8 @@ namespace Capnproto_test.Capnp.Test public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public ulong Grault => ctx.ReadDataULong(256UL, 0UL); public ushort Garply => ctx.ReadDataUShort(192UL, (ushort)0); - public string Plugh => ctx.ReadText(2, ""); - public string Xyzzy => ctx.ReadText(4, ""); + public string Plugh => ctx.ReadText(2, null); + public string Xyzzy => ctx.ReadText(4, null); } public class WRITER : SerializerState @@ -4559,21 +4559,21 @@ namespace Capnproto_test.Capnp.Test public string Plugh { - get => this.ReadText(2, ""); - set => this.WriteText(2, value, ""); + get => this.ReadText(2, null); + set => this.WriteText(2, value, null); } public string Xyzzy { - get => this.ReadText(4, ""); - set => this.WriteText(4, value, ""); + get => this.ReadText(4, null); + set => this.WriteText(4, value, null); } } } } [TypeId(0xcc85a335569990e9UL)] - public class @group2 : ICapnpSerializable + public class group2 : ICapnpSerializable { public const UInt64 typeId = 0xcc85a335569990e9UL; public enum WHICH : ushort @@ -4593,7 +4593,7 @@ namespace Capnproto_test.Capnp.Test Qux = reader.Qux; break; case WHICH.Corge: - Corge = CapnpSerializable.Create(reader.Corge); + Corge = CapnpSerializable.Create(reader.Corge); break; case WHICH.Fred: Fred = reader.Fred; @@ -4683,9 +4683,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2.@corge Corge + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group2.corge Corge { - get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2.@corge)_content : null; + get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.group2.corge)_content : null; set { _which = WHICH.Corge; @@ -4724,9 +4724,9 @@ namespace Capnproto_test.Capnp.Test public uint Foo => ctx.ReadDataUInt(32UL, 0U); public ulong Bar => ctx.ReadDataULong(128UL, 0UL); public ushort Qux => which == WHICH.Qux ? ctx.ReadDataUShort(208UL, (ushort)0) : default; - public @corge.READER Corge => which == WHICH.Corge ? new @corge.READER(ctx) : default; - public string Waldo => ctx.ReadText(1, ""); - public string Fred => which == WHICH.Fred ? ctx.ReadText(3, "") : default; + public corge.READER Corge => which == WHICH.Corge ? new corge.READER(ctx) : default; + public string Waldo => ctx.ReadText(1, null); + public string Fred => which == WHICH.Fred ? ctx.ReadText(3, null) : default; } public class WRITER : SerializerState @@ -4759,26 +4759,26 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(208UL, value, (ushort)0); } - public @corge.WRITER Corge + public corge.WRITER Corge { - get => which == WHICH.Corge ? Rewrap<@corge.WRITER>() : default; + get => which == WHICH.Corge ? Rewrap() : default; } public string Waldo { - get => this.ReadText(1, ""); - set => this.WriteText(1, value, ""); + get => this.ReadText(1, null); + set => this.WriteText(1, value, null); } public string Fred { - get => which == WHICH.Fred ? this.ReadText(3, "") : default; - set => this.WriteText(3, value, ""); + get => which == WHICH.Fred ? this.ReadText(3, null) : default; + set => this.WriteText(3, value, null); } } [TypeId(0xa017f0366827ee37UL)] - public class @corge : ICapnpSerializable + public class corge : ICapnpSerializable { public const UInt64 typeId = 0xa017f0366827ee37UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4845,8 +4845,8 @@ namespace Capnproto_test.Capnp.Test public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public ulong Grault => ctx.ReadDataULong(320UL, 0UL); public ushort Garply => ctx.ReadDataUShort(208UL, (ushort)0); - public string Plugh => ctx.ReadText(3, ""); - public string Xyzzy => ctx.ReadText(5, ""); + public string Plugh => ctx.ReadText(3, null); + public string Xyzzy => ctx.ReadText(5, null); } public class WRITER : SerializerState @@ -4869,14 +4869,14 @@ namespace Capnproto_test.Capnp.Test public string Plugh { - get => this.ReadText(3, ""); - set => this.WriteText(3, value, ""); + get => this.ReadText(3, null); + set => this.WriteText(3, value, null); } public string Xyzzy { - get => this.ReadText(5, ""); - set => this.WriteText(5, value, ""); + get => this.ReadText(5, null); + set => this.WriteText(5, value, null); } } } @@ -4914,13 +4914,13 @@ namespace Capnproto_test.Capnp.Test { S16s8s64s8Set = S16s8s64s8Set ?? new Capnproto_test.Capnp.Test.TestUnion() { - Union0 = new Capnproto_test.Capnp.Test.TestUnion.@union0() + Union0 = new Capnproto_test.Capnp.Test.TestUnion.union0() { }, - Union1 = new Capnproto_test.Capnp.Test.TestUnion.@union1() + Union1 = new Capnproto_test.Capnp.Test.TestUnion.union1() { }, - Union2 = new Capnproto_test.Capnp.Test.TestUnion.@union2() + Union2 = new Capnproto_test.Capnp.Test.TestUnion.union2() { }, - Union3 = new Capnproto_test.Capnp.Test.TestUnion.@union3() + Union3 = new Capnproto_test.Capnp.Test.TestUnion.union3() { }, Bit0 = false, Bit2 = false, @@ -4933,13 +4933,13 @@ namespace Capnproto_test.Capnp.Test }; S0sps1s32Set = S0sps1s32Set ?? new Capnproto_test.Capnp.Test.TestUnion() { - Union0 = new Capnproto_test.Capnp.Test.TestUnion.@union0() + Union0 = new Capnproto_test.Capnp.Test.TestUnion.union0() { }, - Union1 = new Capnproto_test.Capnp.Test.TestUnion.@union1() + Union1 = new Capnproto_test.Capnp.Test.TestUnion.union1() { }, - Union2 = new Capnproto_test.Capnp.Test.TestUnion.@union2() + Union2 = new Capnproto_test.Capnp.Test.TestUnion.union2() { }, - Union3 = new Capnproto_test.Capnp.Test.TestUnion.@union3() + Union3 = new Capnproto_test.Capnp.Test.TestUnion.union3() { }, Bit0 = false, Bit2 = false, @@ -5298,16 +5298,16 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - List0 = reader.List0.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List1 = reader.List1.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List8 = reader.List8.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List16 = reader.List16.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List32 = reader.List32.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List64 = reader.List64.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - ListP = reader.ListP.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List0 = reader.List0?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List1 = reader.List1?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List8 = reader.List8?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List16 = reader.List16?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List32 = reader.List32?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List64 = reader.List64?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + ListP = reader.ListP?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); Int32ListList = reader.Int32ListList; TextListList = reader.TextListList; - StructListList = reader.StructListList.ToReadOnlyList(_2 => _2.ToReadOnlyList(_ => CapnpSerializable.Create(_))); + StructListList = reader.StructListList?.ToReadOnlyList(_2 => _2?.ToReadOnlyList(_ => CapnpSerializable.Create(_))); applyDefaults(); } @@ -5872,7 +5872,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string F => ctx.ReadText(0, ""); + public string F => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -5884,8 +5884,8 @@ namespace Capnproto_test.Capnp.Test public string F { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -5932,7 +5932,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string Pad => ctx.ReadText(0, ""); + public string Pad => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -5944,8 +5944,8 @@ namespace Capnproto_test.Capnp.Test public string Pad { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -6001,7 +6001,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public bool F => ctx.ReadDataBool(0UL, false); - public string Pad => ctx.ReadText(0, ""); + public string Pad => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -6019,8 +6019,8 @@ namespace Capnproto_test.Capnp.Test public string Pad { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -6076,7 +6076,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public byte F => ctx.ReadDataByte(0UL, (byte)0); - public string Pad => ctx.ReadText(0, ""); + public string Pad => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -6094,8 +6094,8 @@ namespace Capnproto_test.Capnp.Test public string Pad { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -6151,7 +6151,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public ushort F => ctx.ReadDataUShort(0UL, (ushort)0); - public string Pad => ctx.ReadText(0, ""); + public string Pad => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -6169,8 +6169,8 @@ namespace Capnproto_test.Capnp.Test public string Pad { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -6226,7 +6226,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public uint F => ctx.ReadDataUInt(0UL, 0U); - public string Pad => ctx.ReadText(0, ""); + public string Pad => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -6244,8 +6244,8 @@ namespace Capnproto_test.Capnp.Test public string Pad { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -6301,7 +6301,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public ulong F => ctx.ReadDataULong(0UL, 0UL); - public string Pad => ctx.ReadText(0, ""); + public string Pad => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -6319,8 +6319,8 @@ namespace Capnproto_test.Capnp.Test public string Pad { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -6375,7 +6375,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string F => ctx.ReadText(0, ""); + public string F => ctx.ReadText(0, null); public ulong Pad => ctx.ReadDataULong(0UL, 0UL); } @@ -6388,8 +6388,8 @@ namespace Capnproto_test.Capnp.Test public string F { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public ulong Pad @@ -6598,8 +6598,8 @@ namespace Capnproto_test.Capnp.Test Foo = reader.Foo; Bar = reader.Bar; Baz = reader.Baz; - TheUnion = CapnpSerializable.Create(reader.TheUnion); - AnotherUnion = CapnpSerializable.Create(reader.AnotherUnion); + TheUnion = CapnpSerializable.Create(reader.TheUnion); + AnotherUnion = CapnpSerializable.Create(reader.AnotherUnion); applyDefaults(); } @@ -6639,13 +6639,13 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestLateUnion.@theUnion TheUnion + public Capnproto_test.Capnp.Test.TestLateUnion.theUnion TheUnion { get; set; } - public Capnproto_test.Capnp.Test.TestLateUnion.@anotherUnion AnotherUnion + public Capnproto_test.Capnp.Test.TestLateUnion.anotherUnion AnotherUnion { get; set; @@ -6663,10 +6663,10 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public int Foo => ctx.ReadDataInt(0UL, 0); - public string Bar => ctx.ReadText(0, ""); + public string Bar => ctx.ReadText(0, null); public short Baz => ctx.ReadDataShort(32UL, (short)0); - public @theUnion.READER TheUnion => new @theUnion.READER(ctx); - public @anotherUnion.READER AnotherUnion => new @anotherUnion.READER(ctx); + public theUnion.READER TheUnion => new theUnion.READER(ctx); + public anotherUnion.READER AnotherUnion => new anotherUnion.READER(ctx); } public class WRITER : SerializerState @@ -6684,8 +6684,8 @@ namespace Capnproto_test.Capnp.Test public string Bar { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public short Baz @@ -6694,19 +6694,19 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(32UL, value, (short)0); } - public @theUnion.WRITER TheUnion + public theUnion.WRITER TheUnion { - get => Rewrap<@theUnion.WRITER>(); + get => Rewrap(); } - public @anotherUnion.WRITER AnotherUnion + public anotherUnion.WRITER AnotherUnion { - get => Rewrap<@anotherUnion.WRITER>(); + get => Rewrap(); } } [TypeId(0x807280a2901aa079UL)] - public class @theUnion : ICapnpSerializable + public class theUnion : ICapnpSerializable { public const UInt64 typeId = 0x807280a2901aa079UL; public enum WHICH : ushort @@ -6829,7 +6829,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); - public string Qux => which == WHICH.Qux ? ctx.ReadText(1, "") : default; + public string Qux => which == WHICH.Qux ? ctx.ReadText(1, null) : default; public IReadOnlyList Corge => which == WHICH.Corge ? ctx.ReadList(1).CastInt() : default; public float Grault => which == WHICH.Grault ? ctx.ReadDataFloat(64UL, 0F) : default; } @@ -6848,8 +6848,8 @@ namespace Capnproto_test.Capnp.Test public string Qux { - get => which == WHICH.Qux ? this.ReadText(1, "") : default; - set => this.WriteText(1, value, ""); + get => which == WHICH.Qux ? this.ReadText(1, null) : default; + set => this.WriteText(1, value, null); } public ListOfPrimitivesSerializer Corge @@ -6867,7 +6867,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc1973984dee98e3aUL)] - public class @anotherUnion : ICapnpSerializable + public class anotherUnion : ICapnpSerializable { public const UInt64 typeId = 0xc1973984dee98e3aUL; public enum WHICH : ushort @@ -6990,7 +6990,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(96U, (ushort)0); - public string Qux => which == WHICH.Qux ? ctx.ReadText(2, "") : default; + public string Qux => which == WHICH.Qux ? ctx.ReadText(2, null) : default; public IReadOnlyList Corge => which == WHICH.Corge ? ctx.ReadList(2).CastInt() : default; public float Grault => which == WHICH.Grault ? ctx.ReadDataFloat(128UL, 0F) : default; } @@ -7009,8 +7009,8 @@ namespace Capnproto_test.Capnp.Test public string Qux { - get => which == WHICH.Qux ? this.ReadText(2, "") : default; - set => this.WriteText(2, value, ""); + get => which == WHICH.Qux ? this.ReadText(2, null) : default; + set => this.WriteText(2, value, null); } public ListOfPrimitivesSerializer Corge @@ -7087,7 +7087,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public long Old1 => ctx.ReadDataLong(0UL, 0L); - public string Old2 => ctx.ReadText(0, ""); + public string Old2 => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.TestOldVersion.READER Old3 => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestOldVersion.READER.create); } @@ -7106,8 +7106,8 @@ namespace Capnproto_test.Capnp.Test public string Old2 { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.TestOldVersion.WRITER Old3 @@ -7195,7 +7195,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public long Old1 => ctx.ReadDataLong(0UL, 0L); - public string Old2 => ctx.ReadText(0, ""); + public string Old2 => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.TestNewVersion.READER Old3 => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestNewVersion.READER.create); public long New1 => ctx.ReadDataLong(64UL, 987L); public string New2 => ctx.ReadText(2, "baz"); @@ -7216,8 +7216,8 @@ namespace Capnproto_test.Capnp.Test public string Old2 { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.TestNewVersion.WRITER Old3 @@ -7373,7 +7373,7 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.A: - A = CapnpSerializable.Create(reader.A); + A = CapnpSerializable.Create(reader.A); break; case WHICH.B: B = reader.B; @@ -7428,9 +7428,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestNewUnionVersion.@a A + public Capnproto_test.Capnp.Test.TestNewUnionVersion.a A { - get => _which == WHICH.A ? (Capnproto_test.Capnp.Test.TestNewUnionVersion.@a)_content : null; + get => _which == WHICH.A ? (Capnproto_test.Capnp.Test.TestNewUnionVersion.a)_content : null; set { _which = WHICH.A; @@ -7460,7 +7460,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); - public @a.READER A => which == WHICH.A ? new @a.READER(ctx) : default; + public a.READER A => which == WHICH.A ? new a.READER(ctx) : default; public ulong B => which == WHICH.B ? ctx.ReadDataULong(64UL, 0UL) : default; } @@ -7477,9 +7477,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(0U, (ushort)value, (ushort)0); } - public @a.WRITER A + public a.WRITER A { - get => which == WHICH.A ? Rewrap<@a.WRITER>() : default; + get => which == WHICH.A ? Rewrap() : default; } public ulong B @@ -7490,7 +7490,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x86232c1de4513e84UL)] - public class @a : ICapnpSerializable + public class a : ICapnpSerializable { public const UInt64 typeId = 0x86232c1de4513e84UL; public enum WHICH : ushort @@ -7612,7 +7612,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Un = CapnpSerializable.Create(reader.Un); + Un = CapnpSerializable.Create(reader.Un); applyDefaults(); } @@ -7630,7 +7630,7 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestStructUnion.@un Un + public Capnproto_test.Capnp.Test.TestStructUnion.un Un { get; set; @@ -7647,7 +7647,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @un.READER Un => new @un.READER(ctx); + public un.READER Un => new un.READER(ctx); } public class WRITER : SerializerState @@ -7657,14 +7657,14 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(1, 1); } - public @un.WRITER Un + public un.WRITER Un { - get => Rewrap<@un.WRITER>(); + get => Rewrap(); } } [TypeId(0x992edc677bef5a3cUL)] - public class @un : ICapnpSerializable + public class un : ICapnpSerializable { public const UInt64 typeId = 0x992edc677bef5a3cUL; public enum WHICH : ushort @@ -7847,8 +7847,8 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string SomeText => ctx.ReadText(0, ""); - public string MoreText => ctx.ReadText(1, ""); + public string SomeText => ctx.ReadText(0, null); + public string MoreText => ctx.ReadText(1, null); } public class WRITER : SerializerState @@ -7860,14 +7860,14 @@ namespace Capnproto_test.Capnp.Test public string SomeText { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public string MoreText { - get => this.ReadText(1, ""); - set => this.WriteText(1, value, ""); + get => this.ReadText(1, null); + set => this.WriteText(1, value, null); } } } @@ -7881,7 +7881,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); SomeText = reader.SomeText; - StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + StructList = reader.StructList?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); applyDefaults(); } @@ -7923,7 +7923,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string SomeText => ctx.ReadText(0, ""); + public string SomeText => ctx.ReadText(0, null); public IReadOnlyList StructList => ctx.ReadList(1).Cast(Capnproto_test.Capnp.Test.TestPrintInlineStructs.InlineStruct.READER.create); } @@ -7936,8 +7936,8 @@ namespace Capnproto_test.Capnp.Test public string SomeText { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public ListOfStructsSerializer StructList @@ -7998,7 +7998,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public int Int32Field => ctx.ReadDataInt(0UL, 0); - public string TextField => ctx.ReadText(0, ""); + public string TextField => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -8016,8 +8016,8 @@ namespace Capnproto_test.Capnp.Test public string TextField { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -8120,13 +8120,13 @@ namespace Capnproto_test.Capnp.Test which = reader.which; break; case WHICH.Ug: - Ug = CapnpSerializable.Create.@ug>(reader.Ug); + Ug = CapnpSerializable.Create.ug>(reader.Ug); break; } Foo = CapnpSerializable.Create(reader.Foo); Rev = CapnpSerializable.Create>(reader.Rev); - List = reader.List.ToReadOnlyList(_ => CapnpSerializable.Create.Inner>(_)); + List = reader.List?.ToReadOnlyList(_ => CapnpSerializable.Create.Inner>(_)); applyDefaults(); } @@ -8189,9 +8189,9 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics.@ug Ug + public Capnproto_test.Capnp.Test.TestGenerics.ug Ug { - get => _which == WHICH.Ug ? (Capnproto_test.Capnp.Test.TestGenerics.@ug)_content : null; + get => _which == WHICH.Ug ? (Capnproto_test.Capnp.Test.TestGenerics.ug)_content : null; set { _which = WHICH.Ug; @@ -8219,7 +8219,7 @@ namespace Capnproto_test.Capnp.Test public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); public DeserializerState Foo => ctx.StructReadPointer(0); public Capnproto_test.Capnp.Test.TestGenerics.READER Rev => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.READER.create); - public @ug.READER Ug => which == WHICH.Ug ? new @ug.READER(ctx) : default; + public ug.READER Ug => which == WHICH.Ug ? new ug.READER(ctx) : default; public IReadOnlyList.Inner.READER> List => ctx.ReadList(2).Cast(Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); } @@ -8248,9 +8248,9 @@ namespace Capnproto_test.Capnp.Test set => Link(1, value); } - public @ug.WRITER Ug + public ug.WRITER Ug { - get => which == WHICH.Ug ? Rewrap<@ug.WRITER>() : default; + get => which == WHICH.Ug ? Rewrap() : default; } public ListOfStructsSerializer.Inner.WRITER> List @@ -8261,7 +8261,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb46a779beaf3384eUL)] - public class @ug : ICapnpSerializable + public class ug : ICapnpSerializable { public const UInt64 typeId = 0xb46a779beaf3384eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8612,13 +8612,15 @@ namespace Capnproto_test.Capnp.Test { public async Task Call(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Params_call.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestGenerics.Inner2.DeepNest.DeepNestInterface.Params_call() + var in_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Params_Call.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestGenerics.Inner2.DeepNest.DeepNestInterface.Params_Call() { }; - arg_.serialize(in_); - var d_ = await Call(9816138025992274567UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_call>(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(9816138025992274567UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_Call>(d_); + return; + } } } @@ -8632,9 +8634,12 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9816138025992274567UL; async Task Call(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Call(cancellationToken_); - var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_call.WRITER>(); - return s_; + using (d_) + { + await Impl.Call(cancellationToken_); + var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_Call.WRITER>(); + return s_; + } } } @@ -8642,7 +8647,7 @@ namespace Capnproto_test.Capnp.Test where TQuux : class { [TypeId(0xb84eecc799437049UL)] - public class Params_call : ICapnpSerializable + public class Params_Call : ICapnpSerializable { public const UInt64 typeId = 0xb84eecc799437049UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8687,7 +8692,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe080f0fc54614f6fUL)] - public class Result_call : ICapnpSerializable + public class Result_Call : ICapnpSerializable { public const UInt64 typeId = 0xe080f0fc54614f6fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8745,11 +8750,14 @@ namespace Capnproto_test.Capnp.Test public Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc.Inner2.WRITER>(); - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(14548678385738242652UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create.Interface.Result_call>(d_); - return (r_.Qux, r_.Gen); + using (d_) + { + var r_ = CapnpSerializable.Create.Interface.Result_Call>(d_); + return (r_.Qux, r_.Gen); + } } ); @@ -8766,15 +8774,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 14548678385738242652UL; Task Call(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.Call(CapnpSerializable.Create.Inner2>(d_), cancellationToken_), (qux, gen) => + using (d_) { - var s_ = SerializerState.CreateForRpc.Interface.Result_call.WRITER>(); - var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_call { Qux = qux, Gen = gen }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.Call(CapnpSerializable.Create.Inner2>(d_), cancellationToken_), (qux, gen) => + { + var s_ = SerializerState.CreateForRpc.Interface.Result_Call.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_Call { Qux = qux, Gen = gen }; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -8782,7 +8793,7 @@ namespace Capnproto_test.Capnp.Test where TQux : class { [TypeId(0xa5b46224e33581adUL)] - public class Result_call : ICapnpSerializable + public class Result_Call : ICapnpSerializable { public const UInt64 typeId = 0xa5b46224e33581adUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -9116,23 +9127,26 @@ namespace Capnproto_test.Capnp.Test [TypeId(0x8b9717a3f8d85a9aUL), Proxy(typeof(TestImplicitMethodParams_Proxy)), Skeleton(typeof(TestImplicitMethodParams_Skeleton))] public interface ITestImplicitMethodParams : IDisposable { - Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } public class TestImplicitMethodParams_Proxy : Proxy, ITestImplicitMethodParams { - public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + public Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class { - var in_ = SerializerState.CreateForRpc.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParams.Params_call() - { Foo = foo, Bar = bar }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParams.Params_Call() + { Foo = Foo, Bar = Bar }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(10058534285777328794UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create>(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create>(d_); + return r_; + } } ); @@ -9150,22 +9164,25 @@ namespace Capnproto_test.Capnp.Test Task Call(DeserializerState d_, CancellationToken cancellationToken_) where TT : class where TU : class { - var in_ = CapnpSerializable.Create>(d_); - return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc.WRITER>(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create>(d_); + return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc.WRITER>(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } public static class TestImplicitMethodParams { [TypeId(0xf83f8caf54bdc486UL)] - public class Params_call : ICapnpSerializable where TT : class where TU : class + public class Params_Call : ICapnpSerializable where TT : class where TU : class { public const UInt64 typeId = 0xf83f8caf54bdc486UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -9243,23 +9260,26 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xdf9ccdeb81a704c9UL), Proxy(typeof(TestImplicitMethodParamsInGeneric_Proxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGeneric_Skeleton<>))] public interface ITestImplicitMethodParamsInGeneric : IDisposable where TV : class { - Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } public class TestImplicitMethodParamsInGeneric_Proxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class { - public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + public Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class { - var in_ = SerializerState.CreateForRpc.Params_call.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParamsInGeneric.Params_call() - { Foo = foo, Bar = bar }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc.Params_Call.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParamsInGeneric.Params_Call() + { Foo = Foo, Bar = Bar }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(16112979978201007305UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create>(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create>(d_); + return r_; + } } ); @@ -9277,15 +9297,18 @@ namespace Capnproto_test.Capnp.Test Task Call(DeserializerState d_, CancellationToken cancellationToken_) where TT : class where TU : class { - var in_ = CapnpSerializable.Create.Params_call>(d_); - return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc.WRITER>(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create.Params_Call>(d_); + return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc.WRITER>(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -9293,7 +9316,7 @@ namespace Capnproto_test.Capnp.Test where TV : class { [TypeId(0x9aab8e25c808d71eUL)] - public class Params_call : ICapnpSerializable where TT : class where TU : class + public class Params_Call : ICapnpSerializable where TT : class where TU : class { public const UInt64 typeId = 0x9aab8e25c808d71eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10702,7 +10725,7 @@ namespace Capnproto_test.Capnp.Test AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); - AnyListAsList = reader.AnyListAsList.ToReadOnlyList(_ => (object)_); + AnyListAsList = reader.AnyListAsList?.ToReadOnlyList(_ => (object)_); applyDefaults(); } @@ -10800,44 +10823,50 @@ namespace Capnproto_test.Capnp.Test [TypeId(0x88eb12a0e0af92b2UL), Proxy(typeof(TestInterface_Proxy)), Skeleton(typeof(TestInterface_Skeleton))] public interface ITestInterface : IDisposable { - Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default); + Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default); Task Bar(CancellationToken cancellationToken_ = default); - Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default); + Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default); } public class TestInterface_Proxy : Proxy, ITestInterface { - public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() - { I = i, J = j }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.X); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() + { I = I, J = J }; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } } public async Task Bar(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() { }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } - public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() - { S = s }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() + { S = S }; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -10851,38 +10880,47 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9865999890858873522UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.J, cancellationToken_), x => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_foo { X = x }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.J, cancellationToken_), x => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_Foo { X = x }; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task Bar(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Bar(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Bar(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Baz(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.Baz(in_.S, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.Baz(in_.S, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } public static class TestInterface { [TypeId(0xb874edc0d559b391UL)] - public class Params_foo : ICapnpSerializable + public class Params_Foo : ICapnpSerializable { public const UInt64 typeId = 0xb874edc0d559b391UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10957,7 +10995,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb04fcaddab714ba4UL)] - public class Result_foo : ICapnpSerializable + public class Result_Foo : ICapnpSerializable { public const UInt64 typeId = 0xb04fcaddab714ba4UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10998,7 +11036,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string X => ctx.ReadText(0, ""); + public string X => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -11010,14 +11048,14 @@ namespace Capnproto_test.Capnp.Test public string X { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0xd044893357b42568UL)] - public class Params_bar : ICapnpSerializable + public class Params_Bar : ICapnpSerializable { public const UInt64 typeId = 0xd044893357b42568UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11062,7 +11100,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9bf141df4247d52fUL)] - public class Result_bar : ICapnpSerializable + public class Result_Bar : ICapnpSerializable { public const UInt64 typeId = 0x9bf141df4247d52fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11107,7 +11145,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xd9ac8abb2a91cfbcUL)] - public class Params_baz : ICapnpSerializable + public class Params_Baz : ICapnpSerializable { public const UInt64 typeId = 0xd9ac8abb2a91cfbcUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11167,7 +11205,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9b99d14f2f375b2dUL)] - public class Result_baz : ICapnpSerializable + public class Result_Baz : ICapnpSerializable { public const UInt64 typeId = 0x9b99d14f2f375b2dUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11224,66 +11262,78 @@ namespace Capnproto_test.Capnp.Test { public async Task Qux(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_qux() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Qux() { }; - arg_.serialize(in_); - var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); - arg_.serialize(in_); - var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Grault(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_grault() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Grault() { }; - arg_.serialize(in_); - var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + arg_?.serialize(in_); + using (var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } - public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() - { I = i, J = j }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.X); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() + { I = I, J = J }; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } } public async Task Bar(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() { }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } - public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() - { S = s }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() + { S = S }; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -11297,35 +11347,44 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 16494920484927878984UL; async Task Qux(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Qux(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Qux(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Corge(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Corge(CapnpSerializable.Create(d_), cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Corge(CapnpSerializable.Create(d_), cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task Grault(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.Grault(cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.Grault(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } public static class TestExtends { [TypeId(0x83a4bc5471363f17UL)] - public class Params_qux : ICapnpSerializable + public class Params_Qux : ICapnpSerializable { public const UInt64 typeId = 0x83a4bc5471363f17UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11370,7 +11429,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8e4b3d1a3e2753ddUL)] - public class Result_qux : ICapnpSerializable + public class Result_Qux : ICapnpSerializable { public const UInt64 typeId = 0x8e4b3d1a3e2753ddUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11415,7 +11474,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xacf67532a7e7bad9UL)] - public class Result_corge : ICapnpSerializable + public class Result_Corge : ICapnpSerializable { public const UInt64 typeId = 0xacf67532a7e7bad9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11460,7 +11519,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf3b834e851ea8af6UL)] - public class Params_grault : ICapnpSerializable + public class Params_Grault : ICapnpSerializable { public const UInt64 typeId = 0xf3b834e851ea8af6UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11514,66 +11573,78 @@ namespace Capnproto_test.Capnp.Test { public async Task Qux(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_qux() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Qux() { }; - arg_.serialize(in_); - var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); - arg_.serialize(in_); - var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Grault(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_grault() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Grault() { }; - arg_.serialize(in_); - var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + arg_?.serialize(in_); + using (var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } - public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() - { I = i, J = j }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.X); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() + { I = I, J = J }; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } } public async Task Bar(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() { }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } - public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() - { S = s }; - arg_.serialize(in_); - var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() + { S = S }; + arg_?.serialize(in_); + using (var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -11590,49 +11661,57 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xa5a404caa61d4cd0UL), Proxy(typeof(TestPipeline_Proxy)), Skeleton(typeof(TestPipeline_Skeleton))] public interface ITestPipeline : IDisposable { - Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); - Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); - Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); + Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint N, Capnproto_test.Capnp.Test.ITestInterface InCap, CancellationToken cancellationToken_ = default); + Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface Cap, object Obj, IReadOnlyList List, CancellationToken cancellationToken_ = default); + Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint N, BareProxy InCap, CancellationToken cancellationToken_ = default); } public class TestPipeline_Proxy : Proxy, ITestPipeline { - public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default) + public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint N, Capnproto_test.Capnp.Test.ITestInterface InCap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_getCap() - { N = n, InCap = inCap }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_GetCap() + { N = N, InCap = InCap }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(11935670180855499984UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.S, r_.OutBox); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S, r_.OutBox); + } } ); } - public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) + public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface Cap, object Obj, IReadOnlyList List, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_testPointers() - { Cap = cap, Obj = obj, List = list }; - arg_.serialize(in_); - var d_ = await Call(11935670180855499984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_TestPointers() + { Cap = Cap, Obj = Obj, List = List }; + arg_?.serialize(in_); + using (var d_ = await Call(11935670180855499984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } - public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default) + public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint N, BareProxy InCap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_getAnyCap() - { N = n, InCap = inCap }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_GetAnyCap() + { N = N, InCap = InCap }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(11935670180855499984UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.S, r_.OutBox); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S, r_.OutBox); + } } ); @@ -11649,38 +11728,47 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11935670180855499984UL; Task GetCap(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.GetCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_getCap { S = s, OutBox = outBox }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetCap { S = s, OutBox = outBox }; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task TestPointers(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.TestPointers(in_.Cap, in_.Obj, in_.List, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.TestPointers(in_.Cap, in_.Obj, in_.List, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task GetAnyCap(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.GetAnyCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_getAnyCap { S = s, OutBox = outBox }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetAnyCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetAnyCap { S = s, OutBox = outBox }; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -11807,7 +11895,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc7e8df5096257034UL)] - public class Params_getCap : ICapnpSerializable + public class Params_GetCap : ICapnpSerializable { public const UInt64 typeId = 0xc7e8df5096257034UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11882,7 +11970,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb2442a9e0ba28fdfUL)] - public class Result_getCap : ICapnpSerializable + public class Result_GetCap : ICapnpSerializable { public const UInt64 typeId = 0xb2442a9e0ba28fdfUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11931,7 +12019,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string S => ctx.ReadText(0, ""); + public string S => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.TestPipeline.Box.READER OutBox => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestPipeline.Box.READER.create); } @@ -11944,8 +12032,8 @@ namespace Capnproto_test.Capnp.Test public string S { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.TestPipeline.Box.WRITER OutBox @@ -11957,7 +12045,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa604ee63cf37819fUL)] - public class Params_testPointers : ICapnpSerializable + public class Params_TestPointers : ICapnpSerializable { public const UInt64 typeId = 0xa604ee63cf37819fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12047,7 +12135,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8eda54756c6070d6UL)] - public class Result_testPointers : ICapnpSerializable + public class Result_TestPointers : ICapnpSerializable { public const UInt64 typeId = 0x8eda54756c6070d6UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12092,7 +12180,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf8e36b53ab093d4eUL)] - public class Params_getAnyCap : ICapnpSerializable + public class Params_GetAnyCap : ICapnpSerializable { public const UInt64 typeId = 0xf8e36b53ab093d4eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12167,7 +12255,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xbf44b4c94c26ef79UL)] - public class Result_getAnyCap : ICapnpSerializable + public class Result_GetAnyCap : ICapnpSerializable { public const UInt64 typeId = 0xbf44b4c94c26ef79UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12216,7 +12304,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string S => ctx.ReadText(0, ""); + public string S => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.TestPipeline.AnyBox.READER OutBox => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestPipeline.AnyBox.READER.create); } @@ -12229,8 +12317,8 @@ namespace Capnproto_test.Capnp.Test public string S { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.TestPipeline.AnyBox.WRITER OutBox @@ -12245,20 +12333,22 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xa0e77035bdff0051UL), Proxy(typeof(TestCallOrder_Proxy)), Skeleton(typeof(TestCallOrder_Skeleton))] public interface ITestCallOrder : IDisposable { - Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default); + Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default); } public class TestCallOrder_Proxy : Proxy, ITestCallOrder { - public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) + public async Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_getCallSequence() - { Expected = expected }; - arg_.serialize(in_); - var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.N); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_GetCallSequence() + { Expected = Expected }; + arg_?.serialize(in_); + using (var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.N); + } } } @@ -12272,23 +12362,26 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11594359141811814481UL; Task GetCallSequence(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.GetCallSequence(in_.Expected, cancellationToken_), n => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_getCallSequence { N = n }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetCallSequence(in_.Expected, cancellationToken_), n => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_GetCallSequence { N = n }; + r_.serialize(s_); + return s_; + } - ); + ); + } } } public static class TestCallOrder { [TypeId(0x8f1e8cd56ceb74dcUL)] - public class Params_getCallSequence : ICapnpSerializable + public class Params_GetCallSequence : ICapnpSerializable { public const UInt64 typeId = 0x8f1e8cd56ceb74dcUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12348,7 +12441,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdedbb6bf3810eab7UL)] - public class Result_getCallSequence : ICapnpSerializable + public class Result_GetCallSequence : ICapnpSerializable { public const UInt64 typeId = 0xdedbb6bf3810eab7UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12411,21 +12504,24 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xddd699207eb8e23bUL), Proxy(typeof(TestTailCallee_Proxy)), Skeleton(typeof(TestTailCallee_Skeleton))] public interface ITestTailCallee : IDisposable { - Task Foo(int i, string t, CancellationToken cancellationToken_ = default); + Task Foo(int I, string T, CancellationToken cancellationToken_ = default); } public class TestTailCallee_Proxy : Proxy, ITestTailCallee { - public Task Foo(int i, string t, CancellationToken cancellationToken_ = default) + public Task Foo(int I, string T, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestTailCallee.Params_foo() - { I = i, T = t }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestTailCallee.Params_Foo() + { I = I, T = T }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15985132292242203195UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } ); @@ -12442,15 +12538,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15985132292242203195UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.T, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.T, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -12515,7 +12614,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public uint I => ctx.ReadDataUInt(0UL, 0U); - public string T => ctx.ReadText(0, ""); + public string T => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.ITestCallOrder C => ctx.ReadCap(1); } @@ -12534,8 +12633,8 @@ namespace Capnproto_test.Capnp.Test public string T { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.ITestCallOrder C @@ -12547,7 +12646,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc5e1efc325614957UL)] - public class Params_foo : ICapnpSerializable + public class Params_Foo : ICapnpSerializable { public const UInt64 typeId = 0xc5e1efc325614957UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12597,7 +12696,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public int I => ctx.ReadDataInt(0UL, 0); - public string T => ctx.ReadText(0, ""); + public string T => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -12615,8 +12714,8 @@ namespace Capnproto_test.Capnp.Test public string T { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -12625,21 +12724,24 @@ namespace Capnproto_test.Capnp.Test [TypeId(0x870bf40110ce3035UL), Proxy(typeof(TestTailCaller_Proxy)), Skeleton(typeof(TestTailCaller_Skeleton))] public interface ITestTailCaller : IDisposable { - Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default); + Task Foo(int I, Capnproto_test.Capnp.Test.ITestTailCallee Callee, CancellationToken cancellationToken_ = default); } public class TestTailCaller_Proxy : Proxy, ITestTailCaller { - public Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default) + public Task Foo(int I, Capnproto_test.Capnp.Test.ITestTailCallee Callee, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestTailCaller.Params_foo() - { I = i, Callee = callee }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestTailCaller.Params_Foo() + { I = I, Callee = Callee }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(9731139705278181429UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } ); @@ -12656,22 +12758,25 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9731139705278181429UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.Callee, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.Callee, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } public static class TestTailCaller { [TypeId(0xb07a279515dc8ac5UL)] - public class Params_foo : ICapnpSerializable + public class Params_Foo : ICapnpSerializable { public const UInt64 typeId = 0xb07a279515dc8ac5UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12768,144 +12873,168 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xddc70bf9784133cfUL), Proxy(typeof(TestMoreStuff_Proxy)), Skeleton(typeof(TestMoreStuff_Skeleton))] public interface ITestMoreStuff : Capnproto_test.Capnp.Test.ITestCallOrder { - Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task Hold(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task Hold(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); Task CallHeld(CancellationToken cancellationToken_ = default); Task GetHeld(CancellationToken cancellationToken_ = default); - Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder cap, CancellationToken cancellationToken_ = default); - Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task<(string, string)> MethodWithDefaults(string a, uint b, string c, CancellationToken cancellationToken_ = default); + Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder Cap, CancellationToken cancellationToken_ = default); + Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task<(string, string)> MethodWithDefaults(string A, uint B, string C, CancellationToken cancellationToken_ = default); Task GetHandle(CancellationToken cancellationToken_ = default); Task GetNull(CancellationToken cancellationToken_ = default); Task GetEnormousString(CancellationToken cancellationToken_ = default); - Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default); + Task MethodWithNullDefault(string A, Capnproto_test.Capnp.Test.ITestInterface B, CancellationToken cancellationToken_ = default); } public class TestMoreStuff_Proxy : Proxy, ITestMoreStuff { - public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callFoo() - { Cap = cap }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.S); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallFoo() + { Cap = Cap }; + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } } - public async Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callFooWhenResolved() - { Cap = cap }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.S); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallFooWhenResolved() + { Cap = Cap }; + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } } - public Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_neverReturn() - { Cap = cap }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_NeverReturn() + { Cap = Cap }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.CapCopy); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.CapCopy); + } } ); } - public async Task Hold(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task Hold(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_hold() - { Cap = cap }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_Hold() + { Cap = Cap }; + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task CallHeld(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callHeld() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallHeld() { }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.S); + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } } public Task GetHeld(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getHeld() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetHeld() { }; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 5, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Cap); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } } ); } - public Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder cap, CancellationToken cancellationToken_ = default) + public Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_echo() - { Cap = cap }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_Echo() + { Cap = Cap }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 6, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Cap); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } } ); } - public async Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_expectCancel() - { Cap = cap }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 7, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_ExpectCancel() + { Cap = Cap }; + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 7, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } - public async Task<(string, string)> MethodWithDefaults(string a, uint b, string c, CancellationToken cancellationToken_ = default) + public async Task<(string, string)> MethodWithDefaults(string A, uint B, string C, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_methodWithDefaults() - { A = a, B = b, C = c }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 8, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.D, r_.E); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_MethodWithDefaults() + { A = A, B = B, C = C }; + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 8, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.D, r_.E); + } } public Task GetHandle(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getHandle() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetHandle() { }; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 9, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Handle); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Handle); + } } ); @@ -12913,14 +13042,17 @@ namespace Capnproto_test.Capnp.Test public Task GetNull(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getNull() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetNull() { }; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 10, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.NullCap); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.NullCap); + } } ); @@ -12928,35 +13060,41 @@ namespace Capnproto_test.Capnp.Test public async Task GetEnormousString(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getEnormousString() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetEnormousString() { }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 11, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.Str); + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 11, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Str); + } } - public async Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default) + public async Task MethodWithNullDefault(string A, Capnproto_test.Capnp.Test.ITestInterface B, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_methodWithNullDefault() - { A = a, B = b }; - arg_.serialize(in_); - var d_ = await Call(15980754968839795663UL, 12, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_MethodWithNullDefault() + { A = A, B = B }; + arg_?.serialize(in_); + using (var d_ = await Call(15980754968839795663UL, 12, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } - public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) + public async Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_getCallSequence() - { Expected = expected }; - arg_.serialize(in_); - var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.N); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_GetCallSequence() + { Expected = Expected }; + arg_?.serialize(in_); + using (var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.N); + } } } @@ -12970,168 +13108,207 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15980754968839795663UL; Task CallFoo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallFoo(in_.Cap, cancellationToken_), s => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callFoo { S = s }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallFoo(in_.Cap, cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFoo { S = s }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task CallFooWhenResolved(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallFooWhenResolved(in_.Cap, cancellationToken_), s => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callFooWhenResolved { S = s }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallFooWhenResolved(in_.Cap, cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFooWhenResolved { S = s }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task NeverReturn(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.NeverReturn(in_.Cap, cancellationToken_), capCopy => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_neverReturn { CapCopy = capCopy }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.NeverReturn(in_.Cap, cancellationToken_), capCopy => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_NeverReturn { CapCopy = capCopy }; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task Hold(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.Hold(in_.Cap, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.Hold(in_.Cap, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task CallHeld(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.CallHeld(cancellationToken_), s => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callHeld { S = s }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.CallHeld(cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallHeld { S = s }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetHeld(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetHeld(cancellationToken_), cap => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getHeld { Cap = cap }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetHeld(cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHeld { Cap = cap }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task Echo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Echo(in_.Cap, cancellationToken_), cap => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_echo { Cap = cap }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Echo(in_.Cap, cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_Echo { Cap = cap }; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task ExpectCancel(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.ExpectCancel(in_.Cap, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.ExpectCancel(in_.Cap, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task MethodWithDefaults(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.MethodWithDefaults(in_.A, in_.B, in_.C, cancellationToken_), (d, e) => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_methodWithDefaults { D = d, E = e }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.MethodWithDefaults(in_.A, in_.B, in_.C, cancellationToken_), (d, e) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_MethodWithDefaults { D = d, E = e }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetHandle(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetHandle(cancellationToken_), handle => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getHandle { Handle = handle }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetHandle(cancellationToken_), handle => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHandle { Handle = handle }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetNull(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetNull(cancellationToken_), nullCap => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getNull { NullCap = nullCap }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetNull(cancellationToken_), nullCap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetNull { NullCap = nullCap }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetEnormousString(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetEnormousString(cancellationToken_), str => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getEnormousString { Str = str }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetEnormousString(cancellationToken_), str => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetEnormousString { Str = str }; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task MethodWithNullDefault(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.MethodWithNullDefault(in_.A, in_.B, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.MethodWithNullDefault(in_.A, in_.B, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } public static class TestMoreStuff { [TypeId(0x931ba418da60f6e4UL)] - public class Params_callFoo : ICapnpSerializable + public class Params_CallFoo : ICapnpSerializable { public const UInt64 typeId = 0x931ba418da60f6e4UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13191,7 +13368,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9a28970beccecdd0UL)] - public class Result_callFoo : ICapnpSerializable + public class Result_CallFoo : ICapnpSerializable { public const UInt64 typeId = 0x9a28970beccecdd0UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13232,7 +13409,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string S => ctx.ReadText(0, ""); + public string S => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -13244,14 +13421,14 @@ namespace Capnproto_test.Capnp.Test public string S { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0xfabc700c2ebe6378UL)] - public class Params_callFooWhenResolved : ICapnpSerializable + public class Params_CallFooWhenResolved : ICapnpSerializable { public const UInt64 typeId = 0xfabc700c2ebe6378UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13311,7 +13488,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa54ce1e9aa822f90UL)] - public class Result_callFooWhenResolved : ICapnpSerializable + public class Result_CallFooWhenResolved : ICapnpSerializable { public const UInt64 typeId = 0xa54ce1e9aa822f90UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13352,7 +13529,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string S => ctx.ReadText(0, ""); + public string S => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -13364,14 +13541,14 @@ namespace Capnproto_test.Capnp.Test public string S { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0x94fe60465c95182bUL)] - public class Params_neverReturn : ICapnpSerializable + public class Params_NeverReturn : ICapnpSerializable { public const UInt64 typeId = 0x94fe60465c95182bUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13431,7 +13608,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdef4e5fa6999c5dcUL)] - public class Result_neverReturn : ICapnpSerializable + public class Result_NeverReturn : ICapnpSerializable { public const UInt64 typeId = 0xdef4e5fa6999c5dcUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13491,7 +13668,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfe7c8fbb769d8e58UL)] - public class Params_hold : ICapnpSerializable + public class Params_Hold : ICapnpSerializable { public const UInt64 typeId = 0xfe7c8fbb769d8e58UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13551,7 +13728,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf839fb1374d003c9UL)] - public class Result_hold : ICapnpSerializable + public class Result_Hold : ICapnpSerializable { public const UInt64 typeId = 0xf839fb1374d003c9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13596,7 +13773,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf8c5e5ef1edf83beUL)] - public class Params_callHeld : ICapnpSerializable + public class Params_CallHeld : ICapnpSerializable { public const UInt64 typeId = 0xf8c5e5ef1edf83beUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13641,7 +13818,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe59935f160ac7578UL)] - public class Result_callHeld : ICapnpSerializable + public class Result_CallHeld : ICapnpSerializable { public const UInt64 typeId = 0xe59935f160ac7578UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13682,7 +13859,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string S => ctx.ReadText(0, ""); + public string S => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -13694,14 +13871,14 @@ namespace Capnproto_test.Capnp.Test public string S { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0xfeffc025fce317e3UL)] - public class Params_getHeld : ICapnpSerializable + public class Params_GetHeld : ICapnpSerializable { public const UInt64 typeId = 0xfeffc025fce317e3UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13746,7 +13923,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xef4e146185af67ceUL)] - public class Result_getHeld : ICapnpSerializable + public class Result_GetHeld : ICapnpSerializable { public const UInt64 typeId = 0xef4e146185af67ceUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13806,7 +13983,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc07526f7e2e533b9UL)] - public class Params_echo : ICapnpSerializable + public class Params_Echo : ICapnpSerializable { public const UInt64 typeId = 0xc07526f7e2e533b9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13866,7 +14043,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa6224536593d5b92UL)] - public class Result_echo : ICapnpSerializable + public class Result_Echo : ICapnpSerializable { public const UInt64 typeId = 0xa6224536593d5b92UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13926,7 +14103,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa1cc32d87f3edeb1UL)] - public class Params_expectCancel : ICapnpSerializable + public class Params_ExpectCancel : ICapnpSerializable { public const UInt64 typeId = 0xa1cc32d87f3edeb1UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13986,7 +14163,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8a3eba1758c0916eUL)] - public class Result_expectCancel : ICapnpSerializable + public class Result_ExpectCancel : ICapnpSerializable { public const UInt64 typeId = 0x8a3eba1758c0916eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14031,7 +14208,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x99160a25fa50fbf1UL)] - public class Params_methodWithDefaults : ICapnpSerializable + public class Params_MethodWithDefaults : ICapnpSerializable { public const UInt64 typeId = 0x99160a25fa50fbf1UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14090,7 +14267,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string A => ctx.ReadText(0, ""); + public string A => ctx.ReadText(0, null); public uint B => ctx.ReadDataUInt(0UL, 123U); public string C => ctx.ReadText(1, "foo"); } @@ -14104,8 +14281,8 @@ namespace Capnproto_test.Capnp.Test public string A { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public uint B @@ -14123,7 +14300,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9c7e066f845a6c56UL)] - public class Result_methodWithDefaults : ICapnpSerializable + public class Result_MethodWithDefaults : ICapnpSerializable { public const UInt64 typeId = 0x9c7e066f845a6c56UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14173,7 +14350,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string D => ctx.ReadText(0, ""); + public string D => ctx.ReadText(0, null); public string E => ctx.ReadText(1, "bar"); } @@ -14186,8 +14363,8 @@ namespace Capnproto_test.Capnp.Test public string D { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public string E @@ -14199,7 +14376,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xead024a301a092a1UL)] - public class Params_getHandle : ICapnpSerializable + public class Params_GetHandle : ICapnpSerializable { public const UInt64 typeId = 0xead024a301a092a1UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14244,7 +14421,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc3490d75420a1fe8UL)] - public class Result_getHandle : ICapnpSerializable + public class Result_GetHandle : ICapnpSerializable { public const UInt64 typeId = 0xc3490d75420a1fe8UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14304,7 +14481,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xd8493f0e175d61f2UL)] - public class Params_getNull : ICapnpSerializable + public class Params_GetNull : ICapnpSerializable { public const UInt64 typeId = 0xd8493f0e175d61f2UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14349,7 +14526,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe6955d8ef1023671UL)] - public class Result_getNull : ICapnpSerializable + public class Result_GetNull : ICapnpSerializable { public const UInt64 typeId = 0xe6955d8ef1023671UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14409,7 +14586,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x805df436f55dd07aUL)] - public class Params_getEnormousString : ICapnpSerializable + public class Params_GetEnormousString : ICapnpSerializable { public const UInt64 typeId = 0x805df436f55dd07aUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14454,7 +14631,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x860e7512dc3925b0UL)] - public class Result_getEnormousString : ICapnpSerializable + public class Result_GetEnormousString : ICapnpSerializable { public const UInt64 typeId = 0x860e7512dc3925b0UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14495,7 +14672,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string Str => ctx.ReadText(0, ""); + public string Str => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -14507,14 +14684,14 @@ namespace Capnproto_test.Capnp.Test public string Str { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0xfb92899aeb0ee74fUL)] - public class Params_methodWithNullDefault : ICapnpSerializable + public class Params_MethodWithNullDefault : ICapnpSerializable { public const UInt64 typeId = 0xfb92899aeb0ee74fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14563,7 +14740,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string A => ctx.ReadText(0, ""); + public string A => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.ITestInterface B => ctx.ReadCap(1); } @@ -14576,8 +14753,8 @@ namespace Capnproto_test.Capnp.Test public string A { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.ITestInterface B @@ -14589,7 +14766,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8467348247305cf7UL)] - public class Result_methodWithNullDefault : ICapnpSerializable + public class Result_MethodWithNullDefault : ICapnpSerializable { public const UInt64 typeId = 0x8467348247305cf7UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14638,9 +14815,9 @@ namespace Capnproto_test.Capnp.Test public interface ITestMembrane : IDisposable { Task MakeThing(CancellationToken cancellationToken_ = default); - Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default); - Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default); - Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, CancellationToken cancellationToken_ = default); + Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default); + Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default); + Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, CancellationToken cancellationToken_ = default); Task WaitForever(CancellationToken cancellationToken_ = default); } @@ -14648,51 +14825,61 @@ namespace Capnproto_test.Capnp.Test { public Task MakeThing(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_makeThing() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_MakeThing() { }; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(13870398341137210380UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Thing); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Thing); + } } ); } - public async Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default) + public async Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_callPassThrough() - { Thing = thing, TailCall = tailCall }; - arg_.serialize(in_); - var d_ = await Call(13870398341137210380UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_CallPassThrough() + { Thing = Thing, TailCall = TailCall }; + arg_?.serialize(in_); + using (var d_ = await Call(13870398341137210380UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } - public async Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default) + public async Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_callIntercept() - { Thing = thing, TailCall = tailCall }; - arg_.serialize(in_); - var d_ = await Call(13870398341137210380UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_CallIntercept() + { Thing = Thing, TailCall = TailCall }; + arg_?.serialize(in_); + using (var d_ = await Call(13870398341137210380UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } - public Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, CancellationToken cancellationToken_ = default) + public Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_loopback() - { Thing = thing }; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_Loopback() + { Thing = Thing }; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(13870398341137210380UL, 3, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Thing); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Thing); + } } ); @@ -14700,13 +14887,15 @@ namespace Capnproto_test.Capnp.Test public async Task WaitForever(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_waitForever() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_WaitForever() { }; - arg_.serialize(in_); - var d_ = await Call(13870398341137210380UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(13870398341137210380UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -14720,62 +14909,77 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 13870398341137210380UL; Task MakeThing(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.MakeThing(cancellationToken_), thing => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_makeThing { Thing = thing }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.MakeThing(cancellationToken_), thing => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_MakeThing { Thing = thing }; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task CallPassThrough(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallPassThrough(in_.Thing, in_.TailCall, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallPassThrough(in_.Thing, in_.TailCall, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } Task CallIntercept(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallIntercept(in_.Thing, in_.TailCall, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallIntercept(in_.Thing, in_.TailCall, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } Task Loopback(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Loopback(in_.Thing, cancellationToken_), thing => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_loopback { Thing = thing }; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Loopback(in_.Thing, cancellationToken_), thing => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_Loopback { Thing = thing }; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task WaitForever(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.WaitForever(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.WaitForever(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } @@ -14792,24 +14996,28 @@ namespace Capnproto_test.Capnp.Test { public async Task PassThrough(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_passThrough() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_PassThrough() { }; - arg_.serialize(in_); - var d_ = await Call(10615798940090972439UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + arg_?.serialize(in_); + using (var d_ = await Call(10615798940090972439UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } public async Task Intercept(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_intercept() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_Intercept() { }; - arg_.serialize(in_); - var d_ = await Call(10615798940090972439UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + arg_?.serialize(in_); + using (var d_ = await Call(10615798940090972439UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } } @@ -14823,33 +15031,39 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 10615798940090972439UL; Task PassThrough(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.PassThrough(cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.PassThrough(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } Task Intercept(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.Intercept(cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.Intercept(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } public static class Thing { [TypeId(0xff9bdcd05085d786UL)] - public class Params_passThrough : ICapnpSerializable + public class Params_PassThrough : ICapnpSerializable { public const UInt64 typeId = 0xff9bdcd05085d786UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14894,7 +15108,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xee94bed3615ee745UL)] - public class Params_intercept : ICapnpSerializable + public class Params_Intercept : ICapnpSerializable { public const UInt64 typeId = 0xee94bed3615ee745UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14981,7 +15195,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string Text => ctx.ReadText(0, ""); + public string Text => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -14993,14 +15207,14 @@ namespace Capnproto_test.Capnp.Test public string Text { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } [TypeId(0xd8ac2acc3ece6556UL)] - public class Params_makeThing : ICapnpSerializable + public class Params_MakeThing : ICapnpSerializable { public const UInt64 typeId = 0xd8ac2acc3ece6556UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15045,7 +15259,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe5d4904814ccbf29UL)] - public class Result_makeThing : ICapnpSerializable + public class Result_MakeThing : ICapnpSerializable { public const UInt64 typeId = 0xe5d4904814ccbf29UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15105,7 +15319,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x945d9f634a6a29daUL)] - public class Params_callPassThrough : ICapnpSerializable + public class Params_CallPassThrough : ICapnpSerializable { public const UInt64 typeId = 0x945d9f634a6a29daUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15180,7 +15394,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8749aac3375c5c71UL)] - public class Params_callIntercept : ICapnpSerializable + public class Params_CallIntercept : ICapnpSerializable { public const UInt64 typeId = 0x8749aac3375c5c71UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15255,7 +15469,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x869a1b7ab34b42c9UL)] - public class Params_loopback : ICapnpSerializable + public class Params_Loopback : ICapnpSerializable { public const UInt64 typeId = 0x869a1b7ab34b42c9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15315,7 +15529,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xecd19398fd88ab5cUL)] - public class Result_loopback : ICapnpSerializable + public class Result_Loopback : ICapnpSerializable { public const UInt64 typeId = 0xecd19398fd88ab5cUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15375,7 +15589,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8f6bb30cc62917ffUL)] - public class Params_waitForever : ICapnpSerializable + public class Params_WaitForever : ICapnpSerializable { public const UInt64 typeId = 0x8f6bb30cc62917ffUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15420,7 +15634,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc343a4907280be01UL)] - public class Result_waitForever : ICapnpSerializable + public class Result_WaitForever : ICapnpSerializable { public const UInt64 typeId = 0xc343a4907280be01UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15547,7 +15761,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - List = reader.List.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List = reader.List?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); applyDefaults(); } @@ -15649,7 +15863,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string Text => ctx.ReadText(0, ""); + public string Text => ctx.ReadText(0, null); public Capnproto_test.Capnp.Test.ITestInterface Cap => ctx.ReadCap(1); } @@ -15662,8 +15876,8 @@ namespace Capnproto_test.Capnp.Test public string Text { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } public Capnproto_test.Capnp.Test.ITestInterface Cap @@ -15688,46 +15902,54 @@ namespace Capnproto_test.Capnp.Test { public async Task Delete(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_delete() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Delete() { }; - arg_.serialize(in_); - var d_ = await Call(11160837778045172988UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(11160837778045172988UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Class(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_class() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Class() { }; - arg_.serialize(in_); - var d_ = await Call(11160837778045172988UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(11160837778045172988UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Void(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_void() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Void() { }; - arg_.serialize(in_); - var d_ = await Call(11160837778045172988UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(11160837778045172988UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Return(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_return() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Return() { }; - arg_.serialize(in_); - var d_ = await Call(11160837778045172988UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + arg_?.serialize(in_); + using (var d_ = await Call(11160837778045172988UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -15741,37 +15963,49 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11160837778045172988UL; async Task Delete(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Delete(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Delete(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Class(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Class(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Class(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Void(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Void(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Void(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Return(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Return(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Return(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } public static class TestKeywordMethods { [TypeId(0xca3a89cdeb6bd6b7UL)] - public class Params_delete : ICapnpSerializable + public class Params_Delete : ICapnpSerializable { public const UInt64 typeId = 0xca3a89cdeb6bd6b7UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15816,7 +16050,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xeeb5843598307592UL)] - public class Result_delete : ICapnpSerializable + public class Result_Delete : ICapnpSerializable { public const UInt64 typeId = 0xeeb5843598307592UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15861,7 +16095,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9cf5a8313c5db036UL)] - public class Params_class : ICapnpSerializable + public class Params_Class : ICapnpSerializable { public const UInt64 typeId = 0x9cf5a8313c5db036UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15906,7 +16140,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc0253868ac12e7d8UL)] - public class Result_class : ICapnpSerializable + public class Result_Class : ICapnpSerializable { public const UInt64 typeId = 0xc0253868ac12e7d8UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15951,7 +16185,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa4a08763833c7757UL)] - public class Params_void : ICapnpSerializable + public class Params_Void : ICapnpSerializable { public const UInt64 typeId = 0xa4a08763833c7757UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15996,7 +16230,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xde82773089c0aeabUL)] - public class Result_void : ICapnpSerializable + public class Result_Void : ICapnpSerializable { public const UInt64 typeId = 0xde82773089c0aeabUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16041,7 +16275,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x99817360625e8ca3UL)] - public class Params_return : ICapnpSerializable + public class Params_Return : ICapnpSerializable { public const UInt64 typeId = 0x99817360625e8ca3UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16086,7 +16320,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb70872e07eaa992fUL)] - public class Result_return : ICapnpSerializable + public class Result_Return : ICapnpSerializable { public const UInt64 typeId = 0xb70872e07eaa992fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16141,14 +16375,17 @@ namespace Capnproto_test.Capnp.Test { public Task GetCallerId(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc.Params_getCallerId.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Params_getCallerId() + var in_ = SerializerState.CreateForRpc.Params_GetCallerId.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Params_GetCallerId() { }; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(16893789964317726925UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create.Result_getCallerId>(d_); - return (r_.Caller); + using (d_) + { + var r_ = CapnpSerializable.Create.Result_GetCallerId>(d_); + return (r_.Caller); + } } ); @@ -16165,15 +16402,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 16893789964317726925UL; Task GetCallerId(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetCallerId(cancellationToken_), caller => + using (d_) { - var s_ = SerializerState.CreateForRpc.Result_getCallerId.WRITER>(); - var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_getCallerId { Caller = caller }; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetCallerId(cancellationToken_), caller => + { + var s_ = SerializerState.CreateForRpc.Result_GetCallerId.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_GetCallerId { Caller = caller }; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -16181,7 +16421,7 @@ namespace Capnproto_test.Capnp.Test where TVatId : class { [TypeId(0x8ec30e2451f1cffeUL)] - public class Params_getCallerId : ICapnpSerializable + public class Params_GetCallerId : ICapnpSerializable { public const UInt64 typeId = 0x8ec30e2451f1cffeUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16226,7 +16466,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc71cf776034a3e67UL)] - public class Result_getCallerId : ICapnpSerializable + public class Result_GetCallerId : ICapnpSerializable { public const UInt64 typeId = 0xc71cf776034a3e67UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16403,7 +16643,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public string Host => ctx.ReadText(0, ""); + public string Host => ctx.ReadText(0, null); } public class WRITER : SerializerState @@ -16415,8 +16655,8 @@ namespace Capnproto_test.Capnp.Test public string Host { - get => this.ReadText(0, ""); - set => this.WriteText(0, value, ""); + get => this.ReadText(0, null); + set => this.WriteText(0, value, null); } } } @@ -16697,7 +16937,7 @@ namespace Capnproto_test.Capnp.Test } AnotherBadFieldName = reader.AnotherBadFieldName; - BadlyNamedUnion = CapnpSerializable.Create(reader.BadlyNamedUnion); + BadlyNamedUnion = CapnpSerializable.Create(reader.BadlyNamedUnion); applyDefaults(); } @@ -16775,7 +17015,7 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion BadlyNamedUnion + public Capnproto_test.Capnp.Test.TestNameAnnotation.badlyNamedUnion BadlyNamedUnion { get; set; @@ -16796,7 +17036,7 @@ namespace Capnproto_test.Capnp.Test public bool BadFieldName => which == WHICH.BadFieldName ? ctx.ReadDataBool(0UL, false) : default; public sbyte Bar => which == WHICH.Bar ? ctx.ReadDataSByte(0UL, (sbyte)0) : default; public Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum AnotherBadFieldName => (Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum)ctx.ReadDataUShort(32UL, (ushort)0); - public @badlyNamedUnion.READER BadlyNamedUnion => new @badlyNamedUnion.READER(ctx); + public badlyNamedUnion.READER BadlyNamedUnion => new badlyNamedUnion.READER(ctx); } public class WRITER : SerializerState @@ -16830,14 +17070,14 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(32UL, (ushort)value, (ushort)0); } - public @badlyNamedUnion.WRITER BadlyNamedUnion + public badlyNamedUnion.WRITER BadlyNamedUnion { - get => Rewrap<@badlyNamedUnion.WRITER>(); + get => Rewrap(); } } [TypeId(0x89d9d1626b34017cUL)] - public class @badlyNamedUnion : ICapnpSerializable + public class badlyNamedUnion : ICapnpSerializable { public const UInt64 typeId = 0x89d9d1626b34017cUL; public enum WHICH : ushort @@ -16853,7 +17093,7 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.BadlyNamedGroup: - BadlyNamedGroup = CapnpSerializable.Create(reader.BadlyNamedGroup); + BadlyNamedGroup = CapnpSerializable.Create(reader.BadlyNamedGroup); break; case WHICH.Baz: Baz = CapnpSerializable.Create(reader.Baz); @@ -16908,9 +17148,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion.@badlyNamedGroup BadlyNamedGroup + public Capnproto_test.Capnp.Test.TestNameAnnotation.badlyNamedUnion.badlyNamedGroup BadlyNamedGroup { - get => _which == WHICH.BadlyNamedGroup ? (Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion.@badlyNamedGroup)_content : null; + get => _which == WHICH.BadlyNamedGroup ? (Capnproto_test.Capnp.Test.TestNameAnnotation.badlyNamedUnion.badlyNamedGroup)_content : null; set { _which = WHICH.BadlyNamedGroup; @@ -16940,7 +17180,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); - public @badlyNamedGroup.READER BadlyNamedGroup => which == WHICH.BadlyNamedGroup ? new @badlyNamedGroup.READER(ctx) : default; + public badlyNamedGroup.READER BadlyNamedGroup => which == WHICH.BadlyNamedGroup ? new badlyNamedGroup.READER(ctx) : default; public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER Baz => which == WHICH.Baz ? ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER.create) : default; } @@ -16956,9 +17196,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(48U, (ushort)value, (ushort)0); } - public @badlyNamedGroup.WRITER BadlyNamedGroup + public badlyNamedGroup.WRITER BadlyNamedGroup { - get => which == WHICH.BadlyNamedGroup ? Rewrap<@badlyNamedGroup.WRITER>() : default; + get => which == WHICH.BadlyNamedGroup ? Rewrap() : default; } public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.WRITER Baz @@ -16969,7 +17209,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc3594bce5b24b722UL)] - public class @badlyNamedGroup : ICapnpSerializable + public class badlyNamedGroup : ICapnpSerializable { public const UInt64 typeId = 0xc3594bce5b24b722UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -17108,20 +17348,22 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xd112a69d31ed918bUL), Proxy(typeof(TestNameAnnotationInterface_Proxy)), Skeleton(typeof(TestNameAnnotationInterface_Skeleton))] public interface ITestNameAnnotationInterface : IDisposable { - Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default); + Task BadlyNamedMethod(byte BadlyNamedParam, CancellationToken cancellationToken_ = default); } public class TestNameAnnotationInterface_Proxy : Proxy, ITestNameAnnotationInterface { - public async Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default) + public async Task BadlyNamedMethod(byte BadlyNamedParam, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestNameAnnotationInterface.Params_badlyNamedMethod() - { BadlyNamedParam = badlyNamedParam }; - arg_.serialize(in_); - var d_ = await Call(15065286897585459595UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestNameAnnotationInterface.Params_BadlyNamedMethod() + { BadlyNamedParam = BadlyNamedParam }; + arg_?.serialize(in_); + using (var d_ = await Call(15065286897585459595UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -17135,17 +17377,20 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15065286897585459595UL; async Task BadlyNamedMethod(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.BadlyNamedMethod(in_.BadlyNamedParam, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.BadlyNamedMethod(in_.BadlyNamedParam, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } public static class TestNameAnnotationInterface { [TypeId(0xc12efc3b075adfe9UL)] - public class Params_badlyNamedMethod : ICapnpSerializable + public class Params_BadlyNamedMethod : ICapnpSerializable { public const UInt64 typeId = 0xc12efc3b075adfe9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -17205,7 +17450,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdcc3cdb4b28f6c86UL)] - public class Result_badlyNamedMethod : ICapnpSerializable + public class Result_BadlyNamedMethod : ICapnpSerializable { public const UInt64 typeId = 0xdcc3cdb4b28f6c86UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -17255,23 +17500,22 @@ namespace Capnproto_test.Capnp.Test static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) { - async Task AwaitProxy() => (await task).Item2.Cap; - - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access( - Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap, - AwaitProxy())); + async Task AwaitProxy() => (await task).Item2?.Cap; + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap, AwaitProxy())); } static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) { - return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap)); + async Task AwaitProxy() => (await task).Item2?.Cap; + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap, AwaitProxy())); } static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestTailCallee_foo_C = new MemberAccessPath(1U); public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestTailCallee_foo_C)); + async Task AwaitProxy() => (await task).C; + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestTailCallee_foo_C, AwaitProxy())); } } } \ No newline at end of file diff --git a/Capnp.Net.Runtime.Tests/TcpRpcErrorHandling.cs b/Capnp.Net.Runtime.Tests/TcpRpcErrorHandling.cs index 300320d..be58c28 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcErrorHandling.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcErrorHandling.cs @@ -127,7 +127,7 @@ namespace Capnp.Net.Runtime.Tests _.Call.Target.ImportedCap = bootCapId; _.Call.InterfaceId = ((TypeIdAttribute)typeof(ITestInterface).GetCustomAttributes(typeof(TypeIdAttribute), false)[0]).Id; _.Call.MethodId = 0; - _.Call.Params.Content.Rewrap(); + _.Call.Params.Content.Rewrap(); }); tester.ExpectAbort(); } @@ -154,7 +154,7 @@ namespace Capnp.Net.Runtime.Tests _.Call.Target.ImportedCap = bootCapId; _.Call.InterfaceId = ((TypeIdAttribute)typeof(ITestInterface).GetCustomAttributes(typeof(TypeIdAttribute), false)[0]).Id; _.Call.MethodId = 0; - var wr = _.Call.Params.Content.Rewrap(); + var wr = _.Call.Params.Content.Rewrap(); wr.I = 123u; wr.J = true; }); @@ -168,7 +168,7 @@ namespace Capnp.Net.Runtime.Tests _.Call.Target.ImportedCap = bootCapId; _.Call.InterfaceId = ((TypeIdAttribute)typeof(ITestInterface).GetCustomAttributes(typeof(TypeIdAttribute), false)[0]).Id; _.Call.MethodId = 0; - _.Call.Params.Content.Rewrap(); + _.Call.Params.Content.Rewrap(); }); tester.ExpectAbort(); } @@ -565,7 +565,7 @@ namespace Capnp.Net.Runtime.Tests _.Call.Target.ImportedCap = bootCapId; _.Call.InterfaceId = new TestPipeline_Skeleton().InterfaceId; _.Call.MethodId = 0; - var wr = _.Call.Params.Content.Rewrap(); + var wr = _.Call.Params.Content.Rewrap(); wr.InCap = null; _.Call.Params.CapTable.Init(1); _.Call.Params.CapTable[0].which = CapDescriptor.WHICH.ReceiverHosted; diff --git a/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs b/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs index 6376c49..2f16eff 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs @@ -642,7 +642,7 @@ namespace Capnp.Net.Runtime.Tests }); } - [TestMethod, Timeout(10000)] + [TestMethod] public void RetainAndReleaseClient() { using (var server = SetupServer()) diff --git a/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs b/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs index 5bf3b17..293e595 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging; namespace Capnp.Net.Runtime.Tests { + [TestClass] [TestCategory("Coverage")] public class TcpRpcPorted: TestBase @@ -19,99 +20,19 @@ namespace Capnp.Net.Runtime.Tests [TestMethod] public void Basic() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - server.Main = new TestInterfaceImpl(counters); - using (var main = client.GetMain()) - { - var request1 = main.Foo(123, true, default); - var request3 = Assert.ThrowsExceptionAsync(() => main.Bar(default)); - var s = new TestAllTypes(); - Common.InitTestMessage(s); - var request2 = main.Baz(s, default); - - Assert.IsTrue(request1.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(request2.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(request3.Wait(MediumNonDbgTimeout)); - - Assert.AreEqual("foo", request1.Result); - Assert.AreEqual(2, counters.CallCount); - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.Basic); } [TestMethod] public void Pipeline() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - server.Main = new TestPipelineImpl(counters); - using (var main = client.GetMain()) - { - var chainedCallCount = new Counters(); - var request = main.GetCap(234, new TestInterfaceImpl(chainedCallCount), default); - using (var outBox = request.OutBox_Cap()) - { - var pipelineRequest = outBox.Foo(321, false, default); - var pipelineRequest2 = ((Proxy)outBox).Cast(false).Grault(default); - - Assert.IsTrue(pipelineRequest.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(pipelineRequest2.Wait(MediumNonDbgTimeout)); - - Assert.AreEqual("bar", pipelineRequest.Result); - Common.CheckTestMessage(pipelineRequest2.Result); - - Assert.AreEqual(3, counters.CallCount); - Assert.AreEqual(1, chainedCallCount.CallCount); - } - } - - } + NewLocalhostTcpTestbed().RunTest(Testsuite.Pipeline); } [TestMethod] public void Release() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - server.Main = new TestMoreStuffImpl(counters); - using (var main = client.GetMain()) - { - var task1 = main.GetHandle(default); - var task2 = main.GetHandle(default); - Assert.IsTrue(task1.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(task2.Wait(MediumNonDbgTimeout)); - - Assert.AreEqual(2, counters.HandleCount); - - task1.Result.Dispose(); - - Assert.IsTrue(SpinWait.SpinUntil(() => counters.HandleCount == 1, MediumNonDbgTimeout)); - - task2.Result.Dispose(); - - Assert.IsTrue(SpinWait.SpinUntil(() => counters.HandleCount == 0, MediumNonDbgTimeout)); - } - - } + NewLocalhostTcpTestbed().RunTest(Testsuite.Release); } [TestMethod] @@ -160,482 +81,63 @@ namespace Capnp.Net.Runtime.Tests } [TestMethod] - public void TestTailCall() + public void TailCall() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - server.Main = new TestTailCallerImpl(counters); - using (var main = client.GetMain()) - { - var calleeCallCount = new Counters(); - var callee = new TestTailCalleeImpl(calleeCallCount); - - var promise = main.Foo(456, callee, default); - var dependentCall0 = promise.C().GetCallSequence(0, default); - - Assert.IsTrue(promise.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(456u, promise.Result.I); - Assert.AreEqual("from TestTailCaller", promise.Result.T); - - var dependentCall1 = promise.C().GetCallSequence(0, default); - var dependentCall2 = promise.C().GetCallSequence(0, default); - - Assert.IsTrue(dependentCall0.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(dependentCall1.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(dependentCall2.Wait(MediumNonDbgTimeout)); - - Assert.AreEqual(1, counters.CallCount); - Assert.AreEqual(1, calleeCallCount.CallCount); - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.TailCall); } [TestMethod] public void Cancelation() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - server.Main = new TestMoreStuffImpl(counters); - using (var main = client.GetMain()) - { - var destroyed = new TaskCompletionSource(); - var impl = new TestInterfaceImpl(counters, destroyed); - var cts = new CancellationTokenSource(); - var cancelTask = main.ExpectCancel(impl, cts.Token); - - Assert.IsFalse(SpinWait.SpinUntil(() => destroyed.Task.IsCompleted || cancelTask.IsCompleted, ShortTimeout)); - - cts.Cancel(); - - Assert.IsTrue(destroyed.Task.Wait(MediumNonDbgTimeout)); - Assert.IsFalse(cancelTask.IsCompleted && !cancelTask.IsCanceled); - } - - } + NewLocalhostTcpTestbed().RunTest(Testsuite.Cancelation); } [TestMethod] public void PromiseResolve() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var tcs = new TaskCompletionSource(); - var eager = tcs.Task.Eager(true); - - var request = main.CallFoo(eager, default); - var request2 = main.CallFooWhenResolved(eager, default); - - var gcs = main.GetCallSequence(0, default); - Assert.IsTrue(gcs.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(2u, gcs.Result); - Assert.AreEqual(3, counters.CallCount); - - var chainedCallCount = new Counters(); - var tiimpl = new TestInterfaceImpl(chainedCallCount); - tcs.SetResult(tiimpl); - - Assert.IsTrue(request.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(request2.Wait(MediumNonDbgTimeout)); - - Assert.AreEqual("bar", request.Result); - Assert.AreEqual("bar", request2.Result); - Assert.AreEqual(3, counters.CallCount); - Assert.AreEqual(2, chainedCallCount.CallCount); - } - - } + NewLocalhostTcpTestbed().RunTest(Testsuite.PromiseResolve); } [TestMethod] public void RetainAndRelease() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var destructionPromise = new TaskCompletionSource(); - var destructionTask = destructionPromise.Task; - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var holdTask = main.Hold(new TestInterfaceImpl(new Counters(), destructionPromise), default); - Assert.IsTrue(holdTask.Wait(MediumNonDbgTimeout)); - - var cstask = main.GetCallSequence(0, default); - Assert.IsTrue(cstask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(1u, cstask.Result); - - Assert.IsFalse(destructionTask.IsCompleted); - - var htask = main.CallHeld(default); - Assert.IsTrue(htask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual("bar", htask.Result); - - var gtask = main.GetHeld(default); - Assert.IsTrue(gtask.Wait(MediumNonDbgTimeout)); - // We can get the cap back from it. - using (var cap = gtask.Result) - { - // Wait for balanced state - WaitClientServerIdle(server, client); - - // And call it, without any network communications. - long oldSendCount = client.SendCount; - var ftask = cap.Foo(123, true, default); - Assert.IsTrue(ftask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual("foo", ftask.Result); - Assert.AreEqual(oldSendCount, client.SendCount); - - // We can send another copy of the same cap to another method, and it works. - var ctask = main.CallFoo(cap, default); - Assert.IsTrue(ctask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual("bar", ctask.Result); - - // Give some time to settle. - cstask = main.GetCallSequence(0, default); - Assert.IsTrue(cstask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(5u, cstask.Result); - cstask = main.GetCallSequence(0, default); - Assert.IsTrue(cstask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(6u, cstask.Result); - cstask = main.GetCallSequence(0, default); - Assert.IsTrue(cstask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(7u, cstask.Result); - - // Can't be destroyed, we haven't released it. - Assert.IsFalse(destructionTask.IsCompleted); - } - - // In deviation from original test, we have null the held capability on the main interface. - // This is because the main interface is the bootstrap capability and, as such, won't be disposed - // after disconnect. - var holdNullTask = main.Hold(null, default); - Assert.IsTrue(holdNullTask.Wait(MediumNonDbgTimeout)); - } - - Assert.IsTrue(destructionTask.Wait(MediumNonDbgTimeout)); - } + NewLocalhostTcpTestbed().RunTest(Testsuite.RetainAndRelease); } [TestMethod] public void Cancel() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var destructionPromise = new TaskCompletionSource(); - var destructionTask = destructionPromise.Task; - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - using (var cts = new CancellationTokenSource()) - { - var ntask = main.NeverReturn(new TestInterfaceImpl(counters, destructionPromise), cts.Token); - - // Allow some time to settle. - var cstask = main.GetCallSequence(0, default); - Assert.IsTrue(cstask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(1u, cstask.Result); - cstask = main.GetCallSequence(0, default); - Assert.IsTrue(cstask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(2u, cstask.Result); - - // The cap shouldn't have been destroyed yet because the call never returned. - Assert.IsFalse(destructionTask.IsCompleted); - - // There will be no automatic cancellation just because "ntask" goes of of scope or - // because the Proxy is disposed. Even ntask.Dispose() would not cancel the request. - // In .NET this needs to be done explicitly. - cts.Cancel(); - } - - // Now the cap should be released. - Assert.IsTrue(destructionTask.Wait(MediumNonDbgTimeout)); - } + NewLocalhostTcpTestbed().RunTest(Testsuite.Cancel); } [TestMethod] public void SendTwice() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var destructionPromise = new TaskCompletionSource(); - var destructionTask = destructionPromise.Task; - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var cap = new TestInterfaceImpl(new Counters(), destructionPromise); - - Task ftask1, ftask2; - - using (Skeleton.Claim(cap)) - { - var ftask = main.CallFoo(cap, default); - Assert.IsTrue(ftask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual("bar", ftask.Result); - - var ctask = main.GetCallSequence(0, default); - Assert.IsTrue(ctask.Wait(MediumNonDbgTimeout)); - Assert.AreEqual(1u, ctask.Result); - - ftask1 = main.CallFoo(cap, default); - ftask2 = main.CallFoo(cap, default); - } - - Assert.IsTrue(ftask1.Wait(MediumNonDbgTimeout)); - Assert.AreEqual("bar", ftask1.Result); - Assert.IsTrue(ftask2.Wait(MediumNonDbgTimeout)); - Assert.AreEqual("bar", ftask2.Result); - - // Now the cap should be released. - Assert.IsTrue(destructionTask.Wait(MediumNonDbgTimeout)); - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.SendTwice); } [TestMethod] public void Embargo() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var resolving = main as IResolvingCapability; - Assert.IsTrue(resolving.WhenResolved.Wait(MediumNonDbgTimeout)); - - var cap = new TestCallOrderImpl(); - cap.CountToDispose = 6; - - var earlyCall = main.GetCallSequence(0, default); - - var echo = main.Echo(cap, default); - - using (var pipeline = echo.Eager()) - { - var call0 = pipeline.GetCallSequence(0, default); - var call1 = pipeline.GetCallSequence(1, default); - - Assert.IsTrue(earlyCall.Wait(MediumNonDbgTimeout)); - - impl.EnableEcho(); - - var call2 = pipeline.GetCallSequence(2, default); - - Assert.IsTrue(echo.Wait(MediumNonDbgTimeout)); - using (var resolved = echo.Result) - { - var call3 = pipeline.GetCallSequence(3, default); - var call4 = pipeline.GetCallSequence(4, default); - var call5 = pipeline.GetCallSequence(5, default); - - try - { - bool flag = call0.Wait(MediumNonDbgTimeout); - Assert.IsTrue(flag); - } - catch (AggregateException exception) when (exception.InnerException is RpcException rpcException && rpcException.Message == "Cannot access a disposed object.") - { - Console.WriteLine($"Oops, object disposed. Counter = {cap.Count}, tx count = {client.SendCount}, rx count = {client.RecvCount}"); - throw; - } - - Assert.IsTrue(call1.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(call2.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(call3.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(call4.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(call5.Wait(MediumNonDbgTimeout)); - - Assert.AreEqual(0u, call0.Result); - Assert.AreEqual(1u, call1.Result); - Assert.AreEqual(2u, call2.Result); - Assert.AreEqual(3u, call3.Result); - Assert.AreEqual(4u, call4.Result); - Assert.AreEqual(5u, call5.Result); - } - } - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.Embargo); } [TestMethod] public void EmbargoError() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var resolving = main as IResolvingCapability; - Assert.IsTrue(resolving.WhenResolved.Wait(MediumNonDbgTimeout)); - - var cap = new TaskCompletionSource(); - - var earlyCall = main.GetCallSequence(0, default); - - var echo = main.Echo(cap.Task.Eager(true), default); - - var pipeline = echo.Eager(); - - var call0 = pipeline.GetCallSequence(0, default); - var call1 = pipeline.GetCallSequence(1, default); - - Assert.IsTrue(earlyCall.Wait(MediumNonDbgTimeout)); - - impl.EnableEcho(); - - var call2 = pipeline.GetCallSequence(2, default); - - Assert.IsTrue(echo.Wait(MediumNonDbgTimeout)); - var resolved = echo.Result; - - var call3 = pipeline.GetCallSequence(3, default); - var call4 = pipeline.GetCallSequence(4, default); - var call5 = pipeline.GetCallSequence(5, default); - - cap.SetException(new InvalidOperationException("I'm annoying")); - - ExpectPromiseThrows(call0); - ExpectPromiseThrows(call1); - ExpectPromiseThrows(call2); - ExpectPromiseThrows(call3); - ExpectPromiseThrows(call4); - ExpectPromiseThrows(call5); - - // Verify that we're still connected (there were no protocol errors). - Assert.IsTrue(main.GetCallSequence(1, default).Wait(MediumNonDbgTimeout)); - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.EmbargoError); } [TestMethod] public void EmbargoNull() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var resolving = main as IResolvingCapability; - Assert.IsTrue(resolving.WhenResolved.Wait(MediumNonDbgTimeout)); - - var promise = main.GetNull(default); - - var cap = promise.Eager(); - - var call0 = cap.GetCallSequence(0, default); - - Assert.IsTrue(promise.Wait(MediumNonDbgTimeout)); - - var call1 = cap.GetCallSequence(1, default); - - ExpectPromiseThrows(call0); - ExpectPromiseThrows(call1); - - // Verify that we're still connected (there were no protocol errors). - Assert.IsTrue(main.GetCallSequence(1, default).Wait(MediumNonDbgTimeout)); - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.EmbargoNull); } [TestMethod] public void CallBrokenPromise() { - (var server, var client) = SetupClientServerPair(); - - using (server) - using (client) - { - client.WhenConnected.Wait(); - - var counters = new Counters(); - var impl = new TestMoreStuffImpl(counters); - server.Main = impl; - using (var main = client.GetMain()) - { - var resolving = main as IResolvingCapability; - Assert.IsTrue(resolving.WhenResolved.Wait(MediumNonDbgTimeout)); - - var tcs = new TaskCompletionSource(); - - var req = main.Hold(tcs.Task.Eager(true), default); - Assert.IsTrue(req.Wait(MediumNonDbgTimeout)); - - var req2 = main.CallHeld(default); - - Assert.IsFalse(req2.Wait(ShortTimeout)); - - tcs.SetException(new InvalidOperationException("I'm a promise-breaker!")); - - ExpectPromiseThrows(req2); - - // Verify that we're still connected (there were no protocol errors). - Assert.IsTrue(main.GetCallSequence(1, default).Wait(MediumNonDbgTimeout)); - } - } + NewLocalhostTcpTestbed().RunTest(Testsuite.CallBrokenPromise); } } } diff --git a/Capnp.Net.Runtime.Tests/TcpRpcStress.cs b/Capnp.Net.Runtime.Tests/TcpRpcStress.cs index fd41551..8f6eec1 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcStress.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcStress.cs @@ -6,6 +6,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Net; +using System.Net.Sockets; using System.Text; using System.Threading; @@ -60,7 +61,11 @@ namespace Capnp.Net.Runtime.Tests { var t = new TcpRpcPorted(); Repeat(100, t.Embargo); + } + [TestMethod] + public void EmbargoServer() + { var t2 = new TcpRpcInterop(); Repeat(100, t2.EmbargoServer); } @@ -94,35 +99,45 @@ namespace Capnp.Net.Runtime.Tests [TestMethod] public void ScatteredTransfer() { - - using (var server = new TcpRpcServer(IPAddress.Any, TcpPort)) - using (var client = new TcpRpcClient()) + for (int retry = 0; retry < 10; retry++) { - server.InjectMidlayer(s => new ScatteringStream(s, 7)); - client.InjectMidlayer(s => new ScatteringStream(s, 10)); - client.Connect("localhost", TcpPort); - client.WhenConnected.Wait(); - - var counters = new Counters(); - server.Main = new TestInterfaceImpl(counters); - using (var main = client.GetMain()) + try { - for (int i = 0; i < 100; i++) + using (var server = new TcpRpcServer(IPAddress.Any, TcpPort)) + using (var client = new TcpRpcClient()) { - var request1 = main.Foo(123, true, default); - var request3 = Assert.ThrowsExceptionAsync(() => main.Bar(default)); - var s = new TestAllTypes(); - Common.InitTestMessage(s); - var request2 = main.Baz(s, default); + server.InjectMidlayer(s => new ScatteringStream(s, 7)); + client.InjectMidlayer(s => new ScatteringStream(s, 10)); + client.Connect("localhost", TcpPort); + client.WhenConnected.Wait(); - Assert.IsTrue(request1.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(request2.Wait(MediumNonDbgTimeout)); - Assert.IsTrue(request3.Wait(MediumNonDbgTimeout)); + var counters = new Counters(); + server.Main = new TestInterfaceImpl(counters); + using (var main = client.GetMain()) + { + for (int i = 0; i < 100; i++) + { + var request1 = main.Foo(123, true, default); + var request3 = Assert.ThrowsExceptionAsync(() => main.Bar(default)); + var s = new TestAllTypes(); + Common.InitTestMessage(s); + var request2 = main.Baz(s, default); - Assert.AreEqual("foo", request1.Result); - Assert.AreEqual(2, counters.CallCount); - counters.CallCount = 0; + Assert.IsTrue(request1.Wait(MediumNonDbgTimeout)); + Assert.IsTrue(request2.Wait(MediumNonDbgTimeout)); + Assert.IsTrue(request3.Wait(MediumNonDbgTimeout)); + + Assert.AreEqual("foo", request1.Result); + Assert.AreEqual(2, counters.CallCount); + counters.CallCount = 0; + } + } } + return; + } + catch (SocketException) + { + IncrementTcpPort(); } } } diff --git a/Capnp.Net.Runtime.Tests/TestBase.cs b/Capnp.Net.Runtime.Tests/TestBase.cs deleted file mode 100644 index 3eb33fd..0000000 --- a/Capnp.Net.Runtime.Tests/TestBase.cs +++ /dev/null @@ -1,130 +0,0 @@ -using Capnp.Rpc; -using Microsoft.Extensions.Logging; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Capnp.Net.Runtime.Tests -{ - public class TestBase - { - public static int TcpPort = 49152; - public static int MediumNonDbgTimeout => Debugger.IsAttached ? Timeout.Infinite : 5000; - public static int LargeNonDbgTimeout => Debugger.IsAttached ? Timeout.Infinite : 20000; - public static int ShortTimeout => 500; - - protected ILogger Logger { get; set; } - - protected TcpRpcClient SetupClient() - { - var client = new TcpRpcClient(); - client.AddBuffering(); - client.Connect("localhost", TcpPort); - return client; - } - - protected TcpRpcServer SetupServer() - { - int attempt = 0; - - while (true) - { - try - { - var server = new TcpRpcServer(IPAddress.Any, TcpPort); - server.AddBuffering(); - return server; - } - catch (SocketException) - { - // If the TCP listening port is occupied by some other process, - // retry with a different one - - if (attempt == 5) - throw; - } - - IncrementTcpPort(); - ++attempt; - } - } - - protected (TcpRpcServer, TcpRpcClient) SetupClientServerPair() - { - var server = SetupServer(); - var client = SetupClient(); - return (server, client); - } - - public static void IncrementTcpPort() - { - if (++TcpPort > 49200) - { - TcpPort = 49152; - } - } - - [TestInitialize] - public void InitConsoleLogging() - { - Logging.LoggerFactory?.Dispose(); - Logging.LoggerFactory = new LoggerFactory().AddConsole((msg, level) => true); - Logger = Logging.CreateLogger(); - if (Thread.CurrentThread.Name == null) - Thread.CurrentThread.Name = $"Test Thread {Thread.CurrentThread.ManagedThreadId}"; - } - - /// - /// Somewhat ugly helper method which ensures that both Tcp client and server - /// are waiting for data reception from each other. This is a "balanced" state, meaning - /// that nothing will ever happen in the RcpEngines without some other thread requesting - /// anything. - /// - protected void WaitClientServerIdle(TcpRpcServer server, TcpRpcClient client) - { - var conn = server.Connections[0]; - SpinWait.SpinUntil(() => conn.IsWaitingForData && client.IsWaitingForData && - conn.RecvCount == client.SendCount && - conn.SendCount == client.RecvCount, - MediumNonDbgTimeout); - } - - protected void ExpectPromiseThrows(Task task) - { - async Task ExpectPromiseThrowsAsync(Task t) - { - try - { - await t; - Assert.Fail("Did not throw"); - } - catch (InvalidOperationException) - { - // Happens if the call went to the resolution - // (thus, locally). In this case, the original - // exception is routed here. - } - catch (RpcException) - { - // Happens if the call went to the promise - // (thus, remotely). In this case, the original - // exception had to be serialized, so we receive - // the wrapped version. - } - catch (System.Exception exception) - { - Assert.Fail($"Got wrong kind of exception: {exception}"); - } - } - - Assert.IsTrue(ExpectPromiseThrowsAsync(task).Wait(MediumNonDbgTimeout)); - } - - } -} diff --git a/Capnp.Net.Runtime.Tests/Testsuite.cs b/Capnp.Net.Runtime.Tests/Testsuite.cs new file mode 100644 index 0000000..0d9821a --- /dev/null +++ b/Capnp.Net.Runtime.Tests/Testsuite.cs @@ -0,0 +1,523 @@ +using System; +using System.Linq; +using Capnp.Rpc; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Capnp.Net.Runtime.Tests.GenImpls; +using Capnproto_test.Capnp.Test; +using System.Threading.Tasks; +using System.Threading; +using System.Runtime.CompilerServices; + +namespace Capnp.Net.Runtime.Tests +{ + static class Testsuite + { + static void ExpectPromiseThrows(this ITestbed testbed, params Task[] tasks) + { + async Task ExpectPromiseThrowsAsync(Task t) + { + try + { + await t; + Assert.Fail("Did not throw"); + } + catch (InvalidOperationException) + { + // Happens if the call went to the resolution + // (thus, locally). In this case, the original + // exception is routed here. + } + catch (InvalidTimeZoneException) + { + // Happens if the call went to the resolution + // (thus, locally). In this case, the original + // exception is routed here. + } + catch (RpcException) + { + // Happens if the call went to the promise + // (thus, remotely). In this case, the original + // exception had to be serialized, so we receive + // the wrapped version. + } + catch (System.Exception exception) + { + Assert.Fail($"Got wrong kind of exception: {exception}"); + } + } + + var ftasks = tasks.Select(ExpectPromiseThrowsAsync).ToArray(); + testbed.MustComplete(ftasks); + + foreach (var ftask in ftasks) + ftask.GetAwaiter().GetResult(); // re-throw exception + } + + public static void Embargo(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + + using (var main = testbed.ConnectMain(impl)) + { + var resolving = main as IResolvingCapability; + testbed.MustComplete(resolving.WhenResolved); + + var cap = new TestCallOrderImpl(); + cap.CountToDispose = 6; + + var earlyCall = main.GetCallSequence(0, default); + + var echo = main.Echo(cap, default); + testbed.MustComplete(Task.CompletedTask); + using (var pipeline = echo.Eager()) + { + var call0 = pipeline.GetCallSequence(0, default); + var call1 = pipeline.GetCallSequence(1, default); + + testbed.MustComplete(earlyCall); + + impl.EnableEcho(); + + var call2 = pipeline.GetCallSequence(2, default); + + testbed.MustComplete(echo); + using (var resolved = echo.Result) + { + var call3 = pipeline.GetCallSequence(3, default); + var call4 = pipeline.GetCallSequence(4, default); + var call5 = pipeline.GetCallSequence(5, default); + + try + { + testbed.MustComplete(call0); + testbed.MustComplete(call1); + testbed.MustComplete(call2); + testbed.MustComplete(call3); + testbed.MustComplete(call4); + testbed.MustComplete(call5); + } + catch (System.Exception) + { + cap.CountToDispose = null; + throw; + } + + Assert.AreEqual(0u, call0.Result); + Assert.AreEqual(1u, call1.Result); + Assert.AreEqual(2u, call2.Result); + Assert.AreEqual(3u, call3.Result); + Assert.AreEqual(4u, call4.Result); + Assert.AreEqual(5u, call5.Result); + } + } + } + } + + public static void EmbargoError(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var resolving = main as IResolvingCapability; + testbed.MustComplete(resolving.WhenResolved); + + var cap = new TaskCompletionSource(); + + var earlyCall = main.GetCallSequence(0, default); + var echo = main.Echo(cap.Task.Eager(true), default); + + using (var pipeline = echo.Eager()) + { + var call0 = pipeline.GetCallSequence(0, default); + var call1 = pipeline.GetCallSequence(1, default); + + testbed.MustComplete(earlyCall); + + impl.EnableEcho(); + + var call2 = pipeline.GetCallSequence(2, default); + + testbed.MustComplete(echo); + var resolved = echo.Result; + var call3 = pipeline.GetCallSequence(3, default); + var call4 = pipeline.GetCallSequence(4, default); + var call5 = pipeline.GetCallSequence(5, default); + + cap.SetException(new InvalidTimeZoneException("I'm annoying")); + + testbed.ExpectPromiseThrows(call0, call1, call2, call3, call4, call5); + + // Verify that we're still connected (there were no protocol errors). + testbed.MustComplete(main.GetCallSequence(1, default)); + } + } + } + + public static void EmbargoNull(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var resolving = main as IResolvingCapability; + testbed.MustComplete(resolving.WhenResolved); + + var promise = main.GetNull(default); + + var cap = promise.Eager(); + + var call0 = cap.GetCallSequence(0, default); + + testbed.MustComplete(promise); + + var call1 = cap.GetCallSequence(1, default); + + testbed.ExpectPromiseThrows(call0, call1); + + // Verify that we're still connected (there were no protocol errors). + testbed.MustComplete(main.GetCallSequence(1, default)); + } + } + + public static void CallBrokenPromise(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var resolving = main as IResolvingCapability; + testbed.MustComplete(resolving.WhenResolved); + + var tcs = new TaskCompletionSource(); + + var req = main.Hold(tcs.Task.Eager(true), default); + testbed.MustComplete(req); + + var req2 = main.CallHeld(default); + + testbed.MustNotComplete(req2); + + tcs.SetException(new InvalidOperationException("I'm a promise-breaker!")); + + testbed.ExpectPromiseThrows(req2); + + // Verify that we're still connected (there were no protocol errors). + testbed.MustComplete(main.GetCallSequence(1, default)); + } + } + + public static void TailCall(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestTailCallerImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var calleeCallCount = new Counters(); + var callee = new TestTailCalleeImpl(calleeCallCount); + + var promise = main.Foo(456, callee, default); + using (var c = promise.C()) + { + var dependentCall0 = c.GetCallSequence(0, default); + + testbed.MustComplete(promise); + Assert.AreEqual(456u, promise.Result.I); + Assert.AreEqual("from TestTailCaller", promise.Result.T); + + var dependentCall1 = c.GetCallSequence(0, default); + var dependentCall2 = c.GetCallSequence(0, default); + + testbed.MustComplete(dependentCall0, dependentCall1, dependentCall2); + + Assert.AreEqual(1, counters.CallCount); + Assert.AreEqual(1, calleeCallCount.CallCount); + } + } + } + + public static void SendTwice(ITestbed testbed) + { + var destructionPromise = new TaskCompletionSource(); + var destructionTask = destructionPromise.Task; + + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var cap = new TestInterfaceImpl(new Counters(), destructionPromise); + + Task ftask1, ftask2; + + using (var claimer = Skeleton.Claim(cap)) + { + var ftask = main.CallFoo(cap, default); + testbed.MustComplete(ftask); + Assert.AreEqual("bar", ftask.Result); + + var ctask = main.GetCallSequence(0, default); + testbed.MustComplete(ctask); + Assert.AreEqual(1u, ctask.Result); + + ftask1 = main.CallFoo(cap, default); + ftask2 = main.CallFoo(cap, default); + } + + testbed.MustComplete(ftask1); + Assert.AreEqual("bar", ftask1.Result); + testbed.MustComplete(ftask2); + Assert.AreEqual("bar", ftask2.Result); + + // Now the cap should be released. + testbed.MustComplete(destructionTask); + } + } + + public static void Cancel(ITestbed testbed) + { + var destructionPromise = new TaskCompletionSource(); + var destructionTask = destructionPromise.Task; + + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + using (var cts = new CancellationTokenSource()) + { + var ntask = main.NeverReturn(new TestInterfaceImpl(counters, destructionPromise), cts.Token); + + // Allow some time to settle. + var cstask = main.GetCallSequence(0, default); + testbed.MustComplete(cstask); + Assert.AreEqual(1u, cstask.Result); + cstask = main.GetCallSequence(0, default); + testbed.MustComplete(cstask); + Assert.AreEqual(2u, cstask.Result); + + // The cap shouldn't have been destroyed yet because the call never returned. + Assert.IsFalse(destructionTask.IsCompleted); + + // There will be no automatic cancellation just because "ntask" goes of of scope or + // because the Proxy is disposed. Even ntask.Dispose() would not cancel the request. + // In .NET this needs to be done explicitly. + cts.Cancel(); + } + + // Now the cap should be released. + testbed.MustComplete(destructionTask); + } + + public static void RetainAndRelease(ITestbed testbed) + { + var destructionPromise = new TaskCompletionSource(); + var destructionTask = destructionPromise.Task; + + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var holdTask = main.Hold(new TestInterfaceImpl(new Counters(), destructionPromise), default); + testbed.MustComplete(holdTask); + + var cstask = main.GetCallSequence(0, default); + testbed.MustComplete(cstask); + Assert.AreEqual(1u, cstask.Result); + + Assert.IsFalse(destructionTask.IsCompleted); + + var htask = main.CallHeld(default); + testbed.MustComplete(htask); + Assert.AreEqual("bar", htask.Result); + + var gtask = main.GetHeld(default); + testbed.MustComplete(gtask); + // We can get the cap back from it. + using (var cap = gtask.Result) + { + // Wait for balanced state + testbed.FlushCommunication(); + + // And call it, without any network communications. + long oldSendCount = testbed.ClientSendCount; + var ftask = cap.Foo(123, true, default); + testbed.MustComplete(ftask); + Assert.AreEqual("foo", ftask.Result); + Assert.AreEqual(oldSendCount, testbed.ClientSendCount); + + // We can send another copy of the same cap to another method, and it works. + // Note that this was a bug in previous versions: + // Since passing a cap has move semantics, we need to create an explicit copy. + var copy = Proxy.Share(cap); + var ctask = main.CallFoo(copy, default); + testbed.MustComplete(ctask); + Assert.AreEqual("bar", ctask.Result); + + // Give some time to settle. + cstask = main.GetCallSequence(0, default); + testbed.MustComplete(cstask); + Assert.AreEqual(5u, cstask.Result); + cstask = main.GetCallSequence(0, default); + testbed.MustComplete(cstask); + Assert.AreEqual(6u, cstask.Result); + cstask = main.GetCallSequence(0, default); + testbed.MustComplete(cstask); + Assert.AreEqual(7u, cstask.Result); + + // Can't be destroyed, we haven't released it. + Assert.IsFalse(destructionTask.IsCompleted); + } + + // In deviation from original test, we have null the held capability on the main interface. + // This is because the main interface is the bootstrap capability and, as such, won't be disposed + // after disconnect. + var holdNullTask = main.Hold(null, default); + testbed.MustComplete(holdNullTask); + } + + testbed.MustComplete(destructionTask); + } + + public static void PromiseResolve(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var tcs = new TaskCompletionSource(); + var eager = tcs.Task.Eager(true); + + var request = main.CallFoo(eager, default); + var request2 = main.CallFooWhenResolved(eager, default); + + var gcs = main.GetCallSequence(0, default); + testbed.MustComplete(gcs); + Assert.AreEqual(2u, gcs.Result); + Assert.AreEqual(3, counters.CallCount); + + var chainedCallCount = new Counters(); + var tiimpl = new TestInterfaceImpl(chainedCallCount); + tcs.SetResult(tiimpl); + + testbed.MustComplete(request, request2); + + Assert.AreEqual("bar", request.Result); + Assert.AreEqual("bar", request2.Result); + Assert.AreEqual(3, counters.CallCount); + Assert.AreEqual(2, chainedCallCount.CallCount); + } + } + + public static void Cancelation(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var destroyed = new TaskCompletionSource(); + var impl2 = new TestInterfaceImpl(counters, destroyed); + var cts = new CancellationTokenSource(); + var cancelTask = main.ExpectCancel(impl2, cts.Token); + + testbed.MustNotComplete(destroyed.Task, cancelTask); + + cts.Cancel(); + + testbed.MustComplete(destroyed.Task); + Assert.IsFalse(cancelTask.IsCompleted && !cancelTask.IsCanceled); + } + } + + public static void ReleaseOnCancel(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + using (var cts = new CancellationTokenSource()) + { + var task = main.GetHandle(cts.Token); + testbed.MustComplete(Task.CompletedTask); // turn event loop + cts.Cancel(); + testbed.MustComplete(task); + try + { + task.Result.Dispose(); + } + catch (AggregateException ex) when (ex.InnerException is TaskCanceledException) + { + } + } + + testbed.FlushCommunication(); + Assert.AreEqual(0, counters.HandleCount); + } + } + + public static void Release(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestMoreStuffImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var task1 = main.GetHandle(default); + var task2 = main.GetHandle(default); + testbed.MustComplete(task1, task2); + + Assert.AreEqual(2, counters.HandleCount); + + task1.Result.Dispose(); + + testbed.FlushCommunication(); + Assert.AreEqual(1, counters.HandleCount); + + task2.Result.Dispose(); + + testbed.FlushCommunication(); + Assert.AreEqual(0, counters.HandleCount); + } + } + + public static void Pipeline(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestPipelineImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var chainedCallCount = new Counters(); + var request = main.GetCap(234, new TestInterfaceImpl(chainedCallCount), default); + using (var outBox = request.OutBox_Cap()) + { + var pipelineRequest = outBox.Foo(321, false, default); + var pipelineRequest2 = ((Proxy)outBox).Cast(false).Grault(default); + + testbed.MustComplete(pipelineRequest, pipelineRequest2); + + Assert.AreEqual("bar", pipelineRequest.Result); + Common.CheckTestMessage(pipelineRequest2.Result); + + Assert.AreEqual(3, counters.CallCount); + Assert.AreEqual(1, chainedCallCount.CallCount); + } + } + } + + public static void Basic(ITestbed testbed) + { + var counters = new Counters(); + var impl = new TestInterfaceImpl(counters); + using (var main = testbed.ConnectMain(impl)) + { + var request1 = main.Foo(123, true, default); + var request3 = Assert.ThrowsExceptionAsync(() => main.Bar(default)); + var s = new TestAllTypes(); + Common.InitTestMessage(s); + var request2 = main.Baz(s, default); + + testbed.MustComplete(request1, request2, request3); + + Assert.AreEqual("foo", request1.Result); + Assert.AreEqual(2, counters.CallCount); + } + } + } +} diff --git a/Capnp.Net.Runtime.Tests/Util/DecisionTree.cs b/Capnp.Net.Runtime.Tests/Util/DecisionTree.cs new file mode 100644 index 0000000..038e95f --- /dev/null +++ b/Capnp.Net.Runtime.Tests/Util/DecisionTree.cs @@ -0,0 +1,98 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; + +namespace Capnp.Net.Runtime.Tests +{ + public class DecisionTree + { + readonly ILogger Logger = Logging.CreateLogger(); + + readonly List _decisions = new List(); + readonly Stack _freezeStack = new Stack(); + int _pos, _freezeCounter; + + public DecisionTree() + { + _freezeStack.Push(0); + } + + public DecisionTree(params bool[] initialDecisions): this() + { + _decisions.AddRange(initialDecisions); + } + + public bool MakeDecision() + { + if (_pos >= _decisions.Count) + { + _decisions.Add(false); + } + + try + { + return _decisions[_pos++]; + } + catch (ArgumentOutOfRangeException) + { + Logger.LogError($"WTF?! {_pos - 1}, {_decisions.Count}"); + throw; + } + } + + public void Freeze() + { + _freezeStack.Push(_pos); + } + + public bool NextRound() + { + _pos = 0; + + for (int i = 0; i < _freezeCounter; i++) + _freezeStack.Pop(); + + while (_freezeStack.Count > 1) + { + int end = _freezeStack.Pop(); + int begin = _freezeStack.Peek(); + + for (int i = end - 1; i >= begin; i--) + { + if (_decisions[i] == false) + { + _decisions[i] = true; + _freezeStack.Clear(); + _freezeStack.Push(0); + return true; + } + //else + //{ + // _decisions.RemoveAt(i); + //} + } + + ++_freezeCounter; + } + + return false; + } + + public override string ToString() + { + return "[" + string.Join("|", _decisions) + "]"; + } + + public void Iterate(Action testMethod) + { + Logger.LogInformation("Starting decision-tree based combinatorial test"); + int iter = 0; + do + { + Logger.LogInformation($"Iteration {iter}: pattern {ToString()}"); + testMethod(); + ++iter; + } while (NextRound()); + } + } +} diff --git a/Capnp.Net.Runtime.Tests/JobUtil.cs b/Capnp.Net.Runtime.Tests/Util/JobUtil.cs similarity index 100% rename from Capnp.Net.Runtime.Tests/JobUtil.cs rename to Capnp.Net.Runtime.Tests/Util/JobUtil.cs diff --git a/Capnp.Net.Runtime.Tests/ScatteringStream.cs b/Capnp.Net.Runtime.Tests/Util/ScatteringStream.cs similarity index 100% rename from Capnp.Net.Runtime.Tests/ScatteringStream.cs rename to Capnp.Net.Runtime.Tests/Util/ScatteringStream.cs diff --git a/Capnp.Net.Runtime.Tests/Util/TestBase.cs b/Capnp.Net.Runtime.Tests/Util/TestBase.cs new file mode 100644 index 0000000..b64377f --- /dev/null +++ b/Capnp.Net.Runtime.Tests/Util/TestBase.cs @@ -0,0 +1,350 @@ +using Capnp.Rpc; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Capnp.Net.Runtime.Tests +{ + public interface ITestbed + { + T ConnectMain(T main) where T : class; + void MustComplete(params Task[] tasks); + void MustNotComplete(params Task[] tasks); + void FlushCommunication(); + + long ClientSendCount { get; } + } + + public interface ITestController + { + void RunTest(Action action); + } + + public class TestBase + { + + protected class EnginePair + { + class EngineChannel : IEndpoint + { + readonly Queue _frameBuffer = new Queue(); + readonly Func _decide; + bool _recursion; + bool _dismissed; + + public EngineChannel(Func decide) + { + _decide = decide; + } + + public RpcEngine.RpcEndpoint OtherEndpoint { get; set; } + public bool HasBufferedFrames => _frameBuffer.Count > 0; + public int FrameCounter { get; private set; } + + + public void Dismiss() + { + OtherEndpoint.Dismiss(); + _dismissed = true; + } + + public void Forward(WireFrame frame) + { + if (_dismissed) + return; + + ++FrameCounter; + + if (_recursion || _frameBuffer.Count > 0 || _decide()) + { + _frameBuffer.Enqueue(frame); + } + else + { + _recursion = true; + OtherEndpoint.Forward(frame); + _recursion = false; + } + } + + public bool Flush() + { + if (_frameBuffer.Count > 0) + { + var frame = _frameBuffer.Dequeue(); + _recursion = true; + OtherEndpoint.Forward(frame); + _recursion = false; + + return true; + } + else + { + return false; + } + } + } + + readonly DecisionTree _decisionTree; + readonly EngineChannel _channel1, _channel2; + + public RpcEngine Engine1 { get; } + public RpcEngine Engine2 { get; } + public RpcEngine.RpcEndpoint Endpoint1 { get; } + public RpcEngine.RpcEndpoint Endpoint2 { get; } + + public EnginePair(DecisionTree decisionTree) + { + _decisionTree = decisionTree; + Engine1 = new RpcEngine(); + Engine2 = new RpcEngine(); + _channel1 = new EngineChannel(decisionTree.MakeDecision); + Endpoint1 = Engine1.AddEndpoint(_channel1); + _channel2 = new EngineChannel(() => false); + Endpoint2 = Engine2.AddEndpoint(_channel2); + _channel1.OtherEndpoint = Endpoint2; + _channel2.OtherEndpoint = Endpoint1; + } + + public void FlushChannels(Func pred) + { + while (!pred()) + { + if (!_channel1.Flush() && + !_channel2.Flush()) + return; + } + + while ((_channel1.HasBufferedFrames || _channel2.HasBufferedFrames) && _decisionTree.MakeDecision()) + { + if (_channel1.HasBufferedFrames) + { + int mark = _channel2.FrameCounter; + + while (_channel1.Flush() && _channel2.FrameCounter == mark) + ; + } + else if (_channel2.HasBufferedFrames) + { + int mark = _channel1.FrameCounter; + + while (_channel2.Flush() && _channel1.FrameCounter == mark) + ; + } + + } + } + + public int Channel1SendCount => _channel1.FrameCounter; + public int Channel2SendCount => _channel2.FrameCounter; + } + + protected class DtbdctTestbed : ITestbed, ITestController + { + readonly DecisionTree _decisionTree = new DecisionTree(); + EnginePair _enginePair; + + public void RunTest(Action action) + { + _decisionTree.Iterate(() => action(this)); + } + + T ITestbed.ConnectMain(T main) + { + return SetupEnginePair(main, _decisionTree, out _enginePair); + } + + void ITestbed.MustComplete(params Task[] tasks) + { + bool AllDone() => tasks.All(t => t.IsCompleted); + _enginePair.FlushChannels(AllDone); + _decisionTree.Freeze(); + Assert.IsTrue(AllDone()); + } + + void ITestbed.MustNotComplete(params Task[] tasks) + { + Assert.IsFalse(tasks.Any(t => t.IsCompleted)); + } + + void ITestbed.FlushCommunication() + { + _enginePair.FlushChannels(() => false); + } + + long ITestbed.ClientSendCount => _enginePair.Channel2SendCount; + } + + protected class LocalhostTcpTestbed : ITestbed, ITestController + { + TcpRpcServer _server; + TcpRpcClient _client; + + public void RunTest(Action action) + { + (_server, _client) = SetupClientServerPair(); + _client.WhenConnected.Wait(MediumNonDbgTimeout); + + using (_server) + using (_client) + { + action(this); + } + } + + T ITestbed.ConnectMain(T main) + { + _server.Main = main; + return _client.GetMain(); + } + + void ITestbed.MustComplete(params Task[] tasks) + { + Assert.IsTrue(Task.WaitAll(tasks, MediumNonDbgTimeout)); + } + + void ITestbed.MustNotComplete(params Task[] tasks) + { + Assert.AreEqual(-1, Task.WaitAny(tasks, ShortTimeout)); + } + + void ITestbed.FlushCommunication() + { + WaitClientServerIdle(_server, _client); + } + + long ITestbed.ClientSendCount => _client.SendCount; + } + + public static int TcpPort = 49152; + public static int MediumNonDbgTimeout => Debugger.IsAttached ? Timeout.Infinite : 5000; + public static int LargeNonDbgTimeout => Debugger.IsAttached ? Timeout.Infinite : 20000; + public static int ShortTimeout => 500; + + protected ILogger Logger { get; set; } + + protected static TcpRpcClient SetupClient() + { + var client = new TcpRpcClient(); + client.AddBuffering(); + client.Connect("localhost", TcpPort); + return client; + } + + protected static TcpRpcServer SetupServer() + { + int attempt = 0; + + while (true) + { + try + { + var server = new TcpRpcServer(IPAddress.Any, TcpPort); + server.AddBuffering(); + return server; + } + catch (SocketException) + { + // If the TCP listening port is occupied by some other process, retry with a different one + // TIME_WAIT is 4min: http://blog.davidvassallo.me/2010/07/13/time_wait-and-port-reuse/ + if (attempt == 2400) + throw; + } + + IncrementTcpPort(); + ++attempt; + Thread.Sleep(100); + } + } + + protected static (TcpRpcServer, TcpRpcClient) SetupClientServerPair() + { + var server = SetupServer(); + var client = SetupClient(); + return (server, client); + } + + protected static T SetupEnginePair(T main, DecisionTree decisionTree, out EnginePair pair) where T: class + { + pair = new EnginePair(decisionTree); + pair.Engine1.Main = main; + return (CapabilityReflection.CreateProxy(pair.Endpoint2.QueryMain()) as T); + } + + public static void IncrementTcpPort() + { + if (++TcpPort > 49200) + { + TcpPort = 49152; + } + } + + protected static DtbdctTestbed NewDtbdctTestbed() => new DtbdctTestbed(); + protected static LocalhostTcpTestbed NewLocalhostTcpTestbed() => new LocalhostTcpTestbed(); + + [TestInitialize] + public void InitConsoleLogging() + { + Logging.LoggerFactory?.Dispose(); + Logging.LoggerFactory = new LoggerFactory().AddConsole((msg, level) => true); + Logger = Logging.CreateLogger(); + if (Thread.CurrentThread.Name == null) + Thread.CurrentThread.Name = $"Test Thread {Thread.CurrentThread.ManagedThreadId}"; + } + + /// + /// Somewhat ugly helper method which ensures that both Tcp client and server + /// are waiting for data reception from each other. This is a "balanced" state, meaning + /// that nothing will ever happen in the RcpEngines without some other thread requesting + /// anything. + /// + static protected void WaitClientServerIdle(TcpRpcServer server, TcpRpcClient client) + { + var conn = server.Connections[0]; + SpinWait.SpinUntil(() => conn.IsWaitingForData && client.IsWaitingForData && + conn.RecvCount == client.SendCount && + conn.SendCount == client.RecvCount, + MediumNonDbgTimeout); + } + + protected void ExpectPromiseThrows(Task task) + { + async Task ExpectPromiseThrowsAsync(Task t) + { + try + { + await t; + Assert.Fail("Did not throw"); + } + catch (InvalidOperationException) + { + // Happens if the call went to the resolution + // (thus, locally). In this case, the original + // exception is routed here. + } + catch (RpcException) + { + // Happens if the call went to the promise + // (thus, remotely). In this case, the original + // exception had to be serialized, so we receive + // the wrapped version. + } + catch (System.Exception exception) + { + Assert.Fail($"Got wrong kind of exception: {exception}"); + } + } + + Assert.IsTrue(ExpectPromiseThrowsAsync(task).Wait(MediumNonDbgTimeout)); + } + + } +} diff --git a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj b/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj index af2c400..6f81750 100644 --- a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj +++ b/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj @@ -29,7 +29,7 @@ - DebugCapabilityLifecycle + DebugFinalizers diff --git a/Capnp.Net.Runtime/CapnpSerializable.cs b/Capnp.Net.Runtime/CapnpSerializable.cs index 9f33940..ec7cb48 100644 --- a/Capnp.Net.Runtime/CapnpSerializable.cs +++ b/Capnp.Net.Runtime/CapnpSerializable.cs @@ -160,6 +160,7 @@ namespace Capnp /// The domain object instance. Nullability note: The returned reference may be null if /// represents the nil object. /// Cannot construct object of type + /// Note that capability ownership is moved to the domain object public static T? Create(DeserializerState state) where T: class { diff --git a/Capnp.Net.Runtime/DeserializerState.cs b/Capnp.Net.Runtime/DeserializerState.cs index b420725..ea02416 100644 --- a/Capnp.Net.Runtime/DeserializerState.cs +++ b/Capnp.Net.Runtime/DeserializerState.cs @@ -9,7 +9,7 @@ namespace Capnp /// Although it is public, you should not use it directly. Instead, use the reader, writer, and domain class adapters which are produced /// by the code generator. /// - public struct DeserializerState: IStructDeserializer + public struct DeserializerState: IStructDeserializer, IDisposable { /// /// A wire message is essentially a collection of memory blocks. @@ -50,7 +50,7 @@ namespace Capnp /// public IList? Caps { get; set; } /// - /// Current segment (essentially Segments[CurrentSegmentIndex] + /// Current segment (essentially Segments[CurrentSegmentIndex]) /// public ReadOnlySpan CurrentSegment => Segments != null ? Segments[(int)CurrentSegmentIndex].Span : default; @@ -106,11 +106,6 @@ namespace Capnp case ObjectKind.ListOfStructs: case ObjectKind.Nil: case ObjectKind.Struct: - if (state.Caps != null) - { - foreach (var cap in state.Caps) - cap?.Release(true); - } return new DeserializerState(state.Allocator!.Segments) { CurrentSegmentIndex = state.SegmentIndex, @@ -646,13 +641,10 @@ namespace Capnp /// negative index /// state does not represent a struct, invalid pointer, /// non-capability pointer, traversal limit exceeded - public T? ReadCap(int index, - [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", - [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", - [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) where T: class + public T? ReadCap(int index) where T: class { var cap = StructReadRawCap(index); - return Rpc.CapabilityReflection.CreateProxy(cap, memberName, sourceFilePath, sourceLineNumber) as T; + return Rpc.CapabilityReflection.CreateProxy(cap) as T; } /// @@ -690,5 +682,16 @@ namespace Capnp return (Rpc.CapabilityReflection.CreateProxy(Caps[(int)CapabilityIndex]) as T)!; } + + public void Dispose() + { + if (Caps != null) + { + foreach (var cap in Caps) + { + cap?.Release(false); + } + } + } } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/DynamicSerializerState.cs b/Capnp.Net.Runtime/DynamicSerializerState.cs index edf3d15..fe750d9 100644 --- a/Capnp.Net.Runtime/DynamicSerializerState.cs +++ b/Capnp.Net.Runtime/DynamicSerializerState.cs @@ -44,8 +44,6 @@ namespace Capnp if (state.Caps != null) { mb.InitCapTable(); - foreach (var cap in state.Caps) - cap?.AddRef(); } var sstate = mb.CreateObject(); Reserializing.DeepCopy(state, sstate); diff --git a/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs b/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs index 42ae7ca..6e10a58 100644 --- a/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs +++ b/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs @@ -262,25 +262,11 @@ namespace Capnp.Rpc /// Problem with instatiating the Proxy (constructor threw exception). /// Caller does not have permission to invoke the Proxy constructor. /// Problem with building the Proxy type, or problem with loading some dependent class. - public static Proxy CreateProxy(ConsumedCapability? cap, - [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", - [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", - [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) + public static Proxy CreateProxy(ConsumedCapability? cap) { var factory = GetProxyFactory(typeof(TInterface)); var proxy = factory.NewProxy(); proxy.Bind(cap); -#if DebugFinalizers - proxy.CreatorMemberName = memberName; - proxy.CreatorFilePath = sourceFilePath; - proxy.CreatorLineNumber = sourceLineNumber; - if (cap != null) - { - cap.CreatorFilePath = proxy.CreatorFilePath; - cap.CreatorLineNumber = proxy.CreatorLineNumber; - cap.CreatorMemberName = proxy.CreatorMemberName; - } -#endif return proxy; } } diff --git a/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs b/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs index 1204fa0..4342b84 100644 --- a/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs @@ -1,4 +1,6 @@ -namespace Capnp.Rpc +using System; + +namespace Capnp.Rpc { /// /// Base class for a low-level capability at consumer side. It is created by the . An application does not directly interact with it @@ -13,7 +15,7 @@ /// which usually also means to remove it from the remote peer's export table. /// protected abstract void ReleaseRemotely(); - internal abstract void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer); + internal abstract Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer); internal abstract void Freeze(out IRpcEndpoint? boundEndpoint); internal abstract void Unfreeze(); @@ -23,11 +25,5 @@ [System.Runtime.CompilerServices.CallerMemberName] string methodName = "", [System.Runtime.CompilerServices.CallerFilePath] string filePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0); - -#if DebugFinalizers - public string CreatorMemberName { get; set; } - public string CreatorFilePath { get; set; } - public int CreatorLineNumber { get; set; } -#endif } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs b/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs index 7b774f8..6fc1788 100644 --- a/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs +++ b/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs @@ -24,6 +24,6 @@ namespace Capnp.Rpc /// Pipelined low-level capability ConsumedCapability? Access(MemberAccessPath access); - ConsumedCapability? Access(MemberAccessPath access, Task proxyTask); + ConsumedCapability? Access(MemberAccessPath access, Task proxyTask); } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs b/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs index 339ec26..fccfc6c 100644 --- a/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs +++ b/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs @@ -8,7 +8,6 @@ namespace Capnp.Rpc PendingQuestion BeginQuestion(ConsumedCapability target, SerializerState inParams); void SendQuestion(SerializerState inParams, Payload.WRITER payload); uint AllocateExport(Skeleton providedCapability, out bool first); - void RequestPostAction(Action postAction); void Finish(uint questionId); void ReleaseImport(uint importId); void Resolve(uint preliminaryId, Skeleton preliminaryCap, Func resolvedCapGetter); diff --git a/Capnp.Net.Runtime/Rpc/Impatient.cs b/Capnp.Net.Runtime/Rpc/Impatient.cs index 1a0a81e..b07e5ba 100644 --- a/Capnp.Net.Runtime/Rpc/Impatient.cs +++ b/Capnp.Net.Runtime/Rpc/Impatient.cs @@ -94,7 +94,20 @@ namespace Capnp.Rpc static async Task AwaitProxy(Task task) where T: class { - var item = await task; + T item; + + try + { + item = await task; + } + catch (TaskCanceledException exception) + { + return new Proxy(LazyCapability.CreateCanceledCap(exception.CancellationToken)); + } + catch (System.Exception exception) + { + return new Proxy(LazyCapability.CreateBrokenCap(exception.Message)); + } switch (item) { @@ -124,14 +137,11 @@ namespace Capnp.Rpc /// did not /// quality as capability interface. [Obsolete("Call Eager(task, true) instead")] - public static TInterface PseudoEager(this Task task, - [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", - [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", - [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) + public static TInterface PseudoEager(this Task task) where TInterface : class { var lazyCap = new LazyCapability(AwaitProxy(task)); - return (CapabilityReflection.CreateProxy(lazyCap, memberName, sourceFilePath, sourceLineNumber) as TInterface)!; + return (CapabilityReflection.CreateProxy(lazyCap) as TInterface)!; } static readonly MemberAccessPath Path_OneAndOnly = new MemberAccessPath(0U); @@ -157,7 +167,7 @@ namespace Capnp.Rpc /// Caller does not have permission to invoke the Proxy constructor. /// Problem with building the Proxy type, or problem with loading some dependent class. public static TInterface Eager(this Task task, bool allowNoPipeliningFallback = false) - where TInterface : class + where TInterface : class, IDisposable { var answer = TryGetAnswer(task); if (answer == null) @@ -172,7 +182,12 @@ namespace Capnp.Rpc } else { - return (CapabilityReflection.CreateProxy(answer.Access(Path_OneAndOnly)) as TInterface)!; + async Task AsDisposableTask() + { + return await task; + } + + return (CapabilityReflection.CreateProxy(answer.Access(Path_OneAndOnly, AsDisposableTask())) as TInterface)!; } } diff --git a/Capnp.Net.Runtime/Rpc/ImportedCapability.cs b/Capnp.Net.Runtime/Rpc/ImportedCapability.cs index 9645022..5564351 100644 --- a/Capnp.Net.Runtime/Rpc/ImportedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/ImportedCapability.cs @@ -1,4 +1,6 @@ -namespace Capnp.Rpc +using System; + +namespace Capnp.Rpc { /// /// Low-level capability which as imported from a remote peer. @@ -35,7 +37,7 @@ { } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER capDesc) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER capDesc) { if (endpoint == _ep) { @@ -47,6 +49,7 @@ capDesc.which = CapDescriptor.WHICH.SenderHosted; capDesc.SenderHosted = endpoint.AllocateExport(Vine.Create(this), out var _); } + return null; } } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs b/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs index 36b95d6..018d865 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs @@ -50,7 +50,7 @@ namespace Capnp.Rpc.Interception } } - public ConsumedCapability? Access(MemberAccessPath _, Task task) + public ConsumedCapability? Access(MemberAccessPath _, Task task) { var proxyTask = task.AsProxyTask(); diff --git a/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs b/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs index bd66f9b..3323c16 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs @@ -1,4 +1,6 @@ -namespace Capnp.Rpc.Interception +using System; + +namespace Capnp.Rpc.Interception { class CensorCapability : RefCountingCapability { @@ -26,10 +28,11 @@ return cc.Answer; } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) { writer.which = CapDescriptor.WHICH.SenderHosted; writer.SenderHosted = endpoint.AllocateExport(MyVine, out bool _); + return null; } internal override void Freeze(out IRpcEndpoint? boundEndpoint) diff --git a/Capnp.Net.Runtime/Rpc/LazyCapability.cs b/Capnp.Net.Runtime/Rpc/LazyCapability.cs index d56297c..2c06584 100644 --- a/Capnp.Net.Runtime/Rpc/LazyCapability.cs +++ b/Capnp.Net.Runtime/Rpc/LazyCapability.cs @@ -8,19 +8,15 @@ namespace Capnp.Rpc { public static LazyCapability CreateBrokenCap(string message) { - var cap = new LazyCapability(Task.FromException(new RpcException(message))); - cap.AddRef(); // Instance shall be persistent - return cap; + return new LazyCapability(Task.FromException(new RpcException(message))); } public static LazyCapability CreateCanceledCap(CancellationToken token) { - var cap = new LazyCapability(Task.FromCanceled(token)); - cap.AddRef(); // Instance shall be persistent - return cap; + return new LazyCapability(Task.FromCanceled(token)); } - public static LazyCapability Null { get; } = CreateBrokenCap("Null capability"); + public static LazyCapability Null => CreateBrokenCap("Null capability"); readonly Task? _proxyTask; @@ -63,16 +59,17 @@ namespace Capnp.Rpc { } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) { if (WhenResolved.ReplacementTaskIsCompletedSuccessfully()) { using var proxy = new Proxy(WhenResolved.Result); proxy.Export(endpoint, writer); + return null; } else { - this.ExportAsSenderPromise(endpoint, writer); + return this.ExportAsSenderPromise(endpoint, writer); } } diff --git a/Capnp.Net.Runtime/Rpc/LocalAnswer.cs b/Capnp.Net.Runtime/Rpc/LocalAnswer.cs index a90166f..f88e27b 100644 --- a/Capnp.Net.Runtime/Rpc/LocalAnswer.cs +++ b/Capnp.Net.Runtime/Rpc/LocalAnswer.cs @@ -30,7 +30,7 @@ namespace Capnp.Rpc return new LocalAnswerCapabilityDeprecated(WhenReturned, access); } - public ConsumedCapability Access(MemberAccessPath _, Task task) + public ConsumedCapability Access(MemberAccessPath _, Task task) { return new LocalAnswerCapability(task.AsProxyTask()); } diff --git a/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs b/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs index fdd8ad4..9d6093e 100644 --- a/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs +++ b/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs @@ -29,7 +29,7 @@ namespace Capnp.Rpc public Task WhenResolved { get; private set; } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) { if (_whenResolvedProxy.IsCompleted) { @@ -39,12 +39,14 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } + + return null; } else { - this.ExportAsSenderPromise(endpoint, writer); + return this.ExportAsSenderPromise(endpoint, writer); } } diff --git a/Capnp.Net.Runtime/Rpc/LocalAnswerCapabilityDeprecated.cs b/Capnp.Net.Runtime/Rpc/LocalAnswerCapabilityDeprecated.cs index f78788d..3688638 100644 --- a/Capnp.Net.Runtime/Rpc/LocalAnswerCapabilityDeprecated.cs +++ b/Capnp.Net.Runtime/Rpc/LocalAnswerCapabilityDeprecated.cs @@ -30,7 +30,7 @@ namespace Capnp.Rpc public Task WhenResolved { get; private set; } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) { if (_answer.IsCompleted) { @@ -46,10 +46,11 @@ namespace Capnp.Rpc using var proxy = new Proxy(_access.Eval(result)); proxy.Export(endpoint, writer); + return null; } else { - this.ExportAsSenderPromise(endpoint, writer); + return this.ExportAsSenderPromise(endpoint, writer); } } diff --git a/Capnp.Net.Runtime/Rpc/LocalCapability.cs b/Capnp.Net.Runtime/Rpc/LocalCapability.cs index d0dc90f..5ae7c91 100644 --- a/Capnp.Net.Runtime/Rpc/LocalCapability.cs +++ b/Capnp.Net.Runtime/Rpc/LocalCapability.cs @@ -54,10 +54,11 @@ namespace Capnp.Rpc return new LocalAnswer(cts, AwaitAnswer(call)); } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER capDesc) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER capDesc) { capDesc.which = CapDescriptor.WHICH.SenderHosted; capDesc.SenderHosted = endpoint.AllocateExport(ProvidedCap, out bool _); + return null; } internal override void Freeze(out IRpcEndpoint? boundEndpoint) diff --git a/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs b/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs index 4843c08..3b4cf20 100644 --- a/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs +++ b/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs @@ -132,7 +132,7 @@ namespace Capnp.Rpc { if (state.Kind == ObjectKind.Nil) { - return default(DeserializerState); + return default; } if (state.Kind != ObjectKind.Struct) diff --git a/Capnp.Net.Runtime/Rpc/PendingAnswer.cs b/Capnp.Net.Runtime/Rpc/PendingAnswer.cs index ed51a34..3b4bc38 100644 --- a/Capnp.Net.Runtime/Rpc/PendingAnswer.cs +++ b/Capnp.Net.Runtime/Rpc/PendingAnswer.cs @@ -24,11 +24,35 @@ namespace Capnp.Rpc _cts = cts; _cancelCompleter = new TaskCompletionSource(); _answerTask = CancelableAwaitWhenReady(); + + Chain(async t => + { + var aorcq = default(AnswerOrCounterquestion); + + try + { + aorcq = await t; + } + catch + { + } + + if (aorcq.Answer != null) + { + if (aorcq.Answer.Caps != null) + { + foreach (var cap in aorcq.Answer.Caps) + { + cap?.AddRef(); + } + } + } + }); } public CancellationToken CancellationToken => _cts?.Token ?? CancellationToken.None; - public IReadOnlyList CapTable { get; set; } + public IReadOnlyList? CapTable { get; set; } public void Cancel() { @@ -99,7 +123,7 @@ namespace Capnp.Rpc else { var path = MemberAccessPath.Deserialize(rd); - var cap = new RemoteAnswerCapabilityDeprecated(aorcq.Counterquestion!, path); + var cap = new RemoteAnswerCapability(aorcq.Counterquestion!, path); return new Proxy(cap); } } @@ -111,6 +135,31 @@ namespace Capnp.Rpc public void Dispose() { _cts?.Dispose(); + + Chain(async t => + { + AnswerOrCounterquestion aorcq; + + try + { + aorcq = await t; + } + catch + { + return; + } + + if (aorcq.Answer != null) + { + if (aorcq.Answer.Caps != null) + { + foreach (var cap in aorcq.Answer.Caps) + { + cap?.Release(false); + } + } + } + }); } } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/PendingQuestion.cs b/Capnp.Net.Runtime/Rpc/PendingQuestion.cs index cf7a900..dcdd7be 100644 --- a/Capnp.Net.Runtime/Rpc/PendingQuestion.cs +++ b/Capnp.Net.Runtime/Rpc/PendingQuestion.cs @@ -126,17 +126,17 @@ namespace Capnp.Rpc lock (ReentrancyBlocker) { SetReturned(); - } - if (StateFlags.HasFlag(State.TailCall)) - { - _tcs.TrySetException(new RpcException(ReturnDespiteTailCallMessage)); - } - else - { - if (!_tcs.TrySetResult(results)) + if (StateFlags.HasFlag(State.TailCall)) { - ReleaseOutCaps(results); + _tcs.TrySetException(new RpcException(ReturnDespiteTailCallMessage)); + } + else + { + if (!_tcs.TrySetResult(results)) + { + ReleaseOutCaps(results); + } } } } @@ -146,15 +146,15 @@ namespace Capnp.Rpc lock (ReentrancyBlocker) { SetReturned(); - } - if (!StateFlags.HasFlag(State.TailCall)) - { - _tcs.TrySetException(new RpcException("Peer sent the results of this questions somewhere else. This was not expected and is a protocol error.")); - } - else - { - _tcs.TrySetResult(default); + if (!StateFlags.HasFlag(State.TailCall)) + { + _tcs.TrySetException(new RpcException("Peer sent the results of this questions somewhere else. This was not expected and is a protocol error.")); + } + else + { + _tcs.TrySetResult(default); + } } } @@ -163,9 +163,9 @@ namespace Capnp.Rpc lock (ReentrancyBlocker) { SetReturned(); - } - _tcs.TrySetException(new RpcException(exception.Reason)); + _tcs.TrySetException(new RpcException(exception.Reason)); + } } internal void OnException(System.Exception exception) @@ -173,9 +173,9 @@ namespace Capnp.Rpc lock (ReentrancyBlocker) { SetReturned(); - } - _tcs.TrySetException(exception); + _tcs.TrySetException(exception); + } } internal void OnCanceled() @@ -183,9 +183,9 @@ namespace Capnp.Rpc lock (ReentrancyBlocker) { SetReturned(); - } - _tcs.TrySetCanceled(); + _tcs.TrySetCanceled(); + } } void DeleteMyQuestion() @@ -234,6 +234,7 @@ namespace Capnp.Rpc /// Access path /// Low-level capability /// The referenced member does not exist or does not resolve to a capability pointer. + [Obsolete("Please re-generate. Replaced by Access(MemberAccessPath access, Task task)")] public ConsumedCapability? Access(MemberAccessPath access) { lock (ReentrancyBlocker) @@ -252,7 +253,7 @@ namespace Capnp.Rpc } else { - return new RemoteAnswerCapabilityDeprecated(this, access); + return new RemoteAnswerCapability(this, access); } } } @@ -261,32 +262,14 @@ namespace Capnp.Rpc /// Refer to a (possibly nested) member of this question's (possibly future) result and return /// it as a capability. /// + /// Access path /// promises the cap whose ownership is transferred to this object /// Low-level capability /// The referenced member does not exist or does not resolve to a capability pointer. - public ConsumedCapability? Access(MemberAccessPath access, Task task) + public ConsumedCapability? Access(MemberAccessPath access, Task task) { var proxyTask = task.AsProxyTask(); - - lock (ReentrancyBlocker) - { - if (proxyTask.IsCompleted && !StateFlags.HasFlag(State.TailCall)) - { - try - { - using var proxy = proxyTask.Result; - return proxy.ConsumedCap; - } - catch (AggregateException exception) - { - throw exception.InnerException!; - } - } - else - { - return new RemoteAnswerCapabilityDeprecated(this, access); - } - } + return new RemoteAnswerCapability(this, access, proxyTask); } static void ReleaseCaps(ConsumedCapability? target, SerializerState? inParams) diff --git a/Capnp.Net.Runtime/Rpc/PromisedCapability.cs b/Capnp.Net.Runtime/Rpc/PromisedCapability.cs index 27a23f4..ec9a97b 100644 --- a/Capnp.Net.Runtime/Rpc/PromisedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/PromisedCapability.cs @@ -78,7 +78,7 @@ namespace Capnp.Rpc } } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) { lock (_reentrancyBlocker) { @@ -98,7 +98,7 @@ namespace Capnp.Rpc Debug.Assert(!_released); ++_pendingCallsOnPromise; - _ep.RequestPostAction(() => + return () => { bool release = false; @@ -115,7 +115,7 @@ namespace Capnp.Rpc { _ep.ReleaseImport(_remoteId); } - }); + }; } else { @@ -123,6 +123,8 @@ namespace Capnp.Rpc } } } + + return null; } async void TrackCall(Task call) diff --git a/Capnp.Net.Runtime/Rpc/Proxy.cs b/Capnp.Net.Runtime/Rpc/Proxy.cs index 18ab5f4..1d6c9e0 100644 --- a/Capnp.Net.Runtime/Rpc/Proxy.cs +++ b/Capnp.Net.Runtime/Rpc/Proxy.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Threading; using System.Threading.Tasks; @@ -99,9 +100,12 @@ namespace Capnp.Rpc /// public Proxy() { +#if DebugFinalizers + CreatorStackTrace = Environment.StackTrace; +#endif } - internal Proxy(ConsumedCapability? cap) + internal Proxy(ConsumedCapability? cap): this() { Bind(cap); } @@ -118,7 +122,7 @@ namespace Capnp.Rpc cap.AddRef(); } - internal IProvidedCapability? GetProvider() + internal Skeleton? GetProvider() { switch (ConsumedCap) { @@ -163,7 +167,7 @@ namespace Capnp.Rpc ~Proxy() { #if DebugFinalizers - Logger.LogWarning($"Caught orphaned Proxy, created from {CreatorMemberName} in {CreatorFilePath}, line {CreatorLineNumber}."); + Logger.LogWarning($"Caught orphaned Proxy, created from here: {CreatorStackTrace}."); #endif Dispose(false); @@ -230,9 +234,7 @@ namespace Capnp.Rpc } #if DebugFinalizers - public string CreatorMemberName { get; set; } - public string CreatorFilePath { get; set; } - public int CreatorLineNumber { get; set; } + string CreatorStackTrace { get; set; } #endif } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs index 240fc9e..b6beae8 100644 --- a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs @@ -26,16 +26,33 @@ namespace Capnp.Rpc // Value 0 has the special meaning of being in state C. long _refCount = 1; -#if DebugCapabilityLifecycle +#if DebugCapabilityLifecycle || DebugFinalizers ILogger Logger { get; } = Logging.CreateLogger(); +#endif +#if DebugCapabilityLifecycle string? _releasingMethodName; string? _releasingFilePath; int _releasingLineNumber; #endif +#if DebugFinalizers + string CreatorStackTrace { get; set; } +#endif + + public RefCountingCapability() + { +#if DebugFinalizers + CreatorStackTrace = Environment.StackTrace; +#endif + } + ~RefCountingCapability() { +#if DebugFinalizers + Logger.LogWarning($"Caught orphaned capability, created from here: {CreatorStackTrace}."); +#endif + Dispose(false); } diff --git a/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs b/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs index 328e8e3..8423581 100644 --- a/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs @@ -37,6 +37,19 @@ namespace Capnp.Rpc WhenResolved = AwaitWhenResolved(); } + static async Task TransferOwnershipToDummyProxy(PendingQuestion question, MemberAccessPath access) + { + var result = await question.WhenReturned; + var cap = access.Eval(result); + var proxy = new Proxy(cap); + cap?.Release(false); + return proxy; + } + + public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access) : this(question, access, TransferOwnershipToDummyProxy(question, access)) + { + } + async void ReAllowFinishWhenDone(Task task) { try @@ -64,7 +77,7 @@ namespace Capnp.Rpc { lock (_question.ReentrancyBlocker) { - if (!_question.IsTailCall && WhenResolved.IsCompleted) + if (!_question.IsTailCall && _question.StateFlags.HasFlag(PendingQuestion.State.Returned)) { try { @@ -96,8 +109,8 @@ namespace Capnp.Rpc { lock (_question.ReentrancyBlocker) { - if (_question.StateFlags.HasFlag(PendingQuestion.State.Returned) && - !_question.StateFlags.HasFlag(PendingQuestion.State.TailCall)) + if (!_question.StateFlags.HasFlag(PendingQuestion.State.TailCall) && + _question.StateFlags.HasFlag(PendingQuestion.State.Returned)) { if (ResolvedCap == null) { @@ -165,8 +178,9 @@ namespace Capnp.Rpc { lock (_question.ReentrancyBlocker) { - if (_question.StateFlags.HasFlag(PendingQuestion.State.Returned) && - _pendingCallsOnPromise == 0) + if ( _question.StateFlags.HasFlag(PendingQuestion.State.Returned) && + !_question.StateFlags.HasFlag(PendingQuestion.State.TailCall) && + _pendingCallsOnPromise == 0) { if (ResolvedCap == null) { @@ -200,7 +214,7 @@ namespace Capnp.Rpc } } - internal override void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + internal override Action? Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer) { lock (_question.ReentrancyBlocker) { @@ -236,10 +250,12 @@ namespace Capnp.Rpc } else { - this.ExportAsSenderPromise(endpoint, writer); + return this.ExportAsSenderPromise(endpoint, writer); } } } + + return null; } protected async override void ReleaseRemotely() diff --git a/Capnp.Net.Runtime/Rpc/RemoteAnswerCapabilityDeprecated.cs b/Capnp.Net.Runtime/Rpc/RemoteAnswerCapabilityDeprecated.cs index 51e8ee5..f950659 100644 --- a/Capnp.Net.Runtime/Rpc/RemoteAnswerCapabilityDeprecated.cs +++ b/Capnp.Net.Runtime/Rpc/RemoteAnswerCapabilityDeprecated.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; namespace Capnp.Rpc { +#if false class RemoteAnswerCapabilityDeprecated : RemoteResolvingCapability { @@ -17,7 +18,6 @@ namespace Capnp.Rpc readonly PendingQuestion _question; readonly MemberAccessPath _access; - readonly Task _whenResolvedProxy; ConsumedCapability? _resolvedCap; public RemoteAnswerCapabilityDeprecated(PendingQuestion question, MemberAccessPath access): base(question.RpcEndpoint) @@ -36,9 +36,6 @@ namespace Capnp.Rpc } WhenResolved = AwaitWhenResolved(); - - async Task AwaitProxy() => new Proxy(await WhenResolved); - _whenResolvedProxy = AwaitProxy(); } async void ReAllowFinishWhenDone(Task task) @@ -62,16 +59,6 @@ namespace Capnp.Rpc } } - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - lock (_question.ReentrancyBlocker) - { - using var _ = new Proxy(_resolvedCap); - } - } - protected override ConsumedCapability? ResolvedCap { get @@ -258,8 +245,9 @@ namespace Capnp.Rpc protected async override void ReleaseRemotely() { - try { using var _ = await _whenResolvedProxy; } + try { (await WhenResolved)?.Release(false); } catch { } } } +#endif } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs b/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs index 36d0ae2..ade7ee8 100644 --- a/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs +++ b/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs @@ -5,7 +5,7 @@ namespace Capnp.Rpc { static class ResolvingCapabilityExtensions { - public static void ExportAsSenderPromise(this T cap, IRpcEndpoint endpoint, CapDescriptor.WRITER writer) + public static Action? ExportAsSenderPromise(this T cap, IRpcEndpoint endpoint, CapDescriptor.WRITER writer) where T: ConsumedCapability, IResolvingCapability { var vine = Vine.Create(cap); @@ -16,7 +16,7 @@ namespace Capnp.Rpc if (first) { - endpoint.RequestPostAction(async () => { + return async () => { try { @@ -28,14 +28,21 @@ namespace Capnp.Rpc endpoint.Resolve(preliminaryId, vine, () => throw exception); } - }); + }; } + + return null; } - public static async Task AsProxyTask(this Task task) + public static async Task AsProxyTask(this Task task) { var obj = await task; - return obj is Proxy proxy ? proxy : BareProxy.FromImpl(obj); + switch (obj) + { + case Proxy proxy: return proxy; + case null: return new Proxy(LazyCapability.Null); + default: return BareProxy.FromImpl(obj); + } } } } \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RpcEngine.cs b/Capnp.Net.Runtime/Rpc/RpcEngine.cs index 0b1ad55..74ffc4b 100644 --- a/Capnp.Net.Runtime/Rpc/RpcEngine.cs +++ b/Capnp.Net.Runtime/Rpc/RpcEngine.cs @@ -68,7 +68,6 @@ namespace Capnp.Rpc Dismissed } - static readonly ThreadLocal _exportCapTablePostActions = new ThreadLocal(); static readonly ThreadLocal _tailCall = new ThreadLocal(); static readonly ThreadLocal _canDeferCalls = new ThreadLocal(); @@ -386,7 +385,7 @@ namespace Capnp.Rpc } } - IProvidedCapability? cap; + Skeleton? callTargetCap; PendingAnswer pendingAnswer; bool releaseParamCaps = false; @@ -507,7 +506,7 @@ namespace Capnp.Rpc var inParams = req.Params.Content; inParams.Caps = ImportCapTable(req.Params); - if (cap == null) + if (callTargetCap == null) { releaseParamCaps = true; pendingAnswer = new PendingAnswer( @@ -519,7 +518,7 @@ namespace Capnp.Rpc try { var cts = new CancellationTokenSource(); - var callTask = cap.Invoke(req.InterfaceId, req.MethodId, inParams, cts.Token); + var callTask = callTargetCap.Invoke(req.InterfaceId, req.MethodId, inParams, cts.Token); pendingAnswer = new PendingAnswer(callTask, cts); } catch (System.Exception exception) @@ -528,6 +527,10 @@ namespace Capnp.Rpc pendingAnswer = new PendingAnswer( Task.FromException(exception), null); } + finally + { + callTargetCap.Relinquish(); + } } AwaitAnswerAndReply(); @@ -561,7 +564,8 @@ namespace Capnp.Rpc { if (_exportTable.TryGetValue(req.Target.ImportedCap, out var rc)) { - cap = rc.Cap; + callTargetCap = rc.Cap; + callTargetCap.Claim(); } else { @@ -594,7 +598,8 @@ namespace Capnp.Rpc try { using var proxy = await t; - cap = proxy?.GetProvider(); + callTargetCap = proxy?.GetProvider(); + callTargetCap?.Claim(); CreateAnswerAwaitItAndReply(); } catch (TaskCanceledException) @@ -631,8 +636,9 @@ namespace Capnp.Rpc { _canDeferCalls.Value = false; Impatient.AskingEndpoint = null; - _tailCall.Value?.Send(); + var call = _tailCall.Value; _tailCall.Value = null; + call?.Send(); } } @@ -948,14 +954,6 @@ namespace Capnp.Rpc } } } - - //if (results != null && results.Caps != null) - //{ - // foreach (var cap in results.Caps) - // { - // cap?.Release(); - // } - //} } catch { @@ -1105,7 +1103,7 @@ namespace Capnp.Rpc Tx(mb.Frame); - var main = new RemoteAnswerCapabilityDeprecated( + var main = new RemoteAnswerCapability( pendingBootstrap, MemberAccessPath.BootstrapAccess); @@ -1340,7 +1338,9 @@ namespace Capnp.Rpc { foreach (var capDesc in payload.CapTable) { - list.Add(ImportCap(capDesc)); + var cap = ImportCap(capDesc); + cap.AddRef(); + list.Add(cap); } } } @@ -1348,20 +1348,13 @@ namespace Capnp.Rpc return list; } - void IRpcEndpoint.RequestPostAction(Action postAction) - { - _exportCapTablePostActions.Value += postAction; - } - void ExportCapTableAndSend( SerializerState state, Payload.WRITER payload) { - Debug.Assert(_exportCapTablePostActions.Value == null); - _exportCapTablePostActions.Value = null; - payload.CapTable.Init(state.MsgBuilder!.Caps!.Count); + Action? postAction = null; int i = 0; foreach (var cap in state.MsgBuilder.Caps) { @@ -1373,7 +1366,7 @@ namespace Capnp.Rpc } else { - cap.Export(this, capDesc); + postAction += cap.Export(this, capDesc); cap.Release(false); } } @@ -1386,9 +1379,7 @@ namespace Capnp.Rpc // To avoid that situation, calls to "ReExportCapWhenResolved" are queued (and // therefore deferred) to the postAction. - var pa = _exportCapTablePostActions.Value; - _exportCapTablePostActions.Value = null; - pa?.Invoke(); + postAction?.Invoke(); } PendingQuestion IRpcEndpoint.BeginQuestion(ConsumedCapability target, SerializerState inParams) diff --git a/Capnp.Net.Runtime/Rpc/Vine.cs b/Capnp.Net.Runtime/Rpc/Vine.cs index db63d0c..1542681 100644 --- a/Capnp.Net.Runtime/Rpc/Vine.cs +++ b/Capnp.Net.Runtime/Rpc/Vine.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Threading; using System.Threading.Tasks; @@ -17,8 +18,24 @@ namespace Capnp.Rpc Vine(ConsumedCapability consumedCap) { Proxy = new Proxy(consumedCap ?? throw new ArgumentNullException(nameof(consumedCap))); + +#if DebugFinalizers + CreatorStackTrace = Environment.StackTrace; +#endif } +#if DebugFinalizers + ~Vine() + { + Logger.LogWarning($"Caught orphaned Vine, created from here: {CreatorStackTrace}."); + + Dispose(false); + } + + ILogger Logger { get; } = Logging.CreateLogger(); + string CreatorStackTrace { get; } +#endif + internal override void Bind(object impl) { throw new NotImplementedException(); diff --git a/Capnp.Net.sln b/Capnp.Net.sln index ff53c1c..8540d21 100644 --- a/Capnp.Net.sln +++ b/Capnp.Net.sln @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "capnpc-csharp", "capnpc-csh EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests.Std20", "Capnp.Net.Runtime.Tests\Capnp.Net.Runtime.Tests.Std20.csproj", "{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests.Core21", "Capnp.Net.Runtime.Tests.Core21\Capnp.Net.Runtime.Tests.Core21.csproj", "{58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.Generator.Tests", "CapnpC.CSharp.Generator.Tests\CapnpC.CSharp.Generator.Tests.csproj", "{B77AC567-E232-4072-85C3-8689566BF3D4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CapnpC.CSharp.MsBuild.Generation", "CapnpC.CSharp.MsBuild.Generation\CapnpC.CSharp.MsBuild.Generation.csproj", "{1EFC1F20-C7BB-4F44-8BF9-DBB123AACCF4}" @@ -37,10 +35,6 @@ Global {9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Debug|Any CPU.Build.0 = Debug|Any CPU {9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Release|Any CPU.ActiveCfg = Release|Any CPU {9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Release|Any CPU.Build.0 = Release|Any CPU - {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Release|Any CPU.Build.0 = Release|Any CPU {B77AC567-E232-4072-85C3-8689566BF3D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B77AC567-E232-4072-85C3-8689566BF3D4}.Debug|Any CPU.Build.0 = Debug|Any CPU {B77AC567-E232-4072-85C3-8689566BF3D4}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs index e96c18b..6053239 100644 --- a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs +++ b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs @@ -8480,9 +8480,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestGenerics.Inner2.DeepNest.DeepNestInterface.Params_Call() {}; arg_?.serialize(in_); - var d_ = await Call(9816138025992274567UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_Call>(d_); - return; + using (var d_ = await Call(9816138025992274567UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_Call>(d_); + return; + } } } @@ -8496,9 +8498,12 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9816138025992274567UL; async Task Call(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Call(cancellationToken_); - var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_Call.WRITER>(); - return s_; + using (d_) + { + await Impl.Call(cancellationToken_); + var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_Call.WRITER>(); + return s_; + } } } @@ -8612,8 +8617,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(14548678385738242652UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create.Interface.Result_Call>(d_); - return (r_.Qux, r_.Gen); + using (d_) + { + var r_ = CapnpSerializable.Create.Interface.Result_Call>(d_); + return (r_.Qux, r_.Gen); + } } ); @@ -8630,15 +8638,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 14548678385738242652UL; Task Call(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.Call(CapnpSerializable.Create.Inner2>(d_), cancellationToken_), (qux, gen) => + using (d_) { - var s_ = SerializerState.CreateForRpc.Interface.Result_Call.WRITER>(); - var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_Call{Qux = qux, Gen = gen}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.Call(CapnpSerializable.Create.Inner2>(d_), cancellationToken_), (qux, gen) => + { + var s_ = SerializerState.CreateForRpc.Interface.Result_Call.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_Call{Qux = qux, Gen = gen}; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -8995,8 +9006,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(10058534285777328794UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create>(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create>(d_); + return r_; + } } ); @@ -9014,15 +9028,18 @@ namespace Capnproto_test.Capnp.Test Task Call(DeserializerState d_, CancellationToken cancellationToken_) where TT : class where TU : class { - var in_ = CapnpSerializable.Create>(d_); - return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc.WRITER>(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create>(d_); + return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc.WRITER>(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -9122,8 +9139,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(16112979978201007305UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create>(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create>(d_); + return r_; + } } ); @@ -9141,15 +9161,18 @@ namespace Capnproto_test.Capnp.Test Task Call(DeserializerState d_, CancellationToken cancellationToken_) where TT : class where TU : class { - var in_ = CapnpSerializable.Create.Params_Call>(d_); - return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc.WRITER>(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create.Params_Call>(d_); + return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc.WRITER>(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -10029,9 +10052,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() {I = I, J = J}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.X); + using (var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } } public async Task Bar(CancellationToken cancellationToken_ = default) @@ -10040,9 +10065,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() {}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) @@ -10051,9 +10078,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() {S = S}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -10067,31 +10096,40 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9865999890858873522UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.J, cancellationToken_), x => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_Foo{X = x}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.J, cancellationToken_), x => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_Foo{X = x}; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task Bar(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Bar(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Bar(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Baz(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.Baz(in_.S, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.Baz(in_.S, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } @@ -10444,18 +10482,22 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Qux() {}; arg_?.serialize(in_); - var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); arg_?.serialize(in_); - var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Grault(CancellationToken cancellationToken_ = default) @@ -10464,9 +10506,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Grault() {}; arg_?.serialize(in_); - var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + using (var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) @@ -10475,9 +10519,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() {I = I, J = J}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.X); + using (var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } } public async Task Bar(CancellationToken cancellationToken_ = default) @@ -10486,9 +10532,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() {}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) @@ -10497,9 +10545,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() {S = S}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -10513,28 +10563,37 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 16494920484927878984UL; async Task Qux(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Qux(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Qux(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Corge(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Corge(CapnpSerializable.Create(d_), cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Corge(CapnpSerializable.Create(d_), cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task Grault(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.Grault(cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.Grault(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -10734,18 +10793,22 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Qux() {}; arg_?.serialize(in_); - var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); arg_?.serialize(in_); - var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Grault(CancellationToken cancellationToken_ = default) @@ -10754,9 +10817,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Grault() {}; arg_?.serialize(in_); - var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + using (var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) @@ -10765,9 +10830,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() {I = I, J = J}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.X); + using (var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.X); + } } public async Task Bar(CancellationToken cancellationToken_ = default) @@ -10776,9 +10843,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() {}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) @@ -10787,9 +10856,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() {S = S}; arg_?.serialize(in_); - var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -10821,8 +10892,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(11935670180855499984UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.S, r_.OutBox); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S, r_.OutBox); + } } ); @@ -10834,9 +10908,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_TestPointers() {Cap = Cap, Obj = Obj, List = List}; arg_?.serialize(in_); - var d_ = await Call(11935670180855499984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(11935670180855499984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint N, BareProxy InCap, CancellationToken cancellationToken_ = default) @@ -10847,8 +10923,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(11935670180855499984UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.S, r_.OutBox); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S, r_.OutBox); + } } ); @@ -10865,38 +10944,47 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11935670180855499984UL; Task GetCap(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.GetCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetCap{S = s, OutBox = outBox}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetCap{S = s, OutBox = outBox}; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task TestPointers(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.TestPointers(in_.Cap, in_.Obj, in_.List, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.TestPointers(in_.Cap, in_.Obj, in_.List, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task GetAnyCap(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.GetAnyCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetAnyCap{S = s, OutBox = outBox}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetAnyCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetAnyCap{S = s, OutBox = outBox}; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -11472,9 +11560,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_GetCallSequence() {Expected = Expected}; arg_?.serialize(in_); - var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.N); + using (var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.N); + } } } @@ -11488,16 +11578,19 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11594359141811814481UL; Task GetCallSequence(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.GetCallSequence(in_.Expected, cancellationToken_), n => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_GetCallSequence{N = n}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.GetCallSequence(in_.Expected, cancellationToken_), n => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_GetCallSequence{N = n}; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -11640,8 +11733,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15985132292242203195UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } ); @@ -11658,15 +11754,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15985132292242203195UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.T, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.T, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -11854,8 +11953,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(9731139705278181429UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return r_; + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } ); @@ -11872,15 +11974,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9731139705278181429UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.Callee, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.Callee, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -12007,9 +12112,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallFoo() {Cap = Cap}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.S); + using (var d_ = await Call(15980754968839795663UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } } public async Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) @@ -12018,9 +12125,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallFooWhenResolved() {Cap = Cap}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.S); + using (var d_ = await Call(15980754968839795663UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } } public Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) @@ -12031,8 +12140,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.CapCopy); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.CapCopy); + } } ); @@ -12044,9 +12156,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_Hold() {Cap = Cap}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(15980754968839795663UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task CallHeld(CancellationToken cancellationToken_ = default) @@ -12055,9 +12169,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallHeld() {}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.S); + using (var d_ = await Call(15980754968839795663UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.S); + } } public Task GetHeld(CancellationToken cancellationToken_ = default) @@ -12068,8 +12184,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 5, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Cap); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } } ); @@ -12083,8 +12202,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 6, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Cap); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } } ); @@ -12096,9 +12218,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_ExpectCancel() {Cap = Cap}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 7, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(15980754968839795663UL, 7, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task<(string, string)> MethodWithDefaults(string A, uint B, string C, CancellationToken cancellationToken_ = default) @@ -12107,9 +12231,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_MethodWithDefaults() {A = A, B = B, C = C}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 8, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.D, r_.E); + using (var d_ = await Call(15980754968839795663UL, 8, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.D, r_.E); + } } public Task GetHandle(CancellationToken cancellationToken_ = default) @@ -12120,8 +12246,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 9, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Handle); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Handle); + } } ); @@ -12135,8 +12264,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 10, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.NullCap); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.NullCap); + } } ); @@ -12148,9 +12280,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetEnormousString() {}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 11, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.Str); + using (var d_ = await Call(15980754968839795663UL, 11, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Str); + } } public async Task MethodWithNullDefault(string A, Capnproto_test.Capnp.Test.ITestInterface B, CancellationToken cancellationToken_ = default) @@ -12159,9 +12293,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_MethodWithNullDefault() {A = A, B = B}; arg_?.serialize(in_); - var d_ = await Call(15980754968839795663UL, 12, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(15980754968839795663UL, 12, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default) @@ -12170,9 +12306,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_GetCallSequence() {Expected = Expected}; arg_?.serialize(in_); - var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return (r_.N); + using (var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.N); + } } } @@ -12186,161 +12324,200 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15980754968839795663UL; Task CallFoo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallFoo(in_.Cap, cancellationToken_), s => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFoo{S = s}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallFoo(in_.Cap, cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFoo{S = s}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task CallFooWhenResolved(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallFooWhenResolved(in_.Cap, cancellationToken_), s => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFooWhenResolved{S = s}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallFooWhenResolved(in_.Cap, cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFooWhenResolved{S = s}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task NeverReturn(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.NeverReturn(in_.Cap, cancellationToken_), capCopy => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_NeverReturn{CapCopy = capCopy}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.NeverReturn(in_.Cap, cancellationToken_), capCopy => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_NeverReturn{CapCopy = capCopy}; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task Hold(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.Hold(in_.Cap, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.Hold(in_.Cap, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task CallHeld(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.CallHeld(cancellationToken_), s => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallHeld{S = s}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.CallHeld(cancellationToken_), s => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallHeld{S = s}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetHeld(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetHeld(cancellationToken_), cap => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHeld{Cap = cap}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetHeld(cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHeld{Cap = cap}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task Echo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Echo(in_.Cap, cancellationToken_), cap => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_Echo{Cap = cap}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Echo(in_.Cap, cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_Echo{Cap = cap}; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task ExpectCancel(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.ExpectCancel(in_.Cap, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.ExpectCancel(in_.Cap, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } Task MethodWithDefaults(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.MethodWithDefaults(in_.A, in_.B, in_.C, cancellationToken_), (d, e) => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_MethodWithDefaults{D = d, E = e}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.MethodWithDefaults(in_.A, in_.B, in_.C, cancellationToken_), (d, e) => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_MethodWithDefaults{D = d, E = e}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetHandle(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetHandle(cancellationToken_), handle => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHandle{Handle = handle}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetHandle(cancellationToken_), handle => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHandle{Handle = handle}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetNull(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetNull(cancellationToken_), nullCap => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetNull{NullCap = nullCap}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetNull(cancellationToken_), nullCap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetNull{NullCap = nullCap}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task GetEnormousString(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetEnormousString(cancellationToken_), str => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetEnormousString{Str = str}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetEnormousString(cancellationToken_), str => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetEnormousString{Str = str}; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task MethodWithNullDefault(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.MethodWithNullDefault(in_.A, in_.B, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.MethodWithNullDefault(in_.A, in_.B, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } @@ -13870,8 +14047,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(13870398341137210380UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Thing); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Thing); + } } ); @@ -13883,9 +14063,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_CallPassThrough() {Thing = Thing, TailCall = TailCall}; arg_?.serialize(in_); - var d_ = await Call(13870398341137210380UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + using (var d_ = await Call(13870398341137210380UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } public async Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default) @@ -13894,9 +14076,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_CallIntercept() {Thing = Thing, TailCall = TailCall}; arg_?.serialize(in_); - var d_ = await Call(13870398341137210380UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + using (var d_ = await Call(13870398341137210380UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } public Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, CancellationToken cancellationToken_ = default) @@ -13907,8 +14091,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(13870398341137210380UL, 3, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); - return (r_.Thing); + using (d_) + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Thing); + } } ); @@ -13920,9 +14107,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_WaitForever() {}; arg_?.serialize(in_); - var d_ = await Call(13870398341137210380UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(13870398341137210380UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -13936,62 +14125,77 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 13870398341137210380UL; Task MakeThing(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.MakeThing(cancellationToken_), thing => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_MakeThing{Thing = thing}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.MakeThing(cancellationToken_), thing => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_MakeThing{Thing = thing}; + r_.serialize(s_); + return s_; + } - ); + ); + } } Task CallPassThrough(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallPassThrough(in_.Thing, in_.TailCall, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallPassThrough(in_.Thing, in_.TailCall, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } Task CallIntercept(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.CallIntercept(in_.Thing, in_.TailCall, cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.CallIntercept(in_.Thing, in_.TailCall, cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } Task Loopback(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - return Impatient.MaybeTailCall(Impl.Loopback(in_.Thing, cancellationToken_), thing => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_Loopback{Thing = thing}; - r_.serialize(s_); - return s_; - } + var in_ = CapnpSerializable.Create(d_); + return Impatient.MaybeTailCall(Impl.Loopback(in_.Thing, cancellationToken_), thing => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_Loopback{Thing = thing}; + r_.serialize(s_); + return s_; + } - ); + ); + } } async Task WaitForever(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.WaitForever(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.WaitForever(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } @@ -14012,9 +14216,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_PassThrough() {}; arg_?.serialize(in_); - var d_ = await Call(10615798940090972439UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + using (var d_ = await Call(10615798940090972439UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } public async Task Intercept(CancellationToken cancellationToken_ = default) @@ -14023,9 +14229,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_Intercept() {}; arg_?.serialize(in_); - var d_ = await Call(10615798940090972439UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return r_; + using (var d_ = await Call(10615798940090972439UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return r_; + } } } @@ -14039,26 +14247,32 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 10615798940090972439UL; Task PassThrough(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.PassThrough(cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.PassThrough(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } Task Intercept(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.Intercept(cancellationToken_), r_ => + using (d_) { - var s_ = SerializerState.CreateForRpc(); - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.Intercept(cancellationToken_), r_ => + { + var s_ = SerializerState.CreateForRpc(); + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -14908,9 +15122,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Delete() {}; arg_?.serialize(in_); - var d_ = await Call(11160837778045172988UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(11160837778045172988UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Class(CancellationToken cancellationToken_ = default) @@ -14919,9 +15135,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Class() {}; arg_?.serialize(in_); - var d_ = await Call(11160837778045172988UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(11160837778045172988UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Void(CancellationToken cancellationToken_ = default) @@ -14930,9 +15148,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Void() {}; arg_?.serialize(in_); - var d_ = await Call(11160837778045172988UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(11160837778045172988UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } public async Task Return(CancellationToken cancellationToken_ = default) @@ -14941,9 +15161,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Return() {}; arg_?.serialize(in_); - var d_ = await Call(11160837778045172988UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(11160837778045172988UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -14957,30 +15179,42 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11160837778045172988UL; async Task Delete(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Delete(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Delete(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Class(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Class(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Class(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Void(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Void(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Void(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } async Task Return(DeserializerState d_, CancellationToken cancellationToken_) { - await Impl.Return(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + await Impl.Return(cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } @@ -15363,8 +15597,11 @@ namespace Capnproto_test.Capnp.Test arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(16893789964317726925UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create.Result_GetCallerId>(d_); - return (r_.Caller); + using (d_) + { + var r_ = CapnpSerializable.Create.Result_GetCallerId>(d_); + return (r_.Caller); + } } ); @@ -15381,15 +15618,18 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 16893789964317726925UL; Task GetCallerId(DeserializerState d_, CancellationToken cancellationToken_) { - return Impatient.MaybeTailCall(Impl.GetCallerId(cancellationToken_), caller => + using (d_) { - var s_ = SerializerState.CreateForRpc.Result_GetCallerId.WRITER>(); - var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_GetCallerId{Caller = caller}; - r_.serialize(s_); - return s_; - } + return Impatient.MaybeTailCall(Impl.GetCallerId(cancellationToken_), caller => + { + var s_ = SerializerState.CreateForRpc.Result_GetCallerId.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_GetCallerId{Caller = caller}; + r_.serialize(s_); + return s_; + } - ); + ); + } } } @@ -16335,9 +16575,11 @@ namespace Capnproto_test.Capnp.Test var arg_ = new Capnproto_test.Capnp.Test.TestNameAnnotationInterface.Params_BadlyNamedMethod() {BadlyNamedParam = BadlyNamedParam}; arg_?.serialize(in_); - var d_ = await Call(15065286897585459595UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); - return; + using (var d_ = await Call(15065286897585459595UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned) + { + var r_ = CapnpSerializable.Create(d_); + return; + } } } @@ -16351,10 +16593,13 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15065286897585459595UL; async Task BadlyNamedMethod(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); - await Impl.BadlyNamedMethod(in_.BadlyNamedParam, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); - return s_; + using (d_) + { + var in_ = CapnpSerializable.Create(d_); + await Impl.BadlyNamedMethod(in_.BadlyNamedParam, cancellationToken_); + var s_ = SerializerState.CreateForRpc(); + return s_; + } } } @@ -16471,19 +16716,22 @@ namespace Capnproto_test.Capnp.Test static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap)); + async Task AwaitProxy() => (await task).Item2?.Cap; + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap, AwaitProxy())); } static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) { - return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap)); + async Task AwaitProxy() => (await task).Item2?.Cap; + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap, AwaitProxy())); } static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestTailCallee_foo_C = new MemberAccessPath(1U); public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestTailCallee_foo_C)); + async Task AwaitProxy() => (await task).C; + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestTailCallee_foo_C, AwaitProxy())); } } } \ No newline at end of file diff --git a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs index afcdf19..95f1889 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs @@ -72,6 +72,7 @@ namespace CapnpC.CSharp.Generator.CodeGen public string PipeliningExtensionsClassFormat { get; } public string ProxyClassFormat { get; } public string SkeletonClassFormat { get; } + public Name AwaitProxy { get; } public bool NullableEnable { get; set; } public GenNames(GeneratorOptions options) { @@ -110,6 +111,7 @@ namespace CapnpC.CSharp.Generator.CodeGen PipeliningExtensionsClassFormat = options.PipeliningExtensionsClassFormat; ProxyClassFormat = options.ProxyClassFormat; SkeletonClassFormat = options.SkeletonClassFormat; + AwaitProxy = new Name(options.AwaitProxyName); } public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) diff --git a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs index 3a3eccf..178d41b 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs @@ -37,6 +37,7 @@ public string TaskParameterName { get; set; } = "task"; public string EagerMethodName { get; set; } = "Eager"; public string TypeIdFieldName { get; set; } = "typeId"; + public string AwaitProxyName { get; set; } = "AwaitProxy"; public bool NullableEnableDefault { get; set; } = false; } } diff --git a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs index c683f3b..f1940aa 100644 --- a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs @@ -404,8 +404,11 @@ namespace CapnpC.CSharp.Generator.CodeGen Argument(SimpleLambdaExpression( Parameter(_names.DeserializerLocal.Identifier), Block( - MakeProxyCreateResult(method), - MakeProxyReturnResult(method))))); + UsingStatement( + Block( + MakeProxyCreateResult(method), + MakeProxyReturnResult(method))) + .WithExpression(_names.DeserializerLocal.IdentifierName))))); bodyStmts.Add(ReturnStatement(pipelineAwareCall)); } @@ -422,19 +425,18 @@ namespace CapnpC.CSharp.Generator.CodeGen call, IdentifierName(nameof(Capnp.Rpc.IPromisedAnswer.WhenReturned))); - var assignAwaited = LocalDeclarationStatement( - VariableDeclaration( + bodyStmts.Add(UsingStatement( + Block( + MakeProxyCreateResult(method), + MakeProxyReturnResult(method))) + .WithDeclaration(VariableDeclaration( IdentifierName("var")) - .AddVariables( - VariableDeclarator( - _names.DeserializerLocal.Identifier) - .WithInitializer( - EqualsValueClause( - AwaitExpression(whenReturned))))); - - bodyStmts.Add(assignAwaited); - bodyStmts.Add(MakeProxyCreateResult(method)); - bodyStmts.Add(MakeProxyReturnResult(method)); + .AddVariables( + VariableDeclarator( + _names.DeserializerLocal.Identifier) + .WithInitializer( + EqualsValueClause( + AwaitExpression(whenReturned)))))); } if (method.GenericParameters.Count > 0) @@ -703,7 +705,10 @@ namespace CapnpC.CSharp.Generator.CodeGen Parameter(_names.CancellationTokenParameter.Identifier) .WithType(_names.Type(Nullability.NonNullable))) .AddBodyStatements( - MakeSkeletonMethodBody(method).ToArray()); + UsingStatement( + Block( + MakeSkeletonMethodBody(method).ToArray())) + .WithExpression(_names.DeserializerLocal.IdentifierName)); if (method.Results.Count == 0) { @@ -808,6 +813,59 @@ namespace CapnpC.CSharp.Generator.CodeGen readonly HashSet<(string, string)> _existingExtensionMethods = new HashSet<(string, string)>(); + LocalFunctionStatementSyntax MakeLocalAwaitProxyFunction(Method method, IReadOnlyList path) + { + var members = new List(); + IEnumerable fields = path; + + if (method.Results.Count >= 2) + { + int index = Array.IndexOf(method.ResultStruct.Fields.ToArray(), path[0]) + 1; + members.Add(new Name($"Item{index}")); + fields = path.Skip(1); + } + + foreach (var field in fields) + { + members.Add(_names.GetCodeIdentifier(field)); + } + + ExpressionSyntax memberAccess = + ParenthesizedExpression( + AwaitExpression( + _names.TaskParameter.IdentifierName)); + + memberAccess = MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + memberAccess, + members.First().IdentifierName); + + foreach (var member in members.Skip(1)) + { + memberAccess = ConditionalAccessExpression( + memberAccess, + MemberBindingExpression(member.IdentifierName)); + } + + var idisposable = _names.MakeNullableRefType(IdentifierName(nameof(IDisposable))); + + return LocalFunctionStatement( + GenericName( + Identifier(nameof(Task))) + .WithTypeArgumentList( + TypeArgumentList( + SingletonSeparatedList( + idisposable))), + _names.AwaitProxy.Identifier) + .WithModifiers( + TokenList( + Token(SyntaxKind.AsyncKeyword))) + .WithExpressionBody( + ArrowExpressionClause(memberAccess)) + .WithSemicolonToken( + Token(SyntaxKind.SemicolonToken)); + } + public IEnumerable MakePipeliningSupport(TypeDefinition type) { foreach (var method in type.Methods) @@ -856,6 +914,7 @@ namespace CapnpC.CSharp.Generator.CodeGen .AddModifiers(This) .WithType(TransformReturnType(method))) .AddBodyStatements( + MakeLocalAwaitProxyFunction(method, path), ReturnStatement( CastExpression( capTypeSyntax, @@ -883,7 +942,10 @@ namespace CapnpC.CSharp.Generator.CodeGen IdentifierName(nameof(Capnp.Rpc.IPromisedAnswer.Access)))) .AddArgumentListArguments( Argument( - accessPath.IdentifierName))))))); + accessPath.IdentifierName), + Argument( + InvocationExpression( + _names.AwaitProxy.IdentifierName)))))))); yield return pathDecl; yield return methodDecl;