Expose LocalCast native source hashing

This commit is contained in:
Meta Vens 2026-05-19 12:33:39 +01:00
commit 924aa2f6b4

View file

@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Text;
namespace Aquarium.LocalCast;
@ -112,6 +113,20 @@ public interface ILocalCastNativeRuntime : IDisposable
bool TryReadLatestForSensor(LocalCastNativeSampleKind kind, ulong sensorIdHash, out LocalCastNativeSampleHandle sample);
}
public static class LocalCastNativeSourceId
{
public static ulong HashUtf8(string sourceId)
{
if (string.IsNullOrEmpty(sourceId))
{
return 0;
}
var bytes = Encoding.UTF8.GetBytes(sourceId);
return LocalCastNativeMethods.HashSourceId(bytes, (UIntPtr)bytes.Length);
}
}
public interface ILocalCastNativeProducer : IDisposable
{
ulong NextSequence { get; }
@ -266,6 +281,9 @@ internal static class LocalCastNativeMethods
{
private const string LibraryName = "localcast_reservoir";
[DllImport(LibraryName, EntryPoint = "localcast_hash_source_id")]
internal static extern ulong HashSourceId(byte[] bytes, UIntPtr byteLen);
[DllImport(LibraryName, EntryPoint = "localcast_runtime_create")]
internal static extern IntPtr RuntimeCreate(ulong durationNs);