forked from jancarlsson/snarkfront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBuffer.cpp
68 lines (50 loc) · 1.24 KB
/
DataBuffer.cpp
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
#include <cctype>
#include "DataBuffer.hpp"
using namespace std;
namespace snarkfront {
////////////////////////////////////////////////////////////////////////////////
// clear text buffer
//
ClearText::ClearText(DataBuffer<ClearText>& outer)
: m_data(outer->data())
{}
void ClearText::clear() {
m_data.clear();
}
void ClearText::pushOctet(const uint8_t a) {
m_data.push_back(a);
}
const vector<uint8_t>& ClearText::data() const {
return m_data;
}
bool ClearText::empty() const {
return m_data.empty();
}
size_t ClearText::size() const {
return data().size();
}
size_t ClearText::sizeBits() const {
return size() * CHAR_BIT;
}
////////////////////////////////////////////////////////////////////////////////
// data buffer stream
//
DataBufferStream::DataBufferStream()
: m_index(0)
{}
bool DataBufferStream::empty() const {
return m_index == m_buf->size();
}
const vector<uint8_t>& DataBufferStream::data() const {
return m_buf->data();
}
DataBuffer<ClearText>& DataBufferStream::operator* () {
return m_buf;
}
DataBuffer<ClearText>* DataBufferStream::operator-> () {
return addressof(m_buf);
}
istream& operator>> (istream& is, DataBufferStream& a) {
return is >> *a;
}
} // namespace snarkfront