Files
voice-cat/clients/windows/VoiceCat.Interop/VoiceCatEvent.cs
T

33 lines
884 B
C#
Raw Normal View History

using System.Runtime.InteropServices;
namespace VoiceCat.Interop;
/// <summary>
/// Managed copy of a vc_event — safe to hold/queue past the native callback's return (unlike
/// VcEventNative, whose Text pointer is only valid during the callback).
/// </summary>
public sealed record VoiceCatEvent(
VcEventType Type,
VcConnectionState ConnectionState,
VcResult Result,
uint UserId,
uint ChannelId,
uint StreamId,
VcTextScope TextScope,
uint U32a,
string? Text,
ulong TimestampUnixMs)
{
internal static VoiceCatEvent FromNative(in VcEventNative ev) => new(
ev.Type,
ev.ConnectionState,
(VcResult)ev.Result,
ev.UserId,
ev.ChannelId,
ev.StreamId,
ev.TextScope,
ev.U32a,
ev.Text == IntPtr.Zero ? null : Marshal.PtrToStringUTF8(ev.Text),
ev.TimestampUnixMs);
}