Skip to content

TTLV Data API

API Overview

FunctionDescription
Quos_ttlvAddIdBool()Adds a boolean data node to the TTLV data table.
Quos_ttlvAddIdInt()Adds an integer data node to the TTLV data table.
Quos_ttlvAddIdFloat()Adds a float data node to the TTLV data table.
Quos_ttlvAddIdFloatEx()Adds a float-extended data node to the TTLV data table.
Quos_ttlvAddIdRaw()Adds a raw data node to the TTLV data table.
Quos_ttlvAddIdText()Adds a text data node to the TTLV data table.
Quos_ttlvAddIdStruct()Adds a structure data node to the TTLV data table.
Quos_ttlvGetNodeType()Gets the data type of a node.
Quos_ttlvGetNodeBool()Gets boolean data from a node.
Quos_ttlvGetNodeInt()Gets integer data from a node.
Quos_ttlvGetNodeFloat()Gets float data from a node.
Quos_ttlvGetNodeText()Gets text data from a node.
Quos_ttlvGetNodeStruct()Gets structure data from a node.
Quos_ttlvGetNodeRaw()Gets raw data from a node.
Quos_ttlvGetIdType()Gets the data type of a node.
Quos_ttlvGetIdBool()Gets boolean data from a node.
Quos_ttlvGetIdInt()Gets integer data from a node.
Quos_ttlvGetIdFloat()Gets float data from a node.
Quos_ttlvGetIdText()Gets text data from a node.
Quos_ttlvGetIdStruct()Gets structure data from a node.
Quos_ttlvGetIdRaw()Gets raw data from a node.
Quos_ttlvGetCount()Gets the number of nodes.
Quos_ttlvGetNode()Gets the pointer to a node.
Quos_ttlvRemove()Deletes node.
Quos_ttlvFree()Releases TTLV data table resources.
Quos_ttlvUnformat()Converts byte stream to TTLV data table.
Quos_ttlvFormat()Converts TTLV data to byte stream data.
Quos_ttlvFormatLen()Gets the length of byte stream converted from TTLV object
Quos_ttlvHeadPrintf()Prints the TTLV data table.
Quos_json2Ttlv()Converts JSON data to TTLV data.
Quos_ttlv2Json()Converts TTLV data to JSON data.

API Description

Quos_ttlvAddIdBool

This function adds a boolean data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdBool(void **ttlvHead, quint16_t id, qbool value);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • qboolvalue: Node data.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);

Quos_ttlvAddIdInt

This function adds an integer data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdInt(void **ttlvHead, quint16_t id, qint64_t num);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • qint64_tnum: Node data.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdInt(&ttlvHead, 2, 23);

Quos_ttlvAddIdFloat

This function adds a float data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdFloat(void **ttlvHead, quint16_t id, double num);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • doublenum: Node data.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdFloat(&ttlvHead, 4, 18.5);

Quos_ttlvAddIdFloatEx

This function adds a float-extended data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdFloatEx(void **ttlvHead, quint16_t id, double value, quint8_t precision);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • doublevalue: Node data.
    • quint8_tprecision: Precision of the float value, i.e., number of decimal places.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdFloatEx(&ttlvHead, 4, 18.5, 1);

Quos_ttlvAddIdRaw

This function adds a raw data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdRaw(void **ttlvHead, quint16_t id, const quint8_t *data, quint32_t len);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • quint8_t *data: Node data.
    • quint32_t *len:Length of the node data.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
quint8_t buf[5] = {'a', 'b', 'c', 'd', 'e'};
Quos_ttlvAddIdRaw(&ttlvHead, 5, buf, sizeof(buf));

Quos_ttlvAddIdText

This function adds a text data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdText(void **ttlvHead, quint16_t id, const char *data);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • char *data: Node data.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdText(&ttlvHead, 3, "hello world");

Quos_ttlvAddIdStruct

This function adds a structure data node to the TTLV data table.

Prototype

c
qbool Quos_ttlvAddIdStruct(void **ttlvHead, quint16_t id, void *vStruct);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
    • void *vStruct: Node data.
  • Output Parameter

    • None
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
void *ttlvArrayHead = NULL;
Quos_ttlvAddIdInt(&ttlvArrayHead, 1, 11);
Quos_ttlvAddIdBool(&ttlvArrayHead, 2, FALSE);
Quos_ttlvAddIdFloat(&ttlvArrayHead, 3, 5.7);
Quos_ttlvAddIdStruct(&ttlvHead, 6, ttlvArrayHead);

Quos_ttlvGetNodeType

This function gets the data type of a node.

Prototype

c
qbool Quos_ttlvGetNodeType(const void *ttlvNode, Quos_dpDataType_e *type);

Parameter

  • Input Parameter

  • void **ttlvNode: TTLV data table.

  • Output Parameter

    • Quos_dpDataType_etype: Node data type.
    ValueDescription
    QUOS_DPDATA_TYPE_BOOLBoolean
    QUOS_DPDATA_TYPE_INTInteger
    QUOS_DPDATA_TYPE_FLOATFloat
    QUOS_DPDATA_TYPE_TEXTTText
    QUOS_DPDATA_TYPE_STRUCTStructure
    QUOS_DPDATA_TYPE_RAWRaw
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_dpDataType_e type = 0;
Quos_ttlvAddIdText(&ttlvHead, 3, "hello world");
Quos_ttlvGetNodeType(ttlvHead, &type);

Quos_ttlvGetNodeBool

This function gets boolean data from a node.

Prototype

c
qbool Quos_ttlvGetNodeBool(const void *ttlvNode, qbool *value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
  • Output Parameter

    • qboolvalue: Node data.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
qbool val = 0;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Quos_ttlvGetNodeBool(ttlvHead, &val);

Quos_ttlvGetNodeInt

This function gets integer data from a node.

Prototype

c
qbool Quos_ttlvGetNodeInt(const void *ttlvNode, qint64_t *value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
  • Output Parameter

    • qint64_tvalue: Node data.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
qint64_t val = 0;
Quos_ttlvAddIdInt(&ttlvHead, 2, 23);
Quos_ttlvGetNodeInt(ttlvHead, &val);

Quos_ttlvGetNodeFloat

This function gets float data from a node.

Prototype

c
qbool Quos_ttlvGetNodeFloat(const void *ttlvNode, double *value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
  • Output Parameter

    • doublevalue: Node data.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
double val = 0.0;
Quos_ttlvAddIdFloat(&ttlvHead, 4, 18.5);
Quos_ttlvGetNodeFloat(ttlvHead, &val);

Quos_ttlvGetNodeText

This function gets text data from a node.

Prototype

c
quint32_t Quos_ttlvGetNodeText(const void *ttlvNode, char **value)

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
  • Output Parameter

    • quint8_t **value: Node data.
  • Return Value

    • Length of the node data.

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdText(&ttlvHead, 3, "hello world");
char *ch = NULL;
Quos_ttlvGetNodeText(ttlvHead, &ch);

Quos_ttlvGetNodeStruct

This function gets structure data from a node.

Prototype

c
void *Quos_ttlvGetNodeStruct(const void *ttlvNode);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
  • Output Parameter

    • None
  • Return Value

    • Node data.

Example

c
void *ttlvHead = NULL;
void *ttlvArrayHead = NULL;
Quos_ttlvAddIdInt(&ttlvArrayHead, 1, 11);
Quos_ttlvAddIdBool(&ttlvArrayHead, 2, FALSE);
Quos_ttlvAddIdFloat(&ttlvArrayHead, 3, 5.7);
Quos_ttlvAddIdStruct(&ttlvHead, 6, ttlvArrayHead);
void *st = Quos_ttlvGetNodeStruct(ttlvHead);

Quos_ttlvGetNodeRaw

This function gets raw data from a node.

Prototype

c
quint32_t Quos_ttlvGetNodeRaw(const void *ttlvNode, quint8_t **value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
  • Output Parameter

    • quint8_t **value: Node data.
  • Return Value

    • Length of the node data.

Example

c
void *ttlvHead = NULL;
quint8_t *value = NULL;
Quos_ttlvAddIdRaw(&ttlvHead, 5, buf, sizeof(buf));
quint32_t len = Quos_ttlvGetNodeRaw(ttlvHead, &value);

Quos_ttlvGetIdType

This function gets the data type of a node.

Prototype

c
qbool Quos_ttlvGetIdType(const void *ttlvHead, quint16_t id, Quos_dpDataType_e *type);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • Quos_dpDataType_e *type: Node data type.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
Quos_dpDataType_e type = 0;
Quos_ttlvAddIdText(&ttlvHead, 3, "hello world");
Quos_ttlvGetIdType(ttlvHead, 3, &type);

Quos_ttlvGetIdBool

This function gets boolean data from a node.

Prototype

c
qbool Quos_ttlvGetIdBool(const void *ttlvHead, quint16_t id, qbool *value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • qbool *value: Node data.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
qbool value = 0;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Quos_ttlvGetIdBool(ttlvHead, 1, &value);

Quos_ttlvGetIdInt

This function gets integer data from a node.

Prototype

c
qbool Quos_ttlvGetIdInt(const void *ttlvHead, quint16_t id, qint64_t *value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • qint64_t *value: Node data.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
qint64_t value = 0;
Quos_ttlvAddIdInt(&ttlvHead, 2, 23);
Quos_ttlvGetIdInt(ttlvHead, 2, &value);

Quos_ttlvGetIdFloat

This function gets float data from a node.

Prototype

c
qbool Quos_ttlvGetIdFloat(const void *ttlvHead, quint16_t id, double *value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • double *value: Node data.
  • Return Value

    • TRUE: Successful execution
    • FALSE: Failed execution

Example

c
void *ttlvHead = NULL;
double value = 0.0;
Quos_ttlvAddIdFloat(&ttlvHead, 4, 18.5);
Quos_ttlvGetIdFloat(ttlvHead, 4, &value);

Quos_ttlvGetIdText

This function gets text data from a node.

Prototype

c
quint32_t Quos_ttlvGetIdText(const void *ttlvHead, quint16_t id, char **value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • quint8_t **value: Node data.
  • Return Value

    • Length of the node data.

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdText(&ttlvHead, 3, "hello world");
char *ch = NULL;
Quos_ttlvGetIdText(ttlvHead, 3, &ch);

Quos_ttlvGetIdStruct

This function gets structure data from a node.

Prototype

c
void *Quos_ttlvGetIdStruct(const void *ttlvHead, quint16_t id);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • None
  • Return Value

    • Node data.

Example

c
void *ttlvHead = NULL;
void *ttlvArrayHead = NULL;
Quos_ttlvAddIdInt(&ttlvArrayHead, 1, 11);
Quos_ttlvAddIdBool(&ttlvArrayHead, 2, FALSE);
Quos_ttlvAddIdFloat(&ttlvArrayHead, 3, 5.7);
Quos_ttlvAddIdStruct(&ttlvHead, 6, ttlvArrayHead);
void *st = Quos_ttlvGetIdStruct(ttlvHead, 6);

Quos_ttlvGetIdRaw

This function gets raw data from a node.

Prototype

c
quint32_t Quos_ttlvGetIdRaw(const void *ttlvHead, quint16_t id, quint8_t **value);

Parameter

  • Input Parameter

    • void **ttlvNode: TTLV node.
    • quint16_tid: Node ID.
  • Output Parameter

    • quint8_t **value: Node data.
  • Return Value

    • Length of the node data.

Example

c
void *ttlvHead = NULL;
quint8_t *value = NULL;
quint8_t buf[5] = {'a', 'b', 'c', 'd', 'e'};
Quos_ttlvAddIdRaw(&ttlvHead, 5, buf, sizeof(buf));
quint32_t len = Quos_ttlvGetIdRaw(ttlvHead, 5, &value);

Quos_ttlvGetCount

This function gets the number of nodes.

Prototype

c
quint32_t Quos_ttlvGetCount(const void *ttlvHead);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
  • Output Parameter

    • None
  • Return Value

    • The number of nodes.

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Quos_ttlvAddIdInt(&ttlvHead, 2, 23);
Quos_ttlvAddIdText(&ttlvHead, 3, "hello world");
quint32_t len = Quos_ttlvGetCount(ttlvHead);

Quos_ttlvGetNode

This function gets the pointer to a node.

Prototype

c
void *Quos_ttlvGetNode(const void *ttlvHead, quint16_t index, quint16_t *id, Quos_dpDataType_e *type);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tindex: Node index.
  • Output Parameter

    • quint16_t *id: Node ID.
    • Quos_dpDataType_e *type: Node type.
  • Return Value

    • Pointer to a node.

Example

c
void *ttlvHead = NULL;
quint16_t id = 0;
Quos_dpDataType_e type = 0;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
void *ptr = Quos_ttlvGetNode(ttlvHead, 0, &id, &type);

Quos_ttlvRemove

This function deletes node.

Prototype

c
void Quos_ttlvRemove(void **ttlvHead, quint16_t id);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
    • quint16_tid: Node ID.
  • Output Parameter

    • None
  • Return Value

    • None

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Quos_ttlvRemove(&ttlvHead, 1);

Quos_ttlvFree

This function releases TTLV data table resources.

Prototype

c
void Quos_ttlvFree(void **ttlvHead);

Parameter

  • Input Parameter

    • void **ttlvHead: TTLV data table.
  • Output Parameter

    • None
  • Return Value

    • None

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Quos_ttlvFree(&ttlvHead);

Quos_ttlvUnformat

This function converts byte stream to TTLV data table.

Prototype

c
void *Quos_ttlvUnformat(const quint8_t *buffer, quint32_t len);

Parameter

  • Input Parameter

    • quint8_t *buffer: Byte stream data.
    • quint32_tlen: Length of the byte stream data.
  • Output Parameter

    • None
  • Return Value

    • TTLV data table.

Example

c
void *ttlvHead = Quos_ttlvUnformat(payload, payloadLen);

Quos_ttlvFormat

This function converts TTLV data to byte stream data.

Prototype

c
quint32_t Quos_ttlvFormat(const void *ttlvHead, quint8_t *retBuf);

Parameter

  • Input Parameter

    • void *ttlvHead: TTLV data table.
  • Output Parameter

    • quint8_tretBuf: Byte stream data.
  • Return Value

    • Length of the byte stream data.

Example

c
void *ttlvHead = NULL;
quint8_t buf[128] = {0};
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
quint32_t len = Quos_ttlvFormat(ttlvHead, buf);

Quos_ttlvFormatLen

This function gets the length of byte stream data converted from TTLV data.

Prototype

c
quint32_t Quos_ttlvFormatLen(const void *ttlvHead);

Parameter

  • Input Parameter

    • void *ttlvHead: TTLV data table.
  • Output Parameter

    • None
  • Return Value

    • Length of the byte stream data.

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
quint32_t len = Quos_ttlvFormatLen(ttlvHead);

Quos_ttlvHeadPrintf

This function prints the TTLV data table.

Prototype

c
void Quos_ttlvHeadPrintf(const void *ttlvHead);

Parameter

  • Input Parameter

    • void *ttlvHead: TTLV data table.
  • Output Parameter

    • None
  • Return Value

    • None

Example

c
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Quos_ttlvHeadPrintf(ttlvHead);

Quos_json2Ttlv

This function converts JSON data to TTLV data.

Prototype

c
void *Quos_json2Ttlv(const Quos_cjson_t *json);

Parameter

  • Input Parameter

    • Quos_cjson_t *json: JSON data.
  • Output Parameter

    • None
  • Return Value

    • TTLV data.

Example

c
Quos_cjson_t * js = NULL;
void *ttlvHead = NULL;
js = Quos_cjsonCreateNumber(120);
ttlvHead = Quos_json2Ttlv(js);

Quos_ttlv2Json

This function converts TTLV data to JSON data.

Prototype

c
Quos_cjson_t *Quos_ttlv2Json(const void *ttlvHead);

Parameter

  • Input Parameter

    • void *ttlvHead: TTLV data.
  • Output Parameter

    • None
  • Return Value

    • JSON data.

Example

c
Quos_cjson_t * js = NULL;
void *ttlvHead = NULL;
Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
js = Quos_ttlv2Json(ttlvHead);

Error Code List

Enumeration ValueHexadecimalDecimalDescription
OPRT_OK-0x0000-0Successful execution.