18#ifndef PacketUtilities_h__
19#define PacketUtilities_h__
24#include <short_alloc/short_alloc.h>
62 template<std::
size_t MaxBytesWithoutNullTerminator>
63 struct ByteSize {
static bool Validate(std::string
const& value) {
return value.size() <= MaxBytesWithoutNullTerminator; } };
72 template<std::size_t MaxBytesWithoutNullTerminator,
typename... Validators>
76 std::tuple<Strings::ByteSize<MaxBytesWithoutNullTerminator>,
Strings::Utf8, Validators...>,
77 std::tuple<Strings::ByteSize<MaxBytesWithoutNullTerminator>, Validators...>>;
84 operator std::string_view()
const {
return _storage; }
86 operator std::string
const&()
const {
return _storage; }
115 return ValidateNth(value, std::make_index_sequence<std::tuple_size_v<ValidatorList>>{});
118 template<std::size_t... indexes>
119 static bool ValidateNth(std::string
const& value, std::index_sequence<indexes...>)
121 return (std::tuple_element_t<indexes, ValidatorList>::Validate(value) && ...);
136 template<
typename T, std::
size_t N>
140 using allocator_type = short_alloc::short_alloc<T, (N *
sizeof(T) + (
alignof(std::max_align_t) - 1)) & ~(
alignof(std::max_align_t) - 1)>;
149 using pointer =
typename storage_type::pointer;
160 for (T
const& element : other)
172 for (T
const& element : other)
197 if (newSize > max_capacity::value)
205 if (
_storage.size() >= max_capacity::value)
213 if (
_storage.size() >= max_capacity::value)
216 _storage.push_back(std::forward<value_type>(value));
219 template<
typename... Args>
222 _storage.emplace_back(std::forward<Args>(args)...);
241 template<
typename Underlying =
int64>
257 _value = std::chrono::system_clock::to_time_t(systemTime);
261 operator time_t()
const
268 return static_cast<Underlying
>(
_value);
273 data << static_cast<Underlying>(timestamp.
_value);
279 timestamp.
_value = data.
read<time_t, Underlying>();
287 template<
typename ChronoDuration,
typename Underlying =
int64>
300 operator ChronoDuration()
const
307 data << static_cast<Underlying>(duration.
_value.count());
313 duration.
_value = ChronoDuration(data.
read<Underlying>());
318 ChronoDuration
_value = ChronoDuration::zero();
std::chrono::system_clock::time_point SystemTimePoint
std::string ReadCString(bool requireValidUtf8=true)
typename storage_type::iterator iterator
short_alloc::short_alloc< T,(N *sizeof(T)+(alignof(std::max_align_t) - 1)) &~(alignof(std::max_align_t) - 1)> allocator_type
const_pointer data() const
iterator erase(const_iterator first, const_iterator last)
T & emplace_back(Args &&... args)
Array & operator=(Array &&other) noexcept=delete
std::vector< T, allocator_type > storage_type
typename storage_type::const_pointer const_pointer
typename storage_type::const_reference const_reference
void push_back(value_type const &value)
const_iterator end() const
typename storage_type::reference reference
typename storage_type::size_type size_type
Array & operator=(Array const &other)
typename storage_type::value_type value_type
const_reference operator[](size_type i) const
void push_back(value_type &&value)
Array(Array &&other) noexcept=delete
typename storage_type::const_iterator const_iterator
typename storage_type::pointer pointer
std::integral_constant< std::size_t, N > max_capacity
typename allocator_type::arena_type arena_type
reference operator[](size_type i)
const_iterator begin() const
void resize(size_type newSize)
Array(Array const &other)
Duration & operator=(ChronoDuration value)
friend ByteBuffer & operator>>(ByteBuffer &data, Duration &duration)
Duration(ChronoDuration value)
friend ByteBuffer & operator<<(ByteBuffer &data, Duration duration)
IllegalHyperlinkException(std::string const &value)
InvalidHyperlinkException(std::string const &value)
InvalidStringValueException(std::string const &value)
std::string const & GetInvalidValue() const
InvalidUtf8ValueException(std::string const &value)
PacketArrayMaxCapacityException(std::size_t requestedSize, std::size_t sizeLimit)
char const * c_str() const
std::conditional_t<!Trinity::has_type< Strings::RawBytes, std::tuple< Validators... > >::value, std::tuple< Strings::ByteSize< MaxBytesWithoutNullTerminator >, Strings::Utf8, Validators... >, std::tuple< Strings::ByteSize< MaxBytesWithoutNullTerminator >, Validators... > > ValidatorList
static bool ValidateNth(std::string const &value, std::index_sequence< indexes... >)
String & operator=(std::string const &value)
std::size_t length() const
static bool Validate(std::string const &value)
String & operator=(std::string &&value)
friend ByteBuffer & operator>>(ByteBuffer &data, String &value)
Underlying AsUnderlyingType() const
Timestamp & operator=(time_t value)
friend ByteBuffer & operator<<(ByteBuffer &data, Timestamp timestamp)
Timestamp & operator=(SystemTimePoint const &systemTime)
friend ByteBuffer & operator>>(ByteBuffer &data, Timestamp ×tamp)
Timestamp(SystemTimePoint const &systemTime)
static bool Validate(std::string const &value)
static bool Validate(std::string const &value)
static bool Validate(std::string const &value)
static bool Validate(std::string const &)
static bool Validate(std::string const &value)