diff --git a/data/test/sessionSetupReq.xml.exi b/data/test/sessionSetupReq.xml.exi new file mode 100644 index 0000000..5436fd3 Binary files /dev/null and b/data/test/sessionSetupReq.xml.exi differ diff --git a/data/test/sessionSetupRes.xml.exi b/data/test/sessionSetupRes.xml.exi new file mode 100644 index 0000000..ca56267 Binary files /dev/null and b/data/test/sessionSetupRes.xml.exi differ diff --git a/src/codec/EXIDecoder.c b/src/codec/EXIDecoder.c index 5a01452..99a74b4 100644 --- a/src/codec/EXIDecoder.c +++ b/src/codec/EXIDecoder.c @@ -45,7 +45,6 @@ /* local variables */ -static uint32_t xsi; static uint32_t bits; static int errn; diff --git a/src/codec/EXIEncoder.c b/src/codec/EXIEncoder.c index f6c95b5..1c5d8df 100644 --- a/src/codec/EXIEncoder.c +++ b/src/codec/EXIEncoder.c @@ -45,7 +45,6 @@ /* local variables */ -static uint32_t bits; static int errn; /* ==================================== */ @@ -103,108 +102,6 @@ int exiEncodeListValue(bitstream_t* stream, exi_value_t* val, list_t lt) { return errn; } - - -/* <0 ... Error, 1 .. Not-Found, 0.. Success */ -static int _exiGet1stLevelEventCode(exi_state_t* state, exi_event_t eventType, uint16_t* resGrammarID) { - /* retrieve current grammar-rule ID */ - uint16_t grammarID = state->grammarStack[ state->stackIndex ]; - - switch(grammarID) { - case DOCUMENT: - switch(eventType) { - case EXI_EVENT_START_DOCUMENT: - *resGrammarID = 0; - return 0; - default: - return 1; /* not found */ - } - break; - case DOC_CONTENT: - switch(eventType) { - /* TODO other IDs */ - case EXI_EVENT_START_ELEMENT_GENERIC: - *resGrammarID = 0; - return 0; - default: - return 1; /* not found */ - } - break; - case DOC_END: - switch(eventType) { - case EXI_EVENT_END_DOCUMENT: - *resGrammarID = 0; - return 0; - default: - return 1; /* not found */ - } - break; - case UR_TYPE_GRAMMAR_0: - switch(eventType) { - case EXI_EVENT_ATTRIBUTE_GENERIC: - *resGrammarID = 0; - return 0; - case EXI_EVENT_START_ELEMENT_GENERIC: - *resGrammarID = 1; - return 0; - case EXI_EVENT_END_ELEMENT: - *resGrammarID = 2; - return 0; - case EXI_EVENT_CHARACTERS_GENERIC: - *resGrammarID = 3; - return 0; - default: - return 1; /* not found */ - } - break; - case UR_TYPE_GRAMMAR_1: - switch(eventType) { - case EXI_EVENT_START_ELEMENT_GENERIC: - *resGrammarID = 0; - return 0; - case EXI_EVENT_END_ELEMENT: - *resGrammarID = 1; - return 0; - case EXI_EVENT_CHARACTERS_GENERIC: - *resGrammarID = 2; - return 0; - default: - return 1; /* not found */ - } - break; - } - - return 1; /* not found */ -} - - -static int _exiGetEventCodeLength(exi_state_t* state, uint16_t* eventCodeLength) { - /* retrieve current grammar-rule ID */ - uint16_t grammarID = state->grammarStack[ state->stackIndex ]; - - switch(grammarID) { - /* TODO OTHER IDs */ - case DOCUMENT: - *eventCodeLength = 0; - return 0; - case DOC_CONTENT: - /* TODO other root elements */ - *eventCodeLength = IS_STRICT ? 0 : 1; - return 0; - case DOC_END: - *eventCodeLength = IS_STRICT ? 0 : 1; - return 0; - case UR_TYPE_GRAMMAR_0: - *eventCodeLength = IS_STRICT ? 4 : 5; - return 0; - case UR_TYPE_GRAMMAR_1: - *eventCodeLength = IS_STRICT ? 3 : 4; - return 0; - } - - return EXI_ERROR_UNEXPECTED_GRAMMAR_ID; -} - static int _encodeNBitIntegerValue(bitstream_t* stream, integer_t* iv, uint16_t nbits, int32_t lowerBound) { int errn; uint32_t val; @@ -235,6 +132,8 @@ static int _encodeNBitIntegerValue(bitstream_t* stream, integer_t* iv, uint16_t case EXI_INTEGER_64: val = iv->val.uint64 - lowerBound; break; + default: + return -1; } errn = encodeNBitUnsignedInteger(stream, nbits, val); @@ -303,54 +202,6 @@ static int _exiEncodeNamespaceUriID(bitstream_t* stream, exi_name_table_prepopul return errn; } - -#if EXI_DEBUG == EXI_DEBUG_ON -static int _exiEncodeNamespaceUri(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, - char** uri, uint16_t* uriID) { - int errn; - uint16_t uriCodingLength; - uint16_t uriSize; - - errn = exiGetUriSize(nameTable, runtimeTable, &uriSize); - if (errn) { - return errn; - } - /* URI Entries + 1 */ - errn = exiGetCodingLength(uriSize + 1, &uriCodingLength); - if (errn) { - return errn; - } - - errn = exiGetUriID(nameTable, runtimeTable, *uri, uriID); - if (errn < 0) { - return errn; - } else if (errn == 1) { - /* uri string value was not found */ - /* ==> zero (0) as an n-nit unsigned integer */ - /* followed by uri encoded as string */ - errn = encodeNBitUnsignedInteger(stream, uriCodingLength, 0); - if (errn) { - return errn; - } - /* ASCII String */ - errn = encodeASCII(stream, *uri); - if (errn) { - return errn; - } - /* after encoding string value is added to table */ - /* in UCD Profile NOT */ - *uriID = uriSize; - } else { - /* uri string value found */ - /* ==> value(i+1) is encoded as n-bit unsigned integer */ - errn = encodeNBitUnsignedInteger(stream, uriCodingLength, *uriID + 1); - } - - return errn; -} -#endif /*EXI_DEBUG*/ - - static int _exiEncodeLocalNameID(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, uint16_t uriID, uint16_t localNameID) { int errn; @@ -380,77 +231,6 @@ static int _exiEncodeLocalNameID(bitstream_t* stream, exi_name_table_prepopulate } -#if EXI_DEBUG == EXI_DEBUG_ON -static int _exiEncodeLocalName(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, - char** localName, - uint16_t uriID) { - int errn; - uint16_t localNameID; - uint16_t localNameSize; - uint16_t localNameCodingLength; - uint32_t slen; - - /* look for localNameID */ - errn = exiGetLocalNameID(nameTable, runtimeTable, uriID, *localName, &localNameID); - if (errn < 0) { - return errn; - } - - if (errn == 1) { - /* string value was not found in local partition */ - /* ==> string literal is encoded as a String */ - /* with the length of the string incremented by one */ - slen = (uint32_t)strlen(*localName); - errn = encodeUnsignedInteger32(stream, slen + 1 ); - if (errn >= 0) { - errn = encodeASCIICharacters(stream, *localName, slen); - } - } else { - /* string value found in local partition */ - /* ==> string value is represented as zero (0) encoded as an */ - errn = encodeUnsignedInteger32(stream, 0 ); - if (errn < 0) { - return errn; - } - /* Unsigned Integer followed by an the compact identifier of the */ - /* string value as an n-bit unsigned integer n is log2 m and m is */ - /* the number of entries in the string table partition */ - errn = exiGetLocalNameSize(nameTable, runtimeTable, uriID, &localNameSize); - if (errn < 0) { - return errn; - } - errn = exiGetCodingLength(localNameSize, &localNameCodingLength); - if (errn) { - return errn; - } - errn = encodeNBitUnsignedInteger(stream, localNameCodingLength, localNameID); - } - - return errn; -} -#endif /*EXI_DEBUG*/ - - -#if EXI_DEBUG == EXI_DEBUG_ON -static int _exiEncodeQName(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, - char** uri, char** localName) { - uint16_t uriID; - /* uri */ - int errn =_exiEncodeNamespaceUri(stream, nameTable, runtimeTable, uri, &uriID); - if (errn) { - return errn; - } - /* localName */ - errn = _exiEncodeLocalName(stream, nameTable, runtimeTable, localName, uriID); - if (errn) { - return errn; - } - - return 0 ; -} -#endif /*EXI_DEBUG*/ - - static int _exiEncodeStartElement(bitstream_t* stream, uint16_t nbits, uint32_t val, exi_state_t* state, eqname_t* se, uint16_t stackId, uint16_t newState) { @@ -465,36 +245,6 @@ static int _exiEncodeStartElement(bitstream_t* stream, uint16_t nbits, return exiPushStack(state, newState, se); } -#if EXI_DEBUG == EXI_DEBUG_ON - -static eqname_t eqnGeneric = {65535, 65535}; /* UNSIGNED_INT16_MAX */ - -static int _exiEncodeStartElementGeneric(bitstream_t* stream, uint16_t nbits, - uint32_t val, exi_state_t* state, char** uri, char** localName, uint16_t stackId, - uint16_t newState) { - uint16_t uriID; - /* event-code */ - int errn = encodeNBitUnsignedInteger(stream, nbits, val); - if (errn) { - return errn; - } - /* qualified name */ - errn = _exiEncodeNamespaceUri(stream, &(state->nameTablePrepopulated), &(state->nameTableRuntime), uri, &uriID); - if (errn) { - return errn; - } - errn = _exiEncodeLocalName(stream, &(state->nameTablePrepopulated), &(state->nameTableRuntime), localName, uriID); - if (errn) { - return errn; - } - - /* move on */ - state->grammarStack[state->stackIndex] = stackId; - /* push element on stack */ - return exiPushStack(state, newState, &eqnGeneric); -} -#endif /*EXI_DEBUG*/ - int exiEncodeStartElement(bitstream_t* stream, exi_state_t* state, eqname_t* se) { switch (state->grammarStack[state->stackIndex]) { case 1: @@ -4475,121 +4225,11 @@ int exiEncodeStartElement(bitstream_t* stream, exi_state_t* state, eqname_t* se) return EXI_ERROR_UNEXPECTED_START_ELEMENT; } -/* Qualified Name unknown!! */ -#if EXI_DEBUG == EXI_DEBUG_ON -static int exiEncodeStartElementGenericUnknown(bitstream_t* stream, exi_state_t* state, - char** uri, char** localName) { - uint16_t grammarID; - uint16_t eventCodeLength; - - int errn = _exiGet1stLevelEventCode(state, EXI_EVENT_START_ELEMENT_GENERIC, &grammarID); - if (errn < 0) { - return errn; - } else if (errn == 1) { - /* not found --> try undeclared SE */ - errn = _exiGet1stLevelEventCode(state, EXI_EVENT_START_ELEMENT_GENERIC_UNDECLARED, &grammarID); - if (errn < 0) { - return errn; - } else if (errn == 1) { - /* Should never happen except in STRICT mode */ - return EXI_ERROR_UNEXPECTED_EVENT_LEVEL1; - } else { - /* found START_ELEMENT_GENERIC_UNDECLARED */ - errn = _exiGetEventCodeLength(state, &eventCodeLength); - if (errn < 0) { - return errn; - } else { - /* encode event code*/ - errn = encodeNBitUnsignedInteger(stream, eventCodeLength, grammarID); - if (errn) { - return errn; - } - } - } - } else { - /* found START_ELEMENT_GENERIC */ - errn = _exiGetEventCodeLength(state, &eventCodeLength); - if (errn < 0) { - return errn; - } else { - /* encode event code*/ - errn = encodeNBitUnsignedInteger(stream, eventCodeLength, grammarID); - if (errn) { - return errn; - } - } - } - - /* encode qualified name */ - errn = _exiEncodeQName(stream, &(state->nameTablePrepopulated), &(state->nameTableRuntime), uri, localName); - if (errn) { - return errn; - } - - /* learn event, not in UCD Profile */ - - /* move on */ - /* push element on stack */ - - switch (state->grammarStack[state->stackIndex]) { - /* $EXI_ENCODE_START_ELEMENT_GENERIC$ */ - case DOC_CONTENT: - /* move on to DocEnd */ - state->grammarStack[state->stackIndex] = DOC_END; - /* push new ur-type grammar on stack */ - return exiPushStack(state, UR_TYPE_GRAMMAR_0, NULL); - break; - case UR_TYPE_GRAMMAR_0: - /* move on to UR_TYPE_GRAMMAR_1 */ - state->grammarStack[state->stackIndex] = UR_TYPE_GRAMMAR_1; - /* push new ur-type grammar on stack */ - return exiPushStack(state, UR_TYPE_GRAMMAR_0, NULL); - break; - case UR_TYPE_GRAMMAR_1: - /* remain in UR_TYPE_GRAMMAR_1 */ - /* push new ur-type grammar on stack */ - return exiPushStack(state, UR_TYPE_GRAMMAR_0, NULL); - break; - default: - return EXI_ERROR_UNEXPECTED_START_ELEMENT_GENERIC; - } - - - - return 0; -} -#endif /*EXI_DEBUG*/ - - /* Look first for qualified name */ int exiEncodeStartElementGeneric(bitstream_t* stream, exi_state_t* state, string_ascii_t* namespaceURI , string_ascii_t* localName) { int errn = -1; -#if EXI_DEBUG == EXI_DEBUG_ON - eqname_t se; - /* uri */ - errn = exiGetUriID(&(state->nameTablePrepopulated), &(state->nameTableRuntime), namespaceURI->chars, &se.namespaceURI); - if (errn == -1) { - return errn; - } else if (errn == 1) { - /* No URI (and localNameID) found */ - exiEncodeStartElementGenericUnknown(stream, state, &(namespaceURI->chars), &(localName->chars)); - } else { - /* localName */ - errn = exiGetLocalNameID(&(state->nameTablePrepopulated), &(state->nameTableRuntime), se.namespaceURI, localName->chars, &se.localPart); - if (errn == -1) { - return errn; - } else if (errn == 1) { - /* No localName found, use generic StartElement(*) method */ - exiEncodeStartElementGenericUnknown(stream, state, &(namespaceURI->chars), &(localName->chars)); - } else { - /* Uri&LocalName found, use "efficient" StartElement method */ - return exiEncodeStartElement(stream, state, &se); - } - } -#endif /*EXI_DEBUG*/ - return errn; } @@ -8156,63 +7796,6 @@ int exiEncodeAttribute(bitstream_t* stream, exi_state_t* state, eqname_t* at, /* return EXI_ERROR_UNEXPECTED_ATTRIBUTE; */ } -#if EXI_DEBUG == EXI_DEBUG_ON -static int exiEncodeAttribute2(bitstream_t* stream, exi_state_t* state, qname_t* at, - exi_value_t* val) { - int errn; - eqname_t eat; - - /* attribute generic undeclared */ - uint16_t codeLength1, codeLength2; - uint32_t ec1, ec2; - - errn = exiGetUriID(&state->nameTablePrepopulated, &state->nameTableRuntime, at->namespaceURI.chars, &eat.namespaceURI); - if (errn < 0) { - return errn; - } else if (errn > 0) { - /* uri not found*/ - } else { - /* uri found, try to find localname id */ - errn = exiGetLocalNameID(&state->nameTablePrepopulated, &state->nameTableRuntime, eat.namespaceURI, - at->localName.chars, &eat.localPart); - if (errn < 0) { - return errn; - } else if (errn > 0) { - /* local-name not found*/ - } else { - /* found uri and local-name */ - errn = exiEncodeAttribute(stream, state, &eat, val); - if (errn < 0) { - return errn; - } - if (errn == 0) { - return errn; - } - - } - } - - - /* event codes */ - encodeNBitUnsignedInteger(stream, codeLength1, ec1); - encodeNBitUnsignedInteger(stream, codeLength2, ec2); - - /* qname */ - /* - errn = _exiEncodeQName(stream, state->nameTablePrepopulated, state->nameTableRuntime, - char** uri, char** localName); - QName qname = qnameDatatype.encodeQName(uri, localName, null, channel); - */ - /* content as string */ - /* - typeEncoder.isValid(BuiltIn.DEFAULT_DATATYPE, value); - typeEncoder.writeValue(qname, channel); - */ - return -1; - -} -#endif /*EXI_DEBUG*/ - int exiEncodeAttributeXsiNil(bitstream_t* stream, exi_state_t* state, exi_value_t* val) { diff --git a/src/codec/EXITypes.h b/src/codec/EXITypes.h index 5279119..4a083dc 100644 --- a/src/codec/EXITypes.h +++ b/src/codec/EXITypes.h @@ -302,10 +302,11 @@ typedef struct exiNameTablePrepopulated { } exi_name_table_prepopulated_t; -#define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS 500 -#define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES 25 -#define EXI_RESERVED_NUMBER_URI_PARTITION_ENTRIES 5 -#define EXI_RESERVED_NUMBER_LOCALNAME_PARTITION_ENTRIES 10 +/* not used */ +#define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS 1 +#define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES 1 +#define EXI_RESERVED_NUMBER_URI_PARTITION_ENTRIES 0 +#define EXI_RESERVED_NUMBER_LOCALNAME_PARTITION_ENTRIES 0 typedef enum { EXI_NAME_PARTITION_URI, diff --git a/src/codec/appHandCodec/appHand_EXIDecoder.c b/src/codec/appHandCodec/appHand_EXIDecoder.c index 9418567..43f8b85 100644 --- a/src/codec/appHandCodec/appHand_EXIDecoder.c +++ b/src/codec/appHandCodec/appHand_EXIDecoder.c @@ -45,7 +45,6 @@ /* local variables */ -static uint32_t xsi; static uint32_t bits; static int errn; diff --git a/src/codec/appHandCodec/appHand_EXIEncoder.c b/src/codec/appHandCodec/appHand_EXIEncoder.c index 37a3504..bff5ce6 100644 --- a/src/codec/appHandCodec/appHand_EXIEncoder.c +++ b/src/codec/appHandCodec/appHand_EXIEncoder.c @@ -45,7 +45,6 @@ /* local variables */ -static uint32_t bits; static int errn; /* ==================================== */ @@ -105,106 +104,6 @@ int exiappHandEncodeListValue(bitstream_t* stream, exi_value_t* val, list_t lt) -/* <0 ... Error, 1 .. Not-Found, 0.. Success */ -static int _exiGet1stLevelEventCode(exi_state_t* state, exi_event_t eventType, uint16_t* resGrammarID) { - /* retrieve current grammar-rule ID */ - uint16_t grammarID = state->grammarStack[ state->stackIndex ]; - - switch(grammarID) { - case DOCUMENT: - switch(eventType) { - case EXI_EVENT_START_DOCUMENT: - *resGrammarID = 0; - return 0; - default: - return 1; /* not found */ - } - break; - case DOC_CONTENT: - switch(eventType) { - /* TODO other IDs */ - case EXI_EVENT_START_ELEMENT_GENERIC: - *resGrammarID = 0; - return 0; - default: - return 1; /* not found */ - } - break; - case DOC_END: - switch(eventType) { - case EXI_EVENT_END_DOCUMENT: - *resGrammarID = 0; - return 0; - default: - return 1; /* not found */ - } - break; - case UR_TYPE_GRAMMAR_0: - switch(eventType) { - case EXI_EVENT_ATTRIBUTE_GENERIC: - *resGrammarID = 0; - return 0; - case EXI_EVENT_START_ELEMENT_GENERIC: - *resGrammarID = 1; - return 0; - case EXI_EVENT_END_ELEMENT: - *resGrammarID = 2; - return 0; - case EXI_EVENT_CHARACTERS_GENERIC: - *resGrammarID = 3; - return 0; - default: - return 1; /* not found */ - } - break; - case UR_TYPE_GRAMMAR_1: - switch(eventType) { - case EXI_EVENT_START_ELEMENT_GENERIC: - *resGrammarID = 0; - return 0; - case EXI_EVENT_END_ELEMENT: - *resGrammarID = 1; - return 0; - case EXI_EVENT_CHARACTERS_GENERIC: - *resGrammarID = 2; - return 0; - default: - return 1; /* not found */ - } - break; - } - - return 1; /* not found */ -} - - -static int _exiGetEventCodeLength(exi_state_t* state, uint16_t* eventCodeLength) { - /* retrieve current grammar-rule ID */ - uint16_t grammarID = state->grammarStack[ state->stackIndex ]; - - switch(grammarID) { - /* TODO OTHER IDs */ - case DOCUMENT: - *eventCodeLength = 0; - return 0; - case DOC_CONTENT: - /* TODO other root elements */ - *eventCodeLength = IS_STRICT ? 0 : 1; - return 0; - case DOC_END: - *eventCodeLength = IS_STRICT ? 0 : 1; - return 0; - case UR_TYPE_GRAMMAR_0: - *eventCodeLength = IS_STRICT ? 4 : 5; - return 0; - case UR_TYPE_GRAMMAR_1: - *eventCodeLength = IS_STRICT ? 3 : 4; - return 0; - } - - return EXI_ERROR_UNEXPECTED_GRAMMAR_ID; -} - static int _encodeNBitIntegerValue(bitstream_t* stream, integer_t* iv, uint16_t nbits, int32_t lowerBound) { int errn; uint32_t val; @@ -235,6 +134,8 @@ static int _encodeNBitIntegerValue(bitstream_t* stream, integer_t* iv, uint16_t case EXI_INTEGER_64: val = iv->val.uint64 - lowerBound; break; + default: + return -1; } errn = encodeNBitUnsignedInteger(stream, nbits, val); @@ -304,53 +205,6 @@ static int _exiEncodeNamespaceUriID(bitstream_t* stream, exi_name_table_prepopul } -#if EXI_DEBUG == EXI_DEBUG_ON -static int _exiEncodeNamespaceUri(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, - char** uri, uint16_t* uriID) { - int errn; - uint16_t uriCodingLength; - uint16_t uriSize; - - errn = exiGetUriSize(nameTable, runtimeTable, &uriSize); - if (errn) { - return errn; - } - /* URI Entries + 1 */ - errn = exiGetCodingLength(uriSize + 1, &uriCodingLength); - if (errn) { - return errn; - } - - errn = exiGetUriID(nameTable, runtimeTable, *uri, uriID); - if (errn < 0) { - return errn; - } else if (errn == 1) { - /* uri string value was not found */ - /* ==> zero (0) as an n-nit unsigned integer */ - /* followed by uri encoded as string */ - errn = encodeNBitUnsignedInteger(stream, uriCodingLength, 0); - if (errn) { - return errn; - } - /* ASCII String */ - errn = encodeASCII(stream, *uri); - if (errn) { - return errn; - } - /* after encoding string value is added to table */ - /* in UCD Profile NOT */ - *uriID = uriSize; - } else { - /* uri string value found */ - /* ==> value(i+1) is encoded as n-bit unsigned integer */ - errn = encodeNBitUnsignedInteger(stream, uriCodingLength, *uriID + 1); - } - - return errn; -} -#endif /*EXI_DEBUG*/ - - static int _exiEncodeLocalNameID(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, uint16_t uriID, uint16_t localNameID) { int errn; @@ -380,77 +234,6 @@ static int _exiEncodeLocalNameID(bitstream_t* stream, exi_name_table_prepopulate } -#if EXI_DEBUG == EXI_DEBUG_ON -static int _exiEncodeLocalName(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, - char** localName, - uint16_t uriID) { - int errn; - uint16_t localNameID; - uint16_t localNameSize; - uint16_t localNameCodingLength; - uint32_t slen; - - /* look for localNameID */ - errn = exiGetLocalNameID(nameTable, runtimeTable, uriID, *localName, &localNameID); - if (errn < 0) { - return errn; - } - - if (errn == 1) { - /* string value was not found in local partition */ - /* ==> string literal is encoded as a String */ - /* with the length of the string incremented by one */ - slen = (uint32_t)strlen(*localName); - errn = encodeUnsignedInteger32(stream, slen + 1 ); - if (errn >= 0) { - errn = encodeASCIICharacters(stream, *localName, slen); - } - } else { - /* string value found in local partition */ - /* ==> string value is represented as zero (0) encoded as an */ - errn = encodeUnsignedInteger32(stream, 0 ); - if (errn < 0) { - return errn; - } - /* Unsigned Integer followed by an the compact identifier of the */ - /* string value as an n-bit unsigned integer n is log2 m and m is */ - /* the number of entries in the string table partition */ - errn = exiGetLocalNameSize(nameTable, runtimeTable, uriID, &localNameSize); - if (errn < 0) { - return errn; - } - errn = exiGetCodingLength(localNameSize, &localNameCodingLength); - if (errn) { - return errn; - } - errn = encodeNBitUnsignedInteger(stream, localNameCodingLength, localNameID); - } - - return errn; -} -#endif /*EXI_DEBUG*/ - - -#if EXI_DEBUG == EXI_DEBUG_ON -static int _exiEncodeQName(bitstream_t* stream, exi_name_table_prepopulated_t* nameTable, exi_name_table_runtime_t* runtimeTable, - char** uri, char** localName) { - uint16_t uriID; - /* uri */ - int errn =_exiEncodeNamespaceUri(stream, nameTable, runtimeTable, uri, &uriID); - if (errn) { - return errn; - } - /* localName */ - errn = _exiEncodeLocalName(stream, nameTable, runtimeTable, localName, uriID); - if (errn) { - return errn; - } - - return 0 ; -} -#endif /*EXI_DEBUG*/ - - static int _exiEncodeStartElement(bitstream_t* stream, uint16_t nbits, uint32_t val, exi_state_t* state, eqname_t* se, uint16_t stackId, uint16_t newState) { @@ -465,36 +248,6 @@ static int _exiEncodeStartElement(bitstream_t* stream, uint16_t nbits, return exiPushStack(state, newState, se); } -#if EXI_DEBUG == EXI_DEBUG_ON - -static eqname_t eqnGeneric = {65535, 65535}; /* UNSIGNED_INT16_MAX */ - -static int _exiEncodeStartElementGeneric(bitstream_t* stream, uint16_t nbits, - uint32_t val, exi_state_t* state, char** uri, char** localName, uint16_t stackId, - uint16_t newState) { - uint16_t uriID; - /* event-code */ - int errn = encodeNBitUnsignedInteger(stream, nbits, val); - if (errn) { - return errn; - } - /* qualified name */ - errn = _exiEncodeNamespaceUri(stream, &(state->nameTablePrepopulated), &(state->nameTableRuntime), uri, &uriID); - if (errn) { - return errn; - } - errn = _exiEncodeLocalName(stream, &(state->nameTablePrepopulated), &(state->nameTableRuntime), localName, uriID); - if (errn) { - return errn; - } - - /* move on */ - state->grammarStack[state->stackIndex] = stackId; - /* push element on stack */ - return exiPushStack(state, newState, &eqnGeneric); -} -#endif /*EXI_DEBUG*/ - int exiappHandEncodeStartElement(bitstream_t* stream, exi_state_t* state, eqname_t* se) { switch (state->grammarStack[state->stackIndex]) { case 1: @@ -758,121 +511,12 @@ int exiappHandEncodeStartElement(bitstream_t* stream, exi_state_t* state, eqname return EXI_ERROR_UNEXPECTED_START_ELEMENT; } -/* Qualified Name unknown!! */ -#if EXI_DEBUG == EXI_DEBUG_ON -static int exiEncodeStartElementGenericUnknown(bitstream_t* stream, exi_state_t* state, - char** uri, char** localName) { - uint16_t grammarID; - uint16_t eventCodeLength; - - int errn = _exiGet1stLevelEventCode(state, EXI_EVENT_START_ELEMENT_GENERIC, &grammarID); - if (errn < 0) { - return errn; - } else if (errn == 1) { - /* not found --> try undeclared SE */ - errn = _exiGet1stLevelEventCode(state, EXI_EVENT_START_ELEMENT_GENERIC_UNDECLARED, &grammarID); - if (errn < 0) { - return errn; - } else if (errn == 1) { - /* Should never happen except in STRICT mode */ - return EXI_ERROR_UNEXPECTED_EVENT_LEVEL1; - } else { - /* found START_ELEMENT_GENERIC_UNDECLARED */ - errn = _exiGetEventCodeLength(state, &eventCodeLength); - if (errn < 0) { - return errn; - } else { - /* encode event code*/ - errn = encodeNBitUnsignedInteger(stream, eventCodeLength, grammarID); - if (errn) { - return errn; - } - } - } - } else { - /* found START_ELEMENT_GENERIC */ - errn = _exiGetEventCodeLength(state, &eventCodeLength); - if (errn < 0) { - return errn; - } else { - /* encode event code*/ - errn = encodeNBitUnsignedInteger(stream, eventCodeLength, grammarID); - if (errn) { - return errn; - } - } - } - - /* encode qualified name */ - errn = _exiEncodeQName(stream, &(state->nameTablePrepopulated), &(state->nameTableRuntime), uri, localName); - if (errn) { - return errn; - } - - /* learn event, not in UCD Profile */ - - /* move on */ - /* push element on stack */ - - switch (state->grammarStack[state->stackIndex]) { - /* $EXI_ENCODE_START_ELEMENT_GENERIC$ */ - case DOC_CONTENT: - /* move on to DocEnd */ - state->grammarStack[state->stackIndex] = DOC_END; - /* push new ur-type grammar on stack */ - return exiPushStack(state, UR_TYPE_GRAMMAR_0, NULL); - break; - case UR_TYPE_GRAMMAR_0: - /* move on to UR_TYPE_GRAMMAR_1 */ - state->grammarStack[state->stackIndex] = UR_TYPE_GRAMMAR_1; - /* push new ur-type grammar on stack */ - return exiPushStack(state, UR_TYPE_GRAMMAR_0, NULL); - break; - case UR_TYPE_GRAMMAR_1: - /* remain in UR_TYPE_GRAMMAR_1 */ - /* push new ur-type grammar on stack */ - return exiPushStack(state, UR_TYPE_GRAMMAR_0, NULL); - break; - default: - return EXI_ERROR_UNEXPECTED_START_ELEMENT_GENERIC; - } - - - - return 0; -} -#endif /*EXI_DEBUG*/ - /* Look first for qualified name */ int exiappHandEncodeStartElementGeneric(bitstream_t* stream, exi_state_t* state, string_ascii_t* namespaceURI , string_ascii_t* localName) { int errn = -1; -#if EXI_DEBUG == EXI_DEBUG_ON - eqname_t se; - /* uri */ - errn = exiGetUriID(&(state->nameTablePrepopulated), &(state->nameTableRuntime), namespaceURI->chars, &se.namespaceURI); - if (errn == -1) { - return errn; - } else if (errn == 1) { - /* No URI (and localNameID) found */ - exiEncodeStartElementGenericUnknown(stream, state, &(namespaceURI->chars), &(localName->chars)); - } else { - /* localName */ - errn = exiGetLocalNameID(&(state->nameTablePrepopulated), &(state->nameTableRuntime), se.namespaceURI, localName->chars, &se.localPart); - if (errn == -1) { - return errn; - } else if (errn == 1) { - /* No localName found, use generic StartElement(*) method */ - exiEncodeStartElementGenericUnknown(stream, state, &(namespaceURI->chars), &(localName->chars)); - } else { - /* Uri&LocalName found, use "efficient" StartElement method */ - return exiappHandEncodeStartElement(stream, state, &se); - } - } -#endif /*EXI_DEBUG*/ - return errn; } @@ -1905,63 +1549,6 @@ int exiappHandEncodeAttribute(bitstream_t* stream, exi_state_t* state, eqname_t* /* return EXI_ERROR_UNEXPECTED_ATTRIBUTE; */ } -#if EXI_DEBUG == EXI_DEBUG_ON -static int exiEncodeAttribute2(bitstream_t* stream, exi_state_t* state, qname_t* at, - exi_value_t* val) { - int errn; - eqname_t eat; - - /* attribute generic undeclared */ - uint16_t codeLength1, codeLength2; - uint32_t ec1, ec2; - - errn = exiGetUriID(&state->nameTablePrepopulated, &state->nameTableRuntime, at->namespaceURI.chars, &eat.namespaceURI); - if (errn < 0) { - return errn; - } else if (errn > 0) { - /* uri not found*/ - } else { - /* uri found, try to find localname id */ - errn = exiGetLocalNameID(&state->nameTablePrepopulated, &state->nameTableRuntime, eat.namespaceURI, - at->localName.chars, &eat.localPart); - if (errn < 0) { - return errn; - } else if (errn > 0) { - /* local-name not found*/ - } else { - /* found uri and local-name */ - errn = exiappHandEncodeAttribute(stream, state, &eat, val); - if (errn < 0) { - return errn; - } - if (errn == 0) { - return errn; - } - - } - } - - - /* event codes */ - encodeNBitUnsignedInteger(stream, codeLength1, ec1); - encodeNBitUnsignedInteger(stream, codeLength2, ec2); - - /* qname */ - /* - errn = _exiEncodeQName(stream, state->nameTablePrepopulated, state->nameTableRuntime, - char** uri, char** localName); - QName qname = qnameDatatype.encodeQName(uri, localName, null, channel); - */ - /* content as string */ - /* - typeEncoder.isValid(BuiltIn.DEFAULT_DATATYPE, value); - typeEncoder.writeValue(qname, channel); - */ - return -1; - -} -#endif /*EXI_DEBUG*/ - int exiappHandEncodeAttributeXsiNil(bitstream_t* stream, exi_state_t* state, exi_value_t* val) { diff --git a/src/test/main_codec.c b/src/test/main_codec.c index c40bdf7..c9313c4 100644 --- a/src/test/main_codec.c +++ b/src/test/main_codec.c @@ -47,17 +47,17 @@ #if EXI_STREAM == BYTE_ARRAY /* 64 kilobytes = 65 536 bytes */ /* 1 megabyte = 1 048 576 bytes*/ -#define BUFFER_SIZE 1048576 +#define BUFFER_SIZE 512 uint8_t bufferIn[BUFFER_SIZE]; uint8_t bufferOut[BUFFER_SIZE]; #endif /* EXI_STREAM == BYTE_ARRAY */ /* avoids warning: initializer element is not computable at load time */ -#define ARRAY_SIZE_BYTES 300 +#define ARRAY_SIZE_BYTES 100 uint8_t bytesData[ARRAY_SIZE_BYTES]; -#define ARRAY_SIZE_STRINGS 30000 +#define ARRAY_SIZE_STRINGS 100 uint32_t codepoints[ARRAY_SIZE_STRINGS]; -#define ARRAY_SIZE_STRINGS_ASCII 150 +#define ARRAY_SIZE_STRINGS_ASCII 100 char charsNamespaceURI[ARRAY_SIZE_STRINGS_ASCII]; char charsLocalName[ARRAY_SIZE_STRINGS_ASCII];