tgbotxx  1.1.6.9
Telegram Bot C++ Library
Animation.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 namespace tgbotxx {
8  struct Animation {
9  Animation() = default;
10  explicit Animation(const nl::json& json) {
11  fromJson(json);
12  }
13 
15  std::string fileId;
16 
19  std::string fileUniqueId;
20 
22  std::int32_t width{};
23 
25  std::int32_t height{};
26 
28  std::int32_t duration{};
29 
32 
34  std::string fileName;
35 
37  std::string mimeType;
38 
42  std::int64_t fileSize{};
43 
46  nl::json toJson() const {
47  nl::json json = nl::json::object();
48  OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
49  OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
50  OBJECT_SERIALIZE_FIELD(json, "width", width);
51  OBJECT_SERIALIZE_FIELD(json, "height", height);
52  OBJECT_SERIALIZE_FIELD(json, "duration", duration);
53  OBJECT_SERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail);
54  OBJECT_SERIALIZE_FIELD(json, "file_name", fileName);
55  OBJECT_SERIALIZE_FIELD(json, "mime_type", mimeType);
56  OBJECT_SERIALIZE_FIELD(json, "file_size", fileSize);
57  return json;
58  }
59 
61  void fromJson(const nl::json& json) {
62  OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
63  OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
64  OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, false);
65  OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, false);
66  OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, false);
67  OBJECT_DESERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail, true);
68  OBJECT_DESERIALIZE_FIELD(json, "file_name", fileName, "", true);
69  OBJECT_DESERIALIZE_FIELD(json, "mime_type", mimeType, "", true);
70  OBJECT_DESERIALIZE_FIELD(json, "file_size", fileSize, 0, true);
71  }
72  };
73 }
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition: Object.hpp:22
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition: Object.hpp:70
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition: Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition: Object.hpp:44
Definition: Api.hpp:14
std::shared_ptr< T > Ptr
Definition: Ptr.hpp:6
This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound)....
Definition: Animation.hpp:8
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition: Animation.hpp:19
Animation(const nl::json &json)
Definition: Animation.hpp:10
Ptr< PhotoSize > thumbnail
Optional. Animation thumbnail as defined by sender.
Definition: Animation.hpp:31
std::int64_t fileSize
Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have diff...
Definition: Animation.hpp:42
std::int32_t width
Video width as defined by sender.
Definition: Animation.hpp:22
std::int32_t duration
Duration of the video in seconds as defined by sender.
Definition: Animation.hpp:28
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition: Animation.hpp:15
std::string mimeType
Optional. MIME type of the file as defined by sender.
Definition: Animation.hpp:37
nl::json toJson() const
Serializes this object to JSON.
Definition: Animation.hpp:46
std::int32_t height
Video height as defined by sender.
Definition: Animation.hpp:25
std::string fileName
Optional. Original animation filename as defined by sender.
Definition: Animation.hpp:34
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Animation.hpp:61