blob: a7a2aa40ba044fa7b6e5e8026b0818cfe2307028 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <span>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
#include "common/common_types.h"
namespace Service::News {
struct NewsStruct {
struct Version {
u64 format{};
u64 semantics{};
};
struct Subject {
u64 caption{};
std::string text;
};
struct Footer {
std::string text;
};
struct Body {
std::string text;
u64 main_image_height{};
std::string movie_url;
std::vector<u8> main_image;
};
struct More {
struct Browser {
std::string url;
std::string text;
bool present{};
} browser;
bool has_browser{};
};
Version version;
u64 news_id{};
u64 published_at{};
u64 pickup_limit{};
u64 priority{};
u64 deletion_priority{};
std::string language;
std::vector<std::string> supported_languages;
std::string display_type;
std::string topic_id;
u64 no_photography{};
u64 surprise{};
u64 bashotorya{};
u64 movie{};
Subject subject;
std::string topic_name;
std::vector<u8> list_image;
Footer footer;
std::string allow_domains;
More more;
Body body;
std::string contents_descriptors;
std::string interactive_elements;
};
class MsgPack {
public:
class Writer {
public:
void WriteFixMap(size_t count);
void WriteMap32(size_t count);
void WriteKey(std::string_view key);
void WriteString(std::string_view value);
void WriteInt64(s64 value);
void WriteUInt(u64 value);
void WriteNil();
void WriteFixArray(size_t count);
void WriteBinary(const std::vector<u8>& data);
void WriteBool(bool value);
std::vector<u8> Take();
const std::vector<u8>& Buffer() const { return out; }
void Clear() { out.clear(); }
private:
void WriteBytes(std::span<const u8> bytes);
std::vector<u8> out;
};
class Reader {
public:
explicit Reader(std::span<const u8> buffer);
template <typename T>
bool Read(T& out) {
if constexpr (std::is_same_v<T, NewsStruct>) {
return ReadNewsStruct(out);
} else {
static_assert(sizeof(T) == 0, "Unsupported MsgPack::Reader::Read type");
}
}
bool SkipValue();
bool SkipAll();
bool ReadMapHeader(size_t& count);
bool ReadArrayHeader(size_t& count);
bool ReadUInt(u64& value);
bool ReadInt(s64& value);
bool ReadBool(bool& value);
bool ReadString(std::string& value);
bool ReadBinary(std::vector<u8>& value);
bool End() const { return offset >= data.size(); }
std::string_view Error() const { return error; }
private:
bool Fail(const char* msg);
bool Ensure(size_t n) const;
u8 Peek() const;
u8 ReadByte();
bool ReadSize(size_t byte_count, size_t& out_size);
bool SkipBytes(size_t n);
bool SkipContainer(size_t count, bool map_mode);
bool ReadNewsStruct(NewsStruct& out);
bool ReadNewsVersion(NewsStruct::Version& out);
bool ReadNewsSubject(NewsStruct::Subject& out);
bool ReadNewsFooter(NewsStruct::Footer& out);
bool ReadNewsBody(NewsStruct::Body& out);
bool ReadNewsMore(NewsStruct::More& out);
bool ReadNewsBrowser(NewsStruct::More::Browser& out);
bool ReadStringArray(std::vector<std::string>& out);
bool ReadBinaryCompat(std::vector<u8>& out);
bool ReadByteArray(std::vector<u8>& out);
std::span<const u8> data;
size_t offset{0};
std::string error;
};
};
} // namespace Service::News
|