17 #include "ylt/struct_pack/struct_pack_impl.hpp"
19 namespace struct_pack {
107 template <
typename T>
259 template <
typename T, u
int64_t version>
264 constexpr
compatible(std::optional<T> &&other)
265 : std::optional<T>(std::move(other)){};
266 constexpr
compatible(
const std::optional<T> &other)
267 : std::optional<T>(other){};
270 using std::optional<T>::optional;
273 static constexpr uint64_t version_number = version;
296 template <
typename CharType, std::
size_t Size>
314 constexpr std::size_t
size()
const;
342 constexpr
const CharType *
data()
const;
352 template <std::
size_t Size2>
363 template <std::
size_t Size2>
373 template <
size_t Size2>
378 CharType ar[Size + 1];
412 bool operator==(const
err_code &o) const noexcept {
return ec == o.ec; }
427 operator bool() const noexcept {
return ec != errc::ok; }
460 invalid_width_of_container_length,
475 DISABLE_TYPE_INFO = 0b1,
476 ENABLE_TYPE_INFO = 0b10,
477 DISABLE_ALL_META_INFO = 0b11,
479 ENCODING_WITH_VARINT = 0b100,
480 USE_FAST_VARINT = 0b1000
506 template <
typename T>
553 template <
typename... Args>
571 template <
typename... Args>
595 template <typename... Args>
597 const Args &...args);
628 template <uint64_t conf =
sp_config::DEFAULT, typename Writer, typename... Args>
650 template <uint64_t conf =
sp_config::DEFAULT, typename... Args>
651 void serialize_to(
char *buffer, serialize_buffer_size len, const Args &...args);
669 template <uint64_t conf =
sp_config::DEFAULT, detail::struct_pack_buffer Buffer,
672 const Args &...args);
693 template <detail::struct_pack_buffer Buffer = std::vector<
char>,
711 detail::struct_pack_buffer Buffer = std::vector<
char> typename... Args>
713 const Args &...args);
728 template <uint64_t conf, detail::struct_pack_buffer Buffer = std::vector<
char>,
747 template <uint64_t conf, detail::struct_pack_buffer Buffer = std::vector<
char>,
750 const Args &...args);
779 template <uint64_t conf =
sp_config::DEFAULT, typename T, typename... Args,
780 struct_pack::detail::deserialize_view View>
810 template <uint64_t conf =
sp_config::DEFAULT, typename T, typename... Args>
812 size_t size, Args &...args);
830 template <uint64_t conf =
sp_config::DEFAULT, typename T, typename... Args,
831 struct_pack::reader_t Reader>
853 template <uint64_t conf =
sp_config::DEFAULT, typename T, typename... Args,
854 struct_pack::detail::deserialize_view View>
878 template <uint64_t conf =
sp_config::DEFAULT, typename T, typename... Args>
880 T &t, const
char *data,
size_t size,
size_t &offset, Args &...args);
903 template <typename... Args, struct_pack::detail::deserialize_view View>
928 template <typename... Args>
953 template <typename... Args, struct_pack::reader_t Reader>
971 template <typename... Args, struct_pack::detail::deserialize_view View>
972 [[nodiscard]] auto
deserialize(const View &v,
size_t &consume_len);
989 template <typename... Args>
991 size_t &consume_len);
1015 template <uint64_t conf, typename... Args,
1016 struct_pack::detail::deserialize_view View>
1042 template <uint64_t conf, typename... Args>
1068 template <uint64_t conf, typename... Args, struct_pack::reader_t Reader>
1088 template <uint64_t conf, typename... Args,
1089 struct_pack::detail::deserialize_view View>
1109 template <uint64_t conf, typename... Args>
1111 size_t &consume_len);
1127 template <typename... Args, struct_pack::detail::deserialize_view View>
1160 template <typename... Args>
1192 template <typename T,
size_t I, uint64_t conf =
sp_config::DEFAULT,
1193 typename Field, struct_pack::detail::deserialize_view View>
1221 template <typename T,
size_t I, uint64_t conf =
sp_config::DEFAULT,
1242 template <typename T,
size_t I, uint64_t conf =
sp_config::DEFAULT,
1243 typename Field, struct_pack::reader_t Reader>
1268 template <typename T,
size_t I, uint64_t conf =
sp_config::DEFAULT,
1269 struct_pack::detail::deserialize_view View>
1294 template <typename T,
size_t I, uint64_t conf =
sp_config::DEFAULT>
1295 [[nodiscard]] auto
get_field(const
char *data,
size_t size);
1309 template <typename T,
size_t I, uint64_t conf =
sp_config::DEFAULT,
1310 struct_pack::reader_t Reader>
1342 template <typename BaseClass, typename... DerivedClasses,
1343 struct_pack::detail::deserialize_view View>
1344 [[nodiscard]] struct_pack::
expected<std::unique_ptr<BaseClass>,
1378 template <typename BaseClass, typename... DerivedClasses>
1379 [[nodiscard]] struct_pack::
expected<std::unique_ptr<BaseClass>,
1395 template <typename BaseClass, typename... DerivedClasses,
1396 struct_pack::reader_t Reader>
1397 [[nodiscard]] struct_pack::
expected<std::unique_ptr<BaseClass>,
struct_pack::err_code deserialize_to(T &t, Reader &reader, Args &...args)
将输入流中的数据反序列化到目的对象
auto deserialize_with_offset(const char *data, size_t size, size_t &offset)
从内存中反序列化目的对象并保存到返回值,反序列化时跳过开头的若干字节
auto deserialize(const char *data, size_t size, size_t &consume_len)
按给定配置反序列化内存中的数据,并按值返回,并在参数中返回消耗的数据长度。
std::error_code make_error_code(struct_pack::errc err)
构造std::error_code
constexpr struct_pack::serialize_buffer_size get_needed_size(const Args &...args)
获取序列化长度
struct_pack::expected< std::unique_ptr< BaseClass >, struct_pack::err_code > deserialize_derived_class(Reader &reader)
从输入流中反序列化派生类到基类的指针
void serialize_to(char *buffer, serialize_buffer_size len, const Args &...args)
将对象序列化到给定的内存地址
constexpr std::uint32_t get_type_code()
获取类型校验码
struct_pack::err_code get_field_to(Field &dst, Reader &reader)
从输入流中反序列化一个字段并保存到目的对象
Buffer serialize_with_offset(std::size_t offset, const Args &...args)
按给定配置将序列化结果保存到容器并返回,同时在序列化结果的头部预留一段字节。
auto get_field(Reader &reader)
从输入流中反序列化一个字段并返回
constexpr decltype(auto) get_type_literal()
struct_pack::err_code deserialize_to_with_offset(T &t, const char *data, size_t size, size_t &offset, Args &...args)
将内存中的数据反序列化到目的对象,反序列化时跳过开头的若干字节
Buffer serialize(const Args &...args)
按给定配置序列化对象并返回结果
void serialize_to_with_offset(Buffer &buffer, std::size_t offset, const Args &...args)
将序列化结果保存到给定缓冲区尾部,并在序列化结果的头部预留一段字节。
std::string error_message(struct_pack::errc err)
获取错误消息
constexpr std::size_t members_count
手动标注结构体成员个数
Definition: struct_pack_doc.hpp:507
errc
struct_pack的错误值枚举
Definition: struct_pack_doc.hpp:455
sp_config
struct_pack的配置
Definition: struct_pack_doc.hpp:472
兼容字段类型
Definition: struct_pack_doc.hpp:260
struct_pack的错误码,存储了一个枚举值struct_pack::errc,可用于判断序列化是否成功。
Definition: struct_pack_doc.hpp:388
std::string_view message() const noexcept
返回错误码对应的错误消息
int val() const noexcept
将错误码转换为整数
bool operator!=(const err_code &o)
比较错误码是否不同
err_code() noexcept
err_code的默认构造函数,默认情况下无错误
编译期字符串类型
Definition: struct_pack_doc.hpp:297
constexpr CharType & operator[](std::size_t sz)
获取下标对应的字符
constexpr const CharType * data() const
返回一个C-style(以'\0'结尾)的字符串指针
constexpr const char & operator[](std::size_t sz) const
获取下标对应的字符
constexpr std::size_t size() const
返回字符串的长度
constexpr string_literal< CharType, Size+Size2 > operator+(string_literal< CharType, Size2 > other) const
拼接两个字符串
constexpr bool operator==(const string_literal< CharType, Size2 > &other) const
判断两个字符串是否相等
constexpr bool operator!=(const string_literal< CharType, Size2 > &other) const
判断两个字符串是否不相等
constexpr bool empty() const
判断字符串是否为空字符串
constexpr string_literal(std::basic_string_view< CharType > str)
从string_view构造string_literal类型
constexpr string_literal(const CharType(&value)[Size+1])
从数组构造string_literal类型
trivial_view<T> 是一个平凡结构体的视图,在类型系统上等价于T。
Definition: struct_pack_doc.hpp:108
trivial_view(const T &t)
构造一个指向对象t的trivial_view
void set(const T &obj)
设置trivial_view指向的对象
trivial_view(const T *t)
构造一个指向对象t的trivial_view
const T & get() const
返回trivial_view指向的对象T的常引用
const T * operator->() const
允许trivial_view通过运算符->访问指向对象T
trivial_view()
构造一个指向空对象的trivial_view
Definition: struct_pack_doc.hpp:130
T value_type
trivial_view指向的对象的类型,value_type必须是一个平凡的结构体
Definition: struct_pack_doc.hpp:137