/RLOSF-Screening-Exercise-Flatbuffers

Screening exercise submission for "Improve flatbuffer parser support in VowpalWabbit" project of RLOSF 2022

Primary LanguageC++

RL Open Source Fest Screening Exercise 2022

General Description

This repository contains the files created on completing the screening exercise of "Improve flatbuffer parser support in VowpalWabbit" RLOSF 2022 Project. This is one of the projects of RLOSF to which I am interested in contributing.

Submitted by: Sharvani Laxmi Somayaji
OS used: Windows 10
cmake version: 3.22.0-rc2
g++.exe (GCC): 8.3.0

Description of the Screening exercise

Create a simple flatbuffer schema file. It should be a table with 3 fields:
a_name – string
a_value – float
a_flag - bool

The flatbuffer schema file has been created and can be found in screening_schema.fbs

Create a C++ command line application that writes data to a file using the flatbuffer schema.

For this purpose, write_data.cpp has been created.

Create a C++ command line application that reads the file from previous step and writes the contents to stdout.

For this purpose, read_data.cpp has been created.

Note:

All the files created can be found in this repository. For this purpose, none have been added to .gitignore.

Instructions to build and run the applications:

  • Clone this repository and go to the location of the cloned repo.

  • Go to the schema subfolder.

    cd schema
    
  • Get flatc. Note that this repository already contains the executable file.

    • At the beginning we have to get flatc -- FlatBuffers compiler. It can be built from source code hosted in Google's flatbuffers repository.
    git clone https://github.com/google/flatbuffers.git
    cd flatbuffers
    
    • Build using cmake: (Run the command on the basis of your platform. I have used the first command out of the below three)
    cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
    cmake -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Release
    cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release
    
    • Build as normal for your platform. This should result in a flatc executable. I have generated the Binaries outside the root repository and built them using the make command. After this, I have pasted the generated flatc.exe file in the schema folder in the repository.
  • Generate the C++ header screening_schema_generated.h from the schema screening_schema.fbs using the compiler as follows:

    ./flatc --cpp screening_schema.fbs
    
  • As screening_schema_generated.h header relies on flatbuffers/flatbuffers.h, it needs to be in the include path. One of the ways to do this would be by adding it to the environment variable as follows: image

  • Go back to the root of the repository

    cd ..
    
  • Write the data to a file, data.bin using the flatbuffer schema using the following commands:

    g++ write_data.cpp -o main
    
    ./main Sharvani 12.2 1
    

    The above command takes input from the command line as follows:

    ./main <string> <float> <bool>
    
  • Read the data to a file, data.bin and write the contents to stdout using the following commands:

    g++ read_data.cpp -o main
    
    ./main
    

Output obtained from Step 2 of the Screening exercise:

Example (1)

image

Example (2)

image

Output obtained from the last step (Step 3 of the Screening exercise):

Example (1)

image

Example (2)

image