diff options
| author | Stefan Boberg <[email protected]> | 2023-06-30 11:07:10 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-06-30 11:07:10 +0200 |
| commit | 0396f400a97f71bf743d584acc71a0cdbc155566 (patch) | |
| tree | 829f7764157aecf9c198e4b076e5fb1adcfeb13f /src/zencore/compactbinary.cpp | |
| parent | various zenhttp fixes from sb/proto (diff) | |
| download | zen-0396f400a97f71bf743d584acc71a0cdbc155566.tar.xz zen-0396f400a97f71bf743d584acc71a0cdbc155566.zip | |
* Added Guid::FromString
* Added LoadCompactBinaryObject from file to compactbinaryfile.cpp/h
* Added SaveCompactBinary(BinaryWriter& Ar, ...) functions
* Added ZEN_PLATFORM_NAME define
* Added SystemMetrics functionality to query system properties (see zencore/system.h)
Diffstat (limited to 'src/zencore/compactbinary.cpp')
| -rw-r--r-- | src/zencore/compactbinary.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/zencore/compactbinary.cpp b/src/zencore/compactbinary.cpp index 0db9f02ea..5b599dda3 100644 --- a/src/zencore/compactbinary.cpp +++ b/src/zencore/compactbinary.cpp @@ -358,6 +358,34 @@ Guid::ToString(StringBuilderBase& Sb) const return Sb; } +Guid +Guid::FromString(std::string_view InString) +{ + if (InString.size() != 36) + { + } + + bool Ok = true; + + uint32_t V0 = 0, V5 = 0; + uint16_t V1 = 0, V2 = 0, V3 = 0, V4 = 0; + + Ok = Ok && ParseHexNumber(InString.substr(0, 8), /* out */ V0); + Ok = Ok && ParseHexNumber(InString.substr(9, 4), /* out */ V1); + Ok = Ok && ParseHexNumber(InString.substr(14, 4), /* out */ V2); + Ok = Ok && ParseHexNumber(InString.substr(19, 4), /* out */ V3); + Ok = Ok && ParseHexNumber(InString.substr(24, 4), /* out */ V4); + Ok = Ok && ParseHexNumber(InString.substr(28, 8), /* out */ V5); + + Guid Value; + Value.A = V0; + Value.B = V1 << 16 | V2; + Value.C = V3 << 16 | V4; + Value.D = V5; + + return Value; +} + ////////////////////////////////////////////////////////////////////////// namespace CompactBinaryPrivate { @@ -1943,6 +1971,22 @@ uson_forcelink() { } +TEST_CASE("guid") +{ + using namespace std::literals; + + const Guid A = Guid::FromString("03000c43-d267-36fd-9164-a7555824822b"sv); + + StringBuilder<40> GuidStr; + A.ToString(GuidStr); + + CHECK(std::string_view(GuidStr) == "03000c43-d267-36fd-9164-a7555824822b"sv); + + const Guid B = Guid::FromString(GuidStr); + + CHECK(A == B); +} + TEST_CASE("uson") { using namespace std::literals; @@ -2142,8 +2186,8 @@ TEST_CASE("uson.json") SUBCASE("number.nan") { - const float FloatNan = std::numeric_limits<float>::quiet_NaN(); - const double DoubleNan = std::numeric_limits<double>::quiet_NaN(); + constexpr float FloatNan = std::numeric_limits<float>::quiet_NaN(); + constexpr double DoubleNan = std::numeric_limits<double>::quiet_NaN(); CbObjectWriter Writer; Writer << "FloatNan" << FloatNan; |