EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyCachedObjectDecoder Class Reference

#include "CachedObjectMgr.h"

Collaboration diagram for PyCachedObjectDecoder:

Public Member Functions

 PyCachedObjectDecoder ()
 
 ~PyCachedObjectDecoder ()
 
void Dump (FILE *into, const char *pfx, bool contents_too=false)
 
bool Decode (PySubStream **ss)
 
PyObjectEncodeHint ()
 

Public Attributes

int64 timestamp
 
int32 version
 
uint32 nodeID
 
bool shared
 
PySubStreamcache
 
bool compressed
 
PyRepobjectID
 

Detailed Description

Definition at line 151 of file CachedObjectMgr.h.

Constructor & Destructor Documentation

PyCachedObjectDecoder::PyCachedObjectDecoder ( )

Definition at line 574 of file CachedObjectMgr.cpp.

575 : timestamp(0),
576  version(0),
577  nodeID(0),
578  shared(false),
579  cache(nullptr),
580  compressed(false),
581  objectID(nullptr)
582 {
583 }
PyCachedObjectDecoder::~PyCachedObjectDecoder ( )

Definition at line 585 of file CachedObjectMgr.cpp.

References cache, objectID, and PySafeDecRef.

586 {
587  PySafeDecRef( cache );
589 }
#define PySafeDecRef(op)
Definition: PyRep.h:61

Member Function Documentation

bool PyCachedObjectDecoder::Decode ( PySubStream **  ss)

Definition at line 657 of file CachedObjectMgr.cpp.

References args, PyObject::arguments(), cache, compressed, PySubStream::decoded(), PySubStream::DecodeData(), if(), PyRep::IsObject(), PyRep::IsTuple(), PyTuple::items, nodeID, objectID, PyDecRef, PySafeDecRef, shared, sLog, timestamp, PyRep::TypeString(), PyInt::value(), and version.

Referenced by CachedObjectMgr::LoadCachedObject(), and CachedObjectMgr::UpdateCacheFromSS().

658 {
659  PySubStream *ss = *in_ss; //consume
660  *in_ss = nullptr;
661 
662  PySafeDecRef( cache );
664 
665  ss->DecodeData();
666  if (ss->decoded() == nullptr) {
667  sLog.Error("PyCachedObjectDecoder","Unable to decode initial stream for PycachedObject");
668 
669  PyDecRef( ss );
670  return false;
671  }
672 
673  if (!ss->decoded()->IsObject()) {
674  sLog.Error("PyCachedObjectDecoder","Cache substream does not contain an object: %s", ss->decoded()->TypeString());
675 
676  PyDecRef( ss );
677  return false;
678  }
679  PyObject *po = (PyObject *) ss->decoded();
680  //TODO: could check type string, dont care... (should be objectCaching.CachedObject)
681 
682  if (!po->arguments()->IsTuple()) {
683  sLog.Error("PyCachedObjectDecoder","Cache object's args is not a tuple: %s", po->arguments()->TypeString());
684 
685  PyDecRef( ss );
686  return false;
687  }
688  PyTuple *args = (PyTuple *) po->arguments();
689 
690  if (args->items.size() != 7) {
691  sLog.Error("PyCachedObjectDecoder","Cache object's args tuple has %lu elements instead of 7", args->items.size());
692 
693  PyDecRef( ss );
694  return false;
695  }
696 
697  if (!args->items[0]->IsTuple()) {
698  sLog.Error("PyCachedObjectDecoder","Cache object's arg %d is not a Tuple: %s", 0, args->items[0]->TypeString());
699 
700  PyDecRef( ss );
701  return false;
702  }
703  //ignore unknown [1]
704  /*if (!args->items[1]->IsInt()) {
705  _log(SERVICE__ERROR, "Cache object's arg %d is not a None: %s", 1, args->items[1]->TypeString());
706 
707  PyDecRef( ss );
708  return false;
709  }*/
710  if (!args->items[2]->IsInt()) {
711  sLog.Error("PyCachedObjectDecoder","Cache object's arg %d is not an Integer: %s", 2, args->items[2]->TypeString());
712  PyDecRef( ss );
713  return false;
714  }
715 
716  if (!args->items[3]->IsInt()) {
717  sLog.Error("PyCachedObjectDecoder","Cache object's arg %d is not an Integer: %s", 3, args->items[3]->TypeString());
718  PyDecRef( ss );
719  return false;
720  }
721 
722  if (!args->items[5]->IsInt()) {
723  sLog.Error("PyCachedObjectDecoder","Cache object's arg %d is not a : %s", 5, args->items[5]->TypeString());
724  PyDecRef( ss );
725  return false;
726  }
727 
728  PyTuple *objVt = (PyTuple *) args->items[0];
729  if (!objVt->items[0]->IsInt()) {
730  sLog.Error("PyCachedObjectDecoder","Cache object's version tuple %d is not an Integer: %s", 0, objVt->items[0]->TypeString());
731  PyDecRef( ss );
732  return false;
733  }
734 
735  if (!objVt->items[1]->IsInt()) {
736  sLog.Error("PyCachedObjectDecoder","Cache object's version tuple %d is not an Integer: %s", 1, objVt->items[1]->TypeString());
737  PyDecRef( ss );
738  return false;
739  }
740 
741  PyInt *nodeidr = (PyInt *) args->items[2];
742  PyInt *sharedr = (PyInt *) args->items[3];
743  PyInt *compressedr = (PyInt *) args->items[5];
744  PyInt *timer = (PyInt *) objVt->items[0];
745  PyInt *versionr = (PyInt *) objVt->items[1];
746 
747  timestamp = timer->value();
748  version = versionr->value();
749  nodeID = nodeidr->value();
750  shared = ( sharedr->value() != 0 );
751  compressed = ( compressedr->value() != 0 );
752 
753  //content (do this as the last thing, since its the heavy lifting):
754  if (args->items[4]->IsSubStream()) {
755  cache = (PySubStream *) args->items[4];
756  //take it
757  args->items[4] = nullptr;
758  } else if (args->items[4]->IsBuffer()) {
759  //this is a data buffer, likely compressed.
760  PyBuffer* buf = args->items[4]->AsBuffer();
761  cache = new PySubStream( buf );
762  } else if (args->items[4]->IsString()) {
763  //this is a data buffer, likely compressed, not sure why it comes through as a string...
764  PyString* str = args->items[4]->AsString();
765  cache = new PySubStream( new PyBuffer( *str ) );
766  } else {
767  sLog.Error("PyCachedObjectMgr", "Cache object's arg %d is not a substream or buffer: %s", 4, args->items[4]->TypeString());
768  PyDecRef( ss );
769  return false;
770  }
771 
772  objectID = args->items[6]->Clone();
773 
774  PyDecRef( ss );
775  return true;
776 }
Python string.
Definition: PyRep.h:430
int32 value() const
Definition: PyRep.h:247
bool IsTuple() const
Definition: PyRep.h:108
bool IsObject() const
Definition: PyRep.h:115
Python tuple.
Definition: PyRep.h:567
PyRep * arguments() const
Definition: PyRep.h:845
* args
PyRep * decoded() const
Definition: PyRep.h:1048
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
void DecodeData() const
Definition: PyRep.cpp:1125
Python object.
Definition: PyRep.h:826
Python integer.
Definition: PyRep.h:231
#define PyDecRef(op)
Definition: PyRep.h:57
if(sConfig.world.saveOnMove)
#define PySafeDecRef(op)
Definition: PyRep.h:61
Python buffer.
Definition: PyRep.h:382
storage_type items
Definition: PyRep.h:628
const char * TypeString() const
Definition: PyRep.cpp:76

Here is the call graph for this function:

Here is the caller graph for this function:

void PyCachedObjectDecoder::Dump ( FILE *  into,
const char *  pfx,
bool  contents_too = false 
)

Definition at line 621 of file CachedObjectMgr.cpp.

References cache, compressed, PyRep::Dump(), nodeID, objectID, PRIu64, shared, timestamp, and version.

622 {
623  std::string s(pfx);
624  s += " ";
625  fprintf(into, "%sCached Object:\n", pfx);
626  fprintf(into, "%s ObjectID:\n", pfx);
627  objectID->Dump(into, s.c_str());
628  fprintf(into, "%s Version Time: %" PRIu64 "\n", pfx, timestamp);
629  fprintf(into, "%s Version: %u\n", pfx, version);
630  fprintf(into, "%s NodeID: %u\n", pfx, nodeID);
631  fprintf(into, "%s Shared: %s\n", pfx, shared?"yes":"no");
632  fprintf(into, "%s Compressed: %s\n", pfx, compressed?"yes":"no");
633  if (contents_too) {
634  fprintf(into, "%s Contents:\n", pfx);
635  cache->Dump(into, s.c_str());
636  }
637 }
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
#define PRIu64
Definition: eve-compat.h:85

Here is the call graph for this function:

PyObject * PyCachedObjectDecoder::EncodeHint ( )

Definition at line 815 of file CachedObjectMgr.cpp.

References PyRep::Clone(), PyTuple::items, nodeID, objectID, timestamp, and version.

815  {
816  PyTuple *versiont = new PyTuple(2);
817  versiont->items[0] = new PyLong(timestamp);
818  versiont->items[1] = new PyInt(version);
819  PyTuple *arg_tuple = new PyTuple(3);
820  arg_tuple->items[0] = objectID->Clone();
821  arg_tuple->items[1] = new PyInt(nodeID);
822  arg_tuple->items[2] = versiont;
823 
824  return new PyObject( "util.CachedObject", arg_tuple );
825 }
virtual PyRep * Clone() const =0
Clones object.
Python tuple.
Definition: PyRep.h:567
Python object.
Definition: PyRep.h:826
Python integer.
Definition: PyRep.h:231
storage_type items
Definition: PyRep.h:628
Python long integer.
Definition: PyRep.h:261

Here is the call graph for this function:

Member Data Documentation

PySubStream* PyCachedObjectDecoder::cache
bool PyCachedObjectDecoder::compressed

Definition at line 171 of file CachedObjectMgr.h.

Referenced by Decode(), and Dump().

uint32 PyCachedObjectDecoder::nodeID

Definition at line 166 of file CachedObjectMgr.h.

Referenced by Decode(), Dump(), and EncodeHint().

PyRep* PyCachedObjectDecoder::objectID

Definition at line 172 of file CachedObjectMgr.h.

Referenced by Decode(), Dump(), EncodeHint(), and ~PyCachedObjectDecoder().

bool PyCachedObjectDecoder::shared

Definition at line 167 of file CachedObjectMgr.h.

Referenced by Decode(), and Dump().

int64 PyCachedObjectDecoder::timestamp

Definition at line 162 of file CachedObjectMgr.h.

Referenced by Decode(), Dump(), and EncodeHint().

int32 PyCachedObjectDecoder::version

Definition at line 163 of file CachedObjectMgr.h.

Referenced by Decode(), Dump(), and EncodeHint().


The documentation for this class was generated from the following files: