Реализована запись полученных кадров в файл
This commit is contained in:
27
Client/FrameAssembler.cs
Normal file
27
Client/FrameAssembler.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user