Example #1
0
        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();
        }
Example #2
0
 private void TriggerObjectFinishedAndResetCurrentContainer()
 {
     if (ObjectFinished != null)
         ObjectFinished(currentContainerToFill);
     currentContainerToFill = null;
 }
Example #3
0
 public DataCollector()
 {
     availableData = new Queue<byte>();
     currentContainerToFill = null;
 }
Example #4
0
 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);
     }
 }