From 85860fbe47ca5ec24c70966f42a53162d761b91f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 21 Nov 2014 15:08:39 +0100 Subject: A buffertest that currently does nothing else than writing a buffer to a file. --- CMakeLists.txt | 3 +++ buffertest/CMakeLists.txt | 26 ++++++++++++++++++++++++++ buffertest/calendar.fbs | 12 ++++++++++++ buffertest/main.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 buffertest/CMakeLists.txt create mode 100644 buffertest/calendar.fbs create mode 100644 buffertest/main.cpp 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) # the resource add_subdirectory(resource) +# the buffertest +add_subdirectory(buffertest) + 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 @@ +project(toynadi_buffertest) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +set(toynadinbuffertest_SRCS + main.cpp +) + +set(SCHEMAS calendar.fbs) +set(SCHEMA_SOURCEFILES calendar_generated.h) + +add_custom_command(OUTPUT ${SCHEMA_SOURCEFILES} + COMMAND flatc -c ${CMAKE_CURRENT_SOURCE_DIR}/calendar.fbs + COMMENT "Generating buffers" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${SCHEMAS} + VERBATIM +) + +SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1) +ADD_CUSTOM_TARGET(generate_buffers ALL DEPENDS ${SCHEMA_SOURCEFILES}) + +add_executable(${PROJECT_NAME} ${toynadinbuffertest_SRCS}) +qt5_use_modules(${PROJECT_NAME} Core) +install(TARGETS ${PROJECT_NAME} DESTINATION bin) + 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 @@ +// example IDL file + +namespace Calendar; + +table Event { + summary:string; + description:string; + attachment:[byte]; +} + +root_type Event; +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 @@ +#include "calendar_generated.h" +#include +#include + +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(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(); +} -- cgit v1.2.3