Skip to content

Commit d7172e3

Browse files
committed
feat(Read): add Bytes API
1 parent 6642f1d commit d7172e3

6 files changed

Lines changed: 22 additions & 1 deletion

File tree

ZenKit/Native.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ internal static class Native
103103
public static ZkRead_newPath ZkRead_newPath;
104104
public static ZkRead_newExt ZkRead_newExt;
105105
public static ZkRead_del ZkRead_del;
106+
public static ZkRead_getSize ZkRead_getSize;
107+
public static ZkRead_getBytes ZkRead_getBytes;
106108
public static ZkVfs_new ZkVfs_new;
107109
public static ZkVfs_del ZkVfs_del;
108110
public static ZkVfs_getRoot ZkVfs_getRoot;
@@ -1289,7 +1291,7 @@ public static ZkParticleEffectEmitKeyInstance_getEmCheckCollision
12891291

12901292
static Native()
12911293
{
1292-
var loader = new NativeLibrary("czenkit", LibraryLoader.GetPlatformDefaultLoader(),
1294+
var loader = new NativeLibrary("zenkitcapi", LibraryLoader.GetPlatformDefaultLoader(),
12931295
new NativePathResolver());
12941296

12951297
ZkAnimation_getFps = loader.LoadFunction<ZkAnimation_getFps>("ZkAnimation_getFps");
@@ -1302,6 +1304,8 @@ static Native()
13021304
ZkRead_newPath = loader.LoadFunction<ZkRead_newPath>("ZkRead_newPath");
13031305
ZkRead_newExt = loader.LoadFunction<ZkRead_newExt>("ZkRead_newExt");
13041306
ZkRead_del = loader.LoadFunction<ZkRead_del>("ZkRead_del");
1307+
ZkRead_getSize = loader.LoadFunction<ZkRead_getSize>("ZkRead_getSize");
1308+
ZkRead_getBytes = loader.LoadFunction<ZkRead_getBytes>("ZkRead_getBytes");
13051309
ZkVfs_new = loader.LoadFunction<ZkVfs_new>("ZkVfs_new");
13061310
ZkVfs_del = loader.LoadFunction<ZkVfs_del>("ZkVfs_del");
13071311
ZkVfs_getRoot = loader.LoadFunction<ZkVfs_getRoot>("ZkVfs_getRoot");

ZenKit/NativeLoader/NativeFunctions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ namespace NativeFunctions
156156
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
157157
public delegate void ZkRead_del(UIntPtr slf);
158158

159+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
160+
public delegate ulong ZkRead_getSize(UIntPtr slf);
161+
162+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
163+
public delegate ulong ZkRead_getBytes(UIntPtr slf, byte[] buf, ulong length);
164+
159165
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
160166
public delegate UIntPtr ZkVfs_new();
161167

ZenKit/Stream.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using ZenKit.NativeLoader.NativeFunctions;
23
using ZenKit.NativeLoader.NativeStructs;
34

45
namespace ZenKit
@@ -50,6 +51,16 @@ internal Read(UIntPtr handle)
5051

5152
internal UIntPtr Handle { get; }
5253

54+
public byte[] Bytes
55+
{
56+
get
57+
{
58+
var buf = new byte[Native.ZkRead_getSize(Handle)];
59+
Native.ZkRead_getBytes(Handle, buf, (ulong)buf.Length);
60+
return buf;
61+
}
62+
}
63+
5364
~Read()
5465
{
5566
Native.ZkRead_del(Handle);
-1.66 MB
Binary file not shown.
1.66 MB
Binary file not shown.
2.36 MB
Binary file not shown.

0 commit comments

Comments
 (0)