tgbotxx  1.1.6.9
Telegram Bot C++ Library
Audio.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 namespace tgbotxx {
8  struct Audio {
9  Audio() = default;
10  explicit Audio(const nl::json& json) {
11  fromJson(json);
12  }
13 
15  std::string fileId;
16 
19  std::string fileUniqueId;
20 
22  std::int32_t duration{};
23 
25  std::string performer;
26 
28  std::string title;
29 
31  std::string fileName;
32 
34  std::string mimeType;
35 
39  std::int64_t fileSize{};
40 
43 
44 
47  nl::json toJson() const {
48  nl::json json = nl::json::object();
49  OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
50  OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
51  OBJECT_SERIALIZE_FIELD(json, "duration", duration);
52  OBJECT_SERIALIZE_FIELD(json, "performer", performer);
53  OBJECT_SERIALIZE_FIELD(json, "title", title);
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  OBJECT_SERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail);
58  return json;
59  }
60 
62  void fromJson(const nl::json& json) {
63  OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
64  OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
65  OBJECT_DESERIALIZE_FIELD(json, "duration", duration, 0, false);
66  OBJECT_DESERIALIZE_FIELD(json, "performer", performer, "", true);
67  OBJECT_DESERIALIZE_FIELD(json, "title", title, "", 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  OBJECT_DESERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail, true);
72  }
73  };
74 }
#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 audio file to be treated as music by the Telegram clients....
Definition: Audio.hpp:8
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition: Audio.hpp:19
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Audio.hpp:62
std::string fileName
Optional. Original filename as defined by sender.
Definition: Audio.hpp:31
Ptr< PhotoSize > thumbnail
Optional. Thumbnail of the album cover to which the music file belongs.
Definition: Audio.hpp:42
std::int64_t fileSize
Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have diff...
Definition: Audio.hpp:39
Audio()=default
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition: Audio.hpp:15
std::int32_t duration
Duration of the audio in seconds as defined by sender.
Definition: Audio.hpp:22
Audio(const nl::json &json)
Definition: Audio.hpp:10
std::string title
Optional. Title of the audio as defined by sender or by audio tags.
Definition: Audio.hpp:28
std::string mimeType
Optional. MIME type of the file as defined by sender.
Definition: Audio.hpp:34
nl::json toJson() const
Serializes this object to JSON.
Definition: Audio.hpp:47
std::string performer
Optional. Performer of the audio as defined by sender or by audio tags.
Definition: Audio.hpp:25