diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-11-21 15:08:39 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-11-21 15:08:39 +0100 |
commit | 85860fbe47ca5ec24c70966f42a53162d761b91f (patch) | |
tree | d64ba3ec411579c3e886b0b6673f726fb99ad3ce /buffertest/main.cpp | |
parent | 4adae7c3711abbeaa7f03c699a7d366c78f776bc (diff) | |
download | sink-85860fbe47ca5ec24c70966f42a53162d761b91f.tar.gz sink-85860fbe47ca5ec24c70966f42a53162d761b91f.zip |
A buffertest that currently does nothing else than writing a buffer to a file.
Diffstat (limited to 'buffertest/main.cpp')
-rw-r--r-- | buffertest/main.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/buffertest/main.cpp b/buffertest/main.cpp new file mode 100644 index 0000000..5bc2326 --- /dev/null +++ b/buffertest/main.cpp | |||
@@ -0,0 +1,38 @@ | |||
1 | #include "calendar_generated.h" | ||
2 | #include <iostream> | ||
3 | #include <fstream> | ||
4 | |||
5 | using namespace Calendar; | ||
6 | using namespace flatbuffers; | ||
7 | |||
8 | std::string createEvent() | ||
9 | { | ||
10 | FlatBufferBuilder fbb; | ||
11 | { | ||
12 | auto summary = fbb.CreateString("summary"); | ||
13 | const int attachmentSize = 1024 * 1024; // 1MB | ||
14 | int8_t rawData[attachmentSize]; | ||
15 | auto data = fbb.CreateVector(rawData, attachmentSize); | ||
16 | |||
17 | Calendar::EventBuilder eventBuilder(fbb); | ||
18 | eventBuilder.add_summary(summary); | ||
19 | eventBuilder.add_attachment(data); | ||
20 | auto eventLocation = eventBuilder.Finish(); | ||
21 | FinishEventBuffer(fbb, eventLocation); | ||
22 | } | ||
23 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
24 | } | ||
25 | |||
26 | void readEvent(const std::string &data) | ||
27 | { | ||
28 | auto readEvent = GetEvent(data.c_str()); | ||
29 | std::cout << readEvent->summary()->c_str() << std::endl; | ||
30 | } | ||
31 | |||
32 | int main(int argc, char **argv) | ||
33 | { | ||
34 | std::ofstream myfile; | ||
35 | myfile.open ("buffer.fb"); | ||
36 | myfile << createEvent(); | ||
37 | myfile.close(); | ||
38 | } | ||