Private Sub astream_NewData (Buffer() As Byte)
bc.ArrayCopy(Buffer, 0, DataBuffer, DataBufferLength, Buffer.Length)
DataBufferLength = DataBufferLength + Buffer.Length
If FindBeginMark Then
CallSub2(Main, "NewValue", FindEndMark) 'we have a full message here.
End If
End Sub
Private Sub FindBeginMark As Boolean
For i = 0 To DataBufferLength - 1
If DataBuffer(i) = MARK_BEGIN Then Exit
Next
If i > 0 Then
'remove the beginning
bc.ArrayCopy(DataBuffer, i, DataBuffer, 0, DataBufferLength - i)
DataBufferLength = DataBufferLength - i
End If
Return DataBuffer(0) = MARK_BEGIN
End Sub
Private Sub FindEndMark As Object()
For i = 0 To DataBufferLength - 1
If DataBuffer(i) = MARK_END And (i = DataBufferLength - 1 Or DataBuffer(i + 1) = MARK_BEGIN) Then
Dim b(i + 1) As Byte
bc.ArrayCopy(DataBuffer, 0, b, 0, i + 1)
'remove the current message
bc.ArrayCopy(DataBuffer, i + 1, DataBuffer, 0, DataBufferLength - i - 1)
DataBufferLength = DataBufferLength - i - 1
Return ser.ConvertBytesToArray(b)
End If
Next
Return Array()
End Sub