From 1e31c3411eb84f3424c6ed20428cddcc2ac6a062 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Wed, 15 Jan 2025 15:11:35 +0000 Subject: [PATCH] Add overload for sequences of unmanaged types --- Bonsai.Dsp/MatrixWriter.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Bonsai.Dsp/MatrixWriter.cs b/Bonsai.Dsp/MatrixWriter.cs index 2f222fe6..97a8ab94 100644 --- a/Bonsai.Dsp/MatrixWriter.cs +++ b/Bonsai.Dsp/MatrixWriter.cs @@ -71,6 +71,30 @@ public unsafe IObservable Process(IObservable }); } + /// + /// Writes all of the values in an observable sequence to the specified raw binary output stream. + /// + /// + /// The type of the elements in the sequence. This type must be a non-pointer, non-nullable + /// unmanaged type. + /// + /// The sequence of values to write. + /// + /// An observable sequence that is identical to the source sequence but where + /// there is an additional side effect of writing the values to a binary stream. + /// + public unsafe IObservable Process(IObservable source) where TElement : unmanaged + { + return Process(source, input => + { + var valuePtr = &input; + var bytes = new byte[sizeof(TElement)]; + fixed (byte* bytesPtr = bytes) + System.Buffer.MemoryCopy(valuePtr, bytesPtr, bytes.Length, bytes.Length); + return new ArraySegment(bytes); + }); + } + /// /// Writes all of the arrays in an observable sequence to the /// specified raw binary output stream.