| 23 | { |
| 24 | template <typename T> |
| 25 | std::string vectorSerialize(const std::vector<T> & data) |
| 26 | { |
| 27 | // TODO: optimize it to use better encoding |
| 28 | static_assert(std::is_integral_v<T> || std::is_floating_point_v<T> || IsWideInteger<T>); |
| 29 | static_assert(std::is_trivial_v<T>); |
| 30 | // bool not supported due to stupid vector<bool> |
| 31 | static_assert(!std::is_same_v<bool, T>); |
| 32 | const char * ptr = reinterpret_cast<const char *>(data.data()); |
| 33 | auto bytes = sizeof(T) * data.size(); |
| 34 | return std::string(ptr, bytes); |
| 35 | } |
| 36 | |
| 37 | template <typename T> |
| 38 | std::vector<T> vectorDeserialize(std::string_view blob) |