Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTDB::OTPacker Class Referenceabstract

#include <OTStorage.hpp>

Inheritance diagram for opentxs::OTDB::OTPacker:

Public Member Functions

virtual ~OTPacker ()
 
PackType GetType () const
 
PackedBufferPack (Storable &inObj)
 
EXPORT bool Unpack (PackedBuffer &inBuf, Storable &outObj)
 
PackedBufferPack (std::string &inObj)
 
bool Unpack (PackedBuffer &inBuf, std::string &outObj)
 
virtual PackedBufferCreateBuffer ()=0
 

Static Public Member Functions

static OTPackerCreate (PackType ePackType)
 

Protected Member Functions

 OTPacker ()
 

Detailed Description

Definition at line 542 of file OTStorage.hpp.

Constructor & Destructor Documentation

opentxs::OTDB::OTPacker::OTPacker ( )
inlineprotected

Definition at line 545 of file OTStorage.hpp.

546  {
547  } // To instantiate: OTPacker * pPacker =
virtual opentxs::OTDB::OTPacker::~OTPacker ( )
inlinevirtual

Definition at line 551 of file OTStorage.hpp.

552  {
553  }

Member Function Documentation

OTPacker * opentxs::OTDB::OTPacker::Create ( PackType  ePackType)
static

Definition at line 889 of file OTStorage.cpp.

890 {
891  OTPacker* pPacker = nullptr;
892 
893  switch (ePackType) {
894 #if defined(OTDB_MESSAGE_PACK)
895  case PACK_MESSAGE_PACK:
896  pPacker = new PackerMsgpack;
897  OT_ASSERT(nullptr != pPacker);
898  break;
899 #endif
900 #if defined(OTDB_PROTOCOL_BUFFERS)
902  pPacker = new PackerPB;
903  OT_ASSERT(nullptr != pPacker);
904  break;
905 #endif
906  case PACK_TYPE_ERROR:
907  default:
908  break;
909  }
910 
911  return pPacker; // May return nullptr...
912 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
virtual PackedBuffer* opentxs::OTDB::OTPacker::CreateBuffer ( )
pure virtual
PackType opentxs::OTDB::OTPacker::GetType ( ) const

Definition at line 914 of file OTStorage.cpp.

915 {
916 #if defined(OTDB_MESSAGE_PACK)
917  if (typeid(*this) == typeid(PackerMsgpack)) return PACK_MESSAGE_PACK;
918 #endif
919 #if defined(OTDB_PROTOCOL_BUFFERS)
920  if (typeid(*this) == typeid(PackerPB)) return PACK_PROTOCOL_BUFFERS;
921 #endif
922  return PACK_TYPE_ERROR;
923 }
PackedBuffer * opentxs::OTDB::OTPacker::Pack ( Storable inObj)

Definition at line 930 of file OTStorage.cpp.

931 {
932  IStorable* pStorable = dynamic_cast<IStorable*>(&inObj);
933 
934  if (nullptr ==
935  pStorable) // ALL Storables should implement SOME subinterface
936  // of IStorable
937  {
938  otErr << "OTPacker::Pack: Error: IStorable dynamic_cast failed.\n";
939  return nullptr;
940  }
941 
942  // This is polymorphic, so we get the right kind of buffer for the packer.
943  //
944  PackedBuffer* pBuffer = CreateBuffer();
945  OT_ASSERT(nullptr != pBuffer);
946 
947  // Must delete pBuffer, or return it, below this point.
948 
949  pStorable->hookBeforePack(); // Give the subclass a chance to prepare its
950  // data for packing...
951 
952  // This line (commented out) shows how the line below it would have looked
953  // if I had ended
954  // up using polymorphic templates:
955  // if (!makeTStorablepStorable->pack(*pBuffer))
956 
957  if (!pStorable->onPack(*pBuffer, inObj)) {
958  delete pBuffer;
959  return nullptr;
960  }
961 
962  return pBuffer;
963 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
Storable & inObj
Definition: OTStorage.hpp:376
virtual PackedBuffer * CreateBuffer()=0
PackedBuffer * opentxs::OTDB::OTPacker::Pack ( std::string &  inObj)

Definition at line 992 of file OTStorage.cpp.

993 {
994  // This is polymorphic, so we get the right kind of buffer for the packer.
995  //
996  PackedBuffer* pBuffer = CreateBuffer();
997  OT_ASSERT(nullptr != pBuffer);
998 
999  // Must delete pBuffer, or return it, below this point.
1000 
1001  if (!pBuffer->PackString(inObj)) {
1002  delete pBuffer;
1003  return nullptr;
1004  }
1005 
1006  return pBuffer;
1007 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
Storable & inObj
Definition: OTStorage.hpp:376
virtual PackedBuffer * CreateBuffer()=0
bool opentxs::OTDB::OTPacker::Unpack ( PackedBuffer inBuf,
Storable outObj 
)

Definition at line 972 of file OTStorage.cpp.

973 {
974  IStorable* pStorable = dynamic_cast<IStorable*>(&outObj);
975 
976  if (nullptr == pStorable) return false;
977 
978  // outObj is the OUTPUT OBJECT.
979  // If we're unable to unpack the contents of inBuf
980  // into outObj, return false.
981  //
982  if (!pStorable->onUnpack(inBuf, outObj)) {
983  return false;
984  }
985 
986  pStorable->hookAfterUnpack(); // Give the subclass a chance to settle its
987  // data after unpacking...
988 
989  return true;
990 }
bool opentxs::OTDB::OTPacker::Unpack ( PackedBuffer inBuf,
std::string &  outObj 
)

Definition at line 1009 of file OTStorage.cpp.

1010 {
1011 
1012  // outObj is the OUTPUT OBJECT.
1013  // If we're unable to unpack the contents of inBuf
1014  // into outObj, return false.
1015  //
1016  if (!inBuf.UnpackString(outObj)) return false;
1017 
1018  return true;
1019 }

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