source: trunk/src/core2/RpSerialBuffer.h

Last change on this file was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1/*
2 * ======================================================================
3 *  Rappture::SerialBuffer
4 *
5 *  AUTHOR:  Michael McLennan, Purdue University
6 *           Carol X Song, Purdue University
7 *
8 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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 RPSERIALBUFFER_H
15#define RPSERIALBUFFER_H
16
17#include <string>
18#include <vector>
19
20namespace 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 */
28class SerialBuffer {
29public:
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
54private:
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 /*RPSERIALBUFFER_H*/
Note: See TracBrowser for help on using the repository browser.