diff --git a/Capnp.Net.Runtime.Core21/Capnp.Net.Runtime.Core21.csproj b/Capnp.Net.Runtime.Core21/Capnp.Net.Runtime.Core21.csproj
new file mode 100644
index 0000000..5381f55
--- /dev/null
+++ b/Capnp.Net.Runtime.Core21/Capnp.Net.Runtime.Core21.csproj
@@ -0,0 +1,98 @@
+
+
+
+ netcoreapp2.2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj b/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj
new file mode 100644
index 0000000..9f5c4b9
--- /dev/null
+++ b/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj
@@ -0,0 +1,44 @@
+
+
+
+ netcoreapp2.2
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.csproj b/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj
similarity index 97%
rename from Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.csproj
rename to Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj
index d5e3394..0fabb7b 100644
--- a/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.csproj
+++ b/Capnp.Net.Runtime.Tests/Capnp.Net.Runtime.Tests.Std20.csproj
@@ -22,7 +22,7 @@
-
+
diff --git a/Capnp.Net.Runtime.Tests/TcpRpc.cs b/Capnp.Net.Runtime.Tests/TcpRpc.cs
index 7239075..337c1fe 100644
--- a/Capnp.Net.Runtime.Tests/TcpRpc.cs
+++ b/Capnp.Net.Runtime.Tests/TcpRpc.cs
@@ -7,7 +7,6 @@ using Capnp.Rpc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
-using Exception = Capnp.Rpc.Exception;
namespace Capnp.Net.Runtime.Tests
{
@@ -68,7 +67,7 @@ namespace Capnp.Net.Runtime.Tests
SpinWait.SpinUntil(() => server.ConnectionCount > 0, MediumTimeout);
Assert.AreEqual(1, server.ConnectionCount);
}
- catch (Exception e)
+ catch (System.Exception e)
{
Console.WriteLine(e);
throw;
diff --git a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj b/Capnp.Net.Runtime/Capnp.Net.Runtime.Std20.csproj
similarity index 89%
rename from Capnp.Net.Runtime/Capnp.Net.Runtime.csproj
rename to Capnp.Net.Runtime/Capnp.Net.Runtime.Std20.csproj
index 2c53100..7823ba4 100644
--- a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj
+++ b/Capnp.Net.Runtime/Capnp.Net.Runtime.Std20.csproj
@@ -4,6 +4,7 @@
netstandard2.0
Capnp
7.2
+ Capnp.Net.Runtime.Std20
diff --git a/Capnp.Net.Runtime/FramePump.cs b/Capnp.Net.Runtime/FramePump.cs
index 9781ae8..dcfc154 100644
--- a/Capnp.Net.Runtime/FramePump.cs
+++ b/Capnp.Net.Runtime/FramePump.cs
@@ -81,8 +81,6 @@ namespace Capnp
if (segment.Length == 0)
throw new ArgumentException("Segment must not have zero length");
}
-
-
lock (_writeLock)
{
@@ -101,7 +99,11 @@ namespace Capnp
foreach (var segment in frame.Segments)
{
+#if NETSTANDARD2_0
var bytes = MemoryMarshal.Cast(segment.Span).ToArray();
+#else
+ var bytes = MemoryMarshal.Cast(segment.Span);
+#endif
_writer.Write(bytes);
}
}
diff --git a/Capnp.Net.Runtime/Framing.cs b/Capnp.Net.Runtime/Framing.cs
index 188f2e7..d9f8b69 100644
--- a/Capnp.Net.Runtime/Framing.cs
+++ b/Capnp.Net.Runtime/Framing.cs
@@ -34,13 +34,20 @@ namespace Capnp
public static WireFrame ReadWireFrame(this BinaryReader reader)
{
uint scount = reader.ReadUInt32();
- if(scount++ == UInt32.MaxValue) throw new InvalidDataException("Encountered Invalid Framing Data");
+ if (scount++ == uint.MaxValue)
+ {
+ throw new InvalidDataException("Encountered invalid framing data");
+ }
+
var buffers = new Memory[scount];
for (uint i = 0; i < scount; i++)
{
uint size = reader.ReadUInt32();
- if(size==0) throw new EndOfStreamException("Stream Closed");
+ if (size == 0)
+ {
+ throw new EndOfStreamException("Stream closed");
+ }
buffers[i] = new Memory(new ulong[size]);
}
@@ -55,10 +62,11 @@ namespace Capnp
return new WireFrame(buffers);
}
- public static void FillBuffersFromFrames(Memory[] buffers, uint segmentCount, BinaryReader reader)
+ static void FillBuffersFromFrames(Memory[] buffers, uint segmentCount, BinaryReader reader)
{
for (uint i = 0; i < segmentCount; i++)
{
+#if NETSTANDARD2_0
var buffer = MemoryMarshal.Cast(buffers[i].Span.ToArray());
var tmpBuffer = reader.ReadBytes(buffer.Length);
@@ -73,6 +81,10 @@ namespace Capnp
var value = BitConverter.ToUInt64(tmpBuffer, j*8);
buffers[i].Span[j] = value;
}
+#else
+ var buffer = MemoryMarshal.Cast(buffers[i].Span);
+ reader.Read(buffer);
+#endif
}
}
}
diff --git a/Capnp.Net.Runtime/PrimitiveCoder.cs b/Capnp.Net.Runtime/PrimitiveCoder.cs
index 6412199..3614f67 100644
--- a/Capnp.Net.Runtime/PrimitiveCoder.cs
+++ b/Capnp.Net.Runtime/PrimitiveCoder.cs
@@ -24,8 +24,8 @@ namespace Capnp
Coder.Fn = (x, y) => x ^ y;
Coder.Fn = (x, y) =>
{
- int xi = x.SingleToInt32();
- int yi = y.SingleToInt32();
+ int xi = x.ReplacementSingleToInt32Bits();
+ int yi = y.ReplacementSingleToInt32Bits();
int zi = xi ^ yi;
return BitConverter.ToSingle(BitConverter.GetBytes(zi), 0);
};
diff --git a/Capnp.Net.Runtime/Rpc/RpcEngine.cs b/Capnp.Net.Runtime/Rpc/RpcEngine.cs
index 95f8bdf..2546415 100644
--- a/Capnp.Net.Runtime/Rpc/RpcEngine.cs
+++ b/Capnp.Net.Runtime/Rpc/RpcEngine.cs
@@ -179,9 +179,7 @@ namespace Capnp.Rpc
uint RandId()
{
- var holder = new byte[4];
- _random.NextBytes(holder);
- return BitConverter.ToUInt32(holder,0);
+ return unchecked((uint)_random.Next(int.MinValue, int.MaxValue));
}
uint AllocateExport(Skeleton providedCapability, out bool first)
diff --git a/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs b/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs
index 78c6482..6e3bfa4 100644
--- a/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs
+++ b/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs
@@ -63,12 +63,8 @@ namespace Capnp.Rpc
{
throw new RpcException("TcpRpcClient is unable to connect", exception);
}
- catch (Exception e)
- {
- Logger.LogError("UNHANDLED EXCEPTION");
- }
-
}
+
async Task Connect(string host, int port)
{
await ConnectAsync(host, port);
diff --git a/Capnp.Net.Runtime/Rpc/rpc.cs b/Capnp.Net.Runtime/Rpc/rpc.cs
index b0e5f31..35b0269 100644
--- a/Capnp.Net.Runtime/Rpc/rpc.cs
+++ b/Capnp.Net.Runtime/Rpc/rpc.cs
@@ -2528,7 +2528,7 @@ namespace Capnp.Rpc
}
}
- public class Exception : System.Exception, ICapnpSerializable
+ public class Exception : ICapnpSerializable
{
void ICapnpSerializable.Deserialize(DeserializerState arg_)
{
diff --git a/Capnp.Net.Runtime/SerializerExtensions.cs b/Capnp.Net.Runtime/SerializerExtensions.cs
index 727f043..d9d384e 100644
--- a/Capnp.Net.Runtime/SerializerExtensions.cs
+++ b/Capnp.Net.Runtime/SerializerExtensions.cs
@@ -285,9 +285,9 @@ namespace Capnp
public static float ReadDataFloat(this T d, ulong bitOffset, float defaultValue = 0)
where T : IStructDeserializer
{
- int defaultBits = defaultValue.SingleToInt32();
+ int defaultBits = defaultValue.ReplacementSingleToInt32Bits();
int bits = (int)d.StructReadData(bitOffset, 32) ^ defaultBits;
- return bits.Int32ToSingle();
+ return bits.ReplacementInt32ToSingleBits();
}
///
@@ -301,8 +301,8 @@ namespace Capnp
public static void WriteData(this T d, ulong bitOffset, float value, float defaultValue = 0.0f)
where T : IStructSerializer
{
- int bits = value.SingleToInt32();
- int defaultBits = defaultValue.SingleToInt32();
+ int bits = value.ReplacementSingleToInt32Bits();
+ int defaultBits = defaultValue.ReplacementSingleToInt32Bits();
WriteData(d, bitOffset, bits, defaultBits);
}
diff --git a/Capnp.Net.Runtime/SerializerState.cs b/Capnp.Net.Runtime/SerializerState.cs
index be50748..c92fa9d 100644
--- a/Capnp.Net.Runtime/SerializerState.cs
+++ b/Capnp.Net.Runtime/SerializerState.cs
@@ -1068,7 +1068,11 @@ namespace Capnp
{
var bytes = ListGetBytes();
if (bytes.Length == 0) return string.Empty;
+#if NETSTANDARD2_0
return Encoding.UTF8.GetString(bytes.Slice(0, bytes.Length - 1).ToArray());
+#else
+ return Encoding.UTF8.GetString(bytes.Slice(0, bytes.Length - 1));
+#endif
}
///
@@ -1164,8 +1168,8 @@ namespace Capnp
/// is out of bounds.
public void ListWriteValue(int index, float value, float defaultValue = 0)
{
- int rcastValue = value.SingleToInt32();
- int rcastDefaultValue = defaultValue.SingleToInt32();
+ int rcastValue = value.ReplacementSingleToInt32Bits();
+ int rcastDefaultValue = defaultValue.ReplacementSingleToInt32Bits();
ListWriteValue(index, rcastValue, rcastDefaultValue);
}
diff --git a/Capnp.Net.Runtime/UtilityExtensions.cs b/Capnp.Net.Runtime/UtilityExtensions.cs
index cb880ac..ac448cf 100644
--- a/Capnp.Net.Runtime/UtilityExtensions.cs
+++ b/Capnp.Net.Runtime/UtilityExtensions.cs
@@ -5,63 +5,77 @@ using System.Threading.Tasks;
namespace Capnp
{
- public static class UtilityExtensions
+ internal static class UtilityExtensions
{
- ///
- /// This method exists until NET Standard 2.1 is released
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static bool ReplacementTryAdd(this Dictionary thisDict, K key, V value)
- {
- if (thisDict.ContainsKey(key))
- return false;
- thisDict.Add(key, value);
- return true;
- }
-
- ///
- /// This method exists until NET Standard 2.1 is released
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static bool ReplacementTryRemove(this Dictionary thisDict, K key, out V value)
- {
- if (!thisDict.ContainsKey(key))
- {
- value = default;
- return false;
- }
- value = thisDict[key];
- return thisDict.Remove(key);
- }
+ ///
+ /// This method exists until NET Standard 2.1 is released
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+#if NETSTANDARD2_0
+ public static bool ReplacementTryAdd(this Dictionary thisDict, K key, V value)
+ {
+ if (thisDict.ContainsKey(key)) return false;
+ thisDict.Add(key, value);
+ return true;
+ }
+#else
+ public static bool ReplacementTryAdd(this Dictionary thisDict, K key, V value) => thisDict.TryAdd(key, value);
+#endif
- ///
- /// This method exists until NET Standard 2.1 is released
- ///
- ///
- ///
- ///
- public static bool ReplacementTaskIsCompletedSuccessfully(this Task task)
- {
- return task.IsCompleted && !task.IsCanceled && !task.IsFaulted;
- }
+ ///
+ /// This method exists until NET Standard 2.1 is released
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+#if NETSTANDARD2_0
+ public static bool ReplacementTryRemove(this Dictionary thisDict, K key, out V value)
+ {
+ if (!thisDict.ContainsKey(key))
+ {
+ value = default;
+ return false;
+ }
+ value = thisDict[key];
+ return thisDict.Remove(key);
+ }
+#else
+ public static bool ReplacementTryRemove(this Dictionary thisDict, K key, out V value) => thisDict.Remove(key, out value);
+#endif
- public static int SingleToInt32(this float value)
- {
- var valueBytes = BitConverter.GetBytes(value);
- return BitConverter.ToInt32(valueBytes,0);
+ ///
+ /// This method exists until NET Standard 2.1 is released
+ ///
+ ///
+ ///
+ ///
+#if NETSTANDARD2_0
+ public static bool ReplacementTaskIsCompletedSuccessfully(this Task task)
+ {
+ return task.IsCompleted && !task.IsCanceled && !task.IsFaulted;
+ }
+#else
+ public static bool ReplacementTaskIsCompletedSuccessfully(this Task task) => task.IsCompletedSuccessfully;
+#endif
+
+#if NETSTANDARD2_0
+ public static int ReplacementSingleToInt32Bits(this float value) => BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
+#else
+ public static int ReplacementSingleToInt32Bits(this float value) => BitConverter.SingleToInt32Bits(value);
+#endif
+
+#if NETSTANDARD2_0
+ public static float ReplacementInt32ToSingleBits(this int value) => BitConverter.ToSingle(BitConverter.GetBytes(value), 0);
+#else
+ public static float ReplacementInt32ToSingleBits(this int value) => BitConverter.Int32BitsToSingle(value);
+#endif
}
-
- public static float Int32ToSingle(this int value) =>
- BitConverter.ToSingle(BitConverter.GetBytes(value),0);
- }
}
\ No newline at end of file
diff --git a/Capnp.Net.sln b/Capnp.Net.sln
index 080c747..f2ecd9c 100644
--- a/Capnp.Net.sln
+++ b/Capnp.Net.sln
@@ -3,11 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29001.49
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime", "Capnp.Net.Runtime\Capnp.Net.Runtime.csproj", "{D4326221-63C9-4AC5-805A-B4D8CA47546A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Std20", "Capnp.Net.Runtime\Capnp.Net.Runtime.Std20.csproj", "{D4326221-63C9-4AC5-805A-B4D8CA47546A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "capnpc-csharp", "capnpc-csharp\capnpc-csharp.csproj", "{D19E5EA7-D35B-4A1F-99CB-ED136316B577}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests", "Capnp.Net.Runtime.Tests\Capnp.Net.Runtime.Tests.csproj", "{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime.Tests.Std20", "Capnp.Net.Runtime.Tests\Capnp.Net.Runtime.Tests.Std20.csproj", "{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capnp.Net.Runtime.Core21", "Capnp.Net.Runtime.Core21\Capnp.Net.Runtime.Core21.csproj", "{B9EE68D1-0474-4697-A121-D21D1B76DB47}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capnp.Net.Runtime.Tests.Core21", "Capnp.Net.Runtime.Tests.Core21\Capnp.Net.Runtime.Tests.Core21.csproj", "{58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -23,14 +27,18 @@ Global
{D19E5EA7-D35B-4A1F-99CB-ED136316B577}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D19E5EA7-D35B-4A1F-99CB-ED136316B577}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D19E5EA7-D35B-4A1F-99CB-ED136316B577}.Release|Any CPU.Build.0 = Release|Any CPU
- {8C17F147-D784-4584-80FF-21BE03AC0D17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8C17F147-D784-4584-80FF-21BE03AC0D17}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8C17F147-D784-4584-80FF-21BE03AC0D17}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8C17F147-D784-4584-80FF-21BE03AC0D17}.Release|Any CPU.Build.0 = Release|Any CPU
{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9ED38750-F83F-4B10-B3A3-4FD6183F9E86}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B9EE68D1-0474-4697-A121-D21D1B76DB47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B9EE68D1-0474-4697-A121-D21D1B76DB47}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B9EE68D1-0474-4697-A121-D21D1B76DB47}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B9EE68D1-0474-4697-A121-D21D1B76DB47}.Release|Any CPU.Build.0 = Release|Any CPU
+ {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {58E8FFC8-D207-4B0F-842A-58ED9D3D9EEF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/capnpc-csharp/capnpc-csharp.csproj b/capnpc-csharp/capnpc-csharp.csproj
index 76ee9e5..2c210b9 100644
--- a/capnpc-csharp/capnpc-csharp.csproj
+++ b/capnpc-csharp/capnpc-csharp.csproj
@@ -17,7 +17,7 @@
-
+