EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEMarshal.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #ifndef EVE_MARSHAL_H
27 #define EVE_MARSHAL_H
28 
30 #include "python/PyVisitor.h"
31 
32 /*
33  * @brief Marshal Stream builder.
34  *
35  * @param[in] rep Python object to marshal.
36  * @param[out] into Buffer which receives marshaled stream.
37  *
38  * @retval true Marshaling ran successfully.
39  * @retval false Error occured during marshaling.
40  */
41 extern bool Marshal( const PyRep* rep, Buffer& into );
42 /*
43  * @brief Deflated Marshal Stream builder.
44  *
45  * @param[in] rep Python object to marshal.
46  * @param[out] into Buffer which receives deflated marshaled stream.
47  * @param[in] deflationLimit The least size of buffer which gets deflated.
48  *
49  * @retval true Marshaling ran successfully.
50  * @retval false Error occured during marshaling.
51  */
52 extern bool MarshalDeflate( const PyRep* rep, Buffer& into, const uint32 deflationLimit = 0x2000 );
53 
60 : protected PyVisitor
61 {
62 public:
64  MarshalStream();
65 
67  bool Save( const PyRep* rep, Buffer& into );
68 
69 protected:
71  bool SaveStream( const PyRep* rep );
72 
74  template<typename T>
75  void Put( const T& value ) { mBuffer->Append<T>( value ); }
77  template<typename Iter>
78  void Put( Iter first, Iter last ) { mBuffer->AppendSeq<Iter>( first, last ); }
79 
81  void PutSizeEx( uint32 size )
82  {
83  if( size < 0xFF )
84  {
85  Put<uint8>( size );
86  }
87  else
88  {
89  Put<uint8>( 0xFF );
90  Put<uint32>( size );
91  }
92  }
93 
100  bool VisitInteger( const PyInt* rep );
102  bool VisitLong( const PyLong* rep );
104  bool VisitBoolean( const PyBool* rep );
106  bool VisitReal( const PyFloat* rep );
108  bool VisitNone( const PyNone* rep );
110  bool VisitBuffer( const PyBuffer* rep );
112  bool VisitString( const PyString* rep );
114  bool VisitWString( const PyWString* rep );
116  bool VisitToken( const PyToken* rep );
117 
119  bool VisitTuple( const PyTuple* rep );
121  bool VisitList( const PyList* rep );
123  bool VisitDict( const PyDict* rep );
124 
126  bool VisitObject( const PyObject* rep );
128  bool VisitObjectEx( const PyObjectEx* rep );
129 
131  bool VisitPackedRow( const PyPackedRow* pyPackedRow );
132 
134  bool VisitSubStruct( const PySubStruct* rep );
136  bool VisitSubStream( const PySubStream* rep );
138  bool VisitChecksumedStream( const PyChecksumedStream* rep );
139 
140 private:
141  // utility to handle Op_PyVarInteger (a bit hacky......)
142  void SaveVarInteger( const PyLong* v );
143  // zero-compresses given buffer and adds it to the stream
144  bool SaveRLE(const Buffer& in );
145 
147 };
148 
149 #endif
150 
void Append(const T &value)
Appends a single value to buffer.
Definition: Buffer.h:437
Base Python wire object.
Definition: PyRep.h:66
bool VisitWString(const PyWString *rep)
add a wide string object to the data stream
Definition: EVEMarshal.cpp:189
bool VisitInteger(const PyInt *rep)
Definition: EVEMarshal.cpp:92
Python string.
Definition: PyRep.h:430
bool VisitDict(const PyDict *rep)
Definition: EVEMarshal.cpp:251
Python's dictionary.
Definition: PyRep.h:719
bool Save(const PyRep *rep, Buffer &into)
Definition: EVEMarshal.cpp:69
void SaveVarInteger(const PyLong *v)
Definition: EVEMarshal.cpp:503
bool VisitPackedRow(const PyPackedRow *pyPackedRow)
Adds a packed row to the stream.
Definition: EVEMarshal.cpp:306
bool VisitObject(const PyObject *rep)
Adds an object to the stream.
Definition: EVEMarshal.cpp:269
Python floating point number.
Definition: PyRep.h:292
Python wide string.
Definition: PyRep.h:475
bool VisitBuffer(const PyBuffer *rep)
Adds a buffer to the stream.
Definition: EVEMarshal.cpp:151
Turns Python objects into marshal bytecode.
Definition: EVEMarshal.h:59
Python tuple.
Definition: PyRep.h:567
Python boolean.
Definition: PyRep.h:323
Python extended object.
Definition: PyRep.h:861
Buffer * mBuffer
Definition: EVEMarshal.h:146
Generic class for buffers.
Definition: Buffer.h:40
void AppendSeq(Iter first, Iter last)
Appends a sequence of elements to buffer.
Definition: Buffer.h:455
bool VisitLong(const PyLong *rep)
Adds a long to the stream.
Definition: EVEMarshal.cpp:116
Python object.
Definition: PyRep.h:826
Python's "none".
Definition: PyRep.h:352
bool VisitSubStream(const PySubStream *rep)
Adds a sub stream to the stream.
Definition: EVEMarshal.cpp:464
bool MarshalDeflate(const PyRep *rep, Buffer &into, const uint32 deflationLimit=0x2000)
Definition: EVEMarshal.cpp:44
void Put(const T &value)
Definition: EVEMarshal.h:75
Python integer.
Definition: PyRep.h:231
bool VisitChecksumedStream(const PyChecksumedStream *rep)
Adds a checksumed stream to the stream.
Definition: EVEMarshal.cpp:493
unsigned __int32 uint32
Definition: eve-compat.h:50
bool VisitBoolean(const PyBool *rep)
Adds a boolean to the stream.
Definition: EVEMarshal.cpp:123
bool VisitString(const PyString *rep)
add a string object to the data stream
Definition: EVEMarshal.cpp:163
Python token (eg. class name).
Definition: PyRep.h:522
bool SaveStream(const PyRep *rep)
Definition: EVEMarshal.cpp:78
bool SaveRLE(const Buffer &in)
Definition: EVEMarshal.cpp:524
bool VisitNone(const PyNone *rep)
Adds a None object to the stream.
Definition: EVEMarshal.cpp:145
bool VisitObjectEx(const PyObjectEx *rep)
Adds a New object to the stream.
Definition: EVEMarshal.cpp:275
Python buffer.
Definition: PyRep.h:382
Packed row.
Definition: PyRep.h:961
bool VisitToken(const PyToken *rep)
add a token object to the data stream
Definition: EVEMarshal.cpp:207
bool VisitSubStruct(const PySubStruct *rep)
Adds a sub structure to the stream.
Definition: EVEMarshal.cpp:458
bool VisitTuple(const PyTuple *rep)
Definition: EVEMarshal.cpp:219
bool VisitList(const PyList *rep)
Definition: EVEMarshal.cpp:236
Python list.
Definition: PyRep.h:639
void Put(Iter first, Iter last)
Definition: EVEMarshal.h:78
bool Marshal(const PyRep *rep, Buffer &into)
Definition: EVEMarshal.cpp:36
void PutSizeEx(uint32 size)
Definition: EVEMarshal.h:81
Python long integer.
Definition: PyRep.h:261
bool VisitReal(const PyFloat *rep)
Adds a double to the stream.
Definition: EVEMarshal.cpp:133