-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamSerialization.hpp
More file actions
50 lines (41 loc) · 1.35 KB
/
StreamSerialization.hpp
File metadata and controls
50 lines (41 loc) · 1.35 KB
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
/*******************************************************************************
* Rohan data serialization library.
* Serialization to unix++ streams
*
* © 2020—2024, Sauron
******************************************************************************/
#ifndef __ROHAN_STREAMSERIALIZATION_HPP
#define __ROHAN_STREAMSERIALIZATION_HPP
#include <unix++/Stream.hpp>
#include "Reader.hpp"
#include "Writer.hpp"
namespace rohan {
/** Base class for StreamReader and StreamWriter **/
class StreamSerializer {
public:
/** Initialize with a reference to the stream **/
explicit StreamSerializer(upp::Stream &stream);
/** Returns the underlying stream **/
upp::Stream &getStream() const { return stream; }
protected:
upp::Stream &stream;
};
/**/
class StreamReader : public Reader, StreamSerializer {
public:
/** Initialize with a reference to the stream **/
explicit StreamReader(upp::Stream &stream);
/** Read a portion of data **/
size_t read(void * to, size_t length) override;
/** Skip a portion of data **/
size_t skip(size_t length) override;
};
class StreamWriter : public Writer, StreamSerializer {
public:
/** Initialize with a reference to the stream **/
explicit StreamWriter(upp::Stream &stream);
/** Write a portion of data **/
void write(const void * from, size_t length) override;
};
}
#endif