How to write the content of a TMessage to a file

Hi,

This is certainly a trivial question but I can’t figure out how to write the content of a TMessage into a file. Could someone give me a hint ?

Thanks
Barth

What is the meaning of doing that?
Instead of writing your TObject* to the TMessage, write directly teh TObject* to the file.

Rene

Hi,

The object I am writing to the TMessage is actually not a TObject.

I don’t know if it is correct, but we are writing an object, not inheriting from TObject but with a Dictionary, to a TMessage and then we provide this buffer to TMySQLStatement::SetBinary(…).
I would like to have what we are writing to the database to be written to a file, just for a test. As I already have the TMessage, I thought I could write the content of the buffer to a file.

I didn’t write this code and there might be a better way of doing this.

Cheers,
Barth

Hi, Barth

With TSQLStatement::SetBinary() method you can put arbitrary binary data into the database.

If you stream object into TMessage, you should use TMessage::GetBuffer() and TMessage::BufferSize() to access binary data, produced by the streamer.

It means, somewhere in code you should have:

...
stmt->SetBinary(0, msg.GetBuffer(), msg.BufferSize(), 0x10000);
...

Last argument in SetBinary specifies maximum possible length of your binary buffer. It is important for mysql to correctly treat buffers bigger than 64K.

With TMessage you can use data compression. In this case TMessage::CompBuffer() and TMessage::CompLength() should be used.

Regards,
Sergey

Hi Serguey!

Ok, that confirm what I was doing for the database. I didn’t know about the compression, this is interesting.

However, this doesn’t explain me how to get a string containing the content of the buffer of the TMessage. To make it clear, it is just to make a test, it is not a big issue, but now I am wondering what is the solution. I tried a memcpy but without success.

Thanks for your help Serguey

Barth

Hi, Barth

To access binary data from the message, you should use msg.GetBuffer() and msg.BufferSize() methods. You also can copy binary data into some other memory with memcpy like here:

char buf[10000];
memcpy(buf, msg.GetBuffer(), msg.BufferSize());

Content of buffer is pure binary data - you cannot store it in text file or simply print it on standard output.

If you need conversion of your object into the text representation,
you may look TBufferXML::ConvertToXML method:

http://root.cern.ch/root/html/TBufferXML.html#TBufferXML:ConvertToXML

Regards,
Sergey

Thanks a lot for your help, I will try that.

Cheers,