diff --git a/src/Aquarium.LocalCast/LocalCastNativeReservoir.cs b/src/Aquarium.LocalCast/LocalCastNativeReservoir.cs index 99f5823..7651b16 100644 --- a/src/Aquarium.LocalCast/LocalCastNativeReservoir.cs +++ b/src/Aquarium.LocalCast/LocalCastNativeReservoir.cs @@ -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);