From 924aa2f6b4fdc2881d2a784848a2c487cb5d7079 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 12:33:39 +0100 Subject: [PATCH] Expose LocalCast native source hashing --- .../LocalCastNativeReservoir.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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);