mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
adjusted functions for flag PARSE_BEGIN_AT_CONTENT
This commit is contained in:
parent
ac29663a47
commit
6463c3e9bb
3 changed files with 14 additions and 2 deletions
|
@ -22,6 +22,7 @@ extern (C):
|
||||||
enum ParseFlag
|
enum ParseFlag
|
||||||
{
|
{
|
||||||
PARSE_HEADER_ONLY = 1,
|
PARSE_HEADER_ONLY = 1,
|
||||||
|
PARSE_BEGIN_AT_CONTENT = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,7 +23,7 @@ typedef enum
|
||||||
{
|
{
|
||||||
PSYC_PARSE_HEADER_ONLY = 1,
|
PSYC_PARSE_HEADER_ONLY = 1,
|
||||||
/// Expects only the content part of a packet. The length of the content must fit exactly in this case
|
/// 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;
|
} psycParseFlag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
13
src/parser.c
13
src/parser.c
|
@ -24,6 +24,9 @@ inline void psyc_initParseState2 (psycParseState* state, uint8_t flags)
|
||||||
{
|
{
|
||||||
memset(state, 0, sizeof(psycParseState));
|
memset(state, 0, sizeof(psycParseState));
|
||||||
state->flags = flags;
|
state->flags = flags;
|
||||||
|
|
||||||
|
if (flags & PSYC_PARSE_BEGIN_AT_CONTENT)
|
||||||
|
state->part = PSYC_PART_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void psyc_initParseListState (psycParseListState* state)
|
inline void psyc_initParseListState (psycParseListState* state)
|
||||||
|
@ -33,6 +36,12 @@ inline void psyc_initParseListState (psycParseListState* state)
|
||||||
|
|
||||||
inline void psyc_nextParseBuffer (psycParseState* state, psycString newBuf)
|
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->buffer = newBuf;
|
||||||
state->cursor = 0;
|
state->cursor = 0;
|
||||||
}
|
}
|
||||||
|
@ -275,6 +284,7 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
|
||||||
{
|
{
|
||||||
state->contentLengthFound = 1;
|
state->contentLengthFound = 1;
|
||||||
state->contentLength = 0;
|
state->contentLength = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
state->contentLength = 10 * state->contentLength + state->buffer.ptr[state->cursor] - '0';
|
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:
|
case PSYC_PART_CONTENT:
|
||||||
// In case of an incomplete binary variable resume parsing it.
|
// 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));
|
ret = psyc_parseBinaryValue(state, value, &(state->valueLength), &(state->valueParsed));
|
||||||
state->contentParsed += value->length;
|
state->contentParsed += value->length;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue