// @(#)root/net:$Id$
// Author: Fons Rademakers   19/12/96

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TMessage
#define ROOT_TMessage


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TMessage                                                             //
//                                                                      //
// Message buffer class used for serializing objects and sending them   //
// over the network.                                                    //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TBufferFile
#include "TBufferFile.h"
#endif
#ifndef ROOT_MessageTypes
#include "MessageTypes.h"
#endif
#ifndef ROOT_TBits
#include "TBits.h"
#endif

class TList;
class TVirtualStreamerInfo;

class TMessage : public TBufferFile {

friend class TAuthenticate;
friend class TSocket;
friend class TUDPSocket;
friend class TPSocket;
friend class TXSocket;

private:
   TList   *fInfos;       //List of TStreamerInfo used in WriteObject
   TBits    fBitsPIDs;    //Array of bits to mark the TProcessIDs uids written to the message
   UInt_t   fWhat;        //Message type
   TClass  *fClass;       //If message is kMESS_OBJECT pointer to object's class
   Int_t    fCompress;    //Compression level and algorithm
   char    *fBufComp;     //Compressed buffer
   char    *fBufCompCur;  //Current position in compressed buffer
   char    *fCompPos;     //Position of fBufCur when message was compressed
   Bool_t   fEvolution;   //True if support for schema evolution required

   static Bool_t fgEvolution;  //True if global support for schema evolution required

   // TMessage objects cannot be copied or assigned
   TMessage(const TMessage &);           // not implemented
   void operator=(const TMessage &);     // not implemented

   // used by friend TSocket
   Bool_t TestBitNumber(UInt_t bitnumber) const { return fBitsPIDs.TestBitNumber(bitnumber); }

protected:
   TMessage(void *buf, Int_t bufsize);   // only called by T(P)Socket::Recv()
   void SetLength() const;               // only called by T(P)Socket::Send()

public:
   TMessage(UInt_t what = kMESS_ANY, Int_t bufsiz = TBuffer::kInitialSize);
   virtual ~TMessage();

   void     ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force);
   void     Forward();
   TClass  *GetClass() const { return fClass;}
   void     TagStreamerInfo(TVirtualStreamerInfo* info);
   void     Reset();
   void     Reset(UInt_t what) { SetWhat(what); Reset(); }
   UInt_t   What() const { return fWhat; }
   void     SetWhat(UInt_t what);

   void     EnableSchemaEvolution(Bool_t enable = kTRUE) { fEvolution = enable; }
   Bool_t   UsesSchemaEvolution() const { return fEvolution; }
   TList   *GetStreamerInfos() const { return fInfos; }
   Int_t    GetCompressionAlgorithm() const;
   Int_t    GetCompressionLevel() const;
   Int_t    GetCompressionSettings() const;
   void     SetCompressionAlgorithm(Int_t algorithm=0);
   void     SetCompressionLevel(Int_t level=1);
   void     SetCompressionSettings(Int_t settings=1);
   Int_t    Compress();
   Int_t    Uncompress();
   char    *CompBuffer() const { return fBufComp; }
   Int_t    CompLength() const { return (Int_t)(fBufCompCur - fBufComp); }
   void     WriteObject(const TObject *obj);
   UShort_t WriteProcessID(TProcessID *pid);

   static void   EnableSchemaEvolutionForAll(Bool_t enable = kTRUE);
   static Bool_t UsesSchemaEvolutionForAll();

   ClassDef(TMessage,0)  // Message buffer class
};

//______________________________________________________________________________
inline Int_t TMessage::GetCompressionAlgorithm() const
{
   return (fCompress < 0) ? -1 : fCompress / 100;
}

//______________________________________________________________________________
inline Int_t TMessage::GetCompressionLevel() const
{
   return (fCompress < 0) ? -1 : fCompress % 100;
}

//______________________________________________________________________________
inline Int_t TMessage::GetCompressionSettings() const
{
   return (fCompress < 0) ? -1 : fCompress;
}

#endif
 TMessage.h:1
 TMessage.h:2
 TMessage.h:3
 TMessage.h:4
 TMessage.h:5
 TMessage.h:6
 TMessage.h:7
 TMessage.h:8
 TMessage.h:9
 TMessage.h:10
 TMessage.h:11
 TMessage.h:12
 TMessage.h:13
 TMessage.h:14
 TMessage.h:15
 TMessage.h:16
 TMessage.h:17
 TMessage.h:18
 TMessage.h:19
 TMessage.h:20
 TMessage.h:21
 TMessage.h:22
 TMessage.h:23
 TMessage.h:24
 TMessage.h:25
 TMessage.h:26
 TMessage.h:27
 TMessage.h:28
 TMessage.h:29
 TMessage.h:30
 TMessage.h:31
 TMessage.h:32
 TMessage.h:33
 TMessage.h:34
 TMessage.h:35
 TMessage.h:36
 TMessage.h:37
 TMessage.h:38
 TMessage.h:39
 TMessage.h:40
 TMessage.h:41
 TMessage.h:42
 TMessage.h:43
 TMessage.h:44
 TMessage.h:45
 TMessage.h:46
 TMessage.h:47
 TMessage.h:48
 TMessage.h:49
 TMessage.h:50
 TMessage.h:51
 TMessage.h:52
 TMessage.h:53
 TMessage.h:54
 TMessage.h:55
 TMessage.h:56
 TMessage.h:57
 TMessage.h:58
 TMessage.h:59
 TMessage.h:60
 TMessage.h:61
 TMessage.h:62
 TMessage.h:63
 TMessage.h:64
 TMessage.h:65
 TMessage.h:66
 TMessage.h:67
 TMessage.h:68
 TMessage.h:69
 TMessage.h:70
 TMessage.h:71
 TMessage.h:72
 TMessage.h:73
 TMessage.h:74
 TMessage.h:75
 TMessage.h:76
 TMessage.h:77
 TMessage.h:78
 TMessage.h:79
 TMessage.h:80
 TMessage.h:81
 TMessage.h:82
 TMessage.h:83
 TMessage.h:84
 TMessage.h:85
 TMessage.h:86
 TMessage.h:87
 TMessage.h:88
 TMessage.h:89
 TMessage.h:90
 TMessage.h:91
 TMessage.h:92
 TMessage.h:93
 TMessage.h:94
 TMessage.h:95
 TMessage.h:96
 TMessage.h:97
 TMessage.h:98
 TMessage.h:99
 TMessage.h:100
 TMessage.h:101
 TMessage.h:102
 TMessage.h:103
 TMessage.h:104
 TMessage.h:105
 TMessage.h:106
 TMessage.h:107
 TMessage.h:108
 TMessage.h:109
 TMessage.h:110
 TMessage.h:111
 TMessage.h:112
 TMessage.h:113
 TMessage.h:114
 TMessage.h:115
 TMessage.h:116
 TMessage.h:117
 TMessage.h:118
 TMessage.h:119
 TMessage.h:120
 TMessage.h:121
 TMessage.h:122
 TMessage.h:123