6 #include <aws/common/common.h>
11 #include <aws/io/socket.h>
12 #include <aws/mqtt/mqtt.h>
18 #include <unordered_map>
23 struct aws_byte_cursor;
24 struct aws_socket_options;
35 using IStream = std::basic_istream<char, std::char_traits<char>>;
40 using QOS = aws_mqtt_qos;
46 using StringStream = std::basic_stringstream<char, std::char_traits<char>, StlAllocator<char>>;
48 template <
typename K,
typename V>
50 std::unordered_map<K, V, std::hash<K>, std::equal_to<K>, StlAllocator<std::pair<const K, V>>>;
51 template <
typename K,
typename V>
52 using MultiMap = std::multimap<K, V, std::less<K>, StlAllocator<std::pair<const K, V>>>;
53 template <
typename T>
using Vector = std::vector<T, StlAllocator<T>>;
54 template <
typename T>
using List = std::list<T, StlAllocator<T>>;
72 template <typename RawType, typename TargetType> using
TypeConvertor =
std::function<TargetType(RawType)>;
78 template <typename RawType, typename TargetType>
82 size_t cnt = aws_array_list_length(array);
83 for (
size_t i = 0; i < cnt; i++)
86 aws_array_list_get_at(array, &t, i);
87 v.emplace_back(conv(t));
96 template <
typename RawType,
typename TargetType>
100 size_t cnt = aws_array_list_length(array);
101 for (
size_t i = 0; i < cnt; i++)
104 aws_array_list_get_at(array, &t, i);
105 v.emplace_back(TargetType(t));
116 size_t cnt = aws_array_list_length(array);
117 for (
size_t i = 0; i < cnt; i++)
120 aws_array_list_get_at(array, &t, i);
128 return StringView(reinterpret_cast<char *>(bc.ptr), bc.len);
134 bc.ptr = (uint8_t *)(sv.
data());
142 aws_mem_release(allocator, t);
145 template <
typename T,
typename... Args> T *
New(
Allocator *allocator, Args &&...args)
147 T *t =
reinterpret_cast<T *
>(aws_mem_acquire(allocator,
sizeof(T)));
150 return new (t) T(std::forward<Args>(args)...);
153 template <
typename T,
typename... Args> std::shared_ptr<T>
MakeShared(
Allocator *allocator, Args &&...args)
155 T *t =
reinterpret_cast<T *
>(aws_mem_acquire(allocator,
sizeof(T)));
158 new (t) T(std::forward<Args>(args)...);
160 return std::shared_ptr<T>(t, [allocator](T *obj) {
Delete(obj, allocator); });
163 template <
typename T>
using ScopedResource = std::unique_ptr<T, std::function<void(T *)>>;
AWS_CRT_CPP_API ByteBuf ByteBufFromArray(const uint8_t *array, size_t capacity) noexcept
Definition: Types.cpp:23
Vector< TargetType > ArrayListToVector(const aws_array_list *array, TypeConvertor< RawType, TargetType > conv)
Definition: Types.h:79
std::multimap< K, V, std::less< K >, StlAllocator< std::pair< const K, V >>> MultiMap
Definition: Types.h:52
AWS_CRT_CPP_API ByteBuf ByteBufNewCopy(Allocator *alloc, const uint8_t *array, size_t len)
Definition: Types.cpp:28
T * New(Allocator *allocator, Args &&...args)
Definition: Types.h:145
std::shared_ptr< T > MakeShared(Allocator *allocator, Args &&...args)
Definition: Types.h:153
#define AWS_CRT_CPP_API
Definition: Exports.h:36
AWS_CRT_CPP_API ByteBuf ByteBufInit(Allocator *alloc, size_t len)
Definition: Types.cpp:36
AWS_CRT_CPP_API ByteBuf ByteBufFromEmptyArray(const uint8_t *array, size_t len) noexcept
Definition: Types.cpp:18
Definition: StringView.h:861
constexpr const_pointer data() const noexcept
Definition: StringView.h:127
string_view StringView
Definition: StringView.h:856
aws_byte_buf ByteBuf
Definition: Types.h:30
aws_mqtt_connect_return_code ReturnCode
Definition: Types.h:41
AWS_CRT_CPP_API void ByteBufDelete(ByteBuf &)
Definition: Types.cpp:43
std::basic_string< char, std::char_traits< char >, StlAllocator< char >> String
Definition: Types.h:45
std::basic_istream< char, std::char_traits< char >> IStream
Definition: Types.h:35
aws_allocator Allocator
Definition: Allocator.h:14
AWS_CRT_CPP_API ByteCursor ByteCursorFromString(const Crt::String &str) noexcept
Definition: Types.cpp:53
aws_byte_cursor ByteCursor
Definition: Types.h:31
Definition: StlAllocator.h:20
constexpr size_type size() const noexcept
Definition: StringView.h:93
AWS_CRT_CPP_API ByteCursor ByteCursorFromArray(const uint8_t *array, size_t len) noexcept
Definition: Types.cpp:68
std::basic_stringstream< char, std::char_traits< char >, StlAllocator< char >> StringStream
Definition: Types.h:46
AWS_CRT_CPP_API String Base64Encode(const Vector< uint8_t > &encode) noexcept
Definition: Types.cpp:95
AWS_CRT_CPP_API ByteCursor ByteCursorFromByteBuf(const ByteBuf &) noexcept
Definition: Types.cpp:63
AWS_CRT_CPP_API ByteCursor ByteCursorFromCString(const char *str) noexcept
Definition: Types.cpp:48
AWS_CRT_CPP_API ByteCursor ByteCursorFromStringView(const Crt::StringView &str) noexcept
Definition: Types.cpp:58
std::map< K, V, std::less< K >, StlAllocator< std::pair< const K, V >>> Map
Definition: Types.h:47
AWS_CRT_CPP_API StringView ByteCursorToStringView(const ByteCursor &bc)
Definition: Types.h:126
AWS_CRT_CPP_API Vector< uint8_t > Base64Decode(const String &decode) noexcept
Definition: Types.cpp:73
std::vector< T, StlAllocator< T >> Vector
Definition: Types.h:53
aws_mqtt_qos QOS
Definition: Types.h:40
std::list< T, StlAllocator< T >> List
Definition: Types.h:54
std::unique_ptr< T, std::function< void(T *)>> ScopedResource
Definition: Types.h:163
AWS_CRT_CPP_API ByteCursor StringViewToByteCursor(const StringView &sv)
Definition: Types.h:131
Definition: StringView.h:32
void Delete(T *t, Allocator *allocator)
Definition: Types.h:139
std::unordered_map< K, V, std::hash< K >, std::equal_to< K >, StlAllocator< std::pair< const K, V >>> UnorderedMap
Definition: Types.h:50
Definition: Allocator.h:10
std::function< TargetType(RawType)> TypeConvertor
Definition: Types.h:72
AWS_CRT_CPP_API ByteBuf ByteBufFromCString(const char *str) noexcept
Definition: Types.cpp:13