summaryrefslogtreecommitdiffstats
path: root/mocktracer/src/base64.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:44:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:44:33 +0000
commitb196c6498d22e47bb9d0da0153068ec54eac7956 (patch)
tree1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /mocktracer/src/base64.h
parentInitial commit. (diff)
downloadopentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.tar.xz
opentracing-cpp-b196c6498d22e47bb9d0da0153068ec54eac7956.zip
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--mocktracer/src/base64.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/mocktracer/src/base64.h b/mocktracer/src/base64.h
new file mode 100644
index 0000000..438bbda
--- /dev/null
+++ b/mocktracer/src/base64.h
@@ -0,0 +1,48 @@
+#ifndef OPENTRACING_MOCKTRACER_BASE64_H
+#define OPENTRACING_MOCKTRACER_BASE64_H
+
+#include <opentracing/version.h>
+#include <cstdint>
+#include <string>
+
+namespace opentracing {
+BEGIN_OPENTRACING_ABI_NAMESPACE
+namespace mocktracer {
+class Base64 {
+ public:
+ /**
+ * Base64 encode an input char buffer with a given length.
+ * @param input char array to encode.
+ * @param length of the input array.
+ */
+ static std::string encode(const char* input, uint64_t length);
+
+ /**
+ * Base64 decode an input string.
+ * @param input char array to decode.
+ * @param length of the input array.
+ *
+ * Note, decoded string may contain '\0' at any position, it should be treated
+ * as a sequence of bytes.
+ */
+ static std::string decode(const char* input, size_t length);
+
+ private:
+ /**
+ * Helper method for encoding. This is used to encode all of the characters
+ * from the input string.
+ */
+ static void encodeBase(const uint8_t cur_char, uint64_t pos, uint8_t& next_c,
+ std::string& ret);
+
+ /**
+ * Encode last characters. It appends '=' chars to the ret if input
+ * string length is not divisible by 3.
+ */
+ static void encodeLast(uint64_t pos, uint8_t last_char, std::string& ret);
+};
+} // namespace mocktracer
+END_OPENTRACING_ABI_NAMESPACE
+} // namespace opentracing
+
+#endif // OPENTRACING_MOCKTRACER_BASE64_H