Azure IoT middleware for FreeRTOS
Data Structures | Typedefs | Enumerations | Functions
azure_iot_json_reader.h File Reference

The JSON reader used by the middleware for PnP properties. More...

#include <stdbool.h>
#include <stdint.h>
#include "azure_iot_result.h"
#include "azure/core/az_json.h"
#include "azure/core/_az_cfg_prefix.h"
#include "azure/core/_az_cfg_suffix.h"

Go to the source code of this file.

Data Structures

struct  AzureIoTJSONReader
 The struct to use for Azure IoT JSON reader functionality. More...
 

Typedefs

typedef enum AzureIoTJSONTokenType AzureIoTJSONTokenType_t
 Defines symbols for the various kinds of JSON tokens that make up any JSON text.
 
typedef struct AzureIoTJSONReader AzureIoTJSONReader_t
 The struct to use for Azure IoT JSON reader functionality.
 

Enumerations

enum  AzureIoTJSONTokenType {
  eAzureIoTJSONTokenNONE = AZ_JSON_TOKEN_NONE , eAzureIoTJSONTokenBEGIN_OBJECT = AZ_JSON_TOKEN_BEGIN_OBJECT , eAzureIoTJSONTokenEND_OBJECT = AZ_JSON_TOKEN_END_OBJECT , eAzureIoTJSONTokenBEGIN_ARRAY = AZ_JSON_TOKEN_BEGIN_ARRAY ,
  eAzureIoTJSONTokenEND_ARRAY = AZ_JSON_TOKEN_END_ARRAY , eAzureIoTJSONTokenPROPERTY_NAME = AZ_JSON_TOKEN_PROPERTY_NAME , eAzureIoTJSONTokenSTRING = AZ_JSON_TOKEN_STRING , eAzureIoTJSONTokenNUMBER = AZ_JSON_TOKEN_NUMBER ,
  eAzureIoTJSONTokenTRUE = AZ_JSON_TOKEN_TRUE , eAzureIoTJSONTokenFALSE = AZ_JSON_TOKEN_FALSE , eAzureIoTJSONTokenNULL = AZ_JSON_TOKEN_NULL
}
 Defines symbols for the various kinds of JSON tokens that make up any JSON text.
 

Functions

AzureIoTResult_t AzureIoTJSONReader_Init (AzureIoTJSONReader_t *pxReader, const uint8_t *pucBuffer, uint32_t ulBufferSize)
 Initializes an AzureIoTJSONReader_t to read the JSON payload contained within the provided buffer. More...
 
AzureIoTResult_t AzureIoTJSONReader_NextToken (AzureIoTJSONReader_t *pxReader)
 Reads the next token in the JSON text and updates the reader state. More...
 
AzureIoTResult_t AzureIoTJSONReader_SkipChildren (AzureIoTJSONReader_t *pxReader)
 Reads and skips over any nested JSON elements. More...
 
AzureIoTResult_t AzureIoTJSONReader_GetTokenBool (AzureIoTJSONReader_t *pxReader, bool *pxValue)
 Gets the JSON token's boolean value. More...
 
AzureIoTResult_t AzureIoTJSONReader_GetTokenInt32 (AzureIoTJSONReader_t *pxReader, int32_t *plValue)
 Gets the JSON token's number as a 32-bit signed integer. More...
 
AzureIoTResult_t AzureIoTJSONReader_GetTokenDouble (AzureIoTJSONReader_t *pxReader, double *pxValue)
 Gets the JSON token's number as a double. More...
 
AzureIoTResult_t AzureIoTJSONReader_GetTokenString (AzureIoTJSONReader_t *pxReader, uint8_t *pucBuffer, uint32_t ulBufferSize, uint32_t *pusBytesCopied)
 Gets the JSON token's string after unescaping it, if required. More...
 
bool AzureIoTJSONReader_TokenIsTextEqual (AzureIoTJSONReader_t *pxReader, const uint8_t *pucExpectedText, uint32_t ulExpectedTextLength)
 Determines whether the unescaped JSON token value that the AzureIoTJSONReader_t points to is equal to the expected text within the provided buffer bytes by doing a case-sensitive comparison. More...
 
AzureIoTResult_t AzureIoTJSONReader_TokenType (AzureIoTJSONReader_t *pxReader, AzureIoTJSONTokenType_t *pxTokenType)
 Determines type of token currently AzureIoTJSONReader_t points to. More...
 

Detailed Description

The JSON reader used by the middleware for PnP properties.

Note
You MUST NOT use any symbols (macros, functions, structures, enums, etc.) prefixed with an underscore ('_') directly in your application code. These symbols are part of Azure SDK's internal implementation; we do not document these symbols and they are subject to change in future versions of the SDK which would break your code.

Function Documentation

◆ AzureIoTJSONReader_GetTokenBool()

AzureIoTResult_t AzureIoTJSONReader_GetTokenBool ( AzureIoTJSONReader_t pxReader,
bool *  pxValue 
)

Gets the JSON token's boolean value.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance.
[out]pxValueA pointer to a boolean to receive the value.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe boolean value is returned.

◆ AzureIoTJSONReader_GetTokenDouble()

AzureIoTResult_t AzureIoTJSONReader_GetTokenDouble ( AzureIoTJSONReader_t pxReader,
double *  pxValue 
)

Gets the JSON token's number as a double.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance.
[out]pxValueA pointer to a variable to receive the value.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe number is returned.

◆ AzureIoTJSONReader_GetTokenInt32()

AzureIoTResult_t AzureIoTJSONReader_GetTokenInt32 ( AzureIoTJSONReader_t pxReader,
int32_t *  plValue 
)

Gets the JSON token's number as a 32-bit signed integer.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance.
[out]plValueA pointer to a variable to receive the value.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe number is returned.

◆ AzureIoTJSONReader_GetTokenString()

AzureIoTResult_t AzureIoTJSONReader_GetTokenString ( AzureIoTJSONReader_t pxReader,
uint8_t *  pucBuffer,
uint32_t  ulBufferSize,
uint32_t *  pusBytesCopied 
)

Gets the JSON token's string after unescaping it, if required.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance.
[out]pucBufferA pointer to a buffer where the string should be copied into.
[in]ulBufferSizeThe maximum available space within the buffer referred to by pucBuffer.
[out]pusBytesCopiedContains the number of bytes written to the destination which denote the length of the unescaped string.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe property name was appended successfully.

◆ AzureIoTJSONReader_Init()

AzureIoTResult_t AzureIoTJSONReader_Init ( AzureIoTJSONReader_t pxReader,
const uint8_t *  pucBuffer,
uint32_t  ulBufferSize 
)

Initializes an AzureIoTJSONReader_t to read the JSON payload contained within the provided buffer.

Parameters
[out]pxReaderA pointer to an AzureIoTJSONReader_t instance to initialize.
[in]pucBufferA pointer to a buffer containing the JSON text to read.
[in]ulBufferSizeLength of buffer.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe AzureIoTJSONReader_t is initialized successfully.
otherInitialization failed.

◆ AzureIoTJSONReader_NextToken()

AzureIoTResult_t AzureIoTJSONReader_NextToken ( AzureIoTJSONReader_t pxReader)

Reads the next token in the JSON text and updates the reader state.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance containing the JSON to read.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe token was read successfully.

◆ AzureIoTJSONReader_SkipChildren()

AzureIoTResult_t AzureIoTJSONReader_SkipChildren ( AzureIoTJSONReader_t pxReader)

Reads and skips over any nested JSON elements.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance containing the JSON to read.
Returns
An AzureIoTResult_t value indicating the result of the operation.
Return values
eAzureIoTSuccessThe children of the current JSON token are skipped successfully.
Remarks
If the current token kind is a property name, the reader first moves to the property value. Then, if the token kind is start of an object or array, the reader moves to the matching end object or array. For all other token kinds, the reader doesn't move and returns eAzureIoTSuccess.

◆ AzureIoTJSONReader_TokenIsTextEqual()

bool AzureIoTJSONReader_TokenIsTextEqual ( AzureIoTJSONReader_t pxReader,
const uint8_t *  pucExpectedText,
uint32_t  ulExpectedTextLength 
)

Determines whether the unescaped JSON token value that the AzureIoTJSONReader_t points to is equal to the expected text within the provided buffer bytes by doing a case-sensitive comparison.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance containing the JSON string token.
[in]pucExpectedTextA pointer to lookup text to compare the token against.
[in]ulExpectedTextLengthLength of pucExpectedText.
Returns
true if the current JSON token value in the JSON source semantically matches the expected lookup text, with the exact casing; otherwise, false.
Remarks
This operation is only valid for the string and property name token kinds. For all other token kinds, it returns false.

◆ AzureIoTJSONReader_TokenType()

AzureIoTResult_t AzureIoTJSONReader_TokenType ( AzureIoTJSONReader_t pxReader,
AzureIoTJSONTokenType_t pxTokenType 
)

Determines type of token currently AzureIoTJSONReader_t points to.

Parameters
[in]pxReaderA pointer to an AzureIoTJSONReader_t instance.
[out]pxTokenTypeThe returned type of the token.
Returns
An AzureIoTResult_t value indicating the type of token.