Topic string utility functions

group jsdrv_topic

Topic string utility functions.

Defines

JSDRV_TOPIC_INIT

Empty topic structure initializer.

Functions

void jsdrv_topic_clear(struct jsdrv_topic_s *topic)

Clear a topic structure instance to reset it to zero length.

Parameters:

topic[inout] The topic structure, which is modified in place.

void jsdrv_topic_truncate(struct jsdrv_topic_s *topic, uint8_t length)

Truncate a topic structure to a specified length.

If you store length before calling jsdrv_topic_append(), you can use this function to revert the append.

Parameters:
  • topic[inout] The topic structure, which is modified in place.

  • length – The desired length.

void jsdrv_topic_append(struct jsdrv_topic_s *topic, const char *subtopic)

Append a subtopic to a topic structure.

This function intelligently adds the ‘/’ separator. If the topic does not already end with ‘/’, it will be inserted first.

Parameters:
  • topic[inout] The topic structure, which is modified in place.

  • subtopic – The subtopic string to add.

int32_t jsdrv_topic_remove(struct jsdrv_topic_s *topic)

Remove a subtopic from the end of a topic structure.

This function intelligently removes the ‘/’ separator. If the topic already ends with ‘/’, then this it is ignored. This function then removes the “/subtopic”. The resulting topic does NOT end in ‘/’.

Parameters:

topic[inout] The topic structure, which is modified in place.

Returns:

The number of characters removed.

void jsdrv_topic_set(struct jsdrv_topic_s *topic, const char *str)

Set the topic to the provided value.

This function will assert if no room remains.

Parameters:
  • topic[inout] The topic structure, which is modified in place.

  • str – The desired topic value.

void jsdrv_topic_suffix_add(struct jsdrv_topic_s *topic, char ch)

Adds a suffix character to the topic.

This function will assert if no room remains.

Parameters:
  • topic[inout] The topic structure, which is modified in place.

  • ch – The special character to append.

char jsdrv_topic_suffix_remove(struct jsdrv_topic_s *topic)

Remove the suffix character from a topic.

Parameters:

topic[inout] The topic structure, which is modified in place.

Returns:

ch The suffix character removed or 0 if no character was removed.

struct jsdrv_topic_s
#include <topic.h>

The topic structure.

Public Members

char topic[JSDRV_TOPIC_LENGTH_MAX]

The topic string.

uint8_t length

The length in bytes ignoring the null terminator.