Skip to content

Commit

Permalink
NormFile Refactor
Browse files Browse the repository at this point in the history
* Updated NormFileGetName to use sbyte* to avoid casting

* Updated design
  • Loading branch information
mullerj committed Aug 28, 2024
1 parent e4513cc commit 3ee6345
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/dotnet/design/Mil/Navy/Nrl/Norm/NormApi.puml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class NormApi <<static>> {
+ {static} <<extern>> NormObjectCancel(objectHandle:long) : void
+ {static} <<extern>> NormObjectRetain(objectHandle:long) : void
+ {static} <<extern>> NormObjectRelease(objectHandle:long) : void
+ {static} <<extern>> NormFileGetName(fileHandle:long, nameBuffer:nint, bufferLen:int) : bool
+ <<unsafe>> {static} <<extern>> NormFileGetName(fileHandle:long, nameBuffer:sbyte*, bufferLen:int) : bool
+ {static} <<extern>> NormFileRename(fileHandle:long, fileName:string) : bool
+ {static} <<extern>> NormDataAccessData(objectHandle:long) : nint
+ {static} <<extern>> NormObjectGetSender(objectHandle:long) : long
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/src/Mil.Navy.Nrl.Norm/NormApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ public struct NormEvent
/// does not refer to an object of type NORM_OBJECT_FILE.
/// </returns>
[DllImport(NORM_LIBRARY)]
public static extern bool NormFileGetName(long fileHandle, nint nameBuffer, int bufferLen);
public unsafe static extern bool NormFileGetName(long fileHandle, sbyte* nameBuffer, int bufferLen);

/// <summary>
/// This function renames the file used to store content for the NORM_OBJECT_FILE transport object specified by
Expand Down
15 changes: 5 additions & 10 deletions src/dotnet/src/Mil.Navy.Nrl.Norm/NormFile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Runtime.InteropServices;
using System.Text;

namespace Mil.Navy.Nrl.Norm
namespace Mil.Navy.Nrl.Norm
{
/// <summary>
/// A transport object of type NORM_OBJECT_FILE.
Expand Down Expand Up @@ -29,16 +26,14 @@ public unsafe string Name
{
get
{
var buffer = stackalloc byte[FILENAME_MAX];
var bufferPtr = (nint)buffer;
var buffer = stackalloc sbyte[FILENAME_MAX];

if (!NormFileGetName(_handle, bufferPtr, FILENAME_MAX))
if (!NormFileGetName(_handle, buffer, FILENAME_MAX))
{
throw new IOException("Failed to get file name");
}
var name = Marshal.PtrToStringAnsi(bufferPtr);

return name ?? string.Empty;

return new string(buffer);
}
}

Expand Down

0 comments on commit 3ee6345

Please sign in to comment.