2019-06-19 02:18:44 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2019-06-19 02:18:44 +02: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
|
|
|
|
|
2019-07-23 00:50:12 +02:00
|
|
|
#include "td/telegram/PhotoSizeSource.h"
|
2019-06-19 02:18:44 +02:00
|
|
|
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2019-06-19 02:18:44 +02:00
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2019-06-19 02:53:11 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::Legacy &source, StorerT &storer) {
|
2021-04-16 16:43:51 +02:00
|
|
|
UNREACHABLE();
|
2019-06-19 02:53:11 +02:00
|
|
|
store(source.secret, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::Legacy &source, ParserT &parser) {
|
|
|
|
parse(source.secret, parser);
|
|
|
|
}
|
|
|
|
|
2019-06-19 02:18:44 +02:00
|
|
|
template <class StorerT>
|
2019-06-19 02:31:04 +02:00
|
|
|
void store(const PhotoSizeSource::Thumbnail &source, StorerT &storer) {
|
|
|
|
store(source.file_type, storer);
|
|
|
|
store(source.thumbnail_type, storer);
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
2019-06-19 02:31:04 +02:00
|
|
|
void parse(PhotoSizeSource::Thumbnail &source, ParserT &parser) {
|
2019-06-20 03:53:50 +02:00
|
|
|
int32 raw_type;
|
|
|
|
parse(raw_type, parser);
|
|
|
|
if (raw_type < 0 || raw_type >= static_cast<int32>(FileType::Size)) {
|
|
|
|
return parser.set_error("Wrong file type in PhotoSizeSource::Thumbnail");
|
|
|
|
}
|
|
|
|
source.file_type = static_cast<FileType>(raw_type);
|
|
|
|
|
2019-06-19 02:31:04 +02:00
|
|
|
parse(source.thumbnail_type, parser);
|
2021-04-16 16:43:51 +02:00
|
|
|
if (source.thumbnail_type < 0 || source.thumbnail_type > 127) {
|
2019-06-19 02:18:44 +02:00
|
|
|
parser.set_error("Wrong thumbnail type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
2019-06-19 02:31:04 +02:00
|
|
|
void store(const PhotoSizeSource::DialogPhoto &source, StorerT &storer) {
|
|
|
|
store(source.dialog_id, storer);
|
|
|
|
store(source.dialog_access_hash, storer);
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
2019-06-19 02:31:04 +02:00
|
|
|
void parse(PhotoSizeSource::DialogPhoto &source, ParserT &parser) {
|
|
|
|
parse(source.dialog_id, parser);
|
|
|
|
parse(source.dialog_access_hash, parser);
|
2019-06-19 02:18:44 +02:00
|
|
|
|
2019-06-19 02:31:04 +02:00
|
|
|
switch (source.dialog_id.get_type()) {
|
2019-06-19 02:18:44 +02:00
|
|
|
case DialogType::SecretChat:
|
|
|
|
case DialogType::None:
|
2020-05-22 14:59:29 +02:00
|
|
|
return parser.set_error(PSTRING() << "Invalid chat identifier " << source.dialog_id.get());
|
2019-06-19 02:18:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-20 03:35:08 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::DialogPhotoSmall &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::DialogPhoto &>(source), storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::DialogPhotoSmall &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::DialogPhoto &>(source), parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::DialogPhotoBig &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::DialogPhoto &>(source), storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::DialogPhotoBig &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::DialogPhoto &>(source), parser);
|
|
|
|
}
|
|
|
|
|
2021-04-16 16:43:51 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::StickerSetThumbnail &source, StorerT &storer) {
|
|
|
|
store(source.sticker_set_id, storer);
|
|
|
|
store(source.sticker_set_access_hash, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::StickerSetThumbnail &source, ParserT &parser) {
|
|
|
|
parse(source.sticker_set_id, parser);
|
|
|
|
parse(source.sticker_set_access_hash, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::FullLegacy &source, StorerT &storer) {
|
|
|
|
store(source.volume_id, storer);
|
|
|
|
store(source.secret, storer);
|
|
|
|
store(source.local_id, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::FullLegacy &source, ParserT &parser) {
|
|
|
|
parse(source.volume_id, parser);
|
|
|
|
parse(source.secret, parser);
|
|
|
|
parse(source.local_id, parser);
|
2021-08-07 07:46:56 +02:00
|
|
|
// source.local_id can be negative in secret chat thumbnails
|
2021-04-16 16:43:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::DialogPhotoLegacy &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::DialogPhoto &>(source), storer);
|
|
|
|
store(source.volume_id, storer);
|
|
|
|
store(source.local_id, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::DialogPhotoLegacy &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::DialogPhoto &>(source), parser);
|
|
|
|
parse(source.volume_id, parser);
|
|
|
|
parse(source.local_id, parser);
|
|
|
|
if (source.local_id < 0) {
|
|
|
|
parser.set_error("Wrong local_id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::DialogPhotoSmallLegacy &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::DialogPhotoLegacy &>(source), storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::DialogPhotoSmallLegacy &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::DialogPhotoLegacy &>(source), parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::DialogPhotoBigLegacy &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::DialogPhotoLegacy &>(source), storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::DialogPhotoBigLegacy &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::DialogPhotoLegacy &>(source), parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::StickerSetThumbnailLegacy &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::StickerSetThumbnail &>(source), storer);
|
|
|
|
store(source.volume_id, storer);
|
|
|
|
store(source.local_id, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::StickerSetThumbnailLegacy &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::StickerSetThumbnail &>(source), parser);
|
|
|
|
parse(source.volume_id, parser);
|
|
|
|
parse(source.local_id, parser);
|
|
|
|
if (source.local_id < 0) {
|
|
|
|
parser.set_error("Wrong local_id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(const PhotoSizeSource::StickerSetThumbnailVersion &source, StorerT &storer) {
|
|
|
|
store(static_cast<const PhotoSizeSource::StickerSetThumbnail &>(source), storer);
|
|
|
|
store(source.version, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(PhotoSizeSource::StickerSetThumbnailVersion &source, ParserT &parser) {
|
|
|
|
parse(static_cast<PhotoSizeSource::StickerSetThumbnail &>(source), parser);
|
|
|
|
parse(source.version, parser);
|
|
|
|
}
|
|
|
|
|
2019-06-19 02:18:44 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void PhotoSizeSource::store(StorerT &storer) const {
|
2021-10-27 15:52:22 +02:00
|
|
|
td::store(variant_, storer);
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void PhotoSizeSource::parse(ParserT &parser) {
|
2021-10-27 15:52:22 +02:00
|
|
|
td::parse(variant_, parser);
|
2019-06-19 02:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|