-
Notifications
You must be signed in to change notification settings - Fork 2
/
inner.h
76 lines (60 loc) · 1.48 KB
/
inner.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
#ifndef EXAMPLE_INNER_H
#define EXAMPLE_INNER_H
#include <fstream>
#include <iostream>
#include "proto.capnp.h"
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <kj/std/iostream.h>
using namespace std;
namespace example {
class Inner {
public:
Inner() {
f1_ = 0;
f2_ = "none";
};
Inner(int f1, const char* f2) {
f1_ = f1;
f2_ = f2;
}
virtual ~Inner() {};
int getF1() {
return f1_;
}
void setF1(int v) {
f1_ = v;
}
const char* getF2() {
return f2_;
}
void setF2(const char* v) {
f2_ = v;
}
void write(InnerProto::Builder& proto) const {
proto.setF1(f1_);
proto.setF2(f2_);
}
void write(ofstream& f) const {
capnp::MallocMessageBuilder message;
InnerProto::Builder innerProto = message.initRoot<InnerProto>();
write(innerProto);
kj::std::StdOutputStream outputStream(f);
capnp::writeMessage(outputStream, message);
}
void read(InnerProto::Reader& proto) {
f1_ = proto.getF1();
f2_ = proto.getF2().cStr();
}
void read(ifstream& f) {
kj::std::StdInputStream inputStream(f);
capnp::InputStreamMessageReader message(inputStream);
InnerProto::Reader proto = message.getRoot<InnerProto>();
read(proto);
}
private:
int f1_;
const char* f2_;
};
}
#endif // EXAMPLE_INNER_H