TDME2  1.9.200
Hex.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 
5 #include <string>
6 
7 #include <tdme/tdme.h>
9 
10 using std::string;
11 
12 /**
13  * Integer to hex string conversion utility class
14  * @author Andreas Drewke
15  */
17 public:
18 
19  /**
20  * @brief Encodes an 64 bit unsigned integer to a hex string representation
21  * @param decodedInt int value to encode
22  * @returns encodedString
23  */
24  inline static const string encodeInt(const uint64_t decodedInt) {
25  string encodedString;
26  encodeInt(decodedInt, encodedString);
27  return encodedString;
28  }
29 
30  /**
31  * @brief Decodes a hex string representation to an 64 bit unsigned integer
32  * @param encodedInt string value to decode
33  * @returns decodedString
34  */
35  inline static uint64_t decodeInt(const string& encodedString) {
36  uint64_t decodedInt;
37  if (decodeInt(encodedString, decodedInt) == false) return -1LL;
38  return decodedInt;
39  }
40 
41  /**
42  * @brief Encodes an 64 bit unsigned integer to a hex string representation
43  * @param decodedInt int value to encode
44  * @param encodedString string
45  */
46  static void encodeInt(const uint64_t decodedInt, string& encodedString);
47 
48  /**
49  * @brief Decodes an hex string representation to 64 bit unsigned integer
50  * @param encodedString encoded string
51  * @param decodedInt decoded Int
52  * @return success
53  */
54  static bool decodeInt(const string& encodedString, uint64_t& decodedInt);
55 
56 };
Integer to hex string conversion utility class.
Definition: Hex.h:16
static uint64_t decodeInt(const string &encodedString)
Decodes a hex string representation to an 64 bit unsigned integer.
Definition: Hex.h:35
static const string encodeInt(const uint64_t decodedInt)
Encodes an 64 bit unsigned integer to a hex string representation.
Definition: Hex.h:24