18#ifndef TRINITYCORE_PACKET_UTILITIES_H
19#define TRINITYCORE_PACKET_UTILITIES_H
24#include <short_alloc/short_alloc.h>
69 struct ByteSize {
static void Validate(std::string_view value, std::size_t maxSize); };
78 template <std::size_t MaxBytesWithoutNullTerminator,
typename... Validators>
86 operator std::string_view()
const {
return _storage; }
88 operator std::string
const&()
const & {
return _storage; }
89 operator std::string&&() && {
return std::move(
_storage); }
120 return *
this = std::string_view(value);
136 (Validators::Validate(value), ...);
148 [[noreturn]]
void OnInvalidArraySize(std::size_t requestedSize, std::size_t sizeLimit);
150 template <
typename T, std::
size_t N,
bool IsLarge>
153 using allocator_type = short_alloc::short_alloc<T, (N *
sizeof(T) + (
alignof(std::max_align_t) - 1)) & ~(
alignof(std::max_align_t) - 1)>;
158 template <
typename T, std::
size_t N>
168 template<
typename T, std::
size_t N>
182 using pointer =
typename storage_type::pointer;
193 for (T
const& element : other)
205 for (T
const& element : other)
232 if (newSize > max_capacity::value)
240 if (
_storage.size() >= max_capacity::value)
248 if (
_storage.size() >= max_capacity::value)
251 _storage.push_back(std::forward<value_type>(value));
254 template<
typename... Args>
257 _storage.emplace_back(std::forward<Args>(args)...);
276 template<
typename Underlying =
int64>
292 _value = std::chrono::system_clock::to_time_t(systemTime);
296 operator time_t()
const
303 return static_cast<Underlying
>(
_value);
308 data << static_cast<Underlying>(timestamp.
_value);
314 timestamp.
_value =
static_cast<time_t
>(data.
read<Underlying>());
322 template<
typename ChronoDuration,
typename Underlying =
int64>
335 operator ChronoDuration()
const
342 data << static_cast<Underlying>(duration.
_value.count());
348 duration.
_value = ChronoDuration(data.
read<Underlying>());
353 ChronoDuration
_value = ChronoDuration::zero();
std::chrono::system_clock::time_point SystemTimePoint
std::string_view ReadCString(bool requireValidUtf8=true)
typename allocator_traits::allocator_type allocator_type
typename storage_type::iterator iterator
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
typename allocator_traits::resource_type allocator_resource_type
Array & operator=(Array const &other)
typename storage_type::value_type value_type
const_reference operator[](size_type i) const
allocator_resource_type _allocatorResource
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
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)
static char const * GetReasonText(Reason reason)
std::string const & GetInvalidValue() const
char const * c_str() const
void resize(std::size_t size)
String & operator=(std::string const &value)
String & operator=(std::string_view value)
std::size_t length() const
static void Validate(std::string_view value)
String & operator=(std::string &&value)
friend ByteBuffer & operator>>(ByteBuffer &data, String &value)
String & operator=(char const *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)
constexpr bool has_type_in_list_v
void OnInvalidArraySize(std::size_t requestedSize, std::size_t sizeLimit)
std::allocator< T > allocator_type
std::allocator< T > resource_type
typename allocator_type::arena_type resource_type
short_alloc::short_alloc< T,(N *sizeof(T)+(alignof(std::max_align_t) - 1)) &~(alignof(std::max_align_t) - 1)> allocator_type
static void Validate(std::string_view value, std::size_t maxSize)
static void Validate(std::string_view value)
static void Validate(std::string_view value)
static void Validate(std::string_view)
static void Validate(std::string_view value)