kasunath | d073aa1 | 2022-05-12 16:08:49 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "rde_common.h" |
| 4 | |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #ifdef __cplusplus |
| 8 | extern "C" |
| 9 | { |
| 10 | #endif |
| 11 | |
| 12 | /** |
| 13 | * @brief Mask for the type of the dictionary within a bejTupleS. |
| 14 | */ |
| 15 | #define DICTIONARY_TYPE_MASK 0x01 |
| 16 | |
| 17 | /** |
| 18 | * @brief Number of bits needed to shift to get the sequence number from a |
| 19 | * bejTupleS nnint value. |
| 20 | */ |
| 21 | #define DICTIONARY_SEQ_NUM_SHIFT 1 |
| 22 | |
| 23 | /** |
| 24 | * @brief BEJ dictionary type. |
| 25 | */ |
| 26 | enum BejDictionaryType |
| 27 | { |
| 28 | bejPrimary = 0, |
| 29 | bejAnnotation = 1, |
| 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * @brief Dictionary property header. |
| 34 | */ |
| 35 | struct BejDictionaryProperty |
| 36 | { |
| 37 | struct BejTupleF format; |
| 38 | uint16_t sequenceNumber; |
| 39 | uint16_t childPointerOffset; |
| 40 | uint16_t childCount; |
| 41 | uint8_t nameLength; |
| 42 | uint16_t nameOffset; |
| 43 | } __attribute__((__packed__)); |
| 44 | |
| 45 | struct BejDictionaryHeader |
| 46 | { |
| 47 | uint8_t versionTag; |
| 48 | uint8_t truncationFlag : 1; |
| 49 | uint8_t reservedFlags : 7; |
| 50 | uint16_t entryCount; |
| 51 | uint32_t schemaVersion; |
| 52 | uint32_t dictionarySize; |
| 53 | } __attribute__((__packed__)); |
| 54 | |
| 55 | /** |
| 56 | * @brief Get the offset of the first property in a dictionary. |
| 57 | * |
| 58 | * @return the offset to the first property. |
| 59 | */ |
| 60 | uint16_t bejDictGetPropertyHeadOffset(); |
| 61 | |
| 62 | /** |
| 63 | * @brief Get the offset of the first annotated property in an annoation |
| 64 | * dictionary. |
| 65 | * |
| 66 | * @return the offset to the first annotated property in an annoation |
| 67 | * dictionary. |
| 68 | */ |
| 69 | uint16_t bejDictGetFirstAnnotatedPropertyOffset(); |
| 70 | |
| 71 | /** |
| 72 | * @brief Get the property related to the given sequence number. |
| 73 | * |
| 74 | * @param[in] dictionary - dictionary containing the sequence number. |
| 75 | * @param[in] startingPropertyOffset - offset of the starting property for |
| 76 | * the search. |
| 77 | * @param[in] sequenceNumber - sequence number of the property. |
| 78 | * @param[out] property - if the search is successful, this will point to a |
| 79 | * valid property. |
| 80 | * @return 0 if successful. |
| 81 | */ |
| 82 | int bejDictGetProperty(const uint8_t* dictionary, |
| 83 | uint16_t startingPropertyOffset, |
| 84 | uint16_t sequenceNumber, |
| 85 | const struct BejDictionaryProperty** property); |
| 86 | |
| 87 | /** |
| 88 | * @brief Get the name of a property. |
| 89 | * |
| 90 | * @param[in] dictionary - dictionary containing the property. |
| 91 | * @param[in] nameOffset - dictionary offset of the name. |
| 92 | * @param[in] nameLength - length of the name. |
| 93 | * @return a NULL terminated string. If the nameLength is 0, this will |
| 94 | * return an empty string. |
| 95 | */ |
| 96 | const char* bejDictGetPropertyName(const uint8_t* dictionary, |
| 97 | uint16_t nameOffset, uint8_t nameLength); |
| 98 | |
| 99 | #ifdef __cplusplus |
| 100 | } |
| 101 | #endif |