-
Notifications
You must be signed in to change notification settings - Fork 3
/
binaryio.h
84 lines (71 loc) · 1.81 KB
/
binaryio.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
82
83
84
#pragma once
#include <string>
#include <istream>
#include <ostream>
#include "scpak.h"
namespace scpak
{
class BinaryReader
{
public:
virtual byte readByte() = 0;
void readBytes(int size, byte buf[]);
std::int32_t readInt32();
std::float_t readSingle();
std::int32_t read7BitEncodedInt();
int readUtf8Char();
bool readBoolean();
std::string readString();
static int getUtf8CharCount(const std::string &value);
private:
std::istream *m_stream;
};
class StreamBinaryReader : public BinaryReader
{
public:
StreamBinaryReader(std::istream *stream);
byte readByte();
private:
std::istream *m_stream;
};
class MemoryBinaryReader : public BinaryReader
{
public:
MemoryBinaryReader(const byte *buffer);
unsigned position;
byte readByte();
private:
const byte *m_buffer;
};
class BinaryWriter
{
public:
virtual void writeByte(byte value) = 0;
void writeBytes(int size, const byte value[]);
void writeInt(int value);
void writeFloat(std::float_t value);
int write7BitEncodedInt(int value);
int writeUtf8Char(int value);
void writeBoolean(bool value);
void writeString(const std::string &value);
private:
std::ostream *m_stream;
};
class StreamBinaryWriter : public BinaryWriter
{
public:
StreamBinaryWriter(std::ostream *stream);
void writeByte(byte value);
private:
std::ostream *m_stream;
};
class MemoryBinaryWriter : public BinaryWriter
{
public:
MemoryBinaryWriter(byte *buffer);
unsigned position;
void writeByte(byte value);
private:
byte *m_buffer;
};
}