/**
  ******************************************************************************
  * @file           : tlv.h
  * @brief          : Header for TLV (Tag-Length-Value) utilities.
  *                   This file contains type definitions and function
  *                   prototypes for TLV operations.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _TLV_H_
#define _TLV_H_

#ifdef __cplusplus
extern "C" {
#endif

/** @addtogroup TLV_UTILITIES
  * @{
  */

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>


/** @addtogroup TLV_Utilities_Exported_Types
  * @{
  */
/* Exported types ------------------------------------------------------------*/
/**
 * @struct tlv_t
 * @brief Structure representing a TLV (Tag-Length-Value) element.
 */
typedef struct {
  uint8_t tag;         /**< Tag identifier */
  uint8_t *value;      /**< Pointer to value data */
  uint32_t length;     /**< Length of value data */
} tlv_t;


/**
 * @enum tlvStatus_t
 * @brief Status codes for TLV operations.
 */
typedef enum {
  TLV_SUCCESS,              /**< Operation successful */
  TLV_ERROR_SHORT_PAYLOAD,  /**< Payload too short */
  TLV_ERROR_INVALID_LENGTH, /**< Invalid length */
  TLV_ERROR_SHORT_BUFFER,   /**< Buffer too short */
  TLV_ERROR_TAG_NOT_FOUND   /**< Tag not found */
} tlvStatus_t;
/**
  * @}
  */


/** @addtogroup TLV_Utilities_Exported_Functions
  * @{
  */
/* Exported functions ------------------------------------------------------- */
/**
 * @brief Extracts one TLV element from a buffer.
 * @param tlvBuf Pointer to the buffer pointer.
 * @param tlvLength Pointer to the buffer length.
 * @param tlv Pointer to the TLV structure to fill.
 * @return Status code.
 */
tlvStatus_t getOneTlv(uint8_t **tlvBuf, uint32_t *tlvLength, tlv_t *tlv);

/**
 * @brief Appends a TLV element to a buffer.
 * @param inputBuffer Pointer to the buffer pointer.
 * @param inputBufferLen Pointer to the buffer length.
 * @param tlv Pointer to the TLV structure to append.
 * @return Status code.
 */
tlvStatus_t appendTLV(uint8_t **inputBuffer, uint32_t *inputBufferLen, const tlv_t *tlv);
/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* _TLV_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
