-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathouter.h
83 lines (66 loc) · 1.74 KB
/
outer.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
#ifndef EXAMPLE_OUTER_H
#define EXAMPLE_OUTER_H
#include "proto.capnp.h"
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <kj/std/iostream.h>
#include <iostream>
#include "inner.h"
using namespace std;
namespace example {
class Outer {
public:
Outer() {
fieldA_ = 0.0;
}
Outer(float fa, int f1, const char* f2) {
fieldA_ = fa;
inner_.setF1(f1);
inner_.setF2(f2);
}
virtual ~Outer() {};
float getFA() {
return fieldA_;
}
const Inner& getInner() {
return inner_;
}
void write(OuterProto::Builder& proto) const {
proto.setFieldA(fieldA_);
auto innerProto = proto.initInner();
inner_.write(innerProto);
}
void write(ofstream& f) const {
capnp::MallocMessageBuilder message;
OuterProto::Builder outerProto = message.initRoot<OuterProto>();
write(outerProto);
kj::std::StdOutputStream outputStream(f);
capnp::writeMessage(outputStream, message);
}
void write(const char* path) const {
ofstream f(path);
write(f);
f.close();
}
void read(OuterProto::Reader& proto) {
fieldA_ = proto.getFieldA();
auto innerProto = proto.getInner();
inner_.read(innerProto);
}
void read(ifstream& f) {
kj::std::StdInputStream inputStream(f);
capnp::InputStreamMessageReader message(inputStream);
OuterProto::Reader proto = message.getRoot<OuterProto>();
read(proto);
}
void read(const char* path) {
ifstream f(path);
read(f);
f.close();
}
private:
float fieldA_;
Inner inner_;
};
}
#endif // EXAMPLE_OUTER_H