public void ReadBytes() { if (currentContainerToFill == null) { if (availableData.Count < NumberOfReservedBytesForMessageLength) return; currentContainerToFill = new MessageData(ReadLength()); } currentContainerToFill.ReadData(availableData); if (currentContainerToFill.IsDataComplete) TriggerObjectFinishedAndResetCurrentContainer(); if (availableData.Count > 0) ReadBytes(); }
private void TriggerObjectFinishedAndResetCurrentContainer() { if (ObjectFinished != null) ObjectFinished(currentContainerToFill); currentContainerToFill = null; }
public DataCollector() { availableData = new Queue<byte>(); currentContainerToFill = null; }
private void OnObjectFinished(MessageData dataContainer) { using (var dataStream = new MemoryStream(dataContainer.Data)) using (var dataReader = new BinaryReader(dataStream)) { BinaryData receivedMessage = GetReceivedMessage(dataReader); if (DataReceived != null) DataReceived(this, receivedMessage); } }