Hi,

I'm having trouble initializing a TMemoryBuffer with contents. I serialized an 
object (a ContactsList object) with TCompactProtocol and then wrote it out as a 
file to disk. Now, I'm trying to read that file and create the same object, but 
it appears that when I call the object's .read() function, it says "No more 
data to read." I suspect that I did not correctly initialize the TMemoryBuffer 
with anything. Here is what I'm doing:

// contacts_bin is a std::string that is read in from disk and is a binary 
string encoded with TCompactProtocol)
// contacts_bin_copy is a copy of contacts_bin except it's a char* instead of a 
std::string.
ContactsList object;
shared_ptr<TMemoryBuffer> transportIn(new TMemoryBuffer((unsigned 
char*)contacts_bin_copy, contacts_bin.size()));
shared_ptr<TCompactProtocol> protocolIn(new TCompactProtocol(transportIn));
object.read(protocolIn.get());

So, I am creating a new TMemoryBuffer by providing a string and the size of 
that string to the constructor. I might not be doing it right, which is why I'm 
getting problems. Might the buffer have nothing in it because I did not change 
the memory policy to COPY? If that's the case, what's the correct code that 
will do it?

Thanks,
Jack

Reply via email to