EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEUnmarshal.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_UNMARSHAL_H
27 #define EVE_UNMARSHAL_H
28 
29 #include "python/PyRep.h"
30 
31 
39 extern PyRep* Unmarshal( const Buffer& data );
47 extern PyRep* InflateUnmarshal( const Buffer& data );
48 
55 {
56 public:
58  : mStoredObjects( nullptr )
59  {
60  }
61 
63 
71  PyRep* Load( const Buffer& data );
72 
73 protected:
75  template<typename T>
76  const T& Peek() const { return *Peek<T>( 1 ); }
78  template<typename T>
79  Buffer::const_iterator<T> Peek( size_t count ) const { return mInItr.As<T>(); }
80 
82  template<typename T>
83  const T& Read() { return *Read<T>( 1 ); }
85  template<typename T>
87  {
88  Buffer::const_iterator<T> res = Peek<T>( count );
89  mInItr = ( res + count ).template As<uint8>();
90  return res;
91  }
92 
95  {
96  uint32 size = Read<uint8>();
97  if( 0xFF == size )
98  size = Read<uint32>();
99 
100  return size;
101  }
102 
104  PyRep* LoadStream( size_t streamLength );
105 
107  PyRep* LoadRep();
108 
115  void CreateObjectStore( size_t streamLength, uint32 saveCount );
119  void DestroyObjectStore();
120 
134  PyRep* GetStoredObject( uint32 index );
141  void StoreObject( uint32 index, PyRep* object );
142 
143 private:
145  PyRep* LoadNone() { return PyStatic.NewNone(); }
146 
148  PyRep* LoadBoolTrue() { return PyStatic.NewTrue(); }
150  PyRep* LoadBoolFalse() { return PyStatic.NewFalse(); }
151 
153  PyRep* LoadIntegerLongLong() { return new PyLong( Read<int64>() ); }
155  PyRep* LoadIntegerLong() { return new PyInt( Read<int32>() ); }
157  PyRep* LoadIntegerSignedShort() { return new PyInt( Read<int16>() ); }
159  PyRep* LoadIntegerByte() { return new PyInt( Read<int8>() ); }
163  PyRep* LoadIntegerMinusOne() { return new PyInt( -1 ); }
165  PyRep* LoadIntegerZero() { return new PyInt( 0 ); }
167  PyRep* LoadIntegerOne() { return new PyInt( 1 ); }
168 
170  PyRep* LoadReal() { return new PyFloat( Read<double>() ); }
172  PyRep* LoadRealZero() { return new PyFloat( 0.0 ); }
173 
175  PyRep* LoadStringEmpty() { return new PyString( "" ); }
184 
186  PyRep* LoadWStringEmpty() { return new PyWString( "", 0 ); }
193 
195  PyRep* LoadToken();
196 
198  PyRep* LoadBuffer();
199 
201  PyRep* LoadTupleEmpty() { return new PyTuple( 0 ); }
203  PyRep* LoadTuple();
205  PyRep* LoadTupleOne();
207  PyRep* LoadTupleTwo();
208 
210  PyRep* LoadListEmpty() { return new PyList( 0 ); }
212  PyRep* LoadList();
214  PyRep* LoadListOne();
215 
217  PyRep* LoadDict();
218 
220  PyRep* LoadObject();
222  PyRep* LoadObjectEx1();
224  PyRep* LoadObjectEx2();
225 
227  PyRep* LoadSubStream();
229  PyRep* LoadSubStruct();
232 
234  PyRep* LoadPackedRow();
235 
237  PyRep* LoadError();
240 
242  PyObjectEx* LoadObjectEx( bool is_type_2 );
244  bool LoadRLE(Buffer& out );
245 
248 
253 
255  static PyRep* ( UnmarshalStream::* const s_mLoadMap[] )();
256 };
257 
258 #endif
259 
Base Python wire object.
Definition: PyRep.h:66
PyRep * Load(const Buffer &data)
Loads Python object from given bytecode.
PyRep * LoadIntegerVar()
void StoreObject(uint32 index, PyRep *object)
Stores object.
PyRep * LoadStringShort()
PyRep * LoadIntegerOne()
Definition: EVEUnmarshal.h:167
PyRep * LoadSubStruct()
Python string.
Definition: PyRep.h:430
PyRep * LoadIntegerMinusOne()
Definition: EVEUnmarshal.h:163
PyRep * LoadObject()
uint32 GetStorageIndex()
Obtains storage index for StoreObject.
Definition: EVEUnmarshal.h:126
Buffer::const_iterator< uint8 > mInItr
Definition: EVEUnmarshal.h:247
Python floating point number.
Definition: PyRep.h:292
Python wide string.
Definition: PyRep.h:475
PyRep * LoadListOne()
PyRep * GetStoredObject(uint32 index)
Obtains previously stored object.
PyRep * LoadWStringUCS2Char()
PyRep * LoadIntegerLongLong()
Definition: EVEUnmarshal.h:153
Python tuple.
Definition: PyRep.h:567
const_iterator< T2 > As() const
Converts const_iterator to another const_iterator with different type.
Definition: Buffer.h:108
PyRep * LoadIntegerByte()
Definition: EVEUnmarshal.h:159
PyRep * LoadIntegerZero()
Definition: EVEUnmarshal.h:165
PyRep * LoadStringTable()
PyList * mStoredObjects
Definition: EVEUnmarshal.h:252
PyRep * InflateUnmarshal(const Buffer &data)
Turns possibly inflated marshal stream into Python object.
PyRep * LoadStringEmpty()
Definition: EVEUnmarshal.h:175
PyRep * LoadStringLong()
PyRep * LoadTupleEmpty()
Definition: EVEUnmarshal.h:201
PyRep * LoadList()
PyRep * LoadObjectEx2()
PyRep * LoadSubStream()
Python extended object.
Definition: PyRep.h:861
Generic class for buffers.
Definition: Buffer.h:40
PyRep * LoadIntegerLong()
Definition: EVEUnmarshal.h:155
PyRep * LoadTupleOne()
PyRep * LoadTupleTwo()
Python integer.
Definition: PyRep.h:231
PyRep * LoadBoolFalse()
Definition: EVEUnmarshal.h:150
PyRep * LoadWStringUCS2()
PyRep * LoadIntegerSignedShort()
Definition: EVEUnmarshal.h:157
PyRep * LoadWStringEmpty()
Definition: EVEUnmarshal.h:186
#define PyStatic
Definition: PyRep.h:1209
PyRep * LoadSavedStreamElement()
PyRep * LoadTuple()
PyRep * LoadError()
unsigned __int32 uint32
Definition: eve-compat.h:50
PyRep * LoadChecksumedStream()
PyRep * LoadToken()
Buffer::const_iterator< uint32 > mStoreIndexItr
Definition: EVEUnmarshal.h:250
PyRep * LoadObjectEx1()
PyRep * LoadReal()
Definition: EVEUnmarshal.h:170
PyObjectEx * LoadObjectEx(bool is_type_2)
PyRep * LoadNone()
Definition: EVEUnmarshal.h:145
void CreateObjectStore(size_t streamLength, uint32 saveCount)
Initializes object store.
PyRep * LoadPackedRow()
Class which turns marshal bytecode into Python object.
Definition: EVEUnmarshal.h:54
const T & Read()
Definition: EVEUnmarshal.h:83
PyRep * LoadRealZero()
Definition: EVEUnmarshal.h:172
Buffer::const_iterator< T > Peek(size_t count) const
Definition: EVEUnmarshal.h:79
PyRep * LoadListEmpty()
Definition: EVEUnmarshal.h:210
void DestroyObjectStore()
Destroys object store.
PyRep * LoadStream(size_t streamLength)
static PyRep *(UnmarshalStream::*const s_mLoadMap[])()
Definition: EVEUnmarshal.h:255
PyRep * LoadWStringUTF8()
bool LoadRLE(Buffer &out)
PyRep * LoadStringChar()
PyRep * LoadBuffer()
Buffer's const iterator.
Definition: Buffer.h:52
PyRep * Unmarshal(const Buffer &data)
Turns marshal stream into Python object.
Python list.
Definition: PyRep.h:639
const T & Peek() const
Definition: EVEUnmarshal.h:76
uint32 ReadSizeEx()
Definition: EVEUnmarshal.h:94
Python long integer.
Definition: PyRep.h:261
PyRep * LoadBoolTrue()
Definition: EVEUnmarshal.h:148
PyRep * LoadDict()
Buffer::const_iterator< T > Read(size_t count)
Definition: EVEUnmarshal.h:86