Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/GridSolutionsFramework.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=sourceids/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Starlynn/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sttp/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=STTP_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subfile/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subsecond/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subseconds/@EntryIndexedValue">True</s:Boolean>
Expand Down
114 changes: 74 additions & 40 deletions Source/Libraries/GSF.TimeSeries/BufferBlockMeasurement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,91 @@

using System;

namespace GSF.TimeSeries
namespace GSF.TimeSeries;

/// <summary>
/// Represents a byte buffer that can be transported through the system as a <see cref="IMeasurement"/>.
/// </summary>
public class BufferBlockMeasurement : Measurement
{
#region [ Constructors ]

/// <summary>
/// Represents a byte buffer that can be transported through the system as a <see cref="IMeasurement"/>.
/// Creates a new <see cref="BufferBlockMeasurement"/>.
/// </summary>
public class BufferBlockMeasurement : Measurement
public BufferBlockMeasurement()
{
#region [ Constructors ]
Value = double.NaN; // Value of measurement should be indeterminate since this a buffer
}

/// <summary>
/// Creates a new <see cref="BufferBlockMeasurement"/>.
/// </summary>
public BufferBlockMeasurement() =>
Value = double.NaN; // Value of measurement should be indeterminate since this a buffer
/// <summary>
/// Creates a new <see cref="BufferBlockMeasurement"/> from an existing buffer.
/// </summary>
/// <param name="buffer">Source buffer.</param>
/// <param name="startIndex">Start index of valid data in source buffer.</param>
/// <param name="length">Valid length of source buffer.</param>
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> or <paramref name="length"/> is less than 0 -or-
/// <paramref name="startIndex"/> and <paramref name="length"/> will exceed <paramref name="buffer"/> length.
/// </exception>
public BufferBlockMeasurement(byte[] buffer, int startIndex, int length) : this()
{
// Validate buffer parameters
buffer.ValidateParameters(startIndex, length);

/// <summary>
/// Creates a new <see cref="BufferBlockMeasurement"/> from an existing buffer.
/// </summary>
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> or <paramref name="length"/> is less than 0 -or-
/// <paramref name="startIndex"/> and <paramref name="length"/> will exceed <paramref name="buffer"/> length.
/// </exception>
public BufferBlockMeasurement(byte[] buffer, int startIndex, int length)
: this()
{
// Validate buffer parameters
buffer.ValidateParameters(startIndex, length);
// We don't hold on to source buffer (we don't own it), so we instantiate a new one
Buffer = new byte[length];

// We don't hold on to source buffer (we don't own it), so we instantiate a new one
Buffer = new byte[length];
// Copy buffer contents onto our local buffer
System.Buffer.BlockCopy(buffer, startIndex, Buffer, 0, length);
Length = length;
}

// Copy buffer contents onto our local buffer
System.Buffer.BlockCopy(buffer, startIndex, Buffer, 0, length);
Length = length;
}
#endregion

#endregion
#region [ Properties ]

#region [ Properties ]
/// <summary>
/// Cached buffer image.
/// </summary>
public byte[] Buffer { get; }

/// <summary>
/// Cached buffer image.
/// </summary>
public byte[] Buffer { get; }
/// <summary>
/// Valid length of cached buffer image.
/// </summary>
public int Length { get; }

/// <summary>
/// Gets or sets a value indicating whether reception of this buffer block must be acknowledged
/// by the subscriber with a <c>ConfirmBufferBlock</c> command.
/// </summary>
/// <remarks>
/// <para>
/// Maps to IEEE Std 2664-2024 Table 8 bit <c>0x01</c> (REQUIRE CONFIRMATION) on the wire.
/// Default value is <c>true</c>, preserving STTP's traditional retransmission semantics where
/// the publisher caches each buffer block until acknowledged and retransmits on timeout.
/// </para>
/// <para>
/// When set to <c>false</c>, the buffer block is fire-and-forget: no retransmission cache entry
/// is added, the retransmission timer is not (re)started, and the subscriber does not emit a
/// confirmation. Useful for high-rate buffer-block streams over reliable transports (TCP)
/// where the round-trip acknowledgement overhead is unnecessary.
/// </para>
/// </remarks>
public bool RequireConfirmation { get; set; } = true;

/// <summary>
/// Valid length of cached buffer image.
/// </summary>
public int Length { get; }
/// <summary>
/// Gets or sets the raw buffer-block flag byte as it appeared on the wire (IEEE Std 2664-2024
/// Table 8). On receive, this carries the publisher's full intent (REQUIRE CONFIRMATION,
/// COMPRESSED, CACHE INDEX, etc.); on send, this field is unused by the wire codec - the codec
/// constructs the byte from <see cref="RequireConfirmation"/> and other per-block state.
/// </summary>
/// <remarks>
/// Stored as a raw <see cref="byte"/> so this assembly need not take a dependency on the STTP
/// flag enum. Cast to <c>BufferBlockFlags</c> at the call site if structured inspection is needed.
/// </remarks>
public byte Flags { get; set; }

#endregion
}
#endregion
}
Loading