2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/utils/Storer.h"
|
2019-02-12 17:48:52 +01:00
|
|
|
#include "td/utils/StorerBase.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/tl_storers.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
using TLStorer = DefaultStorer<T>;
|
|
|
|
|
|
|
|
template <class T>
|
2021-07-04 04:58:54 +02:00
|
|
|
class TLObjectStorer final : public Storer {
|
2018-12-31 20:04:05 +01:00
|
|
|
mutable size_t size_ = std::numeric_limits<size_t>::max();
|
|
|
|
const T &object_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TLObjectStorer(const T &object) : object_(object) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
size_t size() const final {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (size_ == std::numeric_limits<size_t>::max()) {
|
|
|
|
TlStorerCalcLength storer;
|
2023-09-21 20:31:59 +02:00
|
|
|
storer.store_binary(T::ID);
|
2018-12-31 20:04:05 +01:00
|
|
|
object_.store(storer);
|
|
|
|
size_ = storer.get_length();
|
|
|
|
}
|
|
|
|
return size_;
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
size_t store(uint8 *ptr) const final {
|
2018-06-25 01:58:43 +02:00
|
|
|
TlStorerUnsafe storer(ptr);
|
2023-09-21 20:31:59 +02:00
|
|
|
storer.store_binary(T::ID);
|
2018-12-31 20:04:05 +01:00
|
|
|
object_.store(storer);
|
2018-06-25 01:58:43 +02:00
|
|
|
return static_cast<size_t>(storer.get_buf() - ptr);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace mtproto_api {
|
|
|
|
class Function;
|
|
|
|
} // namespace mtproto_api
|
|
|
|
|
2021-07-05 20:04:23 +02:00
|
|
|
namespace mtproto {
|
|
|
|
|
2023-09-21 20:19:18 +02:00
|
|
|
TLStorer<mtproto_api::Function> create_function_storer(const mtproto_api::Function &function);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-05 20:04:23 +02:00
|
|
|
} // namespace mtproto
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|