Files
NetworkTest/Client/FrameAssembler.cs

27 lines
654 B
C#

using System;
using System.Collections.Generic;
using Domain;
namespace Client;
public class FrameAssembler
{
private readonly Action<List<Data>> _frameCallback;
private readonly List<Data> _buffer = new List<Data>();
private const int FrameSize = 9;
public FrameAssembler(Action<List<Data>> frameCallback)
{
_frameCallback = frameCallback ?? throw new ArgumentNullException(nameof(frameCallback));
}
public void AddData(Data data)
{
_buffer.Add(data);
if (_buffer.Count >= FrameSize)
{
_frameCallback(new List<Data>(_buffer));
_buffer.Clear();
}
}
}