diff --git a/include/d/psyc/parser.d b/include/d/psyc/parser.d index 4345d52..1d03adc 100644 --- a/include/d/psyc/parser.d +++ b/include/d/psyc/parser.d @@ -22,6 +22,7 @@ extern (C): enum ParseFlag { PARSE_HEADER_ONLY = 1, + PARSE_BEGIN_AT_CONTENT = 2, } /** diff --git a/include/psyc/parser.h b/include/psyc/parser.h index f1e8412..bff444d 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -23,7 +23,7 @@ typedef enum { PSYC_PARSE_HEADER_ONLY = 1, /// Expects only the content part of a packet. The length of the content must fit exactly in this case - PSYC_BEGIN_PARSE_AT_CONTENT = 2, + PSYC_PARSE_BEGIN_AT_CONTENT = 2, } psycParseFlag; /** diff --git a/src/parser.c b/src/parser.c index 501c300..914e483 100644 --- a/src/parser.c +++ b/src/parser.c @@ -24,6 +24,9 @@ inline void psyc_initParseState2 (psycParseState* state, uint8_t flags) { memset(state, 0, sizeof(psycParseState)); state->flags = flags; + + if (flags & PSYC_PARSE_BEGIN_AT_CONTENT) + state->part = PSYC_PART_CONTENT; } inline void psyc_initParseListState (psycParseListState* state) @@ -33,6 +36,12 @@ inline void psyc_initParseListState (psycParseListState* state) inline void psyc_nextParseBuffer (psycParseState* state, psycString newBuf) { + if (state->flags & PSYC_PARSE_BEGIN_AT_CONTENT) + { + state->contentLength = newBuf.length; + state->contentLengthFound = PSYC_TRUE; + } + state->buffer = newBuf; state->cursor = 0; } @@ -275,6 +284,7 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc { state->contentLengthFound = 1; state->contentLength = 0; + do { state->contentLength = 10 * state->contentLength + state->buffer.ptr[state->cursor] - '0'; @@ -308,7 +318,8 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc case PSYC_PART_CONTENT: // In case of an incomplete binary variable resume parsing it. - if (state->valueParsed < state->valueLength) { + if (state->valueParsed < state->valueLength) + { ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed)); state->contentParsed += value->length;