#include "TMessage.h"
#include "Bytes.h"
#include "TFile.h"
extern "C" void R__zip (Int_t cxlevel, Int_t *nin, char *bufin, Int_t *lout, char *bufout, Int_t *nout);
extern "C" void R__unzip(Int_t *nin, UChar_t *bufin, Int_t *lout, char *bufout, Int_t *nout);
const Int_t kMAXBUF = 0xffffff;
ClassImp(TMessage)
TMessage::TMessage(UInt_t what) : TBuffer(kWrite)
{
UInt_t reserved = 0;
*this << reserved;
fWhat = what;
*this << what;
fClass = 0;
fCompress = 0;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
}
TMessage::TMessage(void *buf, Int_t bufsize) : TBuffer(kRead, bufsize, buf)
{
fBufCur += sizeof(UInt_t);
*this >> fWhat;
fCompress = 0;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
if (fWhat & kMESS_ZIP) {
fBufComp = fBuffer;
fBufCompCur = fBuffer + bufsize;
fBuffer = 0;
Uncompress();
}
if (fWhat == kMESS_OBJECT) {
InitMap();
fClass = ReadClass();
SetBufferOffset(sizeof(UInt_t) + sizeof(fWhat));
ResetMap();
} else {
fClass = 0;
}
}
TMessage::~TMessage()
{
delete [] fBufComp;
}
void TMessage::Forward()
{
if (IsReading()) {
SetWriteMode();
SetBufferOffset(fBufSize);
if (fBufComp) {
fCompPos = fBufCur;
}
}
}
void TMessage::Reset()
{
SetBufferOffset(sizeof(UInt_t) + sizeof(fWhat));
ResetMap();
if (fBufComp) {
delete [] fBufComp;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
}
}
void TMessage::SetLength() const
{
if (IsWriting()) {
char *buf = Buffer();
tobuf(buf, (UInt_t)(Length() - sizeof(UInt_t)));
if (fBufComp) {
buf = fBufComp;
tobuf(buf, (UInt_t)(CompLength() - sizeof(UInt_t)));
}
}
}
void TMessage::SetWhat(UInt_t what)
{
fWhat = what;
char *buf = Buffer();
buf += sizeof(UInt_t);
tobuf(buf, what);
if (fBufComp) {
buf = fBufComp;
buf += sizeof(UInt_t);
tobuf(buf, what | kMESS_ZIP);
}
}
void TMessage::SetCompressionLevel(Int_t level)
{
if (level < 0) level = 0;
if (level > 9) level = 9;
if (level != fCompress && fBufComp) {
delete [] fBufComp;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
}
fCompress = level;
}
Int_t TMessage::Compress()
{
if (fCompress == 0) {
if (fBufComp) {
delete [] fBufComp;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
}
return 0;
}
if (fBufComp && fCompPos == fBufCur) {
return 0;
}
if (fBufComp) {
delete [] fBufComp;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
}
if (Length() <= (Int_t)(256 + 2*sizeof(UInt_t))) {
return 0;
}
Int_t hdrlen = 2*sizeof(UInt_t);
Int_t messlen = Length() - hdrlen;
Int_t nbuffers = messlen / kMAXBUF;
Int_t chdrlen = 3*sizeof(UInt_t);
Int_t buflen = TMath::Max(512, chdrlen + messlen + 9*nbuffers);
fBufComp = new char[buflen];
char *messbuf = Buffer() + hdrlen;
char *bufcur = fBufComp + chdrlen;
Int_t noutot = 0;
Int_t nzip = 0;
Int_t nout, bufmax;
for (Int_t i = 0; i <= nbuffers; i++) {
if (i == nbuffers)
bufmax = messlen - nzip;
else
bufmax = kMAXBUF;
R__zip(fCompress, &bufmax, messbuf, &bufmax, bufcur, &nout);
if (nout == 0 || nout >= messlen) {
delete [] fBufComp;
fBufComp = 0;
fBufCompCur = 0;
fCompPos = 0;
return -1;
}
bufcur += nout;
noutot += nout;
messbuf += kMAXBUF;
nzip += kMAXBUF;
}
fBufCompCur = bufcur;
fCompPos = fBufCur;
bufcur = fBufComp;
tobuf(bufcur, (UInt_t)(CompLength() - sizeof(UInt_t)));
Int_t what = fWhat | kMESS_ZIP;
tobuf(bufcur, what);
tobuf(bufcur, Length());
return 0;
}
Int_t TMessage::Uncompress()
{
if (!fBufComp || !(fWhat & kMESS_ZIP))
return -1;
Int_t buflen;
Int_t hdrlen = 2*sizeof(UInt_t);
UChar_t *bufcur = (UChar_t*)fBufComp + hdrlen;
frombuf((char *&)bufcur, &buflen);
fBuffer = new char[buflen];
fBufSize = buflen;
fBufCur = fBuffer + sizeof(UInt_t) + sizeof(fWhat);
fBufMax = fBuffer + fBufSize;
char *messbuf = fBuffer + hdrlen;
Int_t nin, nout, nbuf;
Int_t noutot = 0;
while (1) {
nin = 9 + ((Int_t)bufcur[3] | ((Int_t)bufcur[4] << 8) | ((Int_t)bufcur[5] << 16));
nbuf = (Int_t)bufcur[6] | ((Int_t)bufcur[7] << 8) | ((Int_t)bufcur[8] << 16);
R__unzip(&nin, bufcur, &nbuf, messbuf, &nout);
if (!nout) break;
noutot += nout;
if (noutot >= buflen - hdrlen) break;
bufcur += nin;
messbuf += nout;
}
fWhat &= ~kMESS_ZIP;
fCompress = 1;
return 0;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.