116 "Specialize StormByte::Detail::Codec<T> instead of Serializable<T>");
128 "Specialize StormByte::Detail::Codec<T> instead of Serializable<T>");
140 "Specialize StormByte::Detail::Codec<T> instead of Serializable<T>");
339 if (index >= utf8.size())
342 const auto lead =
static_cast<unsigned char>(utf8[index++]);
347 }
else if ((lead & 0xE0u) == 0xC0u) {
350 }
else if ((lead & 0xF0u) == 0xE0u) {
353 }
else if ((lead & 0xF8u) == 0xF0u) {
361 for (
int n = 0; n < extra; ++n) {
362 if (index >= utf8.size()) {
366 const auto cont =
static_cast<unsigned char>(utf8[index]);
367 if ((cont & 0xC0u) != 0x80u) {
372 cp = (cp << 6) | (cont & 0x3Fu);
375 if (cp > 0x10FFFFu || (cp >= 0xD800u && cp <= 0xDFFFu))
384 return std::string(
static_cast<std::string_view
>(payload.value()));
391 return std::wstring(
static_cast<std::wstring_view
>(payload.value()));
398 const std::string_view utf8 = payload.value();
400 std::size_t index = 0;
404 out.push_back(
static_cast<char16_t>(cp));
407 out.push_back(
static_cast<char16_t>(0xD800u + (cp >> 10)));
408 out.push_back(
static_cast<char16_t>(0xDC00u + (cp & 0x3FFu)));
418 const std::string_view utf8 = payload.value();
420 std::size_t index = 0;
452 using DecayedT = std::remove_cvref_t<T>;
455 "Safe::SecureBinary is not serializable: the blob would hold the secret in memory that is never wiped");
517 const DecayedT& m_data;
531 template<typename U = T>
532 Safe::Binary SerializeTrivial() const noexcept
533 requires
Type::TriviallyCopyable<U>;
540 template<typename U = T>
541 Safe::Binary SerializeContainer() const noexcept
542 requires
Type::Container<U>;
549 template<typename U = T>
550 Safe::Binary SerializePair() const noexcept
551 requires
Type::Pair<U>;
561 template<typename U = T>
562 Safe::Binary SerializeOptional() const noexcept
563 requires
Type::Optional<U>;
570 template<typename U = T>
571 Safe::Binary SerializeQueue() const noexcept
572 requires
Type::Queue<U>;
580 template<typename U = T>
581 static
ByteSize SizeContainer(const DecayedT& data) noexcept
582 requires
Type::Container<U>;
590 template<typename U = T>
591 static
ByteSize SizePair(const DecayedT& data) noexcept
592 requires
Type::Pair<U>;
600 template<typename U = T>
601 static
ByteSize SizeOptional(const DecayedT& data) noexcept
602 requires
Type::Optional<U>;
610 template<typename U = T>
611 static
ByteSize SizeQueue(const DecayedT& data) noexcept
612 requires
Type::Queue<U>;
624 template<typename U = T>
626 requires
Type::TriviallyCopyable<U>;
634 template<typename U = T>
636 requires
Type::Container<U>;
644 template<typename U = T>
646 requires
Type::Pair<U>;
654 template<typename U = T>
656 requires
Type::Optional<U>;
664 template<typename U = T>
666 requires
Type::Queue<U>;
705#include <StormByte/serializable.txx>
IEC octet length (uint64_t), implicit only to std::size_t.
Count of octets (uint64_t storage).
Definition byte_size.hxx:105
Deserialization failed.
Definition exception.hxx:172
Owned contiguous sequence of std::byte, stored in a Vector.
Definition binary.hxx:79
Owned UTF-8 text.
Definition string.hxx:113
Wide counterpart of String.
Definition wstring.hxx:104
Serializable(const DecayedT &data) noexcept
Binds data for a later StormByte::Serializable::Serialize.
Definition serializable.hxx:462
static ByteSize Size(const DecayedT &data) noexcept
Serialized size of data.
Safe::Binary Serialize() const noexcept
Encodes the bound value to a little-endian blob.
Serializable(const Serializable &other) noexcept=delete
Copy is deleted: the wrapper only holds a reference.
static Expected< T, DeserializeError > Deserialize(std::span< const std::byte > data) noexcept
Decodes one T from the start of data.
Serializable(Serializable &&other) noexcept=delete
Move is deleted: the wrapper only holds a reference.
~Serializable() noexcept=default
Destructor.
Same type after stripping cv and references from both sides.
Definition relations.hxx:139
constexpr bool codec_always_false_v
Compile-time false dependent on T.
Definition serializable.hxx:83
STORMBYTE_FORCE_INLINE bool NextUtf8(std::string_view utf8, std::size_t &index, char32_t &cp) noexcept
One UTF-8 sequence.
Definition serializable.hxx:338
Owned values that cross a DLL without the caller's CRT.
Root namespace of the StormByte suite.
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, Safe::Shared< E > >, std::expected< T, Safe::Shared< E > > > Expected
std::expected alias with reference and shared-error handling.
Definition expected.hxx:62
auto Unexpected(Safe::Shared< E > error)
Forwards an error already stored by Expected.
Definition expected.hxx:75
Octet count. Defined in byte_size.hxx. Forwarded so Type::Numeral can name it.
static Expected< Safe::String, DeserializeError > Read(std::span< const std::byte > data) noexcept
Decodes a StormByte::Safe::String from the start of data.
static Safe::Binary Write(const Safe::String &data) noexcept
Encodes data.
static ByteSize Size(const Safe::String &data) noexcept
Serialized size of data.
static Expected< Safe::WString, DeserializeError > Read(std::span< const std::byte > data) noexcept
Decodes a StormByte::Safe::WString from the start of data.
static Safe::Binary Write(const Safe::WString &data) noexcept
Encodes data.
static ByteSize Size(const Safe::WString &data) noexcept
Serialized size of data.
static Safe::Binary Write(const std::string &data) noexcept
Encodes data.
static ByteSize Size(const std::string &data) noexcept
Serialized size of data.
static Safe::Binary Write(const std::u16string &data) noexcept
Encodes data.
static ByteSize Size(const std::u16string &data) noexcept
Serialized size of data.
static Safe::Binary Write(const std::u32string &data) noexcept
Encodes data.
static ByteSize Size(const std::u32string &data) noexcept
Serialized size of data.
static Safe::Binary Write(const std::wstring &data) noexcept
Encodes data.
static ByteSize Size(const std::wstring &data) noexcept
Serialized size of data.
Size / write / read for one type T.
Definition serializable.hxx:108
static ByteSize Size(const T &data) noexcept
Serialized size of data.
Definition serializable.hxx:114
static Safe::Binary Write(const T &data) noexcept
Encodes data to a little-endian blob.
Definition serializable.hxx:126
static Expected< T, DeserializeError > Read(std::span< const std::byte > data) noexcept
Decodes T from the start of data.
Definition serializable.hxx:138
#define STORMBYTE_PUBLIC
Definition visibility.h:52