1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Rappture::SerialBuffer |
---|
4 | * |
---|
5 | * AUTHOR: Michael McLennan, Purdue University |
---|
6 | * Carol X Song, Purdue University |
---|
7 | * |
---|
8 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
9 | * ---------------------------------------------------------------------- |
---|
10 | * See the file "license.terms" for information on usage and |
---|
11 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
12 | * ====================================================================== |
---|
13 | */ |
---|
14 | #ifndef RAPPTURE_SERIALBUFFER_H |
---|
15 | #define RAPPTURE_SERIALBUFFER_H |
---|
16 | |
---|
17 | #include <string> |
---|
18 | #include <vector> |
---|
19 | |
---|
20 | namespace Rappture { |
---|
21 | |
---|
22 | /** |
---|
23 | * Used by the Serializer to build up the buffer of serialized |
---|
24 | * data. Similar to a string, but it handles nulls and other |
---|
25 | * control characters. Also handles big/little endian order |
---|
26 | * properly. |
---|
27 | */ |
---|
28 | class SerialBuffer { |
---|
29 | public: |
---|
30 | SerialBuffer(); |
---|
31 | SerialBuffer(const char* bytes, int nbytes); |
---|
32 | SerialBuffer(const SerialBuffer& buffer); |
---|
33 | SerialBuffer& operator=(const SerialBuffer& buffer); |
---|
34 | virtual ~SerialBuffer(); |
---|
35 | |
---|
36 | const char* bytes() const; |
---|
37 | int size() const; |
---|
38 | |
---|
39 | SerialBuffer& clear(); |
---|
40 | SerialBuffer& writeChar(char cval); |
---|
41 | SerialBuffer& writeInt(int ival); |
---|
42 | SerialBuffer& writeDouble(double dval); |
---|
43 | SerialBuffer& writeString(const char* sval); |
---|
44 | SerialBuffer& writeBytes(const char* bval, int nbytes); |
---|
45 | |
---|
46 | void rewind(); |
---|
47 | int atEnd() const; |
---|
48 | char readChar(); |
---|
49 | int readInt(); |
---|
50 | double readDouble(); |
---|
51 | std::string readString(); |
---|
52 | std::vector<char> readBytes(); |
---|
53 | |
---|
54 | private: |
---|
55 | /// Contains the actual data within this buffer. |
---|
56 | std::vector<char> _buffer; |
---|
57 | |
---|
58 | /// Position for the various readXyz() functions. |
---|
59 | int _pos; |
---|
60 | }; |
---|
61 | |
---|
62 | } // namespace Rappture |
---|
63 | |
---|
64 | #endif |
---|