mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-03-26 04:30:21 +00:00
Add Uuids
This commit is contained in:
@@ -143,10 +143,14 @@ struct CaseInsensitiveLess {
|
||||
class HttpUtils
|
||||
{
|
||||
public:
|
||||
static char NibbleToHex(uint8_t b, bool isUppercase);
|
||||
static char NibbleToHex(uint8_t nibble);
|
||||
static uint8_t HexToNibble(char c);
|
||||
static std::string BytesToHex(const std::vector<uint8_t>& data);
|
||||
static void BytesToHex(std::string& text,const std::vector<uint8_t>& data);
|
||||
|
||||
static std::string BytesToHex(const std::vector<uint8_t>& data,bool isUppercase);
|
||||
static void BytesToHex(std::string& text,const std::vector<uint8_t>& data, bool isUppercase);
|
||||
static std::vector<uint8_t> HexToBytes(const std::string& text);
|
||||
static void HexToBytes(std::vector<uint8_t>& data,const std::string& text);
|
||||
static std::string MimeType(std::filesystem::path p);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "../Uuid.hpp"
|
||||
namespace Tesses::Framework::Serialization
|
||||
{
|
||||
|
||||
@@ -39,10 +40,43 @@ class BitConverter {
|
||||
static uint64_t ToUint64BE(uint8_t& b);
|
||||
static uint32_t ToUint32BE(uint8_t& b);
|
||||
static uint16_t ToUint16BE(uint8_t& b);
|
||||
|
||||
static double ToDoubleLE(uint8_t& b);
|
||||
static uint64_t ToUint64LE(uint8_t& b);
|
||||
static uint32_t ToUint32LE(uint8_t& b);
|
||||
static uint16_t ToUint16LE(uint8_t& b);
|
||||
|
||||
static Uuid ToUuidBE(uint8_t& b);
|
||||
|
||||
static Uuid ToUuidMS(uint8_t& b);
|
||||
|
||||
static void ToUuidBE(uint8_t& b, Uuid& uuid);
|
||||
|
||||
static void ToUuidMS(uint8_t& b, Uuid& uuid);
|
||||
|
||||
static void FromDoubleBE(uint8_t& b, double v);
|
||||
static void FromUint64BE(uint8_t& b, uint64_t v);
|
||||
static void FromUint32BE(uint8_t& b, uint32_t v);
|
||||
static void FromUint16BE(uint8_t& b, uint16_t v);
|
||||
static void FromDoubleLE(uint8_t& b, double v);
|
||||
static void FromUint64LE(uint8_t& b, uint64_t v);
|
||||
static void FromUint32LE(uint8_t& b, uint32_t v);
|
||||
static void FromUint16LE(uint8_t& b, uint16_t v);
|
||||
|
||||
static void FromUuidBE(uint8_t& b, const Uuid& uuid);
|
||||
|
||||
static void FromUuidMS(uint8_t& b, const Uuid& uuid);
|
||||
|
||||
|
||||
static inline bool IsLittleEndian()
|
||||
{
|
||||
uint8_t a[2];
|
||||
a[0] = 0x01;
|
||||
a[1] = 0xA4;
|
||||
uint16_t num=0;
|
||||
memcpy(&num,&a, 2);
|
||||
return num != 420;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Stream.hpp"
|
||||
#include "../Uuid.hpp"
|
||||
|
||||
namespace Tesses::Framework::Streams
|
||||
{
|
||||
@@ -26,5 +27,9 @@ namespace Tesses::Framework::Streams
|
||||
float ReadF32LE();
|
||||
double ReadF64BE();
|
||||
double ReadF64LE();
|
||||
Uuid ReadUuidBE();
|
||||
Uuid ReadUuidMS();
|
||||
void ReadUuidBE(Uuid& uuid);
|
||||
void ReadUuidMS(Uuid& uuid);
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "Stream.hpp"
|
||||
|
||||
#include "../Uuid.hpp"
|
||||
namespace Tesses::Framework::Streams
|
||||
{
|
||||
class ByteWriter {
|
||||
@@ -27,5 +27,7 @@ namespace Tesses::Framework::Streams
|
||||
void WriteF32LE(float v);
|
||||
void WriteF64BE(double v);
|
||||
void WriteF64LE(double v);
|
||||
void WriteUuidBE(const Uuid& uuid);
|
||||
void WriteUuidMS(const Uuid& uuid);
|
||||
};
|
||||
}
|
||||
32
include/TessesFramework/Uuid.hpp
Normal file
32
include/TessesFramework/Uuid.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "Common.hpp"
|
||||
|
||||
namespace Tesses::Framework {
|
||||
enum class UuidStringifyConfig {
|
||||
IsUppercase=0b001,
|
||||
HasCurly=0b010,
|
||||
HasDashes=0b100,
|
||||
UppercaseCompact = IsUppercase,
|
||||
LowercaseCompact = 0,
|
||||
UppercaseNoCurly = IsUppercase | HasDashes,
|
||||
LowercaseNoCurly = HasDashes,
|
||||
UppercaseCurly = IsUppercase | HasDashes | HasCurly,
|
||||
LowercaseCurly = HasDashes | HasCurly
|
||||
};
|
||||
struct Uuid {
|
||||
Uuid() = default;
|
||||
uint32_t time_low = 0;
|
||||
uint16_t time_mid = 0;
|
||||
uint16_t time_hi_and_version = 0;
|
||||
uint8_t clock_seq_hi_and_reserved = 0;
|
||||
uint8_t clock_seq_low = 0;
|
||||
uint8_t node[6] = {0,0,0,0,0,0};
|
||||
|
||||
static Uuid Generate();
|
||||
static void Generate(Uuid& uuid);
|
||||
|
||||
static bool TryParse(std::string text, Uuid& uuid);
|
||||
|
||||
std::string ToString(UuidStringifyConfig cfg = UuidStringifyConfig::UppercaseCurly);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user