Skip to content

Commit

Permalink
flatc.md Add more documentation (#8467)
Browse files Browse the repository at this point in the history
* CNAME: add custom domain

* `flatc.md`: Add more documentation
  • Loading branch information
dbaileychess authored Dec 24, 2024
1 parent 28ddfae commit c9125e6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/source/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Once the project files are generated, build as normal for your platform.
=== "Unix"

```sh
make flatc
make -j
```

=== "Windows"
Expand All @@ -50,6 +50,12 @@ Once the project files are generated, build as normal for your platform.
msbuild.exe FlatBuffers.sln
```

=== "MacOS"

```sh
xcodebuild -toolchain clang -configuration Release
```

## Building with Bazel

## Building with VCPKG
85 changes: 83 additions & 2 deletions docs/source/flatc.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,88 @@
# FlatBuffers Compiler (`flatc`)

The main compiler for FlatBuffers is called `flatc` and is used as follows:
The main compiler for FlatBuffers is called `flatc` and is used to convert
schema definitions into generated code files for a variety of languages.

After [building](building.md) `flatc`, it is used as follows:

```sh
flatc [ GENERATOR_OPTIONS ] [ -o PATH ] [- I PATH ] FILES... [ -- BINARY_FILES... ]
flatc [ GENERATOR_OPTIONS ] [ -o PATH ] [- I PATH ]
FILES...
[ -- BINARY_FILES... ]
```

* The `GENERATOR_OPTIONS` specify the language(s) to compile code for as well as
various features to enable/disable.

* The `-o PATH` specifies the path where the generated files are placed. It
defaults to the current path if not specified.

* The `-I PATH` specifies the paths where included schema files are located. It
defaults to the current path if not specified.

## Input Files

`FILES...` specifies one or more schema or data files to process. They are
processed in the order provided.

### Schema Files

For schema files, language specifiers indicate what languages to generate code
for.

* `--cpp`: C++
* `--java`: Java
* `--kotlin`: Kotlin
* `--csharp`: C#
* `--go`: Golang
* `--python`: Python
* `--js`: JavaScript
* `--ts`: TypeScript
* `--php`: PHP
* `--dart`: Dart
* `--lua`: Lua
* `--lobster`: Lobster
* `--rust`: Rust
* `--swift`: Swift
* `--nim`: Nim

Additionally, adding:

* `--grpc` Will generate RPC stub code for gRPC (not available in all
languages)

### Data Files

If `FILES...` contain data files, they can be exported to either a binary or
JSON representation.

* `--binary`, `-b`: Generate a binary file containing a serialized flatbuffer.
* `--json`, `-j`: Generate JSON file from a serialized flatbuffer.

Both options require the corresponding schema file to be included first in the
list of `FILES...`.

=== "To Binary"

To serialize the JSON data in `mydata.json` using the schema `myschema.fbs`:

```sh
flatc --binary myschema.fbs mydata.json
```

This will generate a `mydata_wire.bin` file containing the serialized
flatbuffer data.

=== "To JSON"

To convert the serialized binary flatbuffer `mydata.bin` using the schema
`myschema.fbs` to JSON:

```sh
flatc --json myschema.fbs mydata.bin
```

This will generate a `mydata.json` file.



0 comments on commit c9125e6

Please sign in to comment.