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 | |
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.
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | buffertest/CMakeLists.txt | 26 | ||||
-rw-r--r-- | buffertest/calendar.fbs | 12 | ||||
-rw-r--r-- | buffertest/main.cpp | 38 |
4 files changed, 79 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 469c5c3..e0e3796 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -29,4 +29,7 @@ add_subdirectory(client) | |||
29 | # the resource | 29 | # the resource |
30 | add_subdirectory(resource) | 30 | add_subdirectory(resource) |
31 | 31 | ||
32 | # the buffertest | ||
33 | add_subdirectory(buffertest) | ||
34 | |||
32 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | 35 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) |
diff --git a/buffertest/CMakeLists.txt b/buffertest/CMakeLists.txt new file mode 100644 index 0000000..9505b75 --- /dev/null +++ b/buffertest/CMakeLists.txt | |||
@@ -0,0 +1,26 @@ | |||
1 | project(toynadi_buffertest) | ||
2 | |||
3 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | ||
4 | |||
5 | set(toynadinbuffertest_SRCS | ||
6 | main.cpp | ||
7 | ) | ||
8 | |||
9 | set(SCHEMAS calendar.fbs) | ||
10 | set(SCHEMA_SOURCEFILES calendar_generated.h) | ||
11 | |||
12 | add_custom_command(OUTPUT ${SCHEMA_SOURCEFILES} | ||
13 | COMMAND flatc -c ${CMAKE_CURRENT_SOURCE_DIR}/calendar.fbs | ||
14 | COMMENT "Generating buffers" | ||
15 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
16 | DEPENDS ${SCHEMAS} | ||
17 | VERBATIM | ||
18 | ) | ||
19 | |||
20 | SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1) | ||
21 | ADD_CUSTOM_TARGET(generate_buffers ALL DEPENDS ${SCHEMA_SOURCEFILES}) | ||
22 | |||
23 | add_executable(${PROJECT_NAME} ${toynadinbuffertest_SRCS}) | ||
24 | qt5_use_modules(${PROJECT_NAME} Core) | ||
25 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) | ||
26 | |||
diff --git a/buffertest/calendar.fbs b/buffertest/calendar.fbs new file mode 100644 index 0000000..203ee43 --- /dev/null +++ b/buffertest/calendar.fbs | |||
@@ -0,0 +1,12 @@ | |||
1 | // example IDL file | ||
2 | |||
3 | namespace Calendar; | ||
4 | |||
5 | table Event { | ||
6 | summary:string; | ||
7 | description:string; | ||
8 | attachment:[byte]; | ||
9 | } | ||
10 | |||
11 | root_type Event; | ||
12 | file_identifier "AKFB"; | ||
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 | } | ||