in src/csharp/Protocol.cs [181:211]
private void ProcessData()
{
while (true) {
if (_bodyLength >= 0) {
if (_rawData.Length >= _bodyLength) {
var buf = _rawData.RemoveFirst(_bodyLength);
_bodyLength = -1;
Dispatch(Encoding.GetString(buf));
continue; // there may be more complete messages to process
}
}
else {
string s = _rawData.GetString(Encoding);
var idx = s.IndexOf(TWO_CRLF);
if (idx != -1) {
Match m = CONTENT_LENGTH_MATCHER.Match(s);
if (m.Success && m.Groups.Count == 2) {
_bodyLength = Convert.ToInt32(m.Groups[1].ToString());
_rawData.RemoveFirst(idx + TWO_CRLF.Length);
continue; // try to handle a complete message
}
}
}
break;
}
}