processOctetCounting(const instanceConf_t *const inst,
	struct conn_wrkr_s *connWrkr, const char* buf, size_t len)
{
	DEFiRet;
	const uchar* pbuf = (const uchar*)buf;
	const uchar* pbufLast = pbuf + len;

	while (pbuf < pbufLast) {
		char ch = *pbuf;

		if (connWrkr->parseState.inputState == eAtStrtFram || connWrkr->parseState.inputState == eInOctetCnt) {
			processOctetMsgLen(inst, connWrkr, ch);
			if (connWrkr->parseState.framingMode == TCP_FRAMING_OCTET_COUNTING) {
				pbuf++;
			}
		} else if (connWrkr->parseState.inputState == eInMsg) {
			if (connWrkr->parseState.framingMode == TCP_FRAMING_OCTET_STUFFING) {
				if (connWrkr->iMsg < s_iMaxLine) {
					if (ch == '\n') {
						doSubmitMsg(inst, connWrkr, connWrkr->pMsg, connWrkr->iMsg);
						connWrkr->parseState.inputState = eAtStrtFram;
					} else {
						connWrkr->pMsg[connWrkr->iMsg++] = ch;
					}
				} else {
					doSubmitMsg(inst, connWrkr, connWrkr->pMsg, connWrkr->iMsg);
					connWrkr->parseState.inputState = eAtStrtFram;
				}
				pbuf++;
			} else {
				assert (connWrkr->parseState.framingMode == TCP_FRAMING_OCTET_COUNTING);
				/* parsing payload */
				size_t remainingBytes = pbufLast - pbuf;
				// figure out how much is in block
				size_t count = min (connWrkr->parseState.iOctetsRemain, remainingBytes);
				if (connWrkr->iMsg + count >= s_iMaxLine) {
					count = s_iMaxLine - connWrkr->iMsg;
				}

				// just copy the bytes
				if (count) {
					memcpy(connWrkr->pMsg + connWrkr->iMsg, pbuf, count);
					pbuf += count;
					connWrkr->iMsg += count;
					connWrkr->parseState.iOctetsRemain -= count;
				}

				if (connWrkr->parseState.iOctetsRemain == 0) {
					doSubmitMsg(inst, connWrkr, connWrkr->pMsg, connWrkr->iMsg);
					connWrkr->parseState.inputState = eAtStrtFram;
				}
			}
		} else {
			// unexpected
			assert(0);
			break;
		}
	}
	RETiRet;
}
processOctetCounting(const instanceConf_t *const inst,
	struct conn_wrkr_s *connWrkr, const char* buf, size_t len)
{
	DEFiRet;
	const uchar* pbuf = (const uchar*)buf;
	const uchar* pbufLast = pbuf + len;

	while (pbuf < pbufLast) {
		char ch = *pbuf;

		if (connWrkr->parseState.inputState == eAtStrtFram || connWrkr->parseState.inputState == eInOctetCnt) {
			processOctetMsgLen(inst, connWrkr, ch);
			if (connWrkr->parseState.framingMode == TCP_FRAMING_OCTET_COUNTING) {
				pbuf++;
			}
		} else if (connWrkr->parseState.inputState == eInMsg) {
			if (connWrkr->parseState.framingMode == TCP_FRAMING_OCTET_STUFFING) {
				if (connWrkr->iMsg < s_iMaxLine) {
					if (ch == '\n') {
						doSubmitMsg(inst, connWrkr, connWrkr->pMsg, connWrkr->iMsg);
						connWrkr->parseState.inputState = eAtStrtFram;
					} else {
						connWrkr->pMsg[connWrkr->iMsg++] = ch;
					}
				} else {
					doSubmitMsg(inst, connWrkr, connWrkr->pMsg, connWrkr->iMsg);
					connWrkr->parseState.inputState = eAtStrtFram;
				}
				pbuf++;
			} else {
				assert (connWrkr->parseState.framingMode == TCP_FRAMING_OCTET_COUNTING);
				 
				size_t remainingBytes = pbufLast - pbuf;
				 
				size_t count = min (connWrkr->parseState.iOctetsRemain, remainingBytes);
				if (connWrkr->iMsg + count >= s_iMaxLine) {
					count = s_iMaxLine - connWrkr->iMsg;
				}

				 
				if (count) {
					memcpy(connWrkr->pMsg + connWrkr->iMsg, pbuf, count);
					pbuf += count;
					connWrkr->iMsg += count;
					connWrkr->parseState.iOctetsRemain -= count;
				}

				if (connWrkr->parseState.iOctetsRemain == 0) {
					doSubmitMsg(inst, connWrkr, connWrkr->pMsg, connWrkr->iMsg);
					connWrkr->parseState.inputState = eAtStrtFram;
				}
			}
		} else {
			 
			assert(0);
			break;
		}
	}
	RETiRet;
}