diff --git a/src/libplctag.NativeImport/NativeMethods.cs b/src/libplctag.NativeImport/NativeMethods.cs
index 7076d38..37d2ee2 100644
--- a/src/libplctag.NativeImport/NativeMethods.cs
+++ b/src/libplctag.NativeImport/NativeMethods.cs
@@ -257,9 +257,9 @@ static NativeMethods()
[DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_get_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, [Out] byte[] buffer, int buffer_length);
+ public unsafe static extern int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
[DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_set_raw_bytes), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- public static extern int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, [In] byte[] buffer, int buffer_length);
+ public unsafe static extern int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte* buffer, int buffer_length);
}
}
diff --git a/src/libplctag.NativeImport/libplctag.NativeImport.csproj b/src/libplctag.NativeImport/libplctag.NativeImport.csproj
index 6dd8ce8..9141956 100644
--- a/src/libplctag.NativeImport/libplctag.NativeImport.csproj
+++ b/src/libplctag.NativeImport/libplctag.NativeImport.csproj
@@ -33,10 +33,12 @@
true
true
embedded
+ true
+
diff --git a/src/libplctag.NativeImport/plctag.cs b/src/libplctag.NativeImport/plctag.cs
index 0da0f80..07eb31d 100644
--- a/src/libplctag.NativeImport/plctag.cs
+++ b/src/libplctag.NativeImport/plctag.cs
@@ -295,12 +295,34 @@ public static int plc_tag_get_string_total_length(Int32 tag_id, int string_start
public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length)
{
- return NativeMethods.plc_tag_get_raw_bytes(tag_id, start_offset, buffer, buffer_length);
+ return plc_tag_get_raw_bytes(tag_id, start_offset, buffer.AsSpan(0, buffer_length));
+ }
+
+ public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, Span buffer)
+ {
+ unsafe
+ {
+ fixed (byte* ptr = buffer)
+ {
+ return NativeMethods.plc_tag_get_raw_bytes(tag_id, start_offset, ptr, buffer.Length);
+ }
+ }
}
public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length)
{
- return NativeMethods.plc_tag_set_raw_bytes(tag_id, start_offset, buffer, buffer_length);
+ return plc_tag_set_raw_bytes(tag_id, start_offset, new ReadOnlySpan(buffer, 0, buffer_length));
+ }
+
+ public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, ReadOnlySpan buffer)
+ {
+ unsafe
+ {
+ fixed (byte* ptr = buffer)
+ {
+ return NativeMethods.plc_tag_set_raw_bytes(tag_id, start_offset, ptr, buffer.Length);
+ }
+ }
}