I'm packing my string with this function:
std::vector<char> pack(const std::string& str) { const uint32_t sz = str.size(); const uint32_t n_sz = htonl(sz); std::vector<char> result(sizeof(sz) + sz); memcpy(result.data(), &n_sz, sizeof(n_sz)); memcpy(result.data() + sizeof(sz), str.data(), sz); return result; } How can i unpack it again so...i get the original string back?
I tried to do:
int len; len = ntohl(ourbuffer.size()); char* string = ( char* )malloc(sizeof (char) * (len + 1)); string[len] = '\0'; becouse i know the function pack is using big endian. But that did not work. Can someone please show how to to unpack again??