@echo off
:: Compiles a flatbuffers definition file (fbs) to binary format (*.bfbs) for usage with the Key Value Database (KVD) App.
::
:: 1. Download the latest SDK to get the Flatbuffers compiler flatc from here: https://github.com/boschrexroth/ctrlx-automation-sdk/releases/latest
:: 2. Modify the paths of the flatc and the fbs file.
:: 3. Execute this batch file.
::
:: For more options of the flatc compiler, please see here: https://flatbuffers.dev/flatbuffers_guide_using_schema_compiler.html

set FLATC=flatc.exe
set FBS_FILE=st_TeachPoints.fbs

if not exist %FLATC% (
	echo %FLATC% not found
    goto error
)

if not exist %FBS_FILE% (
	echo %FBS_FILE% not found
    goto error
)

"%FLATC%" --binary --schema --bfbs-comments --bfbs-builtins --no-warnings -o "%CD%" "%FBS_FILE%"
if %ERRORLEVEL% NEQ 0 (	
	goto error
)

::--------------------------------------
:: ERROR HANDLING
::--------------------------------------
::ECHO %ERRORLEVEL%
:success
	color A0
	pause
	exit 0
	
:error
	color C0
	pause
	exit \B %ERRORLEVEL%
