Skip to content

Commit

Permalink
Move BufferSlice an Timestamp storer/parser to their headers.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 9aa62396ea26c8f3b6758262e94986dbd57ac277
  • Loading branch information
levlam committed Mar 14, 2018
1 parent 6855704 commit 6f33dec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
10 changes: 10 additions & 0 deletions tdutils/td/utils/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ class Timestamp {
}
};

template <class T>
void parse(Timestamp &timestamp, T &parser) {
timestamp = Timestamp::in(parser.fetch_double() - Clocks::system());
}

template <class T>
void store(const Timestamp &timestamp, T &storer) {
storer.store_binary(timestamp.at() - Time::now() + Clocks::system());
}

} // namespace td
10 changes: 10 additions & 0 deletions tdutils/td/utils/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ class BufferSlice {
size_t end_ = 0;
};

template <class StorerT>
void store(const BufferSlice &buffer_slice, StorerT &storer) {
storer.store_string(buffer_slice);
}

template <class ParserT>
void parse(BufferSlice &buffer_slice, ParserT &parser) {
buffer_slice = parser.template fetch_string<BufferSlice>();
}

class BufferWriter {
public:
BufferWriter() = default;
Expand Down
19 changes: 0 additions & 19 deletions tdutils/td/utils/tl_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -112,15 +110,6 @@ void parse(string &x, ParserT &parser) {
x = parser.template fetch_string<string>();
}

template <class StorerT>
void store(const BufferSlice &x, StorerT &storer) {
storer.store_string(x);
}
template <class ParserT>
void parse(BufferSlice &x, ParserT &parser) {
x = parser.template fetch_string<BufferSlice>();
}

template <class T, class StorerT>
void store(const vector<T> &vec, StorerT &storer) {
storer.store_binary(narrow_cast<int32>(vec.size()));
Expand All @@ -140,14 +129,6 @@ void parse(vector<T> &vec, ParserT &parser) {
parse(val, parser);
}
}
template <class T>
void parse(Timestamp &timestamp, T &parser) {
timestamp = Timestamp::in(static_cast<double>(parser.fetch_long()) / 1000000 - Clocks::system());
}
template <class T>
void store(const Timestamp &timestamp, T &storer) {
storer.store_long(static_cast<int64>((timestamp.at() - Time::now() + Clocks::system()) * 1000000));
}

template <class Key, class Hash, class KeyEqual, class Allocator, class StorerT>
void store(const std::unordered_set<Key, Hash, KeyEqual, Allocator> &s, StorerT &storer) {
Expand Down

0 comments on commit 6f33dec

Please sign in to comment.