Callisto4Bootloader: ARK/platform_encoder_json.c File Reference

Callisto4Bootloader

Functions | Variables
platform_encoder_json.c File Reference
`#include <stdio.h>`
`#include <ctype.h>`
`#include <string.h>`
`#include "platform_encoder.h"`

Go to the source code of this file.

## Functions

static void | OutputCharacter (stPayloadBuffer_t *pstPayload, uint8_t u8Character)
static void | EncodeStructStart (stPayloadBuffer_t *pstPayload)
static void | EncodeStructEnd (stPayloadBuffer_t *pstPayload)
static void | EncodeArrayStart (stPayloadBuffer_t *pstPayload)
static void | EncodeArraySeparator (stPayloadBuffer_t *pstPayload)
static void | EncodeArrayEnd (stPayloadBuffer_t *pstPayload)
static void | EncodeFieldName (stPayloadBuffer_t *pstPayload, const uint8_t *pau8FieldName)
static void | EncodeFieldSeparator (stPayloadBuffer_t *pstPayload)
static void | EncodeBoolean (stPayloadBuffer_t *pstPayload, bool bValue)
static void | EncodeReal (stPayloadBuffer_t *pstPayload, double dValue)
static void | EncodeUnsignedInt (stPayloadBuffer_t *pstPayload, uint64_t ui64Value)
static void | EncodeSignedInt (stPayloadBuffer_t *pstPayload, int64_t i64Value)
static void | EncodeString (stPayloadBuffer_t *pstPayload, const uint8_t *pau8String)
static bool | SnoopNextCharacter (stPayloadBuffer_t *pstPayload, uint8_t *pu8Next)
static uint32_t | PayloadRemaining (stPayloadBuffer_t *pstPayload)
static void | IgnoreWhitespace (stPayloadBuffer_t *pstPayload)
static bool | ExpectCharacter (stPayloadBuffer_t *pstPayload, uint8_t u8CharacterExpected)
static bool | DecodeStructStart (stPayloadBuffer_t *pstPayload)
static bool | DecodeStructEnd (stPayloadBuffer_t *pstPayload)
static bool | DecodeArrayStart (stPayloadBuffer_t *pstPayload)
static bool | DecodeArraySeparator (stPayloadBuffer_t *pstPayload)
static bool | DecodeArrayEnd (stPayloadBuffer_t *pstPayload)
static bool | DecodeString (stPayloadBuffer_t *pstPayload, const uint8_t **ppau8String, uint32_t *puiStringLength)
static bool | DecodeFieldName (stPayloadBuffer_t *pstPayload, const uint8_t **pau8FieldName, uint32_t *puiNameLength)
static bool | DecodeFieldSeparator (stPayloadBuffer_t *pstPayload)
static bool | DecodeBoolean (stPayloadBuffer_t *pstPayload, bool *pbValue)
static bool | DecodeUnsignedInt (stPayloadBuffer_t *pstPayload, uint64_t *pui64Value)
static bool | DecodeSignedInt (stPayloadBuffer_t *pstPayload, int64_t *pi64Value)
static bool | DecodeReal (stPayloadBuffer_t *pstPayload, double *pdValue)

## Variables

const stPayloadEncoder_t | stJSONEncoder
const stPayloadDecoder_t | stJSONDecoder

## Function Documentation

## ◆ DecodeArrayEnd()

static bool DecodeArrayEnd | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Parse past an expected JSON array end

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 304 of file platform_encoder_json.c.

References ExpectCharacter().

## ◆ DecodeArraySeparator()

static bool DecodeArraySeparator | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Parse past an expected JSON array separator

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 292 of file platform_encoder_json.c.

References ExpectCharacter().

## ◆ DecodeArrayStart()

static bool DecodeArrayStart | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Parse past an expected JSON array start

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 280 of file platform_encoder_json.c.

References ExpectCharacter().

## ◆ DecodeBoolean()

static bool DecodeBoolean | ( | stPayloadBuffer_t * | pstPayload,
|  | bool * | pbValue
| ) |  |

static

Grab a JSON boolean value from the current payload

Parameters

  [in] | pstPayload | Current payload
  [out] | pbValue | Boolean value found

Returns
  true if it was as expected, else false

Definition at line 394 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, PayloadRemaining(), and stPayloadBuffer_t::uiBufferLen.

## ◆ DecodeFieldName()

static bool DecodeFieldName | ( | stPayloadBuffer_t * | pstPayload,
|  | const uint8_t ** | pau8FieldName,
|  | uint32_t * | puiNameLength
| ) |  |

static

Grab a JSON item name from the current payload

Parameters

  [in] | pstPayload | Current payload
  [out] | pau8FieldName | Item name found (note: not zero-terminated!)
  [out] | puiNameLength | Item name length

Returns
  true if it was as expected, else false

Definition at line 353 of file platform_encoder_json.c.

References DecodeString(), and ExpectCharacter().

## ◆ DecodeFieldSeparator()

static bool DecodeFieldSeparator | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Parse past an expected JSON item separator

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 381 of file platform_encoder_json.c.

References ExpectCharacter().

## ◆ DecodeReal()

static bool DecodeReal | ( | stPayloadBuffer_t * | pstPayload,
|  | double * | pdValue
| ) |  |

static

Grab a JSON real value from the current payload

Parameters

  [in] | pstPayload | Current payload
  [out] | pdValue | Real (double) value found

Returns
  true if it was as expected, else false

Definition at line 493 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, PayloadRemaining(), and stPayloadBuffer_t::uiBufferLen.

## ◆ DecodeSignedInt()

static bool DecodeSignedInt | ( | stPayloadBuffer_t * | pstPayload,
|  | int64_t * | pi64Value
| ) |  |

static

Grab a JSON signed int from the current payload

Parameters

  [in] | pstPayload | Current payload
  [out] | pi64Value | Signed int value found

Returns
  true if it was as expected, else false

Definition at line 461 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, PayloadRemaining(), and stPayloadBuffer_t::uiBufferLen.

## ◆ DecodeString()

static bool DecodeString | ( | stPayloadBuffer_t * | pstPayload,
|  | const uint8_t ** | ppau8String,
|  | uint32_t * | puiStringLength
| ) |  |

static

Grab a JSON string from the current payload

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 316 of file platform_encoder_json.c.

References ExpectCharacter(), IgnoreWhitespace(), stPayloadBuffer_t::pau8Buffer, SnoopNextCharacter(), and stPayloadBuffer_t::uiBufferLen.

Referenced by DecodeFieldName().

## ◆ DecodeStructEnd()

static bool DecodeStructEnd | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Parse past an expected JSON struct end

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 268 of file platform_encoder_json.c.

References ExpectCharacter().

## ◆ DecodeStructStart()

static bool DecodeStructStart | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Parse past an expected JSON struct start

Parameters

  [in] | pstPayload | Current payload

Returns
  true if it was as expected, else false

Definition at line 256 of file platform_encoder_json.c.

References ExpectCharacter().

## ◆ DecodeUnsignedInt()

static bool DecodeUnsignedInt | ( | stPayloadBuffer_t * | pstPayload,
|  | uint64_t * | pui64Value
| ) |  |

static

Grab a JSON unsigned int from the current payload

Parameters

  [in] | pstPayload | Current payload
  [out] | pui64Value | Unsigned int value found

Returns
  true if it was as expected, else false

Definition at line 427 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, PayloadRemaining(), and stPayloadBuffer_t::uiBufferLen.

## ◆ EncodeArrayEnd()

static void EncodeArrayEnd | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Finish sending an array out to a JSON payload

Parameters

  [in] | pstPayload | Current payload

Definition at line 73 of file platform_encoder_json.c.

References OutputCharacter().

## ◆ EncodeArraySeparator()

static void EncodeArraySeparator | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Send an array separator out to a JSON payload

Parameters

  [in] | pstPayload | Current payload

Definition at line 63 of file platform_encoder_json.c.

References OutputCharacter().

## ◆ EncodeArrayStart()

static void EncodeArrayStart | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Start sending an array out to a JSON payload

Parameters

  [in] | pstPayload | Current payload

Definition at line 53 of file platform_encoder_json.c.

References OutputCharacter().

## ◆ EncodeBoolean()

static void EncodeBoolean | ( | stPayloadBuffer_t * | pstPayload,
|  | bool | bValue
| ) |  |

static

Send a boolean out to a JSON payload

Parameters

  [in] | pstPayload | Current payload
  [in] | bValue | Boolean value to send

Definition at line 106 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

## ◆ EncodeFieldName()

static void EncodeFieldName | ( | stPayloadBuffer_t * | pstPayload,
|  | const uint8_t * | pau8FieldName
| ) |  |

static

Send an item identifier out to a JSON payload

Parameters

  [in] | pstPayload | Current payload
  [in] | pau8FieldName | Item identifier/name

Definition at line 84 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

## ◆ EncodeFieldSeparator()

static void EncodeFieldSeparator | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Send an item separator out to a JSON payload

Parameters

  [in] | pstPayload | Current payload

Definition at line 95 of file platform_encoder_json.c.

References OutputCharacter().

## ◆ EncodeReal()

static void EncodeReal | ( | stPayloadBuffer_t * | pstPayload,
|  | double | dValue
| ) |  |

static

Send a real out to a JSON payload

Parameters

  [in] | pstPayload | Current payload
  [in] | dValue | Real value to send

Definition at line 118 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

## ◆ EncodeSignedInt()

static void EncodeSignedInt | ( | stPayloadBuffer_t * | pstPayload,
|  | int64_t | i64Value
| ) |  |

static

Send a signed int out to a JSON payload

Parameters

  [in] | pstPayload | Current payload
  [in] | i64Value | Signed integer value to send

Definition at line 146 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

## ◆ EncodeString()

static void EncodeString | ( | stPayloadBuffer_t * | pstPayload,
|  | const uint8_t * | pau8String
| ) |  |

static

Send a string out to a JSON payload

Parameters

  [in] | pstPayload | Current payload
  [in] | pau8String | String to send

Definition at line 162 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

## ◆ EncodeStructEnd()

static void EncodeStructEnd | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Finish sending a struct out to a JSON payload

Parameters

  [in] | pstPayload | Current payload

Definition at line 43 of file platform_encoder_json.c.

References OutputCharacter().

## ◆ EncodeStructStart()

static void EncodeStructStart | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Start sending a struct out to a JSON payload

Parameters

  [in] | pstPayload | Current payload

Definition at line 33 of file platform_encoder_json.c.

References OutputCharacter().

## ◆ EncodeUnsignedInt()

static void EncodeUnsignedInt | ( | stPayloadBuffer_t * | pstPayload,
|  | uint64_t | ui64Value
| ) |  |

static

Send an unsigned int out to a JSON payload

Parameters

  [in] | pstPayload | Current payload
  [in] | ui64Value | Unsigned integer value to send

Definition at line 130 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

## ◆ ExpectCharacter()

static bool ExpectCharacter | ( | stPayloadBuffer_t * | pstPayload,
|  | uint8_t | u8CharacterExpected
| ) |  |

static

Slide the current payload pointer past a specifically expected character, ignoring whitespace

Parameters

  [in] | pstPayload | Current payload
  [in] | u8CharacterExpected | Which character we're expecting to see next

Definition at line 231 of file platform_encoder_json.c.

References IgnoreWhitespace(), SnoopNextCharacter(), and stPayloadBuffer_t::uiBufferLen.

Referenced by DecodeArrayEnd(), DecodeArraySeparator(), DecodeArrayStart(), DecodeFieldName(), DecodeFieldSeparator(), DecodeString(), DecodeStructEnd(), and DecodeStructStart().

## ◆ IgnoreWhitespace()

static void IgnoreWhitespace | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Slide the current payload pointer past any white space

Parameters

  [in] | pstPayload | Current payload

Definition at line 207 of file platform_encoder_json.c.

References SnoopNextCharacter(), and stPayloadBuffer_t::uiBufferLen.

Referenced by DecodeString(), and ExpectCharacter().

## ◆ OutputCharacter()

static void OutputCharacter | ( | stPayloadBuffer_t * | pstPayload,
|  | uint8_t | u8Character
| ) |  |

static

Add a character to the current payload

Parameters

  [in] | pstPayload | Current payload
  [in] | u8Character | Character to add to payload

Definition at line 20 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

Referenced by EncodeArrayEnd(), EncodeArraySeparator(), EncodeArrayStart(), EncodeFieldSeparator(), EncodeStructEnd(), and EncodeStructStart().

## ◆ PayloadRemaining()

static uint32_t PayloadRemaining | ( | stPayloadBuffer_t * | pstPayload | ) |

static

Determine how many characters remain in the payload

Parameters

  [in] | pstPayload | Current payload

Returns
  Number of characters in the payload

Definition at line 197 of file platform_encoder_json.c.

References stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

Referenced by DecodeBoolean(), DecodeReal(), DecodeSignedInt(), and DecodeUnsignedInt().

## ◆ SnoopNextCharacter()

static bool SnoopNextCharacter | ( | stPayloadBuffer_t * | pstPayload,
|  | uint8_t * | pu8Next
| ) |  |

static

Look at (but don't consume) the next character along in the current payload

Parameters

  [in] | pstPayload | Current payload
  [out] | pu8Next | Next character along

Returns
  true if there was a character to read, else false

Definition at line 176 of file platform_encoder_json.c.

References stPayloadBuffer_t::pau8Buffer, stPayloadBuffer_t::uiBufferLen, and stPayloadBuffer_t::uiBufferSize.

Referenced by DecodeString(), ExpectCharacter(), and IgnoreWhitespace().

## Variable Documentation

## ◆ stJSONDecoder

const stPayloadDecoder_t stJSONDecoder

Initial value:
=
{
.pfn_DecodeStructStart = DecodeStructStart,
.pfn_DecodeStructEnd = DecodeStructEnd,
.pfn_DecodeArrayStart = DecodeArrayStart,
.pfn_DecodeArraySeparator = DecodeArraySeparator,
.pfn_DecodeArrayEnd = DecodeArrayEnd,
.pfn_DecodeFieldName = DecodeFieldName,
.pfn_DecodeFieldSeparator = DecodeFieldSeparator,
.pfn_DecodeBoolean = DecodeBoolean,
.pfn_DecodeSignedInt = DecodeSignedInt,
.pfn_DecodeUnsignedInt = DecodeUnsignedInt,
.pfn_DecodeReal = DecodeReal,
.pfn_DecodeString = DecodeString
}

Definition at line 533 of file platform_encoder_json.c.

Referenced by PayloadDecoder_Get().

## ◆ stJSONEncoder

const stPayloadEncoder_t stJSONEncoder

Initial value:
=
{
.pfn_EncodeStructStart = EncodeStructStart,
.pfn_EncodeStructEnd = EncodeStructEnd,
.pfn_EncodeArrayStart = EncodeArrayStart,
.pfn_EncodeArraySeparator = EncodeArraySeparator,
.pfn_EncodeArrayEnd = EncodeArrayEnd,
.pfn_EncodeFieldName = EncodeFieldName,
.pfn_EncodeFieldSeparator = EncodeFieldSeparator,
.pfn_EncodeBoolean = EncodeBoolean,
.pfn_EncodeSignedInt = EncodeSignedInt,
.pfn_EncodeUnsignedInt = EncodeUnsignedInt,
.pfn_EncodeReal = EncodeReal,
.pfn_EncodeString = EncodeString
}

Definition at line 516 of file platform_encoder_json.c.

Referenced by META_Callback(), and PayloadEncoder_Get().

EncodeBoolean
static void EncodeBoolean(stPayloadBuffer_t *pstPayload, bool bValue)
Definition: platform_encoder_json.c:106
DecodeReal
static bool DecodeReal(stPayloadBuffer_t *pstPayload, double *pdValue)
Definition: platform_encoder_json.c:493
EncodeReal
static void EncodeReal(stPayloadBuffer_t *pstPayload, double dValue)
Definition: platform_encoder_json.c:118
EncodeArrayStart
static void EncodeArrayStart(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:53
DecodeBoolean
static bool DecodeBoolean(stPayloadBuffer_t *pstPayload, bool *pbValue)
Definition: platform_encoder_json.c:394
DecodeSignedInt
static bool DecodeSignedInt(stPayloadBuffer_t *pstPayload, int64_t *pi64Value)
Definition: platform_encoder_json.c:461
EncodeStructStart
static void EncodeStructStart(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:33
DecodeArrayStart
static bool DecodeArrayStart(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:280
DecodeString
static bool DecodeString(stPayloadBuffer_t *pstPayload, const uint8_t **ppau8String, uint32_t *puiStringLength)
Definition: platform_encoder_json.c:316
DecodeFieldName
static bool DecodeFieldName(stPayloadBuffer_t *pstPayload, const uint8_t **pau8FieldName, uint32_t *puiNameLength)
Definition: platform_encoder_json.c:353
EncodeString
static void EncodeString(stPayloadBuffer_t *pstPayload, const uint8_t *pau8String)
Definition: platform_encoder_json.c:162
EncodeStructEnd
static void EncodeStructEnd(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:43
DecodeArrayEnd
static bool DecodeArrayEnd(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:304
EncodeSignedInt
static void EncodeSignedInt(stPayloadBuffer_t *pstPayload, int64_t i64Value)
Definition: platform_encoder_json.c:146
EncodeArraySeparator
static void EncodeArraySeparator(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:63
EncodeFieldSeparator
static void EncodeFieldSeparator(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:95
EncodeUnsignedInt
static void EncodeUnsignedInt(stPayloadBuffer_t *pstPayload, uint64_t ui64Value)
Definition: platform_encoder_json.c:130
DecodeArraySeparator
static bool DecodeArraySeparator(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:292
DecodeStructEnd
static bool DecodeStructEnd(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:268
DecodeUnsignedInt
static bool DecodeUnsignedInt(stPayloadBuffer_t *pstPayload, uint64_t *pui64Value)
Definition: platform_encoder_json.c:427
DecodeFieldSeparator
static bool DecodeFieldSeparator(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:381
DecodeStructStart
static bool DecodeStructStart(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:256
EncodeArrayEnd
static void EncodeArrayEnd(stPayloadBuffer_t *pstPayload)
Definition: platform_encoder_json.c:73
EncodeFieldName
static void EncodeFieldName(stPayloadBuffer_t *pstPayload, const uint8_t *pau8FieldName)
Definition: platform_encoder_json.c:84