EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEMarshalTest.cpp
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: Bloody.Rabbit
24 */
25 
26 #include "eve-test.h"
27 
28 int marshal_EVEMarshalTest( int argc, char* argv[] )
29 {
30  DBRowDescriptor *header = new DBRowDescriptor;
31  // Fill header:
32  header->AddColumn( "historyDate", DBTYPE_FILETIME );
33  header->AddColumn( "lowPrice", DBTYPE_CY );
34  header->AddColumn( "highPrice", DBTYPE_CY );
35  header->AddColumn( "avgPrice", DBTYPE_CY );
36  header->AddColumn( "volume", DBTYPE_I8 );
37  header->AddColumn( "orders", DBTYPE_I4 );
38 
39  CRowSet* rs = new CRowSet( &header );
40 
41  PyPackedRow* row = rs->NewRow();
42  row->SetField( "historyDate", new PyLong( Win32TimeNow() ) );
43  row->SetField( "lowPrice", new PyLong( 18000 ) );
44  row->SetField( "highPrice", new PyLong( 19000 ) );
45  row->SetField( "avgPrice", new PyLong( 18400 ) );
46  row->SetField( "volume", new PyLong( 5463586 ) );
47  row->SetField( "orders", new PyInt( 254 ) );
48 
49  ::puts( "Marshaling..." );
50 
51  Buffer marshaled;
52  bool res = MarshalDeflate( rs, marshaled );
53  PyDecRef( rs );
54 
55  if( !res )
56  {
57  ::puts( "Failed to marshal Python object." );
58  return EXIT_FAILURE;
59  }
60 
61  ::puts( "Unmarshaling..." );
62 
63  PyRep* rep = InflateUnmarshal( marshaled );
64  if( NULL == rep )
65  {
66  ::puts( "Failed to unmarshal Python object." );
67  return EXIT_FAILURE;
68  }
69 
70  ::puts( "Final:" );
71  rep->Dump( stdout, " " );
72  PyDecRef( rep );
73 
74  return EXIT_SUCCESS;
75 }
Base Python wire object.
Definition: PyRep.h:66
bool MarshalDeflate(const PyRep *rep, Buffer &into, const uint32 deflationLimit)
Definition: EVEMarshal.cpp:44
PyRep * InflateUnmarshal(const Buffer &data)
Turns possibly inflated marshal stream into Python object.
void AddColumn(const char *name, DBTYPE type)
Definition: PyDatabase.cpp:96
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
int marshal_EVEMarshalTest(int argc, char *argv[])
Generic class for buffers.
Definition: Buffer.h:40
Python object "blue.DBRowDescriptor".
Definition: PyDatabase.h:41
Python object "dbutil.CRowset".
Definition: PyDatabase.h:124
Python integer.
Definition: PyRep.h:231
int64 Win32TimeNow()
Definition: utils_time.cpp:70
#define PyDecRef(op)
Definition: PyRep.h:57
bool SetField(uint32 index, PyRep *value)
Definition: PyRep.cpp:1031
PyPackedRow * NewRow()
Definition: PyDatabase.cpp:132
Packed row.
Definition: PyRep.h:961
Python long integer.
Definition: PyRep.h:261