X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/ce24e1d22d120e6613f3cd1e04d81135f3d048c9..57dbb7df8973a3e0c0c570c1eae9d84802e02bd9:/src/clave_variable.cpp diff --git a/src/clave_variable.cpp b/src/clave_variable.cpp index 47d81ba..48a42a6 100644 --- a/src/clave_variable.cpp +++ b/src/clave_variable.cpp @@ -19,11 +19,12 @@ ClaveVariable::ClaveVariable (uchar *n) str[len] = '\0'; data = std::string ((const char *)(str)); delete [] str; + raw_data = data; } uint ClaveVariable::Size () const { - return data.size ()+sizeof (uint); + return data.size ()*sizeof (uchar)+sizeof (uint); } uchar *ClaveVariable::ToArray () const @@ -32,7 +33,7 @@ uchar *ClaveVariable::ToArray () const uint len = data.size (); out = new uchar[Size ()]; memcpy (out, &len, sizeof (uint)); - memcpy (out+sizeof(uint), data.c_str (), data.size ()); + memcpy (out+sizeof(uint), data.c_str (), data.size ()*sizeof (uchar)); return out; } @@ -82,7 +83,6 @@ bool ClaveVariable::DesAbrev (ClaveVariable *c) if (pos <= 0) return false; std::string siguales = data.substr (0, pos); - std::cout << siguales << std::endl; int iguales = atoi (siguales.c_str ()); std::string primera_parte = c->data.substr (0, iguales); @@ -113,3 +113,14 @@ std::string ClaveVariable::abreviar(std::string &p, std::string &a, int &iguales return std::string (actual); } +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)); + return out; +} +