in source/fleet_provisioning.c [375:432]
static TopicFormatSuffix_t parseTopicFormatSuffix( const char * pRemainingTopic,
uint16_t remainingLength )
{
/* Table of JSON format and suffixes in same order as TopicSuffix_t. */
static const TopicFormatSuffix_t jsonSuffixes[] =
{
TopicJsonPublish,
TopicJsonAccepted,
TopicJsonRejected,
TopicInvalidFormatSuffix
};
/* Table of CBOR format and suffixes in same order as TopicSuffix_t. */
static const TopicFormatSuffix_t cborSuffixes[] =
{
TopicCborPublish,
TopicCborAccepted,
TopicCborRejected,
TopicInvalidFormatSuffix
};
TopicFormatSuffix_t ret = TopicInvalidFormatSuffix;
TopicSuffix_t suffix = TopicInvalidSuffix;
FleetProvisioningStatus_t status = FleetProvisioningNoMatch;
const char * pTopicCursor = pRemainingTopic;
uint16_t cursorLength = remainingLength;
assert( pRemainingTopic != NULL );
/* Check if JSON format */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_API_JSON_FORMAT,
FP_API_LENGTH_JSON_FORMAT );
if( status == FleetProvisioningSuccess )
{
/* Match suffix */
suffix = parseTopicSuffix( pTopicCursor, cursorLength );
ret = jsonSuffixes[ suffix ];
}
if( status == FleetProvisioningNoMatch )
{
/* Check if CBOR format */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_API_CBOR_FORMAT,
FP_API_LENGTH_CBOR_FORMAT );
if( status == FleetProvisioningSuccess )
{
/* Match suffix */
suffix = parseTopicSuffix( pTopicCursor, cursorLength );
ret = cborSuffixes[ suffix ];
}
}
return ret;
}