diff --git a/tdutils/td/utils/Time.h b/tdutils/td/utils/Time.h index 8d7bf493..acdb8b52 100644 --- a/tdutils/td/utils/Time.h +++ b/tdutils/td/utils/Time.h @@ -91,4 +91,14 @@ class Timestamp { } }; +template +void parse(Timestamp ×tamp, T &parser) { + timestamp = Timestamp::in(parser.fetch_double() - Clocks::system()); +} + +template +void store(const Timestamp ×tamp, T &storer) { + storer.store_binary(timestamp.at() - Time::now() + Clocks::system()); +} + } // namespace td diff --git a/tdutils/td/utils/buffer.h b/tdutils/td/utils/buffer.h index 729cd20f..aa4ef8db 100644 --- a/tdutils/td/utils/buffer.h +++ b/tdutils/td/utils/buffer.h @@ -223,6 +223,16 @@ class BufferSlice { size_t end_ = 0; }; +template +void store(const BufferSlice &buffer_slice, StorerT &storer) { + storer.store_string(buffer_slice); +} + +template +void parse(BufferSlice &buffer_slice, ParserT &parser) { + buffer_slice = parser.template fetch_string(); +} + class BufferWriter { public: BufferWriter() = default; diff --git a/tdutils/td/utils/tl_helpers.h b/tdutils/td/utils/tl_helpers.h index 08d3a53c..686dacbe 100644 --- a/tdutils/td/utils/tl_helpers.h +++ b/tdutils/td/utils/tl_helpers.h @@ -6,14 +6,12 @@ // #pragma once -#include "td/utils/buffer.h" // for BufferSlice #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" #include "td/utils/StackAllocator.h" #include "td/utils/Status.h" -#include "td/utils/Time.h" #include "td/utils/tl_parsers.h" #include "td/utils/tl_storers.h" @@ -112,15 +110,6 @@ void parse(string &x, ParserT &parser) { x = parser.template fetch_string(); } -template -void store(const BufferSlice &x, StorerT &storer) { - storer.store_string(x); -} -template -void parse(BufferSlice &x, ParserT &parser) { - x = parser.template fetch_string(); -} - template void store(const vector &vec, StorerT &storer) { storer.store_binary(narrow_cast(vec.size())); @@ -140,14 +129,6 @@ void parse(vector &vec, ParserT &parser) { parse(val, parser); } } -template -void parse(Timestamp ×tamp, T &parser) { - timestamp = Timestamp::in(static_cast(parser.fetch_long()) / 1000000 - Clocks::system()); -} -template -void store(const Timestamp ×tamp, T &storer) { - storer.store_long(static_cast((timestamp.at() - Time::now() + Clocks::system()) * 1000000)); -} template void store(const std::unordered_set &s, StorerT &storer) {