X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/ce24e1d22d120e6613f3cd1e04d81135f3d048c9..9165bd32b76293816e266e9181cc9b9cbc103fba:/src/clave_variable.cpp diff --git a/src/clave_variable.cpp b/src/clave_variable.cpp index 47d81ba..4479a15 100644 --- a/src/clave_variable.cpp +++ b/src/clave_variable.cpp @@ -3,9 +3,10 @@ #include "clave_variable.h" #include -ClaveVariable::ClaveVariable (const std::string &s) +ClaveVariable::ClaveVariable (const std::string &s, uint bd) { data = s; + block_data = bd; } ClaveVariable::ClaveVariable (uchar *n) @@ -19,11 +20,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 (uint); + return data.size ()*sizeof (uchar)+sizeof (uint)*2; } uchar *ClaveVariable::ToArray () const @@ -31,8 +36,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 ()); + 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; } @@ -82,7 +92,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 +122,26 @@ std::string ClaveVariable::abreviar(std::string &p, std::string &a, int &iguales return std::string (actual); } +uchar *ClaveVariable::ToRaw (uint &size) const +{ + 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; +} +