tgbotxx  1.1.6.9
Telegram Bot C++ Library
Document.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 namespace tgbotxx {
13  struct Document {
14  Document() = default;
15  explicit Document(const nl::json& json) {
16  fromJson(json);
17  }
18 
20  std::string fileId;
21 
24  std::string fileUniqueId;
25 
28 
30  std::string fileName;
31 
33  std::string mimeType;
34 
38  std::int64_t fileSize{};
39 
40 
43  nl::json toJson() const {
44  nl::json json = nl::json::object();
45  OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
46  OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
47  OBJECT_SERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail);
48  OBJECT_SERIALIZE_FIELD(json, "file_name", fileName);
49  OBJECT_SERIALIZE_FIELD(json, "mime_type", mimeType);
50  OBJECT_SERIALIZE_FIELD(json, "file_size", fileSize);
51  return json;
52  }
53 
55  void fromJson(const nl::json& json) {
56  OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
57  OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
58  OBJECT_DESERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail, true);
59  OBJECT_DESERIALIZE_FIELD(json, "file_name", fileName, "", true);
60  OBJECT_DESERIALIZE_FIELD(json, "mime_type", mimeType, "", true);
61  OBJECT_DESERIALIZE_FIELD(json, "file_size", fileSize, 0, true);
62  }
63  };
64 }
#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 a general file (as opposed to photos, voice messages and audio files)....
Definition: Document.hpp:13
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition: Document.hpp:24
Document(const nl::json &json)
Definition: Document.hpp:15
Ptr< PhotoSize > thumbnail
Optional. Document thumbnail as defined by sender.
Definition: Document.hpp:27
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Document.hpp:55
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition: Document.hpp:20
std::string fileName
Optional. Original filename as defined by sender.
Definition: Document.hpp:30
Document()=default
std::string mimeType
Optional. MIME type of the file as defined by sender.
Definition: Document.hpp:33
std::int64_t fileSize
Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have diff...
Definition: Document.hpp:38
nl::json toJson() const
Serializes this object to JSON.
Definition: Document.hpp:43