From 3848e1cf6b37edcedd608ce873c91cf733f5df97 Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Wed, 25 Sep 2024 22:48:54 +0300 Subject: [PATCH 1/6] Add vector to memory_resource::stl namespace --- runtime-core/memory-resource/resource_allocator.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime-core/memory-resource/resource_allocator.h b/runtime-core/memory-resource/resource_allocator.h index eca8f3b1a1..1028040558 100644 --- a/runtime-core/memory-resource/resource_allocator.h +++ b/runtime-core/memory-resource/resource_allocator.h @@ -9,9 +9,9 @@ #include #include #include +#include #include "common/wrappers/likely.h" - #include "runtime-core/utils/kphp-assert-core.h" namespace memory_resource { @@ -79,6 +79,9 @@ using deque = std::deque>; template using queue = std::queue>>; + +template +using vector = std::vector>; } // namespace stl } // namespace memory_resource From 5a24a9b72d69d5487564f69a2ce70a6a6ffc043a Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Wed, 25 Sep 2024 22:49:52 +0300 Subject: [PATCH 2/6] Don't use global variable in crypto-functions.cpp --- runtime-light/stdlib/crypto/crypto-functions.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime-light/stdlib/crypto/crypto-functions.cpp b/runtime-light/stdlib/crypto/crypto-functions.cpp index 63e4f32899..aab767c41f 100644 --- a/runtime-light/stdlib/crypto/crypto-functions.cpp +++ b/runtime-light/stdlib/crypto/crypto-functions.cpp @@ -12,7 +12,7 @@ namespace { -const string CRYPTO_COMPONENT = string("crypto"); +constexpr const char *CRYPTO_COMPONENT_NAME = "crypto"; } // namespace @@ -31,7 +31,7 @@ task_t> f$openssl_random_pseudo_bytes(int64_t length) noexcept string request_buf; request_buf.append(buffer.data(), buffer.size()); - auto query = f$component_client_send_request(CRYPTO_COMPONENT, string{buffer.data(), static_cast(buffer.size())}); + auto query = f$component_client_send_request(string{CRYPTO_COMPONENT_NAME}, string{buffer.data(), static_cast(buffer.size())}); string resp = co_await f$component_client_fetch_response(co_await query); buffer.clean(); @@ -55,7 +55,7 @@ task_t>> f$openssl_x509_parse(const string &data, bool sho string request_buf; request_buf.append(buffer.data(), buffer.size()); - auto query = f$component_client_send_request(CRYPTO_COMPONENT, request_buf); + auto query = f$component_client_send_request(string{CRYPTO_COMPONENT_NAME}, request_buf); string resp_from_platform = co_await f$component_client_fetch_response(co_await query); buffer.clean(); @@ -75,7 +75,7 @@ task_t f$openssl_sign(const string &data, string &signature, const string tl::TLBuffer buffer; request.store(buffer); - auto query = f$component_client_send_request(CRYPTO_COMPONENT, string(buffer.data(), buffer.size())); + auto query = f$component_client_send_request(string{CRYPTO_COMPONENT_NAME}, string(buffer.data(), buffer.size())); string resp_from_platform = co_await f$component_client_fetch_response(co_await query); buffer.clean(); @@ -98,7 +98,7 @@ task_t f$openssl_verify(const string &data, const string &signature, co tl::TLBuffer buffer; request.store(buffer); - auto query = f$component_client_send_request(CRYPTO_COMPONENT, string(buffer.data(), buffer.size())); + auto query = f$component_client_send_request(string{CRYPTO_COMPONENT_NAME}, string(buffer.data(), buffer.size())); string resp_from_platform = co_await f$component_client_fetch_response(co_await query); buffer.clean(); From 7644e46487e334f8f4bb1e4b987946b909502f5c Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Wed, 25 Sep 2024 22:50:34 +0300 Subject: [PATCH 3/6] Improve tl-core and add tl_serializable concept --- runtime-light/tl/tl-core.cpp | 2 ++ runtime-light/tl/tl-core.h | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/runtime-light/tl/tl-core.cpp b/runtime-light/tl/tl-core.cpp index b9e4cfa07f..38fd872795 100644 --- a/runtime-light/tl/tl-core.cpp +++ b/runtime-light/tl/tl-core.cpp @@ -5,6 +5,7 @@ #include "runtime-light/tl/tl-core.h" namespace tl { + void TLBuffer::store_string(std::string_view str) noexcept { const char *str_buf{str.data()}; size_t str_len{str.size()}; @@ -94,4 +95,5 @@ std::string_view TLBuffer::fetch_string() noexcept { adjust(total_len_with_padding - size_len); return response; } + } // namespace tl diff --git a/runtime-light/tl/tl-core.h b/runtime-light/tl/tl-core.h index 68467eff10..4064191020 100644 --- a/runtime-light/tl/tl-core.h +++ b/runtime-light/tl/tl-core.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -26,7 +27,7 @@ inline constexpr uint64_t MEDIUM_STRING_MAX_LEN = (static_cast(1) << 2 inline constexpr uint8_t LARGE_STRING_MAGIC = 0xff; inline constexpr uint8_t MEDIUM_STRING_MAGIC = 0xfe; -class TLBuffer : private vk::not_copyable { +class TLBuffer final : private vk::not_copyable { string_buffer m_buffer; size_t m_pos{0}; size_t m_remaining{0}; @@ -57,7 +58,7 @@ class TLBuffer : private vk::not_copyable { } void reset(size_t pos) noexcept { - php_assert(pos >= 0 && pos <= size()); + php_assert(pos <= size()); m_pos = pos; m_remaining = size() - m_pos; } @@ -97,4 +98,10 @@ class TLBuffer : private vk::not_copyable { std::string_view fetch_string() noexcept; }; +template +concept tl_serializable = std::default_initializable && requires(T t, TLBuffer tlb) { + { t.store(tlb) } noexcept -> std::same_as; + { t.fetch(tlb) } noexcept -> std::convertible_to; +}; + } // namespace tl From 69bface0e773e527a3c2c5f4a68aac3f5de94eea Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Wed, 25 Sep 2024 23:01:41 +0300 Subject: [PATCH 4/6] Enhance TL in K2 runtime * Enhance TL for job workers * Add more general TL types * Add TL types and functions for K2 confdata --- runtime-light/tl/tl-functions.cpp | 37 +++-- runtime-light/tl/tl-functions.h | 18 ++- runtime-light/tl/tl-types.cpp | 46 ++++-- runtime-light/tl/tl-types.h | 239 +++++++++++++++++++++++++++++- 4 files changed, 315 insertions(+), 25 deletions(-) diff --git a/runtime-light/tl/tl-functions.cpp b/runtime-light/tl/tl-functions.cpp index e9f4c2f4d4..e62c07060e 100644 --- a/runtime-light/tl/tl-functions.cpp +++ b/runtime-light/tl/tl-functions.cpp @@ -4,6 +4,7 @@ #include "runtime-light/tl/tl-functions.h" +#include #include #include @@ -12,9 +13,6 @@ namespace { -// magic + flags + image_id + job_id + minimum string size length -constexpr auto K2_INVOKE_JW_MIN_SIZE = sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint64_t) + sizeof(int64_t) + sizeof(uint64_t) + tl::SMALL_STRING_SIZE_LEN; - constexpr auto K2_JOB_WORKER_IGNORE_ANSWER_FLAG = static_cast(1U << 0U); } // namespace @@ -22,17 +20,24 @@ constexpr auto K2_JOB_WORKER_IGNORE_ANSWER_FLAG = static_cast(1U << 0U namespace tl { bool K2InvokeJobWorker::fetch(TLBuffer &tlb) noexcept { - if (tlb.size() < K2_INVOKE_JW_MIN_SIZE || *tlb.fetch_trivial() != K2_INVOKE_JOB_WORKER_MAGIC) { + if (tlb.fetch_trivial().value_or(TL_ZERO) != K2_INVOKE_JOB_WORKER_MAGIC) { + return false; + } + + const auto opt_flags{tlb.fetch_trivial()}; + const auto opt_image_id{tlb.fetch_trivial()}; + const auto opt_job_id{tlb.fetch_trivial()}; + const auto opt_timeout_ns{tlb.fetch_trivial()}; + if (!(opt_flags.has_value() && opt_image_id.has_value() && opt_job_id.has_value() && opt_timeout_ns.has_value())) { return false; } + const auto body_view{tlb.fetch_string()}; - const auto flags{*tlb.fetch_trivial()}; - ignore_answer = static_cast(flags & K2_JOB_WORKER_IGNORE_ANSWER_FLAG); - image_id = *tlb.fetch_trivial(); - job_id = *tlb.fetch_trivial(); - timeout_ns = *tlb.fetch_trivial(); - const std::string_view body_view{tlb.fetch_string()}; - body = string{body_view.data(), static_cast(body_view.size())}; + ignore_answer = static_cast(*opt_flags & K2_JOB_WORKER_IGNORE_ANSWER_FLAG); + image_id = *opt_image_id; + job_id = *opt_job_id; + timeout_ns = *opt_timeout_ns; + body = {body_view.data(), static_cast(body_view.size())}; return true; } @@ -72,4 +77,14 @@ void DigestVerify::store(TLBuffer &tlb) const noexcept { tlb.store_string(std::string_view{signature.c_str(), signature.size()}); } +void ConfdataGet::store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(CONFDATA_GET_MAGIC); + tlb.store_string({key.c_str(), static_cast(key.size())}); +} + +void ConfdataGetWildcard::store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(CONFDATA_GET_WILDCARD_MAGIC); + tlb.store_string({wildcard.c_str(), static_cast(wildcard.size())}); +} + } // namespace tl diff --git a/runtime-light/tl/tl-functions.h b/runtime-light/tl/tl-functions.h index cbadfdae60..aca70c65e3 100644 --- a/runtime-light/tl/tl-functions.h +++ b/runtime-light/tl/tl-functions.h @@ -36,7 +36,6 @@ inline constexpr uint32_t GET_PEM_CERT_INFO_MAGIC = 0xa50c'fd6c; inline constexpr uint32_t DIGEST_SIGN_MAGIC = 0xd345'f658; inline constexpr uint32_t DIGEST_VERIFY_MAGIC = 0x5760'bd0e; - struct GetCryptosecurePseudorandomBytes final { int32_t size{}; @@ -67,4 +66,21 @@ struct DigestVerify final { void store(TLBuffer &tlb) const noexcept; }; +// ===== CONFDATA ===== + +inline constexpr uint32_t CONFDATA_GET_MAGIC = 0xf0eb'cd89; +inline constexpr uint32_t CONFDATA_GET_WILDCARD_MAGIC = 0x5759'bd9e; + +struct ConfdataGet final { + string key; + + void store(TLBuffer &tlb) const noexcept; +}; + +struct ConfdataGetWildcard final { + string wildcard; + + void store(TLBuffer &tlb) const noexcept; +}; + } // namespace tl diff --git a/runtime-light/tl/tl-types.cpp b/runtime-light/tl/tl-types.cpp index 3919cda756..971bc9aaa0 100644 --- a/runtime-light/tl/tl-types.cpp +++ b/runtime-light/tl/tl-types.cpp @@ -4,6 +4,7 @@ #include "runtime-light/tl/tl-types.h" +#include #include #include #include @@ -13,27 +14,28 @@ namespace { -// magic + flags + job_id + minimum string size length -constexpr auto K2_JOB_WORKER_RESPONSE_MIN_SIZE = sizeof(uint32_t) + sizeof(uint32_t) + sizeof(int64_t) + tl::SMALL_STRING_SIZE_LEN; +enum CertInfoItem : uint32_t { LONG_MAGIC = 0x533f'f89f, STR_MAGIC = 0xc427'feef, DICT_MAGIC = 0x1ea8'a774 }; -enum CertInfoItem : uint32_t { - LONG_MAGIC = 0x533f'f89f, - STR_MAGIC = 0xc427'feef, - DICT_MAGIC = 0x1ea8'a774 -}; +constexpr uint32_t K2_JOB_WORKER_RESPONSE_MAGIC = 0x3afb'3a08; +constexpr uint32_t CONFDATA_VALUE_MAGIC = 0x3eaa'910b; } // namespace namespace tl { bool K2JobWorkerResponse::fetch(TLBuffer &tlb) noexcept { - if (tlb.size() < K2_JOB_WORKER_RESPONSE_MIN_SIZE || *tlb.fetch_trivial() != K2_JOB_WORKER_RESPONSE_MAGIC) { + if (tlb.fetch_trivial().value_or(TL_ZERO) != K2_JOB_WORKER_RESPONSE_MAGIC) { return false; } std::ignore = tlb.fetch_trivial(); // ignore flags - job_id = *tlb.fetch_trivial(); - const std::string_view body_view{tlb.fetch_string()}; + const auto opt_job_id{tlb.fetch_trivial()}; + if (!opt_job_id.has_value()) { + return false; + } + const auto body_view{tlb.fetch_string()}; + + job_id = *opt_job_id; body = string{body_view.data(), static_cast(body_view.size())}; return true; } @@ -130,4 +132,28 @@ bool GetPemCertInfoResponse::fetch(TLBuffer &tlb) noexcept { return true; } +bool ConfdataValue::fetch(TLBuffer &tlb) noexcept { + if (tlb.fetch_trivial().value_or(TL_ZERO) != CONFDATA_VALUE_MAGIC) { + return false; + } + const auto value_view{tlb.fetch_string()}; + Bool is_php_serialized_{}; + Bool is_json_serialized_{}; + if (!(is_php_serialized_.fetch(tlb) && is_json_serialized_.fetch(tlb))) { + return false; + } + + value = {value_view.data(), static_cast(value_view.size())}; + is_php_serialized = is_php_serialized_.value; + is_json_serialized = is_json_serialized_.value; + return true; +} + +void ConfdataValue::store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(CONFDATA_VALUE_MAGIC); + tlb.store_string({value.c_str(), static_cast(value.size())}); + Bool{.value = is_php_serialized}.store(tlb); + Bool{.value = is_json_serialized}.store(tlb); +} + } // namespace tl diff --git a/runtime-light/tl/tl-types.h b/runtime-light/tl/tl-types.h index d3778eff50..827ab3cce4 100644 --- a/runtime-light/tl/tl-types.h +++ b/runtime-light/tl/tl-types.h @@ -4,16 +4,237 @@ #pragma once +#include +#include #include +#include +#include "common/tl/constants/common.h" +#include "runtime-core/allocator/runtime-allocator.h" +#include "runtime-core/memory-resource/resource_allocator.h" +#include "runtime-core/memory-resource/unsynchronized_pool_resource.h" #include "runtime-core/runtime-core.h" #include "runtime-light/tl/tl-core.h" namespace tl { -// ===== JOB WORKERS ===== +// ===== GENERAL ===== + +struct Bool final { + bool value{}; + + bool fetch(TLBuffer &tlb) noexcept { + const auto magic{tlb.fetch_trivial().value_or(TL_ZERO)}; + value = magic == TL_BOOL_TRUE; + return magic == TL_BOOL_TRUE || magic == TL_BOOL_FALSE; + } + + void store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(value ? TL_BOOL_TRUE : TL_BOOL_FALSE); + } +}; + +template +struct Maybe final { + std::optional opt_value{}; + + bool fetch(TLBuffer &tlb) noexcept { + const auto magic{tlb.fetch_trivial().value_or(TL_ZERO)}; + if (magic == TL_MAYBE_TRUE) { + opt_value.emplace(); + return (*opt_value).fetch(tlb); + } else if (magic == TL_MAYBE_FALSE) { + opt_value = std::nullopt; + return true; + } + return false; + } + + void store(TLBuffer &tlb) const noexcept { + if (opt_value.has_value()) { + tlb.store_trivial(TL_MAYBE_TRUE); + (*opt_value).store(tlb); + } else { + tlb.store_trivial(TL_MAYBE_FALSE); + } + } +}; + +template +struct vector final { + using vector_t = memory_resource::stl::vector; + vector_t data{typename vector_t::allocator_type(RuntimeAllocator::current().memory_resource)}; + + using iterator = vector_t::iterator; + using const_iterator = vector_t::const_iterator; + + iterator begin() noexcept { + return data.begin(); + } + iterator end() noexcept { + return data.end(); + } + const_iterator begin() const noexcept { + return data.begin(); + } + const_iterator end() const noexcept { + return data.end(); + } + const_iterator cbegin() const noexcept { + return data.cbegin(); + } + const_iterator cend() const noexcept { + return data.cend(); + } + + size_t size() const noexcept { + return data.size(); + } + + bool fetch(TLBuffer &tlb) noexcept { + int64_t size{}; + if (const auto opt_size{tlb.fetch_trivial()}; opt_size.has_value()) { + size = *opt_size; + } else { + return false; + } + + data.clear(); + data.reserve(static_cast(size)); + for (auto i = 0; i < size; ++i) { + T t{}; + if (!t.fetch(tlb)) { + return false; + } + data.emplace_back(std::move(t)); + } + + return true; + } + + void store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(static_cast(data.size())); + std::for_each(data.cbegin(), data.cend(), [&tlb](auto &&elem) { std::forward(elem).store(tlb); }); + } +}; + +template +struct Vector final { + vector data{}; + + using iterator = vector::iterator; + using const_iterator = vector::const_iterator; + + iterator begin() noexcept { + return data.begin(); + } + iterator end() noexcept { + return data.end(); + } + const_iterator begin() const noexcept { + return data.begin(); + } + const_iterator end() const noexcept { + return data.end(); + } + const_iterator cbegin() const noexcept { + return data.cbegin(); + } + const_iterator cend() const noexcept { + return data.cend(); + } + + size_t size() const noexcept { + return data.size(); + } + + bool fetch(TLBuffer &tlb) noexcept { + if (tlb.fetch_trivial().value_or(TL_ZERO) != TL_VECTOR) { + return false; + } + return data.fetch(tlb); + } + + void store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(TL_VECTOR); + data.store(tlb); + } +}; + +template +struct dictionaryField final { + string key; + T value{}; + + bool fetch(TLBuffer &tlb) noexcept { + const auto key_view{tlb.fetch_string()}; + key = {key_view.data(), static_cast(key_view.size())}; + return !value.fetch(tlb); + } + + void store(TLBuffer &tlb) const noexcept { + tlb.store_string({key.c_str(), static_cast(key.size())}); + value.store(tlb); + } +}; + +template +struct dictionary final { + vector> data{}; + + using iterator = vector>::iterator; + using const_iterator = vector>::const_iterator; + + iterator begin() noexcept { + return data.begin(); + } + iterator end() noexcept { + return data.end(); + } + const_iterator begin() const noexcept { + return data.begin(); + } + const_iterator end() const noexcept { + return data.end(); + } + const_iterator cbegin() const noexcept { + return data.cbegin(); + } + const_iterator cend() const noexcept { + return data.cend(); + } + + size_t size() const noexcept { + return data.size(); + } + + bool fetch(TLBuffer &tlb) noexcept { + return data.fetch(tlb); + } + + void store(TLBuffer &tlb) const noexcept { + data.store(tlb); + } +}; -inline constexpr uint32_t K2_JOB_WORKER_RESPONSE_MAGIC = 0x3afb'3a08; +template +struct Dictionary final { + dictionary data{}; + + bool fetch(TLBuffer &tlb) noexcept { + if (tlb.fetch_trivial().value_or(TL_ZERO) != TL_DICTIONARY) { + return false; + } + return data.fetch(tlb); + } + + void store(TLBuffer &tlb) const noexcept { + tlb.store_trivial(TL_DICTIONARY); + data.store(tlb); + } +}; + +// ===== JOB WORKERS ===== struct K2JobWorkerResponse final { int64_t job_id{}; @@ -28,7 +249,7 @@ struct K2JobWorkerResponse final { // Actually it's "Maybe (Dictionary CertInfoItem)" // But I now want to have this logic separately -struct GetPemCertInfoResponse { +struct GetPemCertInfoResponse final { array data; bool fetch(TLBuffer &tlb) noexcept; @@ -47,4 +268,16 @@ enum DigestAlgorithm : uint32_t { MD2 = 0x5aca'6998, }; +// ===== CONFDATA ===== + +struct ConfdataValue final { + string value; + bool is_php_serialized{}; + bool is_json_serialized{}; + + bool fetch(TLBuffer &tlb) noexcept; + + void store(TLBuffer &tlb) const noexcept; +}; + } // namespace tl From a1d4ad2eea03ae29fb25c1b34d71361db849bd7c Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Thu, 26 Sep 2024 13:03:26 +0300 Subject: [PATCH 5/6] Split tl_serializable concept to: tl_serializable and tl_deserializable --- runtime-light/tl/tl-core.h | 4 ++++ runtime-light/tl/tl-types.h | 36 ++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/runtime-light/tl/tl-core.h b/runtime-light/tl/tl-core.h index 4064191020..660b6e0748 100644 --- a/runtime-light/tl/tl-core.h +++ b/runtime-light/tl/tl-core.h @@ -101,6 +101,10 @@ class TLBuffer final : private vk::not_copyable { template concept tl_serializable = std::default_initializable && requires(T t, TLBuffer tlb) { { t.store(tlb) } noexcept -> std::same_as; +}; + +template +concept tl_deserializable = std::default_initializable && requires(T t, TLBuffer tlb) { { t.fetch(tlb) } noexcept -> std::convertible_to; }; diff --git a/runtime-light/tl/tl-types.h b/runtime-light/tl/tl-types.h index 827ab3cce4..186ce7c39d 100644 --- a/runtime-light/tl/tl-types.h +++ b/runtime-light/tl/tl-types.h @@ -34,11 +34,11 @@ struct Bool final { } }; -template +template struct Maybe final { std::optional opt_value{}; - bool fetch(TLBuffer &tlb) noexcept { + bool fetch(TLBuffer &tlb) noexcept requires tl_deserializable { const auto magic{tlb.fetch_trivial().value_or(TL_ZERO)}; if (magic == TL_MAYBE_TRUE) { opt_value.emplace(); @@ -50,7 +50,7 @@ struct Maybe final { return false; } - void store(TLBuffer &tlb) const noexcept { + void store(TLBuffer &tlb) const noexcept requires tl_serializable { if (opt_value.has_value()) { tlb.store_trivial(TL_MAYBE_TRUE); (*opt_value).store(tlb); @@ -60,7 +60,7 @@ struct Maybe final { } }; -template +template struct vector final { using vector_t = memory_resource::stl::vector; vector_t data{typename vector_t::allocator_type(RuntimeAllocator::current().memory_resource)}; @@ -91,7 +91,7 @@ struct vector final { return data.size(); } - bool fetch(TLBuffer &tlb) noexcept { + bool fetch(TLBuffer &tlb) noexcept requires tl_deserializable { int64_t size{}; if (const auto opt_size{tlb.fetch_trivial()}; opt_size.has_value()) { size = *opt_size; @@ -112,13 +112,13 @@ struct vector final { return true; } - void store(TLBuffer &tlb) const noexcept { + void store(TLBuffer &tlb) const noexcept requires tl_serializable { tlb.store_trivial(static_cast(data.size())); std::for_each(data.cbegin(), data.cend(), [&tlb](auto &&elem) { std::forward(elem).store(tlb); }); } }; -template +template struct Vector final { vector data{}; @@ -148,37 +148,37 @@ struct Vector final { return data.size(); } - bool fetch(TLBuffer &tlb) noexcept { + bool fetch(TLBuffer &tlb) noexcept requires tl_deserializable { if (tlb.fetch_trivial().value_or(TL_ZERO) != TL_VECTOR) { return false; } return data.fetch(tlb); } - void store(TLBuffer &tlb) const noexcept { + void store(TLBuffer &tlb) const noexcept requires tl_serializable { tlb.store_trivial(TL_VECTOR); data.store(tlb); } }; -template +template struct dictionaryField final { string key; T value{}; - bool fetch(TLBuffer &tlb) noexcept { + bool fetch(TLBuffer &tlb) noexcept requires tl_deserializable { const auto key_view{tlb.fetch_string()}; key = {key_view.data(), static_cast(key_view.size())}; return !value.fetch(tlb); } - void store(TLBuffer &tlb) const noexcept { + void store(TLBuffer &tlb) const noexcept requires tl_serializable { tlb.store_string({key.c_str(), static_cast(key.size())}); value.store(tlb); } }; -template +template struct dictionary final { vector> data{}; @@ -208,27 +208,27 @@ struct dictionary final { return data.size(); } - bool fetch(TLBuffer &tlb) noexcept { + bool fetch(TLBuffer &tlb) noexcept requires tl_deserializable { return data.fetch(tlb); } - void store(TLBuffer &tlb) const noexcept { + void store(TLBuffer &tlb) const noexcept requires tl_serializable { data.store(tlb); } }; -template +template struct Dictionary final { dictionary data{}; - bool fetch(TLBuffer &tlb) noexcept { + bool fetch(TLBuffer &tlb) noexcept requires tl_deserializable { if (tlb.fetch_trivial().value_or(TL_ZERO) != TL_DICTIONARY) { return false; } return data.fetch(tlb); } - void store(TLBuffer &tlb) const noexcept { + void store(TLBuffer &tlb) const noexcept requires tl_serializable { tlb.store_trivial(TL_DICTIONARY); data.store(tlb); } From 8c0f9367c4c2fab964db34d23d6062f581af6d69 Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Thu, 26 Sep 2024 13:03:48 +0300 Subject: [PATCH 6/6] Remove ConfdataValue::store as it seems we don't event need it --- runtime-light/tl/tl-types.cpp | 7 ------- runtime-light/tl/tl-types.h | 2 -- 2 files changed, 9 deletions(-) diff --git a/runtime-light/tl/tl-types.cpp b/runtime-light/tl/tl-types.cpp index 971bc9aaa0..90427ed0db 100644 --- a/runtime-light/tl/tl-types.cpp +++ b/runtime-light/tl/tl-types.cpp @@ -149,11 +149,4 @@ bool ConfdataValue::fetch(TLBuffer &tlb) noexcept { return true; } -void ConfdataValue::store(TLBuffer &tlb) const noexcept { - tlb.store_trivial(CONFDATA_VALUE_MAGIC); - tlb.store_string({value.c_str(), static_cast(value.size())}); - Bool{.value = is_php_serialized}.store(tlb); - Bool{.value = is_json_serialized}.store(tlb); -} - } // namespace tl diff --git a/runtime-light/tl/tl-types.h b/runtime-light/tl/tl-types.h index 186ce7c39d..4f75d3d0ad 100644 --- a/runtime-light/tl/tl-types.h +++ b/runtime-light/tl/tl-types.h @@ -276,8 +276,6 @@ struct ConfdataValue final { bool is_json_serialized{}; bool fetch(TLBuffer &tlb) noexcept; - - void store(TLBuffer &tlb) const noexcept; }; } // namespace tl