Skip to content

Commit 6ba851f

Browse files
committed
Adds a .NET 4 version of the core lib
Too hard to do 3.5, but 4 is easy enough. We only lose proper async support.
1 parent 2391f67 commit 6ba851f

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

src/FRC.NetworkTables.Core.DesktopLibraries/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"define": [ "CORE" ]
3939
},
4040
"frameworks": {
41-
"net45": {},
41+
"net40": {},
4242
"netstandard1.5": {
4343
"buildOptions": {
4444
"define": [ "NETSTANDARD" ]

src/FRC.NetworkTables.Core/Native/CoreMethods.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ internal static long CallRpc(string name, IList<byte> param)
10891089
}
10901090
}
10911091

1092+
#if !NET40
10921093
internal static async Task<byte[]> GetRpcResultAsync(long callUid, CancellationToken token)
10931094
{
10941095
token.Register(() =>
@@ -1118,7 +1119,7 @@ internal static async Task<byte[]> GetRpcResultAsync(long callUid, CancellationT
11181119
return null;
11191120
}
11201121
}
1121-
1122+
#endif //NET40
11221123
internal static bool GetRpcResult(bool blocking, long callUid, TimeSpan timeout, out byte[] result)
11231124
{
11241125
UIntPtr size = UIntPtr.Zero;

src/FRC.NetworkTables.Core/project.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
},
4646
"frameworks": {
4747
"net45": {},
48+
"net40": {
49+
"buildOptions": {
50+
"define": [ "NET40" ]
51+
}
52+
},
4853
"netstandard1.5": {
4954
"buildOptions": {
5055
"define": [ "NETSTANDARD" ]
@@ -67,7 +72,7 @@
6772
}
6873
},
6974
"dependencies": {
70-
"NativeLibraryUtilities": "1.0.0"
75+
"NativeLibraryUtilities": "1.0.3"
7176
},
7277
"configurations": {
7378
"Debug": {

src/Shared/NetworkTable.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ public static string SavePersistent(string filename)
533533
return NtCore.SavePersistent(filename);
534534
}
535535

536+
#if !NET40
536537
/// <summary>
537538
/// Saves persistent keys to a file asynchronously. The server does this automatically.
538539
/// </summary>
@@ -544,6 +545,7 @@ public static async Task<string> SavePersistentAsync(string filename)
544545
{
545546
return await NtCore.SavePersistentAsync(filename).ConfigureAwait(false);
546547
}
548+
#endif //NET40
547549

548550
/// <summary>
549551
/// Loads persistent keys from a file. The server does this automatically.
@@ -557,6 +559,7 @@ public static IList<string> LoadPersistent(string filename)
557559
return NtCore.LoadPersistent(filename);
558560
}
559561

562+
#if !NET40
560563
/// <summary>
561564
/// Loads persistent keys from a file asynchronously. The server does this automatically.
562565
/// </summary>
@@ -568,6 +571,7 @@ public static async Task<IList<string>> LoadPersistentAsync(string filename)
568571
{
569572
return await NtCore.LoadPersistentAsync(filename).ConfigureAwait(false);
570573
}
574+
#endif // NET40
571575

572576
///<inheritdoc/>
573577
[Obsolete("Please use the Default Value Get... Methods instead.")]

src/Shared/NtCore.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ public static string SavePersistent(string filename)
10671067
#endif
10681068
}
10691069

1070+
#if !NET40
10701071
/// <summary>
10711072
/// Saves all persistent variables to the files specified asynchronously
10721073
/// </summary>
@@ -1080,6 +1081,7 @@ public static async Task<string> SavePersistentAsync(string filename)
10801081
return await Storage.Instance.SavePersistentAsync(filename, false).ConfigureAwait(false);
10811082
#endif
10821083
}
1084+
#endif // NET40
10831085

10841086
/// <summary>
10851087
/// Loads persistent variables from a specified file
@@ -1096,6 +1098,7 @@ public static string LoadPersistent(string filename, Action<int, string> warn)
10961098
#endif
10971099
}
10981100

1101+
#if !NET40
10991102
/// <summary>
11001103
/// Loads persistent variables from a specified file asynchronously
11011104
/// </summary>
@@ -1110,6 +1113,7 @@ public static async Task<string> LoadPersistentAsync(string filename, Action<int
11101113
return await Storage.Instance.LoadPersistentAsync(filename, warn).ConfigureAwait(false);
11111114
#endif
11121115
}
1116+
#endif // NET40
11131117

11141118
/// <summary>
11151119
/// Gets the current timestamp of the library to be used for value time comparisons
@@ -1152,6 +1156,7 @@ public static IList<string> LoadPersistent(string filename)
11521156
return warns.ToArray();
11531157
}
11541158

1159+
#if !NET40
11551160
/// <summary>
11561161
/// Loads persistent variables from a specified file asynchronously
11571162
/// </summary>
@@ -1167,5 +1172,6 @@ public static async Task<IList<string>> LoadPersistentAsync(string filename)
11671172
if (err != null) throw new PersistentException($"Load Persistent Failed: {err}");
11681173
return warns.ToArray();
11691174
}
1175+
#endif
11701176
}
11711177
}

src/Shared/RemoteProcedureCall.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public static long CallRpc(string name, IList<Value> param)
179179
#endif
180180
}
181181

182+
#if !NET40
182183
/// <summary>
183184
/// Calls a procedure on a remote server, and awaits a response asynchronously
184185
/// </summary>
@@ -219,6 +220,7 @@ public static async Task<IList<byte>> GetRpcResultAsync(long callUid, Cancellati
219220
return await Storage.Instance.GetRpcResultAsync(callUid, token).ConfigureAwait(false);
220221
#endif
221222
}
223+
#endif // NET40
222224

223225
/// <summary>
224226
/// Gets the result of an Rpc request

src/Shared/Wire/FastBitConverterBE.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ namespace NetworkTables.Wire
66
{
77
internal class FastBitConverterBE : IFastBitConverter
88
{
9+
#if !NET40
910
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11+
#endif
1012
public void AddUShort(List<byte> list, ushort val)
1113
{
1214
list.Add((byte)(val & 0xff));
1315
list.Add((byte)((val >> 8) & 0xff));
1416
}
1517

18+
#if !NET40
1619
[MethodImpl(MethodImplOptions.AggressiveInlining)]
20+
#endif
1721
public void AddShort(List<byte> list, short val)
1822
{
1923
list.Add((byte)(val & 0xff));
2024
list.Add((byte)((val >> 8) & 0xff));
2125
}
2226

27+
#if !NET40
2328
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
#endif
2430
public void AddUInt(List<byte> list, uint val)
2531
{
2632
list.Add((byte)(val & 0xff));
@@ -29,7 +35,9 @@ public void AddUInt(List<byte> list, uint val)
2935
list.Add((byte)((val >> 24) & 0xff));
3036
}
3137

38+
#if !NET40
3239
[MethodImpl(MethodImplOptions.AggressiveInlining)]
40+
#endif
3341
public void AddInt(List<byte> list, int val)
3442
{
3543
list.Add((byte)(val & 0xff));
@@ -38,7 +46,9 @@ public void AddInt(List<byte> list, int val)
3846
list.Add((byte)((val >> 24) & 0xff));
3947
}
4048

49+
#if !NET40
4150
[MethodImpl(MethodImplOptions.AggressiveInlining)]
51+
#endif
4252
public void AddULong(List<byte> list, ulong val)
4353
{
4454
list.Add((byte)(val & 0xff));
@@ -51,7 +61,9 @@ public void AddULong(List<byte> list, ulong val)
5161
list.Add((byte)((val >> 56) & 0xff));
5262
}
5363

64+
#if !NET40
5465
[MethodImpl(MethodImplOptions.AggressiveInlining)]
66+
#endif
5567
public void AddLong(List<byte> list, long val)
5668
{
5769
list.Add((byte)(val & 0xff));
@@ -64,7 +76,9 @@ public void AddLong(List<byte> list, long val)
6476
list.Add((byte)((val >> 56) & 0xff));
6577
}
6678

79+
#if !NET40
6780
[MethodImpl(MethodImplOptions.AggressiveInlining)]
81+
#endif
6882
public void AddDouble(List<byte> list, double val)
6983
{
7084
AddLong(list, BitConverter.DoubleToInt64Bits(val));

src/Shared/Wire/FastBitConverterLE.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,45 @@ namespace NetworkTables.Wire
66
{
77
internal class FastBitConverterLE : IFastBitConverter
88
{
9+
#if !NET40
910
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11+
#endif
1012
public void AddUShort(List<byte> list, ushort val)
1113
{
1214
list.Add((byte)((val >> 8) & 0xff));
1315
list.Add((byte)(val & 0xff));
1416
}
15-
17+
#if !NET40
1618
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
#endif
1720
public void AddShort(List<byte> list, short val)
1821
{
1922
list.Add((byte)((val >> 8) & 0xff));
2023
list.Add((byte)(val & 0xff));
2124
}
22-
25+
#if !NET40
2326
[MethodImpl(MethodImplOptions.AggressiveInlining)]
27+
#endif
2428
public void AddUInt(List<byte> list, uint val)
2529
{
2630
list.Add((byte)((val >> 24) & 0xff));
2731
list.Add((byte)((val >> 16) & 0xff));
2832
list.Add((byte)((val >> 8) & 0xff));
2933
list.Add((byte)(val & 0xff));
3034
}
31-
35+
#if !NET40
3236
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
#endif
3338
public void AddInt(List<byte> list, int val)
3439
{
3540
list.Add((byte)((val >> 24) & 0xff));
3641
list.Add((byte)((val >> 16) & 0xff));
3742
list.Add((byte)((val >> 8) & 0xff));
3843
list.Add((byte)(val & 0xff));
3944
}
40-
45+
#if !NET40
4146
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47+
#endif
4248
public void AddULong(List<byte> list, ulong val)
4349
{
4450
list.Add((byte)((val >> 56) & 0xff));
@@ -50,8 +56,9 @@ public void AddULong(List<byte> list, ulong val)
5056
list.Add((byte)((val >> 8) & 0xff));
5157
list.Add((byte)(val & 0xff));
5258
}
53-
59+
#if !NET40
5460
[MethodImpl(MethodImplOptions.AggressiveInlining)]
61+
#endif
5562
public void AddLong(List<byte> list, long val)
5663
{
5764
list.Add((byte)((val >> 56) & 0xff));
@@ -63,8 +70,9 @@ public void AddLong(List<byte> list, long val)
6370
list.Add((byte)((val >> 8) & 0xff));
6471
list.Add((byte)(val & 0xff));
6572
}
66-
73+
#if !NET40
6774
[MethodImpl(MethodImplOptions.AggressiveInlining)]
75+
#endif
6876
public void AddDouble(List<byte> list, double val)
6977
{
7078
AddLong(list, BitConverter.DoubleToInt64Bits(val));

0 commit comments

Comments
 (0)