X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/57dbb7df8973a3e0c0c570c1eae9d84802e02bd9..5f25f8927d0670eabcbcb8ef1e71b7887c63b887:/src/clave_variable.cpp diff --git a/src/clave_variable.cpp b/src/clave_variable.cpp index 48a42a6..e4452b0 100644 --- a/src/clave_variable.cpp +++ b/src/clave_variable.cpp @@ -19,12 +19,15 @@ ClaveVariable::ClaveVariable (uchar *n) str[len] = '\0'; data = std::string ((const char *)(str)); delete [] str; + n += data.size () * sizeof (uchar); + memcpy (&block_data, n, sizeof (uint)); + raw_data = data; } uint ClaveVariable::Size () const { - return data.size ()*sizeof (uchar)+sizeof (uint); + return data.size ()*sizeof (uchar)+sizeof (uint)*2; } uchar *ClaveVariable::ToArray () const @@ -32,8 +35,13 @@ uchar *ClaveVariable::ToArray () const uchar *out; uint len = data.size (); out = new uchar[Size ()]; + int x = 0; memcpy (out, &len, sizeof (uint)); - memcpy (out+sizeof(uint), data.c_str (), data.size ()*sizeof (uchar)); + x += sizeof (uint); + memcpy (out+x, data.c_str (), data.size ()*sizeof (uchar)); + x += data.size () * sizeof (uchar); + memcpy (out+x, &block_data, sizeof (uint)); + return out; } @@ -115,12 +123,24 @@ std::string ClaveVariable::abreviar(std::string &p, std::string &a, int &iguales uchar *ClaveVariable::ToRaw (uint &size) const { - uchar *out; - size = raw_data.size ()*sizeof (uchar)+sizeof (uint); - uint len = raw_data.size (); - out = new uchar[size]; - memcpy (out, &len, sizeof (uint)); - memcpy (out+sizeof(uint), raw_data.c_str (), raw_data.size ()*sizeof (uchar)); + std::stringstream ss; + + ss << "["; + ss << data.size (); + ss << "]"; + ss << "["; + ss << raw_data; + ss << "]"; + ss << "["; + ss << block_data; + ss << "]"; + + std::string s = ss.str (); + + uchar *out = new uchar[s.size ()]; + memcpy (out, s.c_str (), s.size ()); + + size = s.size (); return out; }