fix base64

This commit is contained in:
tqcq
2024-03-23 12:24:13 +08:00
parent f0f8d77937
commit 5274aca7fd
6 changed files with 127 additions and 92 deletions

View File

@@ -1,25 +0,0 @@
/**
* @file : sequence_checker
* @created : Saturday Feb 03, 2024 13:32:22 CST
* @license : MIT
**/
#pragma once
#ifndef SLED_SEQUENCE_CHECKER_H
#define SLED_SEQUENCE_CHECKER_H
namespace sled {
class SequenceChecker : public internal::SequenceCheckerImpl {
public:
enum InitialState : bool {
kDetached = false,
kAttached = true,
};
explicit SequenceChecker(InitialState initial_state = kAttached) : Impl(initial_state) {}
};
}// namespace sled
#endif// SLED_SEQUENCE_CHECKER_H

View File

@@ -38,6 +38,7 @@
#include "sled/strings/utils.h"
// synchorization
#include "seld/synchronization/sequence_checker.h"
#include "sled/synchronization/event.h"
#include "sled/synchronization/mutex.h"
#include "sled/synchronization/one_time_event.h"

View File

@@ -9,6 +9,7 @@
#define SLED_STRINGS_BASE64_H
#include "sled/status_or.h"
#include <string.h>
#include <string>
#include <vector>
@@ -16,13 +17,44 @@ namespace sled {
class Base64 {
public:
static std::string Encode(const uint8_t *const ptr, size_t len);
static std::string Encode(const std::vector<unsigned char> &data);
static std::string Encode(const std::string &data);
static std::string Encode(const char *const data);
static StatusOr<std::string> Decode(const std::string &base64);
static StatusOr<std::string> Decode(const std::vector<unsigned char> &base64);
static StatusOr<std::string> Decode(const uint8_t *const ptr, size_t len);
static size_t DecodedLength(const char *base64_data, size_t base64_len);
static std::string Encode(const uint8_t *ptr, size_t len);
static StatusOr<std::string> Decode(const uint8_t *ptr, size_t len);
// EncodedLength
static inline size_t EncodedLength(size_t data_len) { return (data_len + 2) / 3 * 4; }
static inline size_t DecodedLength(const std::string &str) { return DecodedLength(str.data(), str.size()); }
static inline size_t DecodedLength(const char *base64_str) { return DecodedLength(base64_str, strlen(base64_str)); }
// Encode
static inline std::string Encode(const std::vector<unsigned char> &data)
{
return Encode(data.data(), data.size());
}
static inline std::string Encode(const std::string &data) { return Encode((uint8_t *) data.data(), data.size()); }
static inline std::string Encode(const char *const data) { return Encode((uint8_t *) data, strlen(data)); }
// Decode
static inline StatusOr<std::string> Decode(const char *ptr, size_t len)
{
return Decode((const uint8_t *) ptr, len);
}
static inline StatusOr<std::string> Decode(const char *ptr) { return Decode(ptr, strlen(ptr)); }
static inline StatusOr<std::string> Decode(const std::string &base64)
{
return Decode(base64.data(), base64.size());
}
static inline StatusOr<std::string> Decode(const std::vector<unsigned char> &base64)
{
return Decode(base64.data(), base64.size());
}
};
}// namespace sled