From 8e029f578a807fe5ec97e734b16f2c3e27cbbf44 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Wed, 15 Jan 2025 15:10:52 +0000 Subject: [PATCH 1/2] Add missing type parameter documentation --- Bonsai.Dsp/MatrixWriter.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Bonsai.Dsp/MatrixWriter.cs b/Bonsai.Dsp/MatrixWriter.cs index 5eb171691..2f222fe65 100644 --- a/Bonsai.Dsp/MatrixWriter.cs +++ b/Bonsai.Dsp/MatrixWriter.cs @@ -52,13 +52,14 @@ protected override void Write(BinaryWriter writer, ArraySegment input) /// /// Writes all of the arrays in an observable sequence to the specified raw binary output stream. /// - /// - /// The sequence of arrays to write. The elements stored in each array must - /// be of an unmanaged type. - /// + /// + /// The type of the elements in each array. This type must be a non-pointer, non-nullable + /// unmanaged type. + /// + /// The sequence of arrays to write. /// /// An observable sequence that is identical to the source sequence but where - /// there is an additional side effect of writing the arrays to a stream. + /// there is an additional side effect of writing the arrays to a binary stream. /// public unsafe IObservable Process(IObservable source) where TElement : unmanaged { From 1e31c3411eb84f3424c6ed20428cddcc2ac6a062 Mon Sep 17 00:00:00 2001 From: glopesdev Date: Wed, 15 Jan 2025 15:11:35 +0000 Subject: [PATCH 2/2] 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 2f222fe65..97a8ab94d 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.