diff options
| author | Dan Engelbrecht <[email protected]> | 2024-05-29 08:54:01 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-05-29 08:54:01 +0200 |
| commit | 3d3a39d69b39d5202960ada6d3512786fa4a8c83 (patch) | |
| tree | f981eaf60b278edc84d7bd959153981fc2934b22 /src/zencore | |
| parent | 5.5.2 (diff) | |
| download | zen-3d3a39d69b39d5202960ada6d3512786fa4a8c83.tar.xz zen-3d3a39d69b39d5202960ada6d3512786fa4a8c83.zip | |
workspace shares (#84)
Feature: New 'workspaces' service which allows a user to share a local folder via zenserver. A workspace can have mulitple workspace shares and they provie an HTTP API that is compatible with the project oplog HTTP API. Workspaces and shares are preserved between runs. Workspaces feature is disabled by default - enable with --workspaces-enabled option when launching zenserver.
Diffstat (limited to 'src/zencore')
| -rw-r--r-- | src/zencore/include/zencore/uid.h | 2 | ||||
| -rw-r--r-- | src/zencore/iobuffer.cpp | 12 | ||||
| -rw-r--r-- | src/zencore/uid.cpp | 28 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/zencore/include/zencore/uid.h b/src/zencore/include/zencore/uid.h index 3abec9d16..f8b1ccf98 100644 --- a/src/zencore/include/zencore/uid.h +++ b/src/zencore/include/zencore/uid.h @@ -61,8 +61,10 @@ struct Oid const Oid& Generate(); [[nodiscard]] static Oid FromHexString(const std::string_view String); + [[nodiscard]] static Oid TryFromHexString(const std::string_view String, const Oid& Default = Oid::Zero); StringBuilderBase& ToString(StringBuilderBase& OutString) const; void ToString(char OutString[StringLength]) const; + std::string ToString() const; [[nodiscard]] static Oid FromMemory(const void* Ptr); auto operator<=>(const Oid& rhs) const = default; diff --git a/src/zencore/iobuffer.cpp b/src/zencore/iobuffer.cpp index fd99a01cb..33762bdb7 100644 --- a/src/zencore/iobuffer.cpp +++ b/src/zencore/iobuffer.cpp @@ -30,6 +30,10 @@ ZEN_THIRD_PARTY_INCLUDES_END # include <unistd.h> #endif +#if ZEN_WITH_TESTS +# include <zencore/testutils.h> +#endif + #include <gsl/gsl-lite.hpp> namespace zen { @@ -723,14 +727,16 @@ TEST_CASE("IoBuffer") TEST_CASE("IoBuffer.mmap") { + zen::ScopedTemporaryDirectory TempDir; + zen::IoBuffer Buffer1{65536}; uint8_t* Mutate = Buffer1.MutableData<uint8_t>(); memcpy(Mutate, "abc123", 6); - zen::WriteFile("test_file.data", Buffer1); + zen::WriteFile(TempDir.Path() / "test_file.data", Buffer1); SUBCASE("in-range") { - zen::IoBuffer FileBuffer = IoBufferBuilder::MakeFromFile("test_file.data", 0, 65536); + zen::IoBuffer FileBuffer = IoBufferBuilder::MakeFromFile(TempDir.Path() / "test_file.data", 0, 65536); const void* Data = FileBuffer.GetData(); CHECK(Data != nullptr); CHECK_EQ(memcmp(Data, "abc123", 6), 0); @@ -741,7 +747,7 @@ TEST_CASE("IoBuffer.mmap") # if ZEN_PLATFORM_WINDOWS SUBCASE("out-of-range") { - zen::IoBuffer FileBuffer = IoBufferBuilder::MakeFromFile("test_file.data", 131072, 65536); + zen::IoBuffer FileBuffer = IoBufferBuilder::MakeFromFile(TempDir.Path() / "test_file.data", 131072, 65536); const void* Data = nullptr; CHECK_THROWS(Data = FileBuffer.GetData()); CHECK(Data == nullptr); diff --git a/src/zencore/uid.cpp b/src/zencore/uid.cpp index 0f04d70ac..8ef660c7a 100644 --- a/src/zencore/uid.cpp +++ b/src/zencore/uid.cpp @@ -83,6 +83,26 @@ Oid::FromHexString(const std::string_view String) } Oid +Oid::TryFromHexString(const std::string_view String, const Oid& Default) +{ + if (String.length() != StringLength) + { + return Default; + } + + Oid Id; + + if (ParseHexBytes(String.data(), String.size(), reinterpret_cast<uint8_t*>(Id.OidBits))) + { + return Id; + } + else + { + return Default; + } +} + +Oid Oid::FromMemory(const void* Ptr) { Oid Id; @@ -97,6 +117,14 @@ Oid::ToString(char OutString[StringLength]) const OutString[StringLength] = '\0'; } +std::string +Oid::ToString() const +{ + char OutString[StringLength + 1]; + ToString(OutString); + return std::string(OutString, StringLength); +} + StringBuilderBase& Oid::ToString(StringBuilderBase& OutString) const { |