Skip to content

Commit 0b74b23

Browse files
author
“llt”
committed
Better AOTDLL testing in RawDb
1 parent cf0a04f commit 0b74b23

3 files changed

Lines changed: 103 additions & 270 deletions

File tree

frameworks/CSharp/appmpower/src/appMpower.Orm/DotnetMethods.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
namespace appMpower.Orm;
1212

13-
//These methods are for test purposes only; not used in actual execution
13+
#if !AOTDLL
14+
1415
public static class DotnetMethods
1516
{
1617
private static JsonWriterOptions _jsonWriterOptions = new JsonWriterOptions
@@ -92,4 +93,6 @@ public static async Task<byte[]> Fortunes()
9293

9394
return byteArray.ToArray();
9495
}
95-
}
96+
}
97+
98+
#endif

frameworks/CSharp/appmpower/src/appMpower.Orm/NativeMethods.cs

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace appMpower.Orm;
1313

14+
#if AOTDLL
15+
1416
public static class NativeMethods
1517
{
1618
private static JsonWriterOptions _jsonWriterOptions = new JsonWriterOptions
@@ -19,9 +21,9 @@ public static class NativeMethods
1921
SkipValidation = true
2022
};
2123

22-
private readonly static WorldSerializer _worldSerializer = new WorldSerializer();
23-
private readonly static WorldsSerializer _worldsSerializer = new WorldsSerializer();
24-
private readonly static FortunesSerializer _fortunesSerializer = new FortunesSerializer();
24+
private readonly static WorldSerializer _worldSerializer = new();
25+
private readonly static WorldsSerializer _worldsSerializer = new();
26+
private readonly static FortunesSerializer _fortunesSerializer = new();
2527
private static readonly byte[] _delimiter = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
2628

2729
[UnmanagedCallersOnly(EntryPoint = "Dbms")]
@@ -87,52 +89,6 @@ public static unsafe IntPtr Fortunes(int* length, IntPtr* handlePointer)
8789
return byteArrayPointer;
8890
}
8991

90-
/*
91-
[UnmanagedCallersOnly(EntryPoint = "Fortunes")]
92-
public static unsafe IntPtr Fortunes(int* length, IntPtr* handlePointer)
93-
{
94-
List<Fortune> fortunes = RawDb.LoadFortunesRows();
95-
96-
int totalSize = 0;
97-
98-
foreach (var fortune in fortunes)
99-
{
100-
totalSize += sizeof(int) // for Id
101-
+ Encoding.UTF8.GetByteCount(fortune.Message ?? "") // for Message
102-
+ _delimiter.Length; // for delimiter
103-
}
104-
105-
// Allocate the total buffer
106-
byte[] buffer = new byte[totalSize];
107-
int offset = 0;
108-
109-
// Write each object to the buffer
110-
foreach (var fortune in fortunes)
111-
{
112-
// Write Id
113-
BitConverter.TryWriteBytes(buffer.AsSpan(offset, sizeof(int)), fortune.Id);
114-
offset += sizeof(int);
115-
116-
// Write Message
117-
int descriptionLength = Encoding.UTF8.GetBytes(fortune.Message ?? "", buffer.AsSpan(offset));
118-
offset += descriptionLength;
119-
120-
// Write Delimiter
121-
_delimiter.CopyTo(buffer, offset);
122-
offset += _delimiter.Length;
123-
}
124-
125-
byte[] byteArray = buffer.ToArray();
126-
*length = byteArray.Length;
127-
128-
GCHandle handle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);
129-
IntPtr byteArrayPointer = handle.AddrOfPinnedObject();
130-
*handlePointer = GCHandle.ToIntPtr(handle);
131-
132-
return byteArrayPointer;
133-
}
134-
*/
135-
13692
[UnmanagedCallersOnly(EntryPoint = "Query")]
13793
public static unsafe IntPtr Query(int queries, int* length, IntPtr* handlePointer)
13894
{
@@ -192,4 +148,6 @@ public static unsafe IntPtr DbById(int id, int* length, IntPtr* handlePointer)
192148

193149
return byteArrayPointer;
194150
}
195-
}
151+
}
152+
153+
#endif

0 commit comments

Comments
 (0)