forked from risvh/minorGems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerializable.h
81 lines (62 loc) · 1.79 KB
/
Serializable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Modification History
*
* 2001-January-10 Jason Rohrer
* Created.
* Added untility functions for converting integers to and from byte arrays.
*
* 2001-January-15 Jason Rohrer
* Made utility functions static.
* Fixed a major bug in the longToBytes function.
*
* 2001-February-3 Jason Rohrer
* Removed the long io functions, which are now contained in the
* input- and outputStream classes.
*
* 2005-November-21 Jason Rohrer
* Fixed a warning by adding a virtual destructor.
*/
#include "minorGems/common.h"
#ifndef SERIALIZABLE_CLASS_INCLUDED
#define SERIALIZABLE_CLASS_INCLUDED
#include "InputStream.h"
#include "OutputStream.h"
/**
* Interface for an object that can be serialized to and deserialized
* from a stream.
*
* Note that the deserialize function is meant to be called from an already
* constructed object (to set object parameters using data read from the
* stream), and is not a method of obtaining an object.
*
* All multi-byte data members should be encoded in using a big endian format.
*
* @author Jason Rohrer
*/
class Serializable {
public:
/**
* Writes this object out to a stream.
*
* @param inOutputStream the stream to write to.
*
* @return the number of bytes written successfully,
* or -1 for a stream error.
*/
virtual int serialize( OutputStream *inOutputStream ) = 0;
/**
* Reads this object in from a stream.
*
* @param inInputStream the stream to read from.
*
* @return the number of bytes read successfully,
* or -1 for a stream error.
*/
virtual int deserialize( InputStream *inInputStream ) = 0;
virtual ~Serializable();
};
inline Serializable::~Serializable() {
// does nothing
// exists to ensure that subclass destructors are called
}
#endif