diff --git a/Bonsai.Dsp/MatrixWriter.cs b/Bonsai.Dsp/MatrixWriter.cs index 5eb17169..97a8ab94 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 { @@ -70,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.