nullable first step

This commit is contained in:
Christian Köllner 2020-01-11 17:21:31 +01:00
parent abe9921ec5
commit 3c9c98bc2b
90 changed files with 501 additions and 260 deletions

View File

@ -1,4 +1,5 @@
namespace Capnp #nullable enable
namespace Capnp
{ {
/// <summary> /// <summary>
/// Generic <see cref="ICapnpSerializable"/> implementation, based on a wrapper around <see cref="DeserializerState"/>. /// Generic <see cref="ICapnpSerializable"/> implementation, based on a wrapper around <see cref="DeserializerState"/>.
@ -29,3 +30,4 @@
} }
} }
} }
#nullable restore

View File

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks> <TargetFrameworks>netstandard2.0;netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
<RootNamespace>Capnp</RootNamespace> <RootNamespace>Capnp</RootNamespace>
<LangVersion>7.2</LangVersion> <LangVersion>8.0</LangVersion>
<AssemblyName>Capnp.Net.Runtime</AssemblyName> <AssemblyName>Capnp.Net.Runtime</AssemblyName>
<PackageId>Capnp.Net.Runtime</PackageId> <PackageId>Capnp.Net.Runtime</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -10,15 +11,15 @@ namespace Capnp
/// </summary> /// </summary>
public static class CapnpSerializable public static class CapnpSerializable
{ {
interface IConstructibleFromDeserializerState<out T> interface IConstructibleFromDeserializerState
{ {
T Create(DeserializerState state); object? Create(DeserializerState state);
} }
class FromStruct<T>: IConstructibleFromDeserializerState<T> class FromStruct<T>: IConstructibleFromDeserializerState
where T : ICapnpSerializable, new() where T : ICapnpSerializable, new()
{ {
public T Create(DeserializerState state) public object Create(DeserializerState state)
{ {
var result = new T(); var result = new T();
if (state.Kind != ObjectKind.Nil) if (state.Kind != ObjectKind.Nil)
@ -29,7 +30,7 @@ namespace Capnp
} }
} }
class FromList<T>: IConstructibleFromDeserializerState<IReadOnlyList<T>> class FromList<T>: IConstructibleFromDeserializerState
where T: class where T: class
{ {
readonly Func<DeserializerState, T> _elementSerializer; readonly Func<DeserializerState, T> _elementSerializer;
@ -39,23 +40,23 @@ namespace Capnp
_elementSerializer = (Func<DeserializerState, T>)GetSerializer(typeof(T)); _elementSerializer = (Func<DeserializerState, T>)GetSerializer(typeof(T));
} }
public IReadOnlyList<T> Create(DeserializerState state) public object Create(DeserializerState state)
{ {
return state.RequireList().Cast(_elementSerializer); return state.RequireList().Cast(_elementSerializer);
} }
} }
class FromCapability<T>: IConstructibleFromDeserializerState<T> class FromCapability<T>: IConstructibleFromDeserializerState
where T: class where T: class
{ {
public T Create(DeserializerState state) public object? Create(DeserializerState state)
{ {
return state.RequireCap<T>(); return state.RequireCap<T>();
} }
} }
static readonly ConditionalWeakTable<Type, Func<DeserializerState, object>> _typeMap = static readonly ConditionalWeakTable<Type, Func<DeserializerState, object?>> _typeMap =
new ConditionalWeakTable<Type, Func<DeserializerState, object>>(); new ConditionalWeakTable<Type, Func<DeserializerState, object?>>();
static CapnpSerializable() static CapnpSerializable()
{ {
@ -73,14 +74,14 @@ namespace Capnp
_typeMap.Add(typeof(IReadOnlyList<double>), d => d.RequireList().CastDouble()); _typeMap.Add(typeof(IReadOnlyList<double>), d => d.RequireList().CastDouble());
} }
static Func<DeserializerState, object> CreateSerializer(Type type) static Func<DeserializerState, object?> CreateSerializer(Type type)
{ {
if (typeof(ICapnpSerializable).IsAssignableFrom(type)) if (typeof(ICapnpSerializable).IsAssignableFrom(type))
{ {
try try
{ {
return ((IConstructibleFromDeserializerState<object>) return ((IConstructibleFromDeserializerState)
Activator.CreateInstance(typeof(FromStruct<>).MakeGenericType(type))).Create; Activator.CreateInstance(typeof(FromStruct<>).MakeGenericType(type))!).Create;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -94,12 +95,12 @@ namespace Capnp
try try
{ {
var elementType = type.GetGenericArguments()[0]; var elementType = type.GetGenericArguments()[0];
return ((IConstructibleFromDeserializerState<object>) return ((IConstructibleFromDeserializerState)
Activator.CreateInstance(typeof(FromList<>).MakeGenericType(elementType))).Create; Activator.CreateInstance(typeof(FromList<>).MakeGenericType(elementType))!).Create;
} }
catch (TargetInvocationException ex) catch (TargetInvocationException ex)
{ {
throw ex.InnerException; throw ex.InnerException!;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -123,8 +124,8 @@ namespace Capnp
try try
{ {
return ((IConstructibleFromDeserializerState<object>) return ((IConstructibleFromDeserializerState)
Activator.CreateInstance(typeof(FromCapability<>).MakeGenericType(type))).Create; Activator.CreateInstance(typeof(FromCapability<>).MakeGenericType(type))!).Create;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -135,7 +136,7 @@ namespace Capnp
} }
} }
static Func<DeserializerState, object> GetSerializer(Type type) static Func<DeserializerState, object?> GetSerializer(Type type)
{ {
return _typeMap.GetValue(type, CreateSerializer); return _typeMap.GetValue(type, CreateSerializer);
} }
@ -164,10 +165,11 @@ namespace Capnp
/// </typeparam> /// </typeparam>
/// <param name="state"></param> /// <param name="state"></param>
/// <returns></returns> /// <returns></returns>
public static T Create<T>(DeserializerState state) public static T? Create<T>(DeserializerState state)
where T: class where T: class
{ {
return (T)GetSerializer(typeof(T))(state); return (T?)GetSerializer(typeof(T))(state);
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -23,3 +24,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -47,7 +49,7 @@ namespace Capnp
/// <summary> /// <summary>
/// The capabilities imported from the capability table. Only valid in RPC context. /// The capabilities imported from the capability table. Only valid in RPC context.
/// </summary> /// </summary>
public IList<Rpc.ConsumedCapability> Caps { get; set; } public IList<Rpc.ConsumedCapability?>? Caps { get; set; }
/// <summary> /// <summary>
/// Current segment (essentially Segments[CurrentSegmentIndex] /// Current segment (essentially Segments[CurrentSegmentIndex]
/// </summary> /// </summary>
@ -83,11 +85,16 @@ namespace Capnp
/// The conversion is cheap, since it does not involve copying any payload. /// The conversion is cheap, since it does not involve copying any payload.
/// </summary> /// </summary>
/// <param name="state">The serializer state to be converted</param> /// <param name="state">The serializer state to be converted</param>
/// <exception cref="ArgumentNullException"><paramref name="state"/> is null</exception>
/// <exception cref="InvalidOperationException"><paramref name="state"/> is not bound to a MessageBuilder</exception>
public static implicit operator DeserializerState(SerializerState state) public static implicit operator DeserializerState(SerializerState state)
{ {
if (state == null) if (state == null)
throw new ArgumentNullException(nameof(state)); throw new ArgumentNullException(nameof(state));
if (state.MsgBuilder == null)
throw new InvalidOperationException("state is not bound to a MessageBuilder");
switch (state.Kind) switch (state.Kind)
{ {
case ObjectKind.ListOfBits: case ObjectKind.ListOfBits:
@ -100,7 +107,7 @@ namespace Capnp
case ObjectKind.ListOfStructs: case ObjectKind.ListOfStructs:
case ObjectKind.Nil: case ObjectKind.Nil:
case ObjectKind.Struct: case ObjectKind.Struct:
return new DeserializerState(state.Allocator.Segments) return new DeserializerState(state.Allocator!.Segments)
{ {
CurrentSegmentIndex = state.SegmentIndex, CurrentSegmentIndex = state.SegmentIndex,
Offset = state.Offset, Offset = state.Offset,
@ -112,7 +119,7 @@ namespace Capnp
}; };
case ObjectKind.Capability: case ObjectKind.Capability:
return new DeserializerState(state.Allocator.Segments) return new DeserializerState(state.Allocator!.Segments)
{ {
Kind = ObjectKind.Capability, Kind = ObjectKind.Capability,
Caps = state.Caps, Caps = state.Caps,
@ -376,11 +383,11 @@ namespace Capnp
/// the capability table. Does not mutate this state. /// the capability table. Does not mutate this state.
/// </summary> /// </summary>
/// <param name="offset">Offset relative to this.Offset within current segment</param> /// <param name="offset">Offset relative to this.Offset within current segment</param>
/// <returns>the low-level capability object</returns> /// <returns>the low-level capability object, or null if it is a null pointer</returns>
/// <exception cref="IndexOutOfRangeException">offset negative or out of range</exception> /// <exception cref="IndexOutOfRangeException">offset negative or out of range</exception>
/// <exception cref="InvalidOperationException">capability table not set</exception> /// <exception cref="InvalidOperationException">capability table not set</exception>
/// <exception cref="Rpc.RpcException">not a capability pointer or invalid capability index</exception> /// <exception cref="Rpc.RpcException">not a capability pointer or invalid capability index</exception>
internal Rpc.ConsumedCapability DecodeCapPointer(int offset) internal Rpc.ConsumedCapability? DecodeCapPointer(int offset)
{ {
if (offset < 0) if (offset < 0)
{ {
@ -490,7 +497,7 @@ namespace Capnp
return state; return state;
} }
internal Rpc.ConsumedCapability StructReadRawCap(int index) internal Rpc.ConsumedCapability? StructReadRawCap(int index)
{ {
if (Kind != ObjectKind.Struct && Kind != ObjectKind.Nil) if (Kind != ObjectKind.Struct && Kind != ObjectKind.Nil)
throw new InvalidOperationException("Allowed on structs only"); throw new InvalidOperationException("Allowed on structs only");
@ -567,7 +574,7 @@ namespace Capnp
/// <exception cref="IndexOutOfRangeException">negative index</exception> /// <exception cref="IndexOutOfRangeException">negative index</exception>
/// <exception cref="DeserializationException">state does not represent a struct, invalid pointer, /// <exception cref="DeserializationException">state does not represent a struct, invalid pointer,
/// non-list-of-bytes pointer, traversal limit exceeded</exception> /// non-list-of-bytes pointer, traversal limit exceeded</exception>
public string ReadText(int index, string defaultText = null) public string? ReadText(int index, string? defaultText = null)
{ {
return StructReadPointer(index).RequireList().CastText() ?? defaultText; return StructReadPointer(index).RequireList().CastText() ?? defaultText;
} }
@ -646,7 +653,7 @@ namespace Capnp
/// <exception cref="IndexOutOfRangeException">negative index</exception> /// <exception cref="IndexOutOfRangeException">negative index</exception>
/// <exception cref="DeserializationException">state does not represent a struct, invalid pointer, /// <exception cref="DeserializationException">state does not represent a struct, invalid pointer,
/// non-capability pointer, traversal limit exceeded</exception> /// non-capability pointer, traversal limit exceeded</exception>
public T ReadCap<T>(int index, public T? ReadCap<T>(int index,
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
[System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) where T: class [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) where T: class
@ -677,7 +684,7 @@ namespace Capnp
/// <returns>capability instance or null if pointer was null</returns> /// <returns>capability instance or null if pointer was null</returns>
/// <exception cref="IndexOutOfRangeException">negative index</exception> /// <exception cref="IndexOutOfRangeException">negative index</exception>
/// <exception cref="DeserializationException">state does not represent a capability</exception> /// <exception cref="DeserializationException">state does not represent a capability</exception>
public T RequireCap<T>() where T: class public T? RequireCap<T>() where T: class
{ {
if (Kind == ObjectKind.Nil) if (Kind == ObjectKind.Nil)
return null; return null;
@ -685,7 +692,11 @@ namespace Capnp
if (Kind != ObjectKind.Capability) if (Kind != ObjectKind.Capability)
throw new DeserializationException("Expected a capability"); throw new DeserializationException("Expected a capability");
if (Caps == null)
throw new InvalidOperationException("Capability table not set. This is a bug.");
return Rpc.CapabilityReflection.CreateProxy<T>(Caps[(int)CapabilityIndex]) as T; return Rpc.CapabilityReflection.CreateProxy<T>(Caps[(int)CapabilityIndex]) as T;
} }
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -226,3 +227,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -36,3 +37,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -86,3 +87,4 @@ namespace Capnp
public override IReadOnlyList<ushort> CastUShort() => new EmptyList<ushort>(); public override IReadOnlyList<ushort> CastUShort() => new EmptyList<ushort>();
} }
} }
#nullable restore

View File

@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -22,7 +23,7 @@ namespace Capnp
int _disposing; int _disposing;
readonly Stream _stream; readonly Stream _stream;
readonly BinaryWriter _writer; readonly BinaryWriter? _writer;
readonly object _writeLock = new object(); readonly object _writeLock = new object();
readonly List<IFrameTracer> _tracers = new List<IFrameTracer>(); readonly List<IFrameTracer> _tracers = new List<IFrameTracer>();
@ -62,7 +63,7 @@ namespace Capnp
/// <summary> /// <summary>
/// Event handler for frame reception. /// Event handler for frame reception.
/// </summary> /// </summary>
public event Action<WireFrame> FrameReceived; public event Action<WireFrame>? FrameReceived;
/// <summary> /// <summary>
/// Sends a message over the stream. /// Sends a message over the stream.
@ -196,3 +197,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp.FrameTracing namespace Capnp.FrameTracing
{ {
/// <summary> /// <summary>
@ -31,3 +32,4 @@ namespace Capnp.FrameTracing
void TraceFrame(FrameDirection direction, WireFrame frame); void TraceFrame(FrameDirection direction, WireFrame frame);
} }
} }
#nullable restore

View File

@ -6,6 +6,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
#nullable enable
namespace Capnp.FrameTracing namespace Capnp.FrameTracing
{ {
/// <summary> /// <summary>
@ -245,3 +246,4 @@ namespace Capnp.FrameTracing
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -107,3 +108,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp #nullable enable
namespace Capnp
{ {
/// <summary> /// <summary>
/// This interface is intended to be implemented by schema-generated domain classes which support deserialization from /// This interface is intended to be implemented by schema-generated domain classes which support deserialization from
@ -19,3 +20,4 @@
void Deserialize(DeserializerState state); void Deserialize(DeserializerState state);
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -27,3 +28,4 @@ namespace Capnp
bool Allocate(uint nwords, uint preferredSegment, out SegmentSlice slice, bool forcePreferredSegment); bool Allocate(uint nwords, uint preferredSegment, out SegmentSlice slice, bool forcePreferredSegment);
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -20,3 +21,4 @@ namespace Capnp
ulong StructReadData(ulong bitOffset, int bitCount); ulong StructReadData(ulong bitOffset, int bitCount);
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -25,3 +26,4 @@ namespace Capnp
Span<ulong> StructDataSection { get; } Span<ulong> StructDataSection { get; }
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -10,7 +11,7 @@ namespace Capnp
{ {
static class GenericCasts<T> static class GenericCasts<T>
{ {
public static Func<ListDeserializer, T> CastFunc; public static Func<ListDeserializer, T>? CastFunc;
} }
static ListDeserializer() static ListDeserializer()
@ -401,3 +402,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp #nullable enable
namespace Capnp
{ {
/// <summary> /// <summary>
/// Enumerates the list element categories which are defined by Cap'n Proto. /// Enumerates the list element categories which are defined by Cap'n Proto.
@ -46,3 +47,4 @@
ListOfStructs = 7 ListOfStructs = 7
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -77,3 +78,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -96,3 +97,4 @@ namespace Capnp
IEnumerator IEnumerable.GetEnumerator() => this.ToArray().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.ToArray().GetEnumerator();
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -29,7 +30,7 @@ namespace Capnp
if (index < 0 || index >= Count) if (index < 0 || index >= Count)
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
return Rpc.CapabilityReflection.CreateProxy<T>(State.DecodeCapPointer(index)) as T; return (Rpc.CapabilityReflection.CreateProxy<T>(State.DecodeCapPointer(index)) as T)!;
} }
} }
@ -70,3 +71,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -34,7 +34,7 @@ namespace Capnp
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of range.</exception> /// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of range.</exception>
public T this[int index] public T this[int index]
{ {
get => Rpc.CapabilityReflection.CreateProxy<T>(DecodeCapPointer(index)) as T; get => (Rpc.CapabilityReflection.CreateProxy<T>(DecodeCapPointer(index)) as T)!;
set set
{ {
if (!IsAllocated) if (!IsAllocated)
@ -109,3 +109,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -64,3 +65,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -31,3 +32,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -89,3 +90,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -12,7 +13,7 @@ namespace Capnp
/// <typeparam name="TS">SerializerState which represents the element type</typeparam> /// <typeparam name="TS">SerializerState which represents the element type</typeparam>
public class ListOfPointersSerializer<TS>: public class ListOfPointersSerializer<TS>:
SerializerState, SerializerState,
IReadOnlyList<TS> IReadOnlyList<TS?>
where TS: SerializerState, new() where TS: SerializerState, new()
{ {
/// <summary> /// <summary>
@ -51,7 +52,7 @@ namespace Capnp
/// </summary> /// </summary>
public int Count => ListElementCount; public int Count => ListElementCount;
IEnumerable<TS> Enumerate() IEnumerable<TS?> Enumerate()
{ {
int count = Count; int count = Count;
@ -64,7 +65,7 @@ namespace Capnp
/// <summary> /// <summary>
/// Implements <see cref="IEnumerable{TS}"/>. /// Implements <see cref="IEnumerable{TS}"/>.
/// </summary> /// </summary>
public IEnumerator<TS> GetEnumerator() public IEnumerator<TS?> GetEnumerator()
{ {
return Enumerate().GetEnumerator(); return Enumerate().GetEnumerator();
} }
@ -115,4 +116,4 @@ namespace Capnp
} }
} }
} }
#nullable enable

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -232,3 +233,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -94,3 +95,4 @@ namespace Capnp
IEnumerator IEnumerable.GetEnumerator() => Data.ToArray().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Data.ToArray().GetEnumerator();
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -79,3 +80,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -93,3 +94,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -9,7 +10,7 @@ namespace Capnp
/// </summary> /// </summary>
public class ListOfTextSerializer : public class ListOfTextSerializer :
SerializerState, SerializerState,
IReadOnlyList<string> IReadOnlyList<string?>
{ {
/// <summary> /// <summary>
/// Gets or sets the text at given index. Once an element is set, it cannot be overwritten. /// Gets or sets the text at given index. Once an element is set, it cannot be overwritten.
@ -18,7 +19,7 @@ namespace Capnp
/// <exception cref="InvalidOperationException">List is not initialized</exception> /// <exception cref="InvalidOperationException">List is not initialized</exception>
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of range.</exception> /// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of range.</exception>
/// <exception cref="ArgumentOutOfRangeException">UTF-8 encoding exceeds 2^29-2 bytes</exception> /// <exception cref="ArgumentOutOfRangeException">UTF-8 encoding exceeds 2^29-2 bytes</exception>
public string this[int index] public string? this[int index]
{ {
get get
{ {
@ -47,7 +48,7 @@ namespace Capnp
/// </summary> /// </summary>
public int Count => ListElementCount; public int Count => ListElementCount;
IEnumerable<string> Enumerate() IEnumerable<string?> Enumerate()
{ {
int count = Count; int count = Count;
@ -60,7 +61,7 @@ namespace Capnp
/// <summary> /// <summary>
/// Implementation of <see cref="IEnumerable{String}"/>/> /// Implementation of <see cref="IEnumerable{String}"/>/>
/// </summary> /// </summary>
public IEnumerator<string> GetEnumerator() public IEnumerator<string?> GetEnumerator()
{ {
return Enumerate().GetEnumerator(); return Enumerate().GetEnumerator();
} }
@ -110,3 +111,4 @@ namespace Capnp
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -21,3 +22,4 @@ namespace Capnp
public static ILogger CreateLogger<T>() => LoggerFactory.CreateLogger<T>(); public static ILogger CreateLogger<T>() => LoggerFactory.CreateLogger<T>();
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -12,7 +13,7 @@ namespace Capnp
{ {
readonly ISegmentAllocator _allocator; readonly ISegmentAllocator _allocator;
readonly DynamicSerializerState _rootPtrBuilder; readonly DynamicSerializerState _rootPtrBuilder;
List<Rpc.ConsumedCapability> _capTable; List<Rpc.ConsumedCapability?>? _capTable;
MessageBuilder(ISegmentAllocator allocator) MessageBuilder(ISegmentAllocator allocator)
{ {
@ -56,10 +57,11 @@ namespace Capnp
/// Gets or sets the root object. The root object must be set exactly once per message. /// Gets or sets the root object. The root object must be set exactly once per message.
/// Setting it manually is only required (and allowed) when it was created with <see cref="CreateObject{TS}"/>. /// Setting it manually is only required (and allowed) when it was created with <see cref="CreateObject{TS}"/>.
/// </summary> /// </summary>
public SerializerState Root /// <exception cref="ArgumentNullException">Attempt to set null reference</exception>
public SerializerState? Root
{ {
get => _rootPtrBuilder.TryGetPointer(0); get => _rootPtrBuilder.TryGetPointer(0);
set => _rootPtrBuilder.Link(0, value); set => _rootPtrBuilder.Link(0, value ?? throw new ArgumentNullException(nameof(value)));
} }
/// <summary> /// <summary>
@ -90,13 +92,14 @@ namespace Capnp
if (_capTable != null) if (_capTable != null)
throw new InvalidOperationException("Capability table was already initialized"); throw new InvalidOperationException("Capability table was already initialized");
_capTable = new List<Rpc.ConsumedCapability>(); _capTable = new List<Rpc.ConsumedCapability?>();
} }
/// <summary> /// <summary>
/// Returns this message builder's segment allocator. /// Returns this message builder's segment allocator.
/// </summary> /// </summary>
public ISegmentAllocator Allocator => _allocator; public ISegmentAllocator Allocator => _allocator;
internal List<Rpc.ConsumedCapability> Caps => _capTable; internal List<Rpc.ConsumedCapability?>? Caps => _capTable;
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -71,3 +72,4 @@ namespace Capnp
Value = 16 Value = 16
} }
} }
#nullable restore

View File

@ -2,13 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
class PrimitiveCoder class PrimitiveCoder
{ {
class Coder<T> class Coder<T>
{ {
public static Func<T, T, T> Fn { get; set; } public static Func<T, T, T>? Fn { get; set; }
} }
static PrimitiveCoder() static PrimitiveCoder()
@ -45,3 +46,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -71,3 +72,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -103,3 +104,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// Helper struct to support tail calls /// Helper struct to support tail calls
@ -33,11 +34,12 @@
/// <summary> /// <summary>
/// SerializerState, if applicable /// SerializerState, if applicable
/// </summary> /// </summary>
public SerializerState Answer => _obj as SerializerState; public SerializerState? Answer => _obj as SerializerState;
/// <summary> /// <summary>
/// PendingQuestion, if applicable /// PendingQuestion, if applicable
/// </summary> /// </summary>
public PendingQuestion Counterquestion => _obj as PendingQuestion; public PendingQuestion? Counterquestion => _obj as PendingQuestion;
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// Generic Proxy implementation which exposes the (usually protected) Call method. /// Generic Proxy implementation which exposes the (usually protected) Call method.
@ -33,7 +34,7 @@
/// Constructs an instance and binds it to the given low-level capability. /// Constructs an instance and binds it to the given low-level capability.
/// </summary> /// </summary>
/// <param name="cap">low-level capability</param> /// <param name="cap">low-level capability</param>
public BareProxy(ConsumedCapability cap): base(cap) public BareProxy(ConsumedCapability? cap): base(cap)
{ {
} }
@ -50,3 +51,4 @@
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -110,7 +111,7 @@ namespace Capnp.Rpc
return (SkeletonFactory)Activator.CreateInstance( return (SkeletonFactory)Activator.CreateInstance(
typeof(SkeletonFactory<>) typeof(SkeletonFactory<>)
.MakeGenericType(skeletonClass)); .MakeGenericType(skeletonClass))!;
} }
static SkeletonFactory GetSkeletonFactory(Type type) static SkeletonFactory GetSkeletonFactory(Type type)
@ -190,7 +191,7 @@ namespace Capnp.Rpc
return (ProxyFactory)Activator.CreateInstance( return (ProxyFactory)Activator.CreateInstance(
typeof(ProxyFactory<>) typeof(ProxyFactory<>)
.MakeGenericType(proxyClass)); .MakeGenericType(proxyClass))!;
} }
else else
{ {
@ -263,7 +264,7 @@ namespace Capnp.Rpc
/// <exception cref="System.Reflection.TargetInvocationException">Problem with instatiating the Proxy (constructor threw exception).</exception> /// <exception cref="System.Reflection.TargetInvocationException">Problem with instatiating the Proxy (constructor threw exception).</exception>
/// <exception cref="MemberAccessException">Caller does not have permission to invoke the Proxy constructor.</exception> /// <exception cref="MemberAccessException">Caller does not have permission to invoke the Proxy constructor.</exception>
/// <exception cref="TypeLoadException">Problem with building the Proxy type, or problem with loading some dependent class.</exception> /// <exception cref="TypeLoadException">Problem with building the Proxy type, or problem with loading some dependent class.</exception>
public static Proxy CreateProxy<TInterface>(ConsumedCapability cap, public static Proxy CreateProxy<TInterface>(ConsumedCapability? cap,
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
[System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
@ -286,3 +287,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// State of an RPC connection /// State of an RPC connection
@ -22,3 +23,4 @@
Down Down
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -18,7 +19,7 @@ namespace Capnp.Rpc
/// </summary> /// </summary>
protected abstract void ReleaseRemotely(); protected abstract void ReleaseRemotely();
internal abstract void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer); internal abstract void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer);
internal abstract void Freeze(out IRpcEndpoint boundEndpoint); internal abstract void Freeze(out IRpcEndpoint? boundEndpoint);
internal abstract void Unfreeze(); internal abstract void Unfreeze();
internal abstract void AddRef(); internal abstract void AddRef();
@ -31,3 +32,4 @@ namespace Capnp.Rpc
#endif #endif
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using Capnp.FrameTracing; using Capnp.FrameTracing;
using System; using System;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -58,3 +59,4 @@ namespace Capnp.Rpc
void Close(); void Close();
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// A uni-directional endpoint, used in conjunction with the <see cref="RpcEngine"/>. /// A uni-directional endpoint, used in conjunction with the <see cref="RpcEngine"/>.
@ -16,3 +17,4 @@
void Dismiss(); void Dismiss();
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// A mono skeleton (as opposed to <see cref="PolySkeleton"/>) is a skeleton which implements one particular RPC interface. /// A mono skeleton (as opposed to <see cref="PolySkeleton"/>) is a skeleton which implements one particular RPC interface.
@ -11,3 +12,4 @@
ulong InterfaceId { get; } ulong InterfaceId { get; }
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -22,6 +23,7 @@ namespace Capnp.Rpc
/// </summary> /// </summary>
/// <param name="access">Path to the desired capability inside the result struct.</param> /// <param name="access">Path to the desired capability inside the result struct.</param>
/// <returns>Pipelined low-level capability</returns> /// <returns>Pipelined low-level capability</returns>
ConsumedCapability Access(MemberAccessPath access); ConsumedCapability? Access(MemberAccessPath access);
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
@ -22,3 +23,4 @@ namespace Capnp.Rpc
DeserializerState args, CancellationToken cancellationToken = default); DeserializerState args, CancellationToken cancellationToken = default);
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -13,3 +14,4 @@ namespace Capnp.Rpc
Task<Proxy> WhenResolved { get; } Task<Proxy> WhenResolved { get; }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
internal interface IRpcEndpoint internal interface IRpcEndpoint
@ -19,3 +20,4 @@ namespace Capnp.Rpc
void DeleteQuestion(PendingQuestion question); void DeleteQuestion(PendingQuestion question);
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -11,7 +12,7 @@ namespace Capnp.Rpc
public static class Impatient public static class Impatient
{ {
static readonly ConditionalWeakTable<Task, IPromisedAnswer> _taskTable = new ConditionalWeakTable<Task, IPromisedAnswer>(); static readonly ConditionalWeakTable<Task, IPromisedAnswer> _taskTable = new ConditionalWeakTable<Task, IPromisedAnswer>();
static readonly ThreadLocal<IRpcEndpoint> _askingEndpoint = new ThreadLocal<IRpcEndpoint>(); static readonly ThreadLocal<IRpcEndpoint?> _askingEndpoint = new ThreadLocal<IRpcEndpoint?>();
/// <summary> /// <summary>
/// Attaches a continuation to the given promise and registers the resulting task for pipelining. /// Attaches a continuation to the given promise and registers the resulting task for pipelining.
@ -51,7 +52,7 @@ namespace Capnp.Rpc
} }
else if (rtask.IsFaulted) else if (rtask.IsFaulted)
{ {
rtask = Task.FromException<T>(rtask.Exception.InnerException); rtask = Task.FromException<T>(rtask.Exception!.InnerException!);
} }
else else
{ {
@ -86,7 +87,7 @@ namespace Capnp.Rpc
return answer; return answer;
} }
internal static IPromisedAnswer TryGetAnswer(Task task) internal static IPromisedAnswer? TryGetAnswer(Task task)
{ {
_taskTable.TryGetValue(task, out var answer); _taskTable.TryGetValue(task, out var answer);
return answer; return answer;
@ -102,10 +103,10 @@ namespace Capnp.Rpc
return proxy; return proxy;
case null: case null:
return null; return CapabilityReflection.CreateProxy<T>(null);
} }
var skel = Skeleton.GetOrCreateSkeleton(item, false); var skel = Skeleton.GetOrCreateSkeleton(item!, false);
var localCap = LocalCapability.Create(skel); var localCap = LocalCapability.Create(skel);
return CapabilityReflection.CreateProxy<T>(localCap); return CapabilityReflection.CreateProxy<T>(localCap);
} }
@ -131,7 +132,7 @@ namespace Capnp.Rpc
where TInterface : class where TInterface : class
{ {
var lazyCap = new LazyCapability(AwaitProxy(task)); var lazyCap = new LazyCapability(AwaitProxy(task));
return CapabilityReflection.CreateProxy<TInterface>(lazyCap, memberName, sourceFilePath, sourceLineNumber) as TInterface; return (CapabilityReflection.CreateProxy<TInterface>(lazyCap, memberName, sourceFilePath, sourceLineNumber) as TInterface)!;
} }
static readonly MemberAccessPath Path_OneAndOnly = new MemberAccessPath(0U); static readonly MemberAccessPath Path_OneAndOnly = new MemberAccessPath(0U);
@ -168,15 +169,15 @@ namespace Capnp.Rpc
} }
var lazyCap = new LazyCapability(AwaitProxy(task)); var lazyCap = new LazyCapability(AwaitProxy(task));
return CapabilityReflection.CreateProxy<TInterface>(lazyCap) as TInterface; return (CapabilityReflection.CreateProxy<TInterface>(lazyCap) as TInterface)!;
} }
else else
{ {
return CapabilityReflection.CreateProxy<TInterface>(answer.Access(Path_OneAndOnly)) as TInterface; return (CapabilityReflection.CreateProxy<TInterface>(answer.Access(Path_OneAndOnly)) as TInterface)!;
} }
} }
internal static IRpcEndpoint AskingEndpoint internal static IRpcEndpoint? AskingEndpoint
{ {
get => _askingEndpoint.Value; get => _askingEndpoint.Value;
set { _askingEndpoint.Value = value; } set { _askingEndpoint.Value = value; }
@ -252,3 +253,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -52,3 +53,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc.Interception namespace Capnp.Rpc.Interception
{ {
@ -34,7 +35,7 @@ namespace Capnp.Rpc.Interception
return new Proxy(Access(access)); return new Proxy(Access(access));
} }
public ConsumedCapability Access(MemberAccessPath access) public ConsumedCapability? Access(MemberAccessPath access)
{ {
if (_futureResult.Task.IsCompleted) if (_futureResult.Task.IsCompleted)
{ {
@ -44,7 +45,7 @@ namespace Capnp.Rpc.Interception
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
} }
else else
@ -107,7 +108,7 @@ namespace Capnp.Rpc.Interception
/// <summary> /// <summary>
/// Input arguments /// Input arguments
/// </summary> /// </summary>
public SerializerState InArgs { get; set; } public SerializerState? InArgs { get; set; }
/// <summary> /// <summary>
/// Output arguments ("return value") /// Output arguments ("return value")
@ -117,7 +118,7 @@ namespace Capnp.Rpc.Interception
/// <summary> /// <summary>
/// Exception text, or null if there is no exception /// Exception text, or null if there is no exception
/// </summary> /// </summary>
public string Exception { get; set; } public string? Exception { get; set; }
/// <summary> /// <summary>
/// Whether the call should return in canceled state to Alice (the original caller). /// Whether the call should return in canceled state to Alice (the original caller).
@ -156,7 +157,7 @@ namespace Capnp.Rpc.Interception
/// <item><description>null</description></item> /// <item><description>null</description></item>
/// </list> /// </list>
/// </summary> /// </summary>
public object Bob public object? Bob
{ {
get => _bob; get => _bob;
set set
@ -196,11 +197,11 @@ namespace Capnp.Rpc.Interception
} }
} }
internal Proxy BobProxy { get; private set; } internal Proxy? BobProxy { get; private set; }
readonly CensorCapability _censorCapability; readonly CensorCapability _censorCapability;
PromisedAnswer _promisedAnswer; PromisedAnswer _promisedAnswer;
object _bob; object? _bob;
internal IPromisedAnswer Answer => _promisedAnswer; internal IPromisedAnswer Answer => _promisedAnswer;
@ -224,8 +225,13 @@ namespace Capnp.Rpc.Interception
{ {
for (int i = 0; i < state.Caps.Count; i++) for (int i = 0; i < state.Caps.Count; i++)
{ {
state.Caps[i] = policy.Attach(state.Caps[i]); var cap = state.Caps[i];
state.Caps[i].AddRef(); if (cap != null)
{
cap = policy.Attach(cap);
state.Caps[i] = cap;
cap.AddRef();
}
} }
} }
} }
@ -236,8 +242,13 @@ namespace Capnp.Rpc.Interception
{ {
for (int i = 0; i < state.Caps.Count; i++) for (int i = 0; i < state.Caps.Count; i++)
{ {
state.Caps[i] = policy.Detach(state.Caps[i]); var cap = state.Caps[i];
state.Caps[i].AddRef(); if (cap != null)
{
cap = policy.Detach(cap);
state.Caps[i] = cap;
cap.AddRef();
}
} }
} }
} }
@ -246,8 +257,12 @@ namespace Capnp.Rpc.Interception
/// Intercepts all capabilies inside the input arguments /// Intercepts all capabilies inside the input arguments
/// </summary> /// </summary>
/// <param name="policyOverride">Policy to use, or null to further use present policy</param> /// <param name="policyOverride">Policy to use, or null to further use present policy</param>
public void InterceptInCaps(IInterceptionPolicy policyOverride = null) /// <exception cref="InvalidOperationException">InArgs not set</exception>
public void InterceptInCaps(IInterceptionPolicy? policyOverride = null)
{ {
if (InArgs == null)
throw new InvalidOperationException("InArgs not set");
InterceptCaps(InArgs, policyOverride ?? _censorCapability.Policy); InterceptCaps(InArgs, policyOverride ?? _censorCapability.Policy);
} }
@ -255,7 +270,7 @@ namespace Capnp.Rpc.Interception
/// Intercepts all capabilies inside the output arguments /// Intercepts all capabilies inside the output arguments
/// </summary> /// </summary>
/// <param name="policyOverride">Policy to use, or null to further use present policy</param> /// <param name="policyOverride">Policy to use, or null to further use present policy</param>
public void InterceptOutCaps(IInterceptionPolicy policyOverride = null) public void InterceptOutCaps(IInterceptionPolicy? policyOverride = null)
{ {
InterceptCaps(OutArgs, policyOverride ?? _censorCapability.Policy); InterceptCaps(OutArgs, policyOverride ?? _censorCapability.Policy);
} }
@ -264,8 +279,12 @@ namespace Capnp.Rpc.Interception
/// Unintercepts all capabilies inside the input arguments /// Unintercepts all capabilies inside the input arguments
/// </summary> /// </summary>
/// <param name="policyOverride">Policy to remove, or null to remove present policy</param> /// <param name="policyOverride">Policy to remove, or null to remove present policy</param>
public void UninterceptInCaps(IInterceptionPolicy policyOverride = null) /// <exception cref="InvalidOperationException">InArgs not set</exception>
public void UninterceptInCaps(IInterceptionPolicy? policyOverride = null)
{ {
if (InArgs == null)
throw new InvalidOperationException("InArgs not set");
UninterceptCaps(InArgs, policyOverride ?? _censorCapability.Policy); UninterceptCaps(InArgs, policyOverride ?? _censorCapability.Policy);
} }
@ -273,7 +292,7 @@ namespace Capnp.Rpc.Interception
/// Unintercepts all capabilies inside the output arguments /// Unintercepts all capabilies inside the output arguments
/// </summary> /// </summary>
/// <param name="policyOverride">Policy to remove, or null to remove present policy</param> /// <param name="policyOverride">Policy to remove, or null to remove present policy</param>
public void UninterceptOutCaps(IInterceptionPolicy policyOverride = null) public void UninterceptOutCaps(IInterceptionPolicy? policyOverride = null)
{ {
UninterceptCaps(OutArgs, policyOverride ?? _censorCapability.Policy); UninterceptCaps(OutArgs, policyOverride ?? _censorCapability.Policy);
} }
@ -281,14 +300,16 @@ namespace Capnp.Rpc.Interception
/// <summary> /// <summary>
/// Forwards this intercepted call to the target capability ("Bob"). /// Forwards this intercepted call to the target capability ("Bob").
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">Bob/InArgs not set</exception>
public void ForwardToBob() public void ForwardToBob()
{ {
if (Bob == null) if (Bob == null)
{
throw new InvalidOperationException("Bob is null"); throw new InvalidOperationException("Bob is null");
}
var answer = BobProxy.Call(InterfaceId, MethodId, InArgs.Rewrap<DynamicSerializerState>(), default, CancelToBob); if (InArgs == null)
throw new InvalidOperationException("InArgs not set");
var answer = BobProxy!.Call(InterfaceId, MethodId, InArgs.Rewrap<DynamicSerializerState>(), default, CancelToBob);
State = InterceptionState.ForwardedToBob; State = InterceptionState.ForwardedToBob;
@ -336,3 +357,4 @@ namespace Capnp.Rpc.Interception
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc.Interception #nullable enable
namespace Capnp.Rpc.Interception
{ {
class CensorCapability : RefCountingCapability class CensorCapability : RefCountingCapability
{ {
@ -32,7 +33,7 @@
writer.SenderHosted = endpoint.AllocateExport(MyVine, out bool _); writer.SenderHosted = endpoint.AllocateExport(MyVine, out bool _);
} }
internal override void Freeze(out IRpcEndpoint boundEndpoint) internal override void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
boundEndpoint = null; boundEndpoint = null;
} }
@ -42,3 +43,4 @@
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp.Rpc.Interception namespace Capnp.Rpc.Interception
{ {
/// <summary> /// <summary>
@ -21,3 +22,4 @@ namespace Capnp.Rpc.Interception
void OnReturnFromBob(CallContext callContext); void OnReturnFromBob(CallContext callContext);
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc.Interception #nullable enable
namespace Capnp.Rpc.Interception
{ {
/// <summary> /// <summary>
/// The state of an intercepted call from Alice to Bob. /// The state of an intercepted call from Alice to Bob.
@ -26,3 +27,4 @@
ReturnedToAlice ReturnedToAlice
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
#nullable enable
namespace Capnp.Rpc.Interception namespace Capnp.Rpc.Interception
{ {
/// <summary> /// <summary>
@ -45,16 +46,16 @@ namespace Capnp.Rpc.Interception
switch (cap) switch (cap)
{ {
case Proxy proxy: case Proxy proxy:
return CapabilityReflection.CreateProxy<TCap>(Attach(policy, proxy.ConsumedCap)) as TCap; return (CapabilityReflection.CreateProxy<TCap>(Attach(policy, proxy.ConsumedCap!)) as TCap)!;
case ConsumedCapability ccap: case ConsumedCapability ccap:
return new CensorCapability(ccap, policy) as TCap; return (new CensorCapability(ccap, policy) as TCap)!;
default: default:
return Attach(policy, return (Attach(policy,
CapabilityReflection.CreateProxy<TCap>( (CapabilityReflection.CreateProxy<TCap>(
LocalCapability.Create( LocalCapability.Create(
Skeleton.GetOrCreateSkeleton(cap, false))) as TCap); Skeleton.GetOrCreateSkeleton(cap, false))) as TCap)!));
} }
} }
@ -79,11 +80,11 @@ namespace Capnp.Rpc.Interception
switch (cap) switch (cap)
{ {
case Proxy proxy: case Proxy proxy:
return CapabilityReflection.CreateProxy<TCap>(Detach(policy, proxy.ConsumedCap)) as TCap; return (CapabilityReflection.CreateProxy<TCap>(Detach(policy, proxy.ConsumedCap!)) as TCap)!;
case CensorCapability ccap: case CensorCapability ccap:
{ {
var cur = ccap; CensorCapability? cur = ccap;
var stk = new Stack<IInterceptionPolicy>(); var stk = new Stack<IInterceptionPolicy>();
do do
@ -96,7 +97,7 @@ namespace Capnp.Rpc.Interception
{ {
cur2 = p.Attach(cur2); cur2 = p.Attach(cur2);
} }
return cur2 as TCap; return (cur2 as TCap)!;
} }
stk.Push(cur.Policy); stk.Push(cur.Policy);
@ -104,7 +105,7 @@ namespace Capnp.Rpc.Interception
} }
while (cur != null); while (cur != null);
return ccap as TCap; return (ccap as TCap)!;
} }
default: default:
@ -113,3 +114,4 @@ namespace Capnp.Rpc.Interception
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// Will be thrown if a type did not qualify as capability interface. /// Will be thrown if a type did not qualify as capability interface.
@ -22,3 +23,4 @@
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class LazyCapability : RefCountingCapability, IResolvingCapability class LazyCapability : RefCountingCapability, IResolvingCapability
@ -27,7 +28,7 @@ namespace Capnp.Rpc
WhenResolved = capabilityTask; WhenResolved = capabilityTask;
} }
internal override void Freeze(out IRpcEndpoint boundEndpoint) internal override void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
if (WhenResolved.IsCompleted) if (WhenResolved.IsCompleted)
{ {
@ -37,7 +38,7 @@ namespace Capnp.Rpc
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
} }
else else
@ -106,3 +107,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class LocalAnswer : IPromisedAnswer class LocalAnswer : IPromisedAnswer
@ -50,3 +51,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class LocalAnswerCapability : RefCountingCapability, IResolvingCapability class LocalAnswerCapability : RefCountingCapability, IResolvingCapability
@ -15,7 +16,7 @@ namespace Capnp.Rpc
_access = access; _access = access;
} }
internal override void Freeze(out IRpcEndpoint boundEndpoint) internal override void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
boundEndpoint = null; boundEndpoint = null;
} }
@ -43,7 +44,7 @@ namespace Capnp.Rpc
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
using (var proxy = new Proxy(_access.Eval(result))) using (var proxy = new Proxy(_access.Eval(result)))
@ -87,3 +88,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class LocalCapability : ConsumedCapability class LocalCapability : ConsumedCapability
@ -14,7 +15,7 @@ namespace Capnp.Rpc
public static ConsumedCapability Create(Skeleton skeleton) public static ConsumedCapability Create(Skeleton skeleton)
{ {
if (skeleton is Vine vine) if (skeleton is Vine vine)
return vine.Proxy.ConsumedCap; return vine.Proxy.ConsumedCap!;
else else
return _localCaps.GetValue(skeleton, _ => new LocalCapability(_)); return _localCaps.GetValue(skeleton, _ => new LocalCapability(_));
} }
@ -22,7 +23,7 @@ namespace Capnp.Rpc
static async Task<DeserializerState> AwaitAnswer(Task<AnswerOrCounterquestion> call) static async Task<DeserializerState> AwaitAnswer(Task<AnswerOrCounterquestion> call)
{ {
var aorcq = await call; var aorcq = await call;
return aorcq.Answer ?? await aorcq.Counterquestion.WhenReturned; return aorcq.Answer ?? await aorcq.Counterquestion!.WhenReturned;
} }
public Skeleton ProvidedCap { get; } public Skeleton ProvidedCap { get; }
@ -55,7 +56,7 @@ namespace Capnp.Rpc
capDesc.SenderHosted = endpoint.AllocateExport(ProvidedCap, out bool _); capDesc.SenderHosted = endpoint.AllocateExport(ProvidedCap, out bool _);
} }
internal override void Freeze(out IRpcEndpoint boundEndpoint) internal override void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
boundEndpoint = null; boundEndpoint = null;
} }
@ -69,3 +70,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -169,7 +170,7 @@ namespace Capnp.Rpc
/// <param name="rpcState">The object (usually "params struct") on which to evaluate this path.</param> /// <param name="rpcState">The object (usually "params struct") on which to evaluate this path.</param>
/// <returns>Resulting low-level capability</returns> /// <returns>Resulting low-level capability</returns>
/// <exception cref="DeserializationException">Evaluation of this path did not give a capability</exception> /// <exception cref="DeserializationException">Evaluation of this path did not give a capability</exception>
public ConsumedCapability Eval(DeserializerState rpcState) public ConsumedCapability? Eval(DeserializerState rpcState)
{ {
var cur = rpcState; var cur = rpcState;
@ -184,7 +185,7 @@ namespace Capnp.Rpc
return null; return null;
case ObjectKind.Capability: case ObjectKind.Capability:
return rpcState.Caps[(int)cur.CapabilityIndex]; return rpcState.Caps![(int)cur.CapabilityIndex];
default: default:
throw new DeserializationException("Access path did not result in a capability"); throw new DeserializationException("Access path did not result in a capability");
@ -192,3 +193,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -3,19 +3,20 @@ using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class PendingAnswer: IDisposable class PendingAnswer: IDisposable
{ {
readonly object _reentrancyBlocker = new object(); readonly object _reentrancyBlocker = new object();
readonly CancellationTokenSource _cts; readonly CancellationTokenSource? _cts;
readonly TaskCompletionSource<int> _whenCanceled; readonly TaskCompletionSource<int> _whenCanceled;
Task<AnswerOrCounterquestion> _callTask; Task<AnswerOrCounterquestion> _callTask;
Task _initialTask; Task? _initialTask;
Task _chainedTask; Task? _chainedTask;
bool _disposed; bool _disposed;
public PendingAnswer(Task<AnswerOrCounterquestion> callTask, CancellationTokenSource cts) public PendingAnswer(Task<AnswerOrCounterquestion> callTask, CancellationTokenSource? cts)
{ {
_cts = cts; _cts = cts;
_callTask = callTask ?? throw new ArgumentNullException(nameof(callTask)); _callTask = callTask ?? throw new ArgumentNullException(nameof(callTask));
@ -138,7 +139,7 @@ namespace Capnp.Rpc
case ObjectKind.Capability: case ObjectKind.Capability:
try try
{ {
var cap = aorcq.Answer.Caps[(int)cur.CapabilityIndex]; var cap = aorcq.Answer.Caps![(int)cur.CapabilityIndex];
proxy = new Proxy(cap ?? LazyCapability.Null); proxy = new Proxy(cap ?? LazyCapability.Null);
} }
catch (ArgumentOutOfRangeException) catch (ArgumentOutOfRangeException)
@ -154,7 +155,7 @@ namespace Capnp.Rpc
else else
{ {
var path = MemberAccessPath.Deserialize(rd); var path = MemberAccessPath.Deserialize(rd);
var cap = new RemoteAnswerCapability(aorcq.Counterquestion, path); var cap = new RemoteAnswerCapability(aorcq.Counterquestion!, path);
return new Proxy(cap); return new Proxy(cap);
} }
} }
@ -169,7 +170,7 @@ namespace Capnp.Rpc
{ {
if (_cts != null) if (_cts != null)
{ {
Task chainedTask; Task? chainedTask;
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -199,3 +200,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -61,11 +62,11 @@ namespace Capnp.Rpc
readonly TaskCompletionSource<DeserializerState> _tcs = new TaskCompletionSource<DeserializerState>(); readonly TaskCompletionSource<DeserializerState> _tcs = new TaskCompletionSource<DeserializerState>();
readonly uint _questionId; readonly uint _questionId;
ConsumedCapability _target; ConsumedCapability? _target;
SerializerState _inParams; SerializerState? _inParams;
int _inhibitFinishCounter; int _inhibitFinishCounter;
internal PendingQuestion(IRpcEndpoint ep, uint id, ConsumedCapability target, SerializerState inParams) internal PendingQuestion(IRpcEndpoint ep, uint id, ConsumedCapability? target, SerializerState? inParams)
{ {
RpcEndpoint = ep ?? throw new ArgumentNullException(nameof(ep)); RpcEndpoint = ep ?? throw new ArgumentNullException(nameof(ep));
_questionId = id; _questionId = id;
@ -75,7 +76,7 @@ namespace Capnp.Rpc
if (inParams != null) if (inParams != null)
{ {
foreach (var cap in inParams.Caps) foreach (var cap in inParams.Caps!)
{ {
cap?.AddRef(); cap?.AddRef();
} }
@ -236,7 +237,7 @@ namespace Capnp.Rpc
/// <param name="access">Access path</param> /// <param name="access">Access path</param>
/// <returns>Low-level capability</returns> /// <returns>Low-level capability</returns>
/// <exception cref="DeserializationException">The referenced member does not exist or does not resolve to a capability pointer.</exception> /// <exception cref="DeserializationException">The referenced member does not exist or does not resolve to a capability pointer.</exception>
public ConsumedCapability Access(MemberAccessPath access) public ConsumedCapability? Access(MemberAccessPath access)
{ {
lock (ReentrancyBlocker) lock (ReentrancyBlocker)
{ {
@ -249,7 +250,7 @@ namespace Capnp.Rpc
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
} }
else else
@ -259,11 +260,11 @@ namespace Capnp.Rpc
} }
} }
static void ReleaseCaps(ConsumedCapability target, SerializerState inParams) static void ReleaseCaps(ConsumedCapability? target, SerializerState? inParams)
{ {
if (inParams != null) if (inParams != null)
{ {
foreach (var cap in inParams.Caps) foreach (var cap in inParams.Caps!)
{ {
cap?.Release(); cap?.Release();
} }
@ -277,7 +278,7 @@ namespace Capnp.Rpc
static void ReleaseOutCaps(DeserializerState outParams) static void ReleaseOutCaps(DeserializerState outParams)
{ {
foreach (var cap in outParams.Caps) foreach (var cap in outParams.Caps!)
{ {
cap?.Release(); cap?.Release();
} }
@ -285,12 +286,13 @@ namespace Capnp.Rpc
internal void Send() internal void Send()
{ {
SerializerState inParams; SerializerState? inParams;
ConsumedCapability target; ConsumedCapability? target;
lock (ReentrancyBlocker) lock (ReentrancyBlocker)
{ {
Debug.Assert(!StateFlags.HasFlag(State.Sent)); if (StateFlags.HasFlag(State.Sent))
throw new InvalidOperationException("Already sent");
inParams = _inParams; inParams = _inParams;
_inParams = null; _inParams = null;
@ -299,7 +301,7 @@ namespace Capnp.Rpc
StateFlags |= State.Sent; StateFlags |= State.Sent;
} }
var msg = (Message.WRITER)inParams.MsgBuilder.Root; var msg = (Message.WRITER)inParams!.MsgBuilder!.Root!;
Debug.Assert(msg.Call.Target.which != MessageTarget.WHICH.undefined); Debug.Assert(msg.Call.Target.which != MessageTarget.WHICH.undefined);
var call = msg.Call; var call = msg.Call;
call.QuestionId = QuestionId; call.QuestionId = QuestionId;
@ -316,15 +318,15 @@ namespace Capnp.Rpc
OnException(exception); OnException(exception);
} }
ReleaseCaps(target, inParams); ReleaseCaps(target!, inParams);
} }
#region IDisposable Support #region IDisposable Support
void Dispose(bool disposing) void Dispose(bool disposing)
{ {
SerializerState inParams; SerializerState? inParams;
ConsumedCapability target; ConsumedCapability? target;
bool justDisposed = false; bool justDisposed = false;
lock (ReentrancyBlocker) lock (ReentrancyBlocker)
@ -377,3 +379,4 @@ namespace Capnp.Rpc
#endregion #endregion
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -71,3 +72,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class PromisedCapability : RemoteResolvingCapability class PromisedCapability : RemoteResolvingCapability
@ -19,7 +20,7 @@ namespace Capnp.Rpc
public override Task<Proxy> WhenResolved => _resolvedCap.Task; public override Task<Proxy> WhenResolved => _resolvedCap.Task;
internal override void Freeze(out IRpcEndpoint boundEndpoint) internal override void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -31,7 +32,7 @@ namespace Capnp.Rpc
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
} }
else else
@ -148,7 +149,7 @@ namespace Capnp.Rpc
} }
} }
protected override Proxy ResolvedCap protected override Proxy? ResolvedCap
{ {
get get
{ {
@ -158,7 +159,7 @@ namespace Capnp.Rpc
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
} }
} }
@ -258,3 +259,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -38,7 +39,7 @@ namespace Capnp.Rpc
/// <summary> /// <summary>
/// Underlying low-level capability /// Underlying low-level capability
/// </summary> /// </summary>
protected internal ConsumedCapability ConsumedCap { get; private set; } protected internal ConsumedCapability? ConsumedCap { get; private set; }
/// <summary> /// <summary>
/// Whether is this a broken capability. /// Whether is this a broken capability.
@ -99,12 +100,12 @@ namespace Capnp.Rpc
{ {
} }
internal Proxy(ConsumedCapability cap) internal Proxy(ConsumedCapability? cap)
{ {
Bind(cap); Bind(cap);
} }
internal void Bind(ConsumedCapability cap) internal void Bind(ConsumedCapability? cap)
{ {
if (ConsumedCap != null) if (ConsumedCap != null)
throw new InvalidOperationException("Proxy was already bound"); throw new InvalidOperationException("Proxy was already bound");
@ -116,7 +117,7 @@ namespace Capnp.Rpc
cap.AddRef(); cap.AddRef();
} }
internal IProvidedCapability GetProvider() internal IProvidedCapability? GetProvider()
{ {
switch (ConsumedCap) switch (ConsumedCap)
{ {
@ -200,7 +201,7 @@ namespace Capnp.Rpc
using (disposeThis ? this : null) using (disposeThis ? this : null)
{ {
return CapabilityReflection.CreateProxy<T>(ConsumedCap) as T; return (CapabilityReflection.CreateProxy<T>(ConsumedCap) as T)!;
} }
} }
@ -215,7 +216,7 @@ namespace Capnp.Rpc
ConsumedCap.Export(endpoint, writer); ConsumedCap.Export(endpoint, writer);
} }
internal void Freeze(out IRpcEndpoint boundEndpoint) internal void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
if (_disposedValue) if (_disposedValue)
throw new ObjectDisposedException(nameof(Proxy)); throw new ObjectDisposedException(nameof(Proxy));
@ -239,3 +240,4 @@ namespace Capnp.Rpc
#endif #endif
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -28,3 +29,4 @@ namespace Capnp.Rpc
public Type ProxyClass { get; } public Type ProxyClass { get; }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
abstract class RefCountingCapability: ConsumedCapability abstract class RefCountingCapability: ConsumedCapability
@ -112,3 +113,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class RemoteAnswerCapability : RemoteResolvingCapability class RemoteAnswerCapability : RemoteResolvingCapability
@ -18,7 +19,7 @@ namespace Capnp.Rpc
readonly PendingQuestion _question; readonly PendingQuestion _question;
readonly MemberAccessPath _access; readonly MemberAccessPath _access;
Proxy _resolvedCap; Proxy? _resolvedCap;
public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access): base(question.RpcEndpoint) public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access): base(question.RpcEndpoint)
{ {
@ -59,7 +60,7 @@ namespace Capnp.Rpc
} }
} }
protected override Proxy ResolvedCap protected override Proxy? ResolvedCap
{ {
get get
{ {
@ -74,7 +75,7 @@ namespace Capnp.Rpc
} }
catch (AggregateException exception) catch (AggregateException exception)
{ {
throw exception.InnerException; throw exception.InnerException!;
} }
_resolvedCap = new Proxy(_access.Eval(result)); _resolvedCap = new Proxy(_access.Eval(result));
@ -87,7 +88,11 @@ namespace Capnp.Rpc
async Task<Proxy> AwaitWhenResolved() async Task<Proxy> AwaitWhenResolved()
{ {
await _question.WhenReturned; await _question.WhenReturned;
return ResolvedCap;
if (_question.IsTailCall)
throw new InvalidOperationException("Question is a tail call, so won't resolve back.");
return ResolvedCap!;
} }
public override Task<Proxy> WhenResolved => AwaitWhenResolved(); public override Task<Proxy> WhenResolved => AwaitWhenResolved();
@ -168,7 +173,7 @@ namespace Capnp.Rpc
return call; return call;
} }
internal override void Freeze(out IRpcEndpoint boundEndpoint) internal override void Freeze(out IRpcEndpoint? boundEndpoint)
{ {
lock (_question.ReentrancyBlocker) lock (_question.ReentrancyBlocker)
{ {
@ -216,7 +221,7 @@ namespace Capnp.Rpc
if (_question.StateFlags.HasFlag(PendingQuestion.State.Returned)) if (_question.StateFlags.HasFlag(PendingQuestion.State.Returned))
{ {
ResolvedCap.Export(endpoint, writer); ResolvedCap?.Export(endpoint, writer);
} }
else else
{ {
@ -255,3 +260,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
@ -24,6 +25,9 @@ namespace Capnp.Rpc
protected virtual Call.WRITER SetupMessage(DynamicSerializerState args, ulong interfaceId, ushort methodId) protected virtual Call.WRITER SetupMessage(DynamicSerializerState args, ulong interfaceId, ushort methodId)
{ {
if (args.MsgBuilder == null)
throw new ArgumentException("Unbound serializer state", nameof(args));
var callMsg = args.MsgBuilder.BuildRoot<Message.WRITER>(); var callMsg = args.MsgBuilder.BuildRoot<Message.WRITER>();
callMsg.which = Message.WHICH.Call; callMsg.which = Message.WHICH.Call;
@ -38,3 +42,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -3,6 +3,7 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
abstract class RemoteResolvingCapability : RemoteCapability, IResolvingCapability abstract class RemoteResolvingCapability : RemoteCapability, IResolvingCapability
@ -23,14 +24,17 @@ namespace Capnp.Rpc
} }
protected int _pendingCallsOnPromise; protected int _pendingCallsOnPromise;
Task _disembargo; Task? _disembargo;
protected abstract Proxy ResolvedCap { get; } protected abstract Proxy? ResolvedCap { get; }
protected abstract void GetMessageTarget(MessageTarget.WRITER wr); protected abstract void GetMessageTarget(MessageTarget.WRITER wr);
protected IPromisedAnswer CallOnResolution(ulong interfaceId, ushort methodId, DynamicSerializerState args) protected IPromisedAnswer CallOnResolution(ulong interfaceId, ushort methodId, DynamicSerializerState args)
{ {
if (ResolvedCap == null)
throw new InvalidOperationException("Capability not yet resolved, calling on resolution not possible");
try try
{ {
ResolvedCap.Freeze(out var resolvedCapEndpoint); ResolvedCap.Freeze(out var resolvedCapEndpoint);
@ -124,3 +128,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
static class ResolvingCapabilityExtensions static class ResolvingCapabilityExtensions
{ {
@ -19,7 +20,7 @@
{ {
var resolvedCap = await cap.WhenResolved; var resolvedCap = await cap.WhenResolved;
endpoint.Resolve(preliminaryId, vine, () => resolvedCap.ConsumedCap); endpoint.Resolve(preliminaryId, vine, () => resolvedCap.ConsumedCap!);
} }
catch (System.Exception exception) catch (System.Exception exception)
{ {
@ -42,3 +43,4 @@
} }
} }
} }
#nullable restore

View File

@ -10,6 +10,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -65,8 +66,8 @@ namespace Capnp.Rpc
internal class RpcEndpoint : IEndpoint, IRpcEndpoint internal class RpcEndpoint : IEndpoint, IRpcEndpoint
{ {
static readonly ThreadLocal<Action> _exportCapTablePostActions = new ThreadLocal<Action>(); static readonly ThreadLocal<Action?> _exportCapTablePostActions = new ThreadLocal<Action?>();
static readonly ThreadLocal<PendingQuestion> _tailCall = new ThreadLocal<PendingQuestion>(); static readonly ThreadLocal<PendingQuestion?> _tailCall = new ThreadLocal<PendingQuestion?>();
static readonly ThreadLocal<bool> _canDeferCalls = new ThreadLocal<bool>(); static readonly ThreadLocal<bool> _canDeferCalls = new ThreadLocal<bool>();
ILogger Logger { get; } = Logging.CreateLogger<RpcEndpoint>(); ILogger Logger { get; } = Logging.CreateLogger<RpcEndpoint>();
@ -145,8 +146,7 @@ namespace Capnp.Rpc
Tx(mb.Frame); Tx(mb.Frame);
} }
void IRpcEndpoint.Resolve(uint preliminaryId, Skeleton preliminaryCap, void IRpcEndpoint.Resolve(uint preliminaryId, Skeleton preliminaryCap, Func<ConsumedCapability> resolvedCapGetter)
Func<ConsumedCapability> resolvedCapGetter)
{ {
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -232,7 +232,7 @@ namespace Capnp.Rpc
return AllocateExport(providedCapability, out first); return AllocateExport(providedCapability, out first);
} }
PendingQuestion AllocateQuestion(ConsumedCapability target, SerializerState inParams) PendingQuestion AllocateQuestion(ConsumedCapability? target, SerializerState? inParams)
{ {
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -293,7 +293,7 @@ namespace Capnp.Rpc
uint q = req.QuestionId; uint q = req.QuestionId;
var bootstrap = DynamicSerializerState.CreateForRpc(); var bootstrap = DynamicSerializerState.CreateForRpc();
var ans = bootstrap.MsgBuilder.BuildRoot<Message.WRITER>(); var ans = bootstrap.MsgBuilder!.BuildRoot<Message.WRITER>();
ans.which = Message.WHICH.Return; ans.which = Message.WHICH.Return;
var ret = ans.Return; var ret = ans.Return;
@ -305,7 +305,7 @@ namespace Capnp.Rpc
if (bootstrapCap != null) if (bootstrapCap != null)
{ {
ret.which = Return.WHICH.Results; ret.which = Return.WHICH.Results;
bootstrap.SetCapability(bootstrap.ProvideCapability(LocalCapability.Create(_host.BootstrapCap))); bootstrap.SetCapability(bootstrap.ProvideCapability(LocalCapability.Create(bootstrapCap)));
ret.Results.Content = bootstrap; ret.Results.Content = bootstrap;
bootstrapTask = Task.FromResult<AnswerOrCounterquestion>(bootstrap); bootstrapTask = Task.FromResult<AnswerOrCounterquestion>(bootstrap);
@ -371,12 +371,12 @@ namespace Capnp.Rpc
} }
catch (RpcException exception) catch (RpcException exception)
{ {
Logger.LogWarning($"Unable to return call: {exception.InnerException.Message}"); Logger.LogWarning($"Unable to return call: {exception.InnerException?.Message ?? exception.Message}");
} }
} }
IProvidedCapability cap; IProvidedCapability? cap;
PendingAnswer pendingAnswer = null; PendingAnswer? pendingAnswer = null;
bool releaseParamCaps = false; bool releaseParamCaps = false;
void AwaitAnswerAndReply() void AwaitAnswerAndReply()
@ -414,8 +414,8 @@ namespace Capnp.Rpc
} }
else if (aorcq.Answer != null || aorcq.Counterquestion != _tailCall.Value) else if (aorcq.Answer != null || aorcq.Counterquestion != _tailCall.Value)
{ {
var results = aorcq.Answer ?? (DynamicSerializerState)(await aorcq.Counterquestion.WhenReturned); var results = aorcq.Answer ?? (DynamicSerializerState)(await aorcq.Counterquestion!.WhenReturned);
var ret = SetupReturn(results.MsgBuilder); var ret = SetupReturn(results.MsgBuilder!);
switch (req.SendResultsTo.which) switch (req.SendResultsTo.which)
{ {
@ -569,7 +569,7 @@ namespace Capnp.Rpc
case MessageTarget.WHICH.PromisedAnswer: case MessageTarget.WHICH.PromisedAnswer:
{ {
bool exists; bool exists;
PendingAnswer previousAnswer; PendingAnswer? previousAnswer;
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -578,7 +578,7 @@ namespace Capnp.Rpc
if (exists) if (exists)
{ {
previousAnswer.Chain( previousAnswer!.Chain(
false, false,
req.Target.PromisedAnswer, req.Target.PromisedAnswer,
async t => async t =>
@ -633,7 +633,7 @@ namespace Capnp.Rpc
void ProcessReturn(Return.READER req) void ProcessReturn(Return.READER req)
{ {
PendingQuestion question; PendingQuestion? question;
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -674,7 +674,7 @@ namespace Capnp.Rpc
case Return.WHICH.TakeFromOtherQuestion: case Return.WHICH.TakeFromOtherQuestion:
{ {
bool exists; bool exists;
PendingAnswer pendingAnswer; PendingAnswer? pendingAnswer;
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -683,7 +683,7 @@ namespace Capnp.Rpc
if (exists) if (exists)
{ {
pendingAnswer.Chain(false, async t => pendingAnswer!.Chain(false, async t =>
{ {
try try
{ {
@ -747,6 +747,8 @@ namespace Capnp.Rpc
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
var resolvedCap = ImportCap(resolve.Cap); var resolvedCap = ImportCap(resolve.Cap);
if (resolvedCap == null)
resolvedCap = LazyCapability.CreateBrokenCap("Failed to resolve this capability");
resolvableCap.ResolveTo(resolvedCap); resolvableCap.ResolveTo(resolvedCap);
} }
break; break;
@ -935,7 +937,7 @@ namespace Capnp.Rpc
{ {
foreach (var cap in results.Caps) foreach (var cap in results.Caps)
{ {
cap.Release(); cap?.Release();
} }
} }
}); });
@ -984,8 +986,8 @@ namespace Capnp.Rpc
try try
{ {
int icount = checked((int)count); int icount = checked((int)count);
rc.Release(icount); rc!.Release(icount);
rc.Cap.Relinquish(icount); rc!.Cap.Relinquish(icount);
if (rc.RefCount == 0) if (rc.RefCount == 0)
{ {
@ -1171,7 +1173,7 @@ namespace Capnp.Rpc
} }
} }
ConsumedCapability ImportCap(CapDescriptor.READER capDesc) ConsumedCapability? ImportCap(CapDescriptor.READER capDesc)
{ {
lock (_reentrancyBlocker) lock (_reentrancyBlocker)
{ {
@ -1192,8 +1194,7 @@ namespace Capnp.Rpc
rcw.Cap.SetTarget(impCap); rcw.Cap.SetTarget(impCap);
} }
Debug.Assert(impCap != null); return impCap!;
return impCap;
} }
else else
{ {
@ -1236,7 +1237,6 @@ namespace Capnp.Rpc
case CapDescriptor.WHICH.ReceiverHosted: case CapDescriptor.WHICH.ReceiverHosted:
if (_exportTable.TryGetValue(capDesc.ReceiverHosted, out var rc)) if (_exportTable.TryGetValue(capDesc.ReceiverHosted, out var rc))
{ {
Debug.Assert(rc.Cap != null);
return LocalCapability.Create(rc.Cap); return LocalCapability.Create(rc.Cap);
} }
else else
@ -1311,9 +1311,9 @@ namespace Capnp.Rpc
} }
} }
public IList<ConsumedCapability> ImportCapTable(Payload.READER payload) public IList<ConsumedCapability?> ImportCapTable(Payload.READER payload)
{ {
var list = new List<ConsumedCapability>(); var list = new List<ConsumedCapability?>();
if (payload.CapTable != null) if (payload.CapTable != null)
{ {
@ -1341,7 +1341,7 @@ namespace Capnp.Rpc
Debug.Assert(_exportCapTablePostActions.Value == null); Debug.Assert(_exportCapTablePostActions.Value == null);
_exportCapTablePostActions.Value = null; _exportCapTablePostActions.Value = null;
payload.CapTable.Init(state.MsgBuilder.Caps.Count); payload.CapTable.Init(state.MsgBuilder!.Caps!.Count);
int i = 0; int i = 0;
foreach (var cap in state.MsgBuilder.Caps) foreach (var cap in state.MsgBuilder.Caps)
@ -1454,7 +1454,7 @@ namespace Capnp.Rpc
} }
catch (RpcException exception) catch (RpcException exception)
{ {
Logger.LogWarning($"Unable to release import: {exception.InnerException.Message}"); Logger.LogWarning($"Unable to release import: {exception.InnerException?.Message ?? exception.Message}");
} }
} }
} }
@ -1492,12 +1492,12 @@ namespace Capnp.Rpc
return inboundEndpoint; return inboundEndpoint;
} }
Skeleton _bootstrapCap; Skeleton? _bootstrapCap;
/// <summary> /// <summary>
/// Gets or sets the bootstrap capability. /// Gets or sets the bootstrap capability.
/// </summary> /// </summary>
public Skeleton BootstrapCap public Skeleton? BootstrapCap
{ {
get => _bootstrapCap; get => _bootstrapCap;
set set
@ -1509,3 +1509,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
/// Thrown when an RPC-related error condition occurs. /// Thrown when an RPC-related error condition occurs.
@ -20,3 +21,4 @@
} }
} }
} }
#nullable restore

View File

@ -1,6 +1,8 @@
namespace Capnp.Rpc #nullable enable
namespace Capnp.Rpc
{ {
class RpcUnimplementedException : System.Exception class RpcUnimplementedException : System.Exception
{ {
} }
} }
#nullable restore

View File

@ -6,6 +6,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -179,8 +180,8 @@ namespace Capnp.Rpc
ILogger Logger { get; } = Logging.CreateLogger<Skeleton<T>>(); ILogger Logger { get; } = Logging.CreateLogger<Skeleton<T>>();
#endif #endif
Func<DeserializerState, CancellationToken, Task<AnswerOrCounterquestion>>[] _methods; Func<DeserializerState, CancellationToken, Task<AnswerOrCounterquestion>>[] _methods = null!;
CancellationTokenSource _disposed = new CancellationTokenSource(); CancellationTokenSource? _disposed = new CancellationTokenSource();
readonly object _reentrancyBlocker = new object(); readonly object _reentrancyBlocker = new object();
int _pendingCalls; int _pendingCalls;
@ -204,7 +205,7 @@ namespace Capnp.Rpc
/// <summary> /// <summary>
/// Gets the underlying capability implementation. /// Gets the underlying capability implementation.
/// </summary> /// </summary>
protected T Impl { get; private set; } protected T Impl { get; private set; } = default!;
/// <summary> /// <summary>
/// Gets the ID of the implemented interface. /// Gets the ID of the implemented interface.
@ -299,3 +300,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -32,3 +33,4 @@ namespace Capnp.Rpc
public Type SkeletonClass { get; } public Type SkeletonClass { get; }
} }
} }
#nullable restore

View File

@ -10,6 +10,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -44,17 +45,17 @@ namespace Capnp.Rpc
readonly RpcEngine _rpcEngine; readonly RpcEngine _rpcEngine;
readonly TcpClient _client; readonly TcpClient _client;
RpcEngine.RpcEndpoint _inboundEndpoint; RpcEngine.RpcEndpoint? _inboundEndpoint;
OutboundTcpEndpoint _outboundEndpoint; OutboundTcpEndpoint? _outboundEndpoint;
FramePump _pump; FramePump? _pump;
Thread _pumpThread; Thread? _pumpThread;
Action _attachTracerAction; Action? _attachTracerAction;
/// <summary> /// <summary>
/// Gets a Task which completes when TCP is connected. Will be /// Gets a Task which completes when TCP is connected. Will be
/// null until connection is actually requested (either by calling Connect or using appropriate constructor). /// null until connection is actually requested (either by calling Connect or using appropriate constructor).
/// </summary> /// </summary>
public Task WhenConnected { get; private set; } public Task? WhenConnected { get; private set; }
async Task ConnectAsync(string host, int port) async Task ConnectAsync(string host, int port)
{ {
@ -152,8 +153,14 @@ namespace Capnp.Rpc
/// </summary> /// </summary>
/// <typeparam name="TProxy">Bootstrap capability interface</typeparam> /// <typeparam name="TProxy">Bootstrap capability interface</typeparam>
/// <returns>A proxy for the bootstrap capability</returns> /// <returns>A proxy for the bootstrap capability</returns>
/// <exception cref="InvalidOperationException">Not connected</exception>
public TProxy GetMain<TProxy>() where TProxy: class public TProxy GetMain<TProxy>() where TProxy: class
{ {
if (WhenConnected == null)
{
throw new InvalidOperationException("Not connecting");
}
if (!WhenConnected.IsCompleted) if (!WhenConnected.IsCompleted)
{ {
throw new InvalidOperationException("Connection not yet established"); throw new InvalidOperationException("Connection not yet established");
@ -164,9 +171,7 @@ namespace Capnp.Rpc
throw new InvalidOperationException("Connection not successfully established"); throw new InvalidOperationException("Connection not successfully established");
} }
Debug.Assert(_inboundEndpoint != null); return (CapabilityReflection.CreateProxy<TProxy>(_inboundEndpoint!.QueryMain()) as TProxy)!;
return CapabilityReflection.CreateProxy<TProxy>(_inboundEndpoint.QueryMain()) as TProxy;
} }
/// <summary> /// <summary>
@ -178,7 +183,7 @@ namespace Capnp.Rpc
try try
{ {
if (!WhenConnected.Wait(500)) if (WhenConnected != null && !WhenConnected.Wait(500))
{ {
Logger.LogError("Unable to join connection task within timeout"); Logger.LogError("Unable to join connection task within timeout");
} }
@ -214,7 +219,7 @@ namespace Capnp.Rpc
_attachTracerAction += () => _attachTracerAction += () =>
{ {
_pump.AttachTracer(tracer); _pump?.AttachTracer(tracer);
}; };
} }
@ -234,33 +239,34 @@ namespace Capnp.Rpc
/// <summary> /// <summary>
/// Gets the number of RPC protocol messages sent by this client so far. /// Gets the number of RPC protocol messages sent by this client so far.
/// </summary> /// </summary>
public long SendCount => _inboundEndpoint.SendCount; public long SendCount => _inboundEndpoint?.SendCount ?? 0;
/// <summary> /// <summary>
/// Gets the number of RPC protocol messages received by this client so far. /// Gets the number of RPC protocol messages received by this client so far.
/// </summary> /// </summary>
public long RecvCount => _inboundEndpoint.RecvCount; public long RecvCount => _inboundEndpoint?.RecvCount ?? 0;
/// <summary> /// <summary>
/// Gets the remote port number which this client is connected to, /// Gets the remote port number which this client is connected to,
/// or null if the connection is not yet established. /// or null if the connection is not yet established.
/// </summary> /// </summary>
public int? RemotePort => ((IPEndPoint)_client.Client?.RemoteEndPoint)?.Port; public int? RemotePort => ((IPEndPoint)_client.Client.RemoteEndPoint)?.Port;
/// <summary> /// <summary>
/// Gets the local port number which this client using, /// Gets the local port number which this client using,
/// or null if the connection is not yet established. /// or null if the connection is not yet established.
/// </summary> /// </summary>
public int? LocalPort => ((IPEndPoint)_client.Client?.LocalEndPoint)?.Port; public int? LocalPort => ((IPEndPoint)_client.Client.LocalEndPoint)?.Port;
/// <summary> /// <summary>
/// Whether the I/O thread is currently running /// Whether the I/O thread is currently running
/// </summary> /// </summary>
public bool IsComputing => _pumpThread.ThreadState == System.Threading.ThreadState.Running; public bool IsComputing => _pumpThread?.ThreadState == System.Threading.ThreadState.Running;
/// <summary> /// <summary>
/// Whether the I/O thread is waiting for data to receive /// Whether the I/O thread is waiting for data to receive
/// </summary> /// </summary>
public bool IsWaitingForData => _pump.IsWaitingForData; public bool IsWaitingForData => _pump?.IsWaitingForData ?? false;
} }
} }
#nullable restore

View File

@ -6,6 +6,7 @@ using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> /// <summary>
@ -103,12 +104,12 @@ namespace Capnp.Rpc
public FramePump Pump { get; private set; } public FramePump Pump { get; private set; }
public OutboundTcpEndpoint OutboundEp { get; private set; } public OutboundTcpEndpoint OutboundEp { get; private set; }
public RpcEngine.RpcEndpoint InboundEp { get; private set; } public RpcEngine.RpcEndpoint InboundEp { get; private set; }
public Thread PumpRunner { get; private set; } public Thread? PumpRunner { get; private set; }
public int? LocalPort => ((IPEndPoint)Client.Client.LocalEndPoint)?.Port; public int? LocalPort => ((IPEndPoint)Client.Client.LocalEndPoint)?.Port;
public int? RemotePort => ((IPEndPoint)Client.Client.RemoteEndPoint)?.Port; public int? RemotePort => ((IPEndPoint)Client.Client.RemoteEndPoint)?.Port;
public long RecvCount => InboundEp.RecvCount; public long RecvCount => InboundEp.RecvCount;
public long SendCount => InboundEp.SendCount; public long SendCount => InboundEp.SendCount;
public bool IsComputing => PumpRunner.ThreadState == ThreadState.Running; public bool IsComputing => PumpRunner?.ThreadState == ThreadState.Running;
public bool IsWaitingForData => Pump.IsWaitingForData; public bool IsWaitingForData => Pump.IsWaitingForData;
public void AttachTracer(IFrameTracer tracer) public void AttachTracer(IFrameTracer tracer)
@ -165,7 +166,7 @@ namespace Capnp.Rpc
connection.Start(); connection.Start();
} }
connection.PumpRunner.Start(); connection.PumpRunner!.Start();
} }
} }
catch (SocketException) catch (SocketException)
@ -180,8 +181,13 @@ namespace Capnp.Rpc
} }
} }
void SafeJoin(Thread thread) void SafeJoin(Thread? thread)
{ {
if (thread == null)
{
return;
}
for (int retry = 0; retry < 5; ++retry) for (int retry = 0; retry < 5; ++retry)
{ {
try try
@ -313,6 +319,7 @@ namespace Capnp.Rpc
/// <summary> /// <summary>
/// Fires when a new incoming connection was accepted, or when an active connection is closed. /// Fires when a new incoming connection was accepted, or when an active connection is closed.
/// </summary> /// </summary>
public event Action<object, ConnectionEventArgs> OnConnectionChanged; public event Action<object, ConnectionEventArgs>? OnConnectionChanged;
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
class Vine : Skeleton class Vine : Skeleton
@ -70,3 +71,4 @@ namespace Capnp.Rpc
} }
} }
} }
#nullable restore

View File

@ -1,4 +1,5 @@
namespace Capnp #nullable enable
namespace Capnp
{ {
/// <summary> /// <summary>
/// Provides the security bounds for defeating amplification and stack overflow DoS attacks. /// Provides the security bounds for defeating amplification and stack overflow DoS attacks.
@ -16,3 +17,4 @@
public static int RecursionLimit { get; set; } = 64; public static int RecursionLimit { get; set; } = 64;
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -145,3 +146,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -18,3 +19,4 @@ namespace Capnp
public int Offset; public int Offset;
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -339,3 +340,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -29,10 +30,10 @@ namespace Capnp
return s; return s;
} }
internal MessageBuilder MsgBuilder { get; set; } internal MessageBuilder? MsgBuilder { get; set; }
internal ISegmentAllocator Allocator => MsgBuilder?.Allocator; internal ISegmentAllocator? Allocator => MsgBuilder?.Allocator;
internal List<Rpc.ConsumedCapability> Caps => MsgBuilder?.Caps; internal List<Rpc.ConsumedCapability?>? Caps => MsgBuilder?.Caps;
internal SerializerState Owner { get; set; } internal SerializerState? Owner { get; set; }
internal int OwnerSlot { get; set; } internal int OwnerSlot { get; set; }
internal uint SegmentIndex { get; set; } internal uint SegmentIndex { get; set; }
internal int Offset { get; set; } internal int Offset { get; set; }
@ -43,7 +44,7 @@ namespace Capnp
internal ObjectKind Kind { get; set; } internal ObjectKind Kind { get; set; }
internal uint CapabilityIndex { get; set; } internal uint CapabilityIndex { get; set; }
SerializerState[] _linkedStates; SerializerState[]? _linkedStates;
/// <summary> /// <summary>
/// Constructs an unbound serializer state. /// Constructs an unbound serializer state.
@ -129,7 +130,7 @@ namespace Capnp
if (Owner != null) if (Owner != null)
ts.Bind(Owner, OwnerSlot); ts.Bind(Owner, OwnerSlot);
else else
ts.Bind(MsgBuilder); ts.Bind(MsgBuilder ?? throw Unbound());
return ts; return ts;
} }
@ -152,8 +153,8 @@ namespace Capnp
/// </summary> /// </summary>
public bool IsAllocated => Offset >= 0; public bool IsAllocated => Offset >= 0;
Span<ulong> SegmentSpan => IsAllocated ? Allocator.Segments[(int)SegmentIndex].Span : Span<ulong>.Empty; Span<ulong> SegmentSpan => IsAllocated && Allocator != null ? Allocator.Segments[(int)SegmentIndex].Span : Span<ulong>.Empty;
Span<ulong> FarSpan(uint index) => Allocator.Segments[(int)index].Span; Span<ulong> FarSpan(uint index) => Allocator!.Segments[(int)index].Span;
/// <summary> /// <summary>
/// Given this state describes a struct and is allocated, returns the struct's data section. /// Given this state describes a struct and is allocated, returns the struct's data section.
@ -181,6 +182,9 @@ namespace Capnp
} }
else else
{ {
if (Allocator == null)
throw Unbound();
SegmentIndex = Owner?.SegmentIndex ?? SegmentIndex; SegmentIndex = Owner?.SegmentIndex ?? SegmentIndex;
Allocator.Allocate(count, SegmentIndex, out var slice, false); Allocator.Allocate(count, SegmentIndex, out var slice, false);
SegmentIndex = slice.SegmentIndex; SegmentIndex = slice.SegmentIndex;
@ -191,7 +195,7 @@ namespace Capnp
} }
/// <summary> /// <summary>
/// Allocates storage for the underlying object. Does nothing if it is already allocated. From the point the object is allocated, its type cannot by changed /// Allocates storage for the underlying object. Does nothing if it is already allocated. From the point the object is allocated, its type cannot be changed
/// anymore (e.g. changing from struct to list, or modifying the struct's section sizes). /// anymore (e.g. changing from struct to list, or modifying the struct's section sizes).
/// </summary> /// </summary>
public void Allocate() public void Allocate()
@ -250,6 +254,9 @@ namespace Capnp
if (!target.IsAllocated) if (!target.IsAllocated)
throw new InvalidOperationException("Target must be allocated before a pointer can be built"); throw new InvalidOperationException("Target must be allocated before a pointer can be built");
if (MsgBuilder == null)
throw Unbound();
try try
{ {
if (SegmentSpan[offset] != 0) if (SegmentSpan[offset] != 0)
@ -345,7 +352,7 @@ namespace Capnp
{ {
WirePointer farPtr = default; WirePointer farPtr = default;
if (Allocator.Allocate(1, target.SegmentIndex, out var landingPadSlice, true)) if (Allocator!.Allocate(1, target.SegmentIndex, out var landingPadSlice, true))
{ {
farPtr.SetFarPointer(target.SegmentIndex, landingPadSlice.Offset, false); farPtr.SetFarPointer(target.SegmentIndex, landingPadSlice.Offset, false);
SegmentSpan[offset] = farPtr; SegmentSpan[offset] = farPtr;
@ -372,7 +379,7 @@ namespace Capnp
} }
} }
internal Rpc.ConsumedCapability DecodeCapPointer(int offset) internal Rpc.ConsumedCapability? DecodeCapPointer(int offset)
{ {
if (offset < 0) if (offset < 0)
throw new IndexOutOfRangeException(nameof(offset)); throw new IndexOutOfRangeException(nameof(offset));
@ -455,7 +462,7 @@ namespace Capnp
throw new InvalidOperationException("This object cannot own pointers to sub-objects"); throw new InvalidOperationException("This object cannot own pointers to sub-objects");
} }
_linkedStates[slot] = target; _linkedStates![slot] = target;
} }
/// <summary> /// <summary>
@ -476,6 +483,7 @@ namespace Capnp
} }
static InvalidOperationException AlreadySet() => new InvalidOperationException("The object type was already set"); static InvalidOperationException AlreadySet() => new InvalidOperationException("The object type was already set");
static InvalidOperationException Unbound() => new InvalidOperationException("This state is not bound to a MessageBuilder");
void VerifyNotYetAllocated() void VerifyNotYetAllocated()
{ {
@ -654,14 +662,21 @@ namespace Capnp
/// <exception cref="EncoderFallbackException">Trying to obtain the UTF-8 encoding might throw this exception.</exception> /// <exception cref="EncoderFallbackException">Trying to obtain the UTF-8 encoding might throw this exception.</exception>
/// <exception cref="InvalidOperationException">The object type was already set to something different</exception> /// <exception cref="InvalidOperationException">The object type was already set to something different</exception>
/// <exception cref="ArgumentOutOfRangeException">UTF-8 encoding exceeds 2^29-2 bytes</exception> /// <exception cref="ArgumentOutOfRangeException">UTF-8 encoding exceeds 2^29-2 bytes</exception>
protected void WriteText(string text) protected void WriteText(string? text)
{ {
byte[] srcBytes = Encoding.UTF8.GetBytes(text); if (text == null)
SetListOfValues(8, srcBytes.Length + 1); {
var srcSpan = new ReadOnlySpan<byte>(srcBytes); VerifyNotYetAllocated();
var dstSpan = ListGetBytes(); }
dstSpan = dstSpan.Slice(0, dstSpan.Length - 1); else
srcSpan.CopyTo(dstSpan); {
byte[] srcBytes = Encoding.UTF8.GetBytes(text);
SetListOfValues(8, srcBytes.Length + 1);
var srcSpan = new ReadOnlySpan<byte>(srcBytes);
var dstSpan = ListGetBytes();
dstSpan = dstSpan.Slice(0, dstSpan.Length - 1);
srcSpan.CopyTo(dstSpan);
}
} }
/// <summary> /// <summary>
@ -761,7 +776,7 @@ namespace Capnp
if (Kind != ObjectKind.Struct && Kind != ObjectKind.ListOfPointers) if (Kind != ObjectKind.Struct && Kind != ObjectKind.ListOfPointers)
throw new InvalidOperationException("This is not a struct or list of pointers"); throw new InvalidOperationException("This is not a struct or list of pointers");
ref var state = ref _linkedStates[index]; ref var state = ref _linkedStates![index];
if (state == null) if (state == null)
{ {
@ -784,12 +799,12 @@ namespace Capnp
/// <item><description>Object at given position is not compatible with the desired target serializer type.</description></item> /// <item><description>Object at given position is not compatible with the desired target serializer type.</description></item>
/// </list></exception> /// </list></exception>
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of bounds.</exception> /// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of bounds.</exception>
public TS TryGetPointer<TS>(int index) where TS : SerializerState, new() public TS? TryGetPointer<TS>(int index) where TS : SerializerState, new()
{ {
if (Kind != ObjectKind.Struct && Kind != ObjectKind.ListOfPointers) if (Kind != ObjectKind.Struct && Kind != ObjectKind.ListOfPointers)
throw new InvalidOperationException("This is not a struct or list of pointers"); throw new InvalidOperationException("This is not a struct or list of pointers");
var state = _linkedStates[index]; var state = _linkedStates![index];
if (state == null) return null; if (state == null) return null;
@ -820,7 +835,7 @@ namespace Capnp
/// <item><description>Object at given position is not compatible with the desired target serializer type.</description></item> /// <item><description>Object at given position is not compatible with the desired target serializer type.</description></item>
/// </list></exception> /// </list></exception>
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of bounds.</exception> /// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of bounds.</exception>
public SerializerState TryGetPointer(int index) => TryGetPointer<SerializerState>(index); public SerializerState? TryGetPointer(int index) => TryGetPointer<SerializerState>(index);
/// <summary> /// <summary>
/// Reads text from a struct field or list element. /// Reads text from a struct field or list element.
@ -829,7 +844,7 @@ namespace Capnp
/// If the underlying object is a list of pointers: Element index</param> /// If the underlying object is a list of pointers: Element index</param>
/// <param name="defaultText">String to return in case of null</param> /// <param name="defaultText">String to return in case of null</param>
/// <returns>The decoded text</returns> /// <returns>The decoded text</returns>
public string ReadText(int index, string defaultText = null) public string? ReadText(int index, string? defaultText = null)
{ {
var b = BuildPointer(index); var b = BuildPointer(index);
@ -851,7 +866,7 @@ namespace Capnp
/// <item><description>Object at given position was already set.</description></item> /// <item><description>Object at given position was already set.</description></item>
/// </list></exception> /// </list></exception>
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of bounds.</exception> /// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of bounds.</exception>
public void WriteText(int index, string text) public void WriteText(int index, string? text)
{ {
BuildPointer(index).WriteText(text); BuildPointer(index).WriteText(text);
} }
@ -886,11 +901,11 @@ namespace Capnp
if (Kind != ObjectKind.ListOfStructs) if (Kind != ObjectKind.ListOfStructs)
throw new InvalidOperationException("This is not a list of structs"); throw new InvalidOperationException("This is not a list of structs");
ref var state = ref _linkedStates[index]; ref var state = ref _linkedStates![index];
if (state == null) if (state == null)
{ {
state = new SerializerState(MsgBuilder); state = new SerializerState(MsgBuilder!);
state.SetStruct(StructDataCount, StructPtrCount); state.SetStruct(StructDataCount, StructPtrCount);
state.SegmentIndex = SegmentIndex; state.SegmentIndex = SegmentIndex;
state.Offset = Offset + 1 + index * (StructDataCount + StructPtrCount); state.Offset = Offset + 1 + index * (StructDataCount + StructPtrCount);
@ -913,12 +928,12 @@ namespace Capnp
if (Kind != ObjectKind.ListOfStructs) if (Kind != ObjectKind.ListOfStructs)
throw new InvalidOperationException("This is not a list of structs"); throw new InvalidOperationException("This is not a list of structs");
ref var state = ref _linkedStates[index]; ref var state = ref _linkedStates![index];
if (state == null) if (state == null)
{ {
state = new TS(); state = new TS();
state.Bind(MsgBuilder); state.Bind(MsgBuilder!);
state.SetStruct(StructDataCount, StructPtrCount); state.SetStruct(StructDataCount, StructPtrCount);
state.SegmentIndex = SegmentIndex; state.SegmentIndex = SegmentIndex;
int stride = StructDataCount + StructPtrCount; int stride = StructDataCount + StructPtrCount;
@ -942,19 +957,19 @@ namespace Capnp
for (int offset = minOffset; offset < maxOffset; offset++) for (int offset = minOffset; offset < maxOffset; offset++)
{ {
ref var state = ref _linkedStates[offset - minOffset]; ref var state = ref _linkedStates![offset - minOffset];
if (state == null) if (state == null)
{ {
state = new TS(); state = new TS();
state.Bind(MsgBuilder); state.Bind(MsgBuilder!);
state.SetStruct(StructDataCount, StructPtrCount); state.SetStruct(StructDataCount, StructPtrCount);
state.SegmentIndex = SegmentIndex; state.SegmentIndex = SegmentIndex;
state.Offset = offset; state.Offset = offset;
} }
} }
return _linkedStates.LazyListSelect(ts => (TS)ts); return _linkedStates!.LazyListSelect(ts => (TS)ts);
} }
/// <summary> /// <summary>
@ -1240,7 +1255,7 @@ namespace Capnp
/// <param name="capability">The low-level capability object to provide.</param> /// <param name="capability">The low-level capability object to provide.</param>
/// <returns>Index of the given capability in the capability table</returns> /// <returns>Index of the given capability in the capability table</returns>
/// <exception cref="InvalidOperationException">The underlying message builder was not configured for capability table support.</exception> /// <exception cref="InvalidOperationException">The underlying message builder was not configured for capability table support.</exception>
public uint ProvideCapability(Rpc.ConsumedCapability capability) public uint ProvideCapability(Rpc.ConsumedCapability? capability)
{ {
if (Caps == null) if (Caps == null)
throw new InvalidOperationException("Underlying MessageBuilder was not enabled to support capabilities"); throw new InvalidOperationException("Underlying MessageBuilder was not enabled to support capabilities");
@ -1279,7 +1294,7 @@ namespace Capnp
/// </list></param> /// </list></param>
/// <returns>Index of the given capability in the capability table</returns> /// <returns>Index of the given capability in the capability table</returns>
/// <exception cref="InvalidOperationException">The underlying message builder was not configured for capability table support.</exception> /// <exception cref="InvalidOperationException">The underlying message builder was not configured for capability table support.</exception>
public uint ProvideCapability(object obj) public uint ProvideCapability(object? obj)
{ {
if (obj == null) if (obj == null)
return ProvideCapability(default(Rpc.ConsumedCapability)); return ProvideCapability(default(Rpc.ConsumedCapability));
@ -1352,7 +1367,7 @@ namespace Capnp
} }
} }
internal Rpc.ConsumedCapability StructReadRawCap(int index) internal Rpc.ConsumedCapability? StructReadRawCap(int index)
{ {
if (Kind != ObjectKind.Struct && Kind != ObjectKind.Nil) if (Kind != ObjectKind.Struct && Kind != ObjectKind.Nil)
throw new InvalidOperationException("Allowed on structs only"); throw new InvalidOperationException("Allowed on structs only");
@ -1372,7 +1387,7 @@ namespace Capnp
/// <exception cref="ArgumentOutOfRangeException"><paramref name="slot"/> is out of range.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="slot"/> is out of range.</exception>
/// <exception cref="ArgumentException">The desired interface does not qualify as capability interface (<see cref="Rpc.ProxyAttribute"/>)</exception> /// <exception cref="ArgumentException">The desired interface does not qualify as capability interface (<see cref="Rpc.ProxyAttribute"/>)</exception>
/// <exception cref="InvalidOperationException">This state does not represent a struct.</exception> /// <exception cref="InvalidOperationException">This state does not represent a struct.</exception>
public T ReadCap<T>(int slot) where T : class public T? ReadCap<T>(int slot) where T : class
{ {
var cap = StructReadRawCap(slot); var cap = StructReadRawCap(slot);
return Rpc.CapabilityReflection.CreateProxy<T>(cap) as T; return Rpc.CapabilityReflection.CreateProxy<T>(cap) as T;
@ -1392,3 +1407,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -1,5 +1,6 @@
using System; using System;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -25,3 +26,4 @@ namespace Capnp
public ulong Id { get; } public ulong Id { get; }
} }
} }
#nullable restore

View File

@ -4,8 +4,9 @@ using System.Threading.Tasks;
namespace Capnp namespace Capnp
{ {
internal static class UtilityExtensions #nullable enable
{ internal static class UtilityExtensions
{
/// <summary> /// <summary>
/// This method exists until NET Standard 2.1 is released /// This method exists until NET Standard 2.1 is released
/// </summary> /// </summary>
@ -23,7 +24,7 @@ namespace Capnp
return true; return true;
} }
#else #else
public static bool ReplacementTryAdd<K, V>(this Dictionary<K, V> thisDict, K key, V value) => thisDict.TryAdd(key, value); public static bool ReplacementTryAdd<K, V>(this Dictionary<K, V> thisDict, K key, V value) where K: struct => thisDict.TryAdd(key, value);
#endif #endif
/// <summary> /// <summary>
@ -40,14 +41,16 @@ namespace Capnp
{ {
if (!thisDict.ContainsKey(key)) if (!thisDict.ContainsKey(key))
{ {
value = default; value = default!; // OK here since .NET Standard 2.0 does not support (non-)nullability anyway.
return false; return false;
} }
value = thisDict[key]; value = thisDict[key];
return thisDict.Remove(key); return thisDict.Remove(key);
} }
#else #else
#pragma warning disable CS8714
public static bool ReplacementTryRemove<K, V>(this Dictionary<K, V> thisDict, K key, out V value) => thisDict.Remove(key, out value); public static bool ReplacementTryRemove<K, V>(this Dictionary<K, V> thisDict, K key, out V value) => thisDict.Remove(key, out value);
#pragma warning restore CS8714
#endif #endif
/// <summary> /// <summary>
@ -77,3 +80,4 @@ namespace Capnp
#endif #endif
} }
} }
#nullable restore

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -22,3 +23,4 @@ namespace Capnp
} }
} }
} }
#nullable restore

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
#nullable enable
namespace Capnp namespace Capnp
{ {
/// <summary> /// <summary>
@ -228,3 +229,4 @@ namespace Capnp
} }
} }
} }
#nullable restore