blob: 5bc2326c40db735706874abb3142c302b63def11 (
plain)
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
|
#include "calendar_generated.h"
#include <iostream>
#include <fstream>
using namespace Calendar;
using namespace flatbuffers;
std::string createEvent()
{
FlatBufferBuilder fbb;
{
auto summary = fbb.CreateString("summary");
const int attachmentSize = 1024 * 1024; // 1MB
int8_t rawData[attachmentSize];
auto data = fbb.CreateVector(rawData, attachmentSize);
Calendar::EventBuilder eventBuilder(fbb);
eventBuilder.add_summary(summary);
eventBuilder.add_attachment(data);
auto eventLocation = eventBuilder.Finish();
FinishEventBuffer(fbb, eventLocation);
}
return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
}
void readEvent(const std::string &data)
{
auto readEvent = GetEvent(data.c_str());
std::cout << readEvent->summary()->c_str() << std::endl;
}
int main(int argc, char **argv)
{
std::ofstream myfile;
myfile.open ("buffer.fb");
myfile << createEvent();
myfile.close();
}
|