[388] | 1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
| 3 |
|
---|
| 4 | #ifndef UUID_H
|
---|
| 5 | #define UUID_H
|
---|
| 6 |
|
---|
| 7 | #ifdef __cplusplus
|
---|
| 8 | #include <cstddef>
|
---|
| 9 | #include <cstdint>
|
---|
| 10 | extern "C" {
|
---|
| 11 | #else
|
---|
| 12 | #include <stddef.h>
|
---|
| 13 | #include <stdint.h>
|
---|
| 14 | #include <stdbool.h>
|
---|
| 15 | #endif /* __cplusplus */
|
---|
| 16 |
|
---|
| 17 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
| 18 |
|
---|
| 19 | typedef unsigned char UUID_T[16];
|
---|
| 20 |
|
---|
| 21 | /* These 2 strings can be conveniently used directly in printf statements
|
---|
| 22 | Notice that PRI_UUID has to be used like any other print format specifier, meaning it
|
---|
| 23 | has to be preceded with % */
|
---|
| 24 | #define PRI_UUID "02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
|
---|
| 25 | #define UUID_FORMAT_VALUES(uuid) \
|
---|
| 26 | (uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], (uuid)[6], (uuid)[7], \
|
---|
| 27 | (uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15]
|
---|
| 28 |
|
---|
| 29 | #define UUID_FORMAT_VALUES_OR_NULL(uuid) \
|
---|
| 30 | ((uuid) == NULL) ? 0 : (uuid)[0], ((uuid) == NULL) ? 0 : (uuid)[1], ((uuid) == NULL) ? 0 : (uuid)[2], ((uuid) == NULL) ? 0 : (uuid)[3], \
|
---|
| 31 | ((uuid) == NULL) ? 0 : (uuid)[4], ((uuid) == NULL) ? 0 : (uuid)[5], ((uuid) == NULL) ? 0 : (uuid)[6], ((uuid) == NULL) ? 0 : (uuid)[7], \
|
---|
| 32 | ((uuid) == NULL) ? 0 : (uuid)[8], ((uuid) == NULL) ? 0 : (uuid)[9], ((uuid) == NULL) ? 0 : (uuid)[10], ((uuid) == NULL) ? 0 : (uuid)[11], \
|
---|
| 33 | ((uuid) == NULL) ? 0 : (uuid)[12], ((uuid) == NULL) ? 0 : (uuid)[13], ((uuid) == NULL) ? 0 : (uuid)[14], ((uuid) == NULL) ? 0 : (uuid)[15] \
|
---|
| 34 |
|
---|
| 35 | /* @brief Generates a true UUID
|
---|
| 36 | * @param uuid A pre-allocated buffer for the bytes of the generated UUID
|
---|
| 37 | * @returns Zero if no failures occur, non-zero otherwise.
|
---|
| 38 | */
|
---|
| 39 | MOCKABLE_FUNCTION(, int, UUID_generate, UUID_T*, uuid);
|
---|
| 40 |
|
---|
| 41 | /* @brief Gets the UUID value (byte sequence) of an well-formed UUID string.
|
---|
| 42 | * @param uuid_string A null-terminated well-formed UUID string (e.g., "7f907d75-5e13-44cf-a1a3-19a01a2b4528").
|
---|
| 43 | * @param uuid Sequence of bytes representing an UUID.
|
---|
| 44 | * @returns Zero if no failures occur, non-zero otherwise.
|
---|
| 45 | */
|
---|
| 46 | MOCKABLE_FUNCTION(, int, UUID_from_string, const char*, uuid_string, UUID_T*, uuid);
|
---|
| 47 |
|
---|
| 48 | /* @brief Gets the string representation of the UUID value.
|
---|
| 49 | * @param uuid Sequence of bytes representing an UUID.
|
---|
| 50 | * @returns A null-terminated string representation of the UUID value provided (e.g., "7f907d75-5e13-44cf-a1a3-19a01a2b4528").
|
---|
| 51 | */
|
---|
| 52 | MOCKABLE_FUNCTION(, char*, UUID_to_string, const UUID_T*, uuid);
|
---|
| 53 |
|
---|
| 54 | #ifdef __cplusplus
|
---|
| 55 | }
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
| 58 | #endif /* UUID_H */
|
---|