13 std::string RestoreFormatString(std::string_view pattern,
const std::vector<uint8_t>& buffer,
size_t& offset,
size_t size);
15 size_t ParseArgument(fmt::dynamic_format_arg_store<fmt::format_context>& store,
const std::vector<uint8_t>& buffer,
size_t& index)
19 std::memcpy(&type, buffer.data() + index,
sizeof(uint8_t));
20 index +=
sizeof(uint8_t);
27 std::memcpy(&length, buffer.data() + index,
sizeof(uint32_t));
28 index +=
sizeof(uint32_t);
31 std::memcpy(name.data(), buffer.data() + index, length);
35 std::memcpy(&type, buffer.data() + index,
sizeof(uint8_t));
36 index +=
sizeof(uint8_t);
45 std::memcpy(&value, buffer.data() + index,
sizeof(uint8_t));
46 index +=
sizeof(uint8_t);
48 name.empty() ? store.push_back(value != 0) : store.push_back(fmt::detail::named_arg(name.c_str(), value != 0));
54 std::memcpy(&value, buffer.data() + index,
sizeof(uint8_t));
55 index +=
sizeof(uint8_t);
57 name.empty() ? store.push_back((
char)value) : store.push_back(fmt::detail::named_arg(name.c_str(), (
char)value));
63 std::memcpy(&value, buffer.data() + index,
sizeof(uint32_t));
64 index +=
sizeof(uint32_t);
66 name.empty() ? store.push_back((
char)value) : store.push_back(fmt::detail::named_arg(name.c_str(), (
char)value));
72 std::memcpy(&value, buffer.data() + index,
sizeof(int8_t));
73 index +=
sizeof(int8_t);
75 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
81 std::memcpy(&value, buffer.data() + index,
sizeof(uint8_t));
82 index +=
sizeof(uint8_t);
84 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
90 std::memcpy(&value, buffer.data() + index,
sizeof(int16_t));
91 index +=
sizeof(int16_t);
93 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
99 std::memcpy(&value, buffer.data() + index,
sizeof(uint16_t));
100 index +=
sizeof(uint16_t);
102 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
108 std::memcpy(&value, buffer.data() + index,
sizeof(int32_t));
109 index +=
sizeof(int32_t);
111 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
117 std::memcpy(&value, buffer.data() + index,
sizeof(uint32_t));
118 index +=
sizeof(uint32_t);
120 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
126 std::memcpy(&value, buffer.data() + index,
sizeof(int64_t));
127 index +=
sizeof(int64_t);
129 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
135 std::memcpy(&value, buffer.data() + index,
sizeof(uint64_t));
136 index +=
sizeof(uint64_t);
138 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
144 std::memcpy(&value, buffer.data() + index,
sizeof(
float));
145 index +=
sizeof(float);
147 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
153 std::memcpy(&value, buffer.data() + index,
sizeof(
double));
154 index +=
sizeof(double);
156 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
162 std::memcpy(&length, buffer.data() + index,
sizeof(uint32_t));
163 index +=
sizeof(uint32_t);
165 const fmt::string_view value((
const char*)buffer.data() + index, length);
168 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
174 std::memcpy(&value, buffer.data() + index,
sizeof(uint64_t));
175 index +=
sizeof(uint64_t);
177 name.empty() ? store.push_back(value) : store.push_back(fmt::detail::named_arg(name.c_str(), value));
183 uint32_t custom_size;
184 std::memcpy(&custom_size, buffer.data() + index,
sizeof(uint32_t));
185 index +=
sizeof(uint32_t);
186 custom_size -=
sizeof(uint32_t);
189 uint32_t custom_pattern_length;
190 std::memcpy(&custom_pattern_length, buffer.data() + index,
sizeof(uint32_t));
191 index +=
sizeof(uint32_t);
192 custom_size -=
sizeof(uint32_t);
195 std::string custom_pattern;
196 custom_pattern.resize(custom_pattern_length);
197 std::memcpy(custom_pattern.data(), buffer.data() + index, custom_pattern_length);
198 index += custom_pattern_length;
199 custom_size -= custom_pattern_length;
201 const std::string custom = RestoreFormatString(custom_pattern, buffer, index, custom_size);
203 name.empty() ? store.push_back(custom) : store.push_back(fmt::detail::named_arg(name.c_str(), custom));
210 std::memcpy(&list_size, buffer.data() + index,
sizeof(uint32_t));
211 index +=
sizeof(uint32_t);
212 list_size -=
sizeof(uint32_t);
214 fmt::dynamic_format_arg_store<fmt::format_context> list_store;
217 size_t list_items = 0;
218 size_t list_offset = index;
219 while (index < (list_offset + list_size))
221 if (ParseArgument(list_store, buffer, index))
228 std::string list_pattern;
229 list_pattern.reserve(2 * list_items);
230 for (
size_t i = 0; i < list_items; ++i)
231 list_pattern.append(
"{}");
234 const std::string list_string = fmt::vformat(list_pattern, list_store);
236 name.empty() ? store.push_back(list_string) : store.push_back(fmt::detail::named_arg(name.c_str(), list_string));
241 assert(
false &&
"Unsupported argument type!");
249 std::string RestoreFormatString(std::string_view pattern,
const std::vector<uint8_t>& buffer,
size_t& offset,
size_t size)
251 fmt::dynamic_format_arg_store<fmt::format_context> store;
254 size_t index = offset;
255 while (index < (offset + size))
256 if (!ParseArgument(store, buffer, index))
261 std::string result = fmt::vformat(pattern, store);
270 std::string
Record::RestoreFormat(std::string_view pattern,
const std::vector<uint8_t>& buffer,
size_t offset,
size_t size)
272 size_t index = offset;
273 return RestoreFormatString(pattern,
buffer, index, size);
std::string RestoreFormat() const
Restore format message and its arguments.
std::vector< uint8_t > buffer
Buffer of the logging record.
C++ Logging project definitions.
Logging record definition.