├── .clang-format ├── .github └── workflows │ ├── cpp.yml │ ├── dot.yml │ ├── generator.yml │ ├── py.yml │ └── rust.yml ├── .gitignore ├── LICENSE ├── README.md ├── ci ├── dot_test_cases.sh └── lint.py ├── docs ├── logo.svg ├── schema-language.md └── why-flatdata.md ├── examples ├── README.md ├── binary_layout.flatdata ├── coappearances │ ├── coappearances.flatdata │ └── karenina.json ├── fibonacci.flatdata └── graph.flatdata ├── flatdata-cpp ├── CMakeLists.txt ├── README.md ├── benchmark │ ├── BreadthFirstSearch.h │ ├── CMakeLists.txt │ ├── Dijkstra.h │ ├── FlatdataGraph.h │ ├── GraphGenerator.h │ ├── Lookup.h │ ├── Printer.h │ ├── StructGraph.h │ ├── graph.flatdata │ ├── main.cpp │ └── run.py ├── ci │ ├── Dockerfile │ └── build-and-test-cpp.sh ├── cmake │ └── flatdata │ │ └── GenerateSource.cmake ├── examples │ ├── CMakeLists.txt │ ├── binary_layout.cpp │ ├── coappearances │ │ ├── coappearances.cpp │ │ └── picojson.h │ ├── fibonacci.cpp │ └── graph.cpp ├── include │ └── flatdata │ │ ├── Archive.h │ │ ├── ArchiveBuilder.h │ │ ├── ArrayView.h │ │ ├── Copy.h │ │ ├── DebugDataAccessStatistics.h │ │ ├── ExternalVector.h │ │ ├── FileResourceStorage.h │ │ ├── Hash.h │ │ ├── MemoryDescriptor.h │ │ ├── MemoryMappedFileStorage.h │ │ ├── MemoryMappedTarFileStorage.h │ │ ├── MemoryResourceStorage.h │ │ ├── MultiArrayView.h │ │ ├── MultiVector.h │ │ ├── ResourceStorage.h │ │ ├── Struct.h │ │ ├── TarArchiveResourceStorage.h │ │ ├── Vector.h │ │ ├── flatdata.h │ │ └── internal │ │ ├── ArchiveUtils.h │ │ ├── ArrayView.inl │ │ ├── ArrayViewIterator.h │ │ ├── ArrayViewIterator.inl │ │ ├── BitHelpers.h │ │ ├── Constants.h │ │ ├── MultiArrayViewImpl.h │ │ ├── Reader.h │ │ ├── ResourceHandle.h │ │ ├── ResourceStorage.inl │ │ ├── ResourceStorageCommon.h │ │ ├── TarReader.h │ │ ├── Writer.h │ │ └── functional │ │ ├── FuncTraits.h │ │ ├── StaticList.h │ │ ├── Tagged.h │ │ └── Utility.h ├── src │ ├── Archive.cpp │ ├── ArchiveBuilder.cpp │ ├── ResourceStorage.cpp │ └── TarReader.cpp ├── test │ ├── ArrayViewTest.cpp │ ├── BackwardCompatibilityTest.cpp │ ├── CMakeLists.txt │ ├── EnumTest.cpp │ ├── ExternalVectorTest.cpp │ ├── FuncTraitsTest.cpp │ ├── GeneratedArchiveTest.cpp │ ├── MultiVectorTest.cpp │ ├── ResourceStorageTest.cpp │ ├── SerializedStructTest.cpp │ ├── StaticListTest.cpp │ ├── StructTest.cpp │ ├── TarReaderTest.cpp │ ├── VectorTest.cpp │ ├── WriterReaderTest.cpp │ ├── main.cpp │ ├── test_structures.flatdata │ └── test_structures2.flatdata └── vendor │ ├── catch_amalgamated.cpp │ ├── catch_amalgamated.hpp │ └── docopt │ ├── LICENSE-MIT │ ├── docopt.cpp │ ├── docopt.h │ ├── docopt_private.h │ ├── docopt_util.h │ └── docopt_value.h ├── flatdata-generator ├── .pylintrc ├── README.md ├── flatdata │ └── generator │ │ ├── __init__.py │ │ ├── app.py │ │ ├── engine.py │ │ ├── generators │ │ ├── __init__.py │ │ ├── cpp.py │ │ ├── dot.py │ │ ├── flatdata.py │ │ ├── go.py │ │ ├── python.py │ │ └── rust.py │ │ ├── grammar.py │ │ ├── templates │ │ ├── __init__.py │ │ ├── cpp │ │ │ ├── __init__.py │ │ │ ├── archive.jinja2 │ │ │ ├── constant.jinja2 │ │ │ ├── cpp.jinja2 │ │ │ ├── enumeration.jinja2 │ │ │ ├── namespace.jinja2 │ │ │ ├── resource.jinja2 │ │ │ └── structure.jinja2 │ │ ├── dot │ │ │ ├── __init__.py │ │ │ ├── archive.jinja2 │ │ │ ├── dot.jinja2 │ │ │ ├── namespace.jinja2 │ │ │ ├── references.jinja2 │ │ │ ├── render.jinja2 │ │ │ ├── resource.jinja2 │ │ │ ├── structure.jinja2 │ │ │ └── styles.jinja2 │ │ ├── flatdata │ │ │ ├── __init__.py │ │ │ ├── archive.jinja2 │ │ │ ├── constant.jinja2 │ │ │ ├── enumeration.jinja2 │ │ │ ├── flatdata.jinja2 │ │ │ ├── namespace.jinja2 │ │ │ ├── resource.jinja2 │ │ │ └── structure.jinja2 │ │ ├── go │ │ │ ├── __init__.py │ │ │ ├── archive.jinja2 │ │ │ ├── base.jinja2 │ │ │ ├── go.jinja2 │ │ │ ├── instance.jinja2 │ │ │ ├── multivector.jinja2 │ │ │ ├── rawdata.jinja2 │ │ │ ├── structure.jinja2 │ │ │ └── vector.jinja2 │ │ ├── py │ │ │ ├── __init__.py │ │ │ └── python.jinja2 │ │ └── rust │ │ │ ├── __init__.py │ │ │ ├── archive.jinja2 │ │ │ ├── constant.jinja2 │ │ │ ├── enumeration.jinja2 │ │ │ ├── index.jinja2 │ │ │ ├── rust.jinja2 │ │ │ ├── structure.jinja2 │ │ │ └── variadic.jinja2 │ │ └── tree │ │ ├── __init__.py │ │ ├── builder.py │ │ ├── errors.py │ │ ├── helpers │ │ ├── __init__.py │ │ ├── basictype.py │ │ └── enumtype.py │ │ ├── nodes │ │ ├── __init__.py │ │ ├── archive.py │ │ ├── explicit_reference.py │ │ ├── node.py │ │ ├── references.py │ │ ├── resources │ │ │ ├── __init__.py │ │ │ ├── archive.py │ │ │ ├── base.py │ │ │ ├── bound_resource.py │ │ │ ├── instance.py │ │ │ ├── multivector.py │ │ │ ├── rawdata.py │ │ │ └── vector.py │ │ ├── root.py │ │ └── trivial │ │ │ ├── __init__.py │ │ │ ├── constant.py │ │ │ ├── enumeration.py │ │ │ ├── enumeration_value.py │ │ │ ├── field.py │ │ │ ├── namespace.py │ │ │ └── structure.py │ │ ├── resolver.py │ │ ├── syntax_tree.py │ │ └── traversal.py ├── generator.py ├── pyproject.toml ├── requirements.txt └── tests │ ├── generators │ ├── __init__.py │ ├── assertions.py │ ├── cpp_expectations │ │ ├── archives │ │ │ ├── comments.h │ │ │ ├── empty.h │ │ │ ├── multivector.h.1 │ │ │ ├── multivector.h.2 │ │ │ ├── namespaces.h │ │ │ ├── ranges.h │ │ │ ├── raw_data.h.1 │ │ │ ├── raw_data.h.2 │ │ │ ├── references.h.1 │ │ │ ├── struct.h.1 │ │ │ ├── struct.h.2 │ │ │ ├── subarchive.h.1 │ │ │ ├── subarchive.h.2 │ │ │ ├── vector.h.1 │ │ │ └── vector.h.2 │ │ ├── constants │ │ │ ├── comments.h.1 │ │ │ ├── comments.h.2 │ │ │ ├── invalid_value.h │ │ │ ├── namespaces.h │ │ │ └── values.h │ │ ├── enums │ │ │ ├── comments.h.1 │ │ │ ├── comments.h.2 │ │ │ ├── default_width.h │ │ │ ├── implicit_values.h │ │ │ ├── namespaces.h.1 │ │ │ ├── namespaces.h.2 │ │ │ ├── structs.h │ │ │ ├── structs.h.1 │ │ │ ├── structs.h.2 │ │ │ ├── values.h.1 │ │ │ └── values.h.2 │ │ └── structs │ │ │ ├── comments.h.1 │ │ │ ├── comments.h.2 │ │ │ ├── default_width.h │ │ │ ├── integers.h.1 │ │ │ ├── integers.h.2 │ │ │ ├── namespaces.h.1 │ │ │ ├── namespaces.h.2 │ │ │ └── unaligned.h │ ├── dot_expectations │ │ ├── archives │ │ │ ├── comments.dot │ │ │ ├── empty.dot │ │ │ ├── multivector.dot │ │ │ ├── namespaces.dot │ │ │ ├── ranges.dot │ │ │ ├── raw_data.dot │ │ │ ├── references.dot │ │ │ ├── struct.dot │ │ │ ├── subarchive.dot │ │ │ └── vector.dot │ │ ├── constants │ │ │ ├── comments.dot │ │ │ ├── invalid_value.dot │ │ │ ├── namespaces.dot │ │ │ └── values.dot │ │ ├── enums │ │ │ ├── comments.dot │ │ │ ├── default_width.dot │ │ │ ├── implicit_values.dot │ │ │ ├── namespaces.dot │ │ │ ├── structs.dot │ │ │ └── values.dot │ │ └── structs │ │ │ ├── comments.dot │ │ │ ├── default_width.dot │ │ │ ├── integers.dot │ │ │ ├── namespaces.dot │ │ │ └── unaligned.dot │ ├── flatdata_expectations │ │ ├── archives │ │ │ ├── comments.flatdata │ │ │ ├── empty.flatdata │ │ │ ├── multivector.flatdata │ │ │ ├── namespaces.flatdata │ │ │ ├── ranges.flatdata │ │ │ ├── raw_data.flatdata │ │ │ ├── references.flatdata │ │ │ ├── struct.flatdata │ │ │ ├── subarchive.flatdata │ │ │ └── vector.flatdata │ │ ├── constants │ │ │ ├── comments.flatdata │ │ │ ├── invalid_value.flatdata │ │ │ ├── namespaces.flatdata │ │ │ └── values.flatdata │ │ ├── enums │ │ │ ├── comments.flatdata │ │ │ ├── default_width.flatdata │ │ │ ├── implicit_values.flatdata │ │ │ ├── namespaces.flatdata │ │ │ ├── structs.flatdata │ │ │ └── values.flatdata │ │ └── structs │ │ │ ├── comments.flatdata │ │ │ ├── default_width.flatdata │ │ │ ├── integers.flatdata │ │ │ ├── namespaces.flatdata │ │ │ └── unaligned.flatdata │ ├── go_expectations │ │ ├── archives │ │ │ ├── comments.go │ │ │ ├── empty.go │ │ │ ├── multivector.go │ │ │ ├── raw_data.go │ │ │ ├── references.go │ │ │ ├── struct.go │ │ │ ├── subarchive.go │ │ │ └── vector.go │ │ ├── constants │ │ │ ├── comments.go │ │ │ └── values.go │ │ └── structs │ │ │ ├── comments.go.1 │ │ │ ├── comments.go.2 │ │ │ ├── default_width.go │ │ │ ├── integers.go │ │ │ └── unaligned.go │ ├── py_expectations │ │ ├── archives │ │ │ ├── comments.py │ │ │ ├── empty.py │ │ │ ├── multivector.py │ │ │ ├── namespaces.py │ │ │ ├── ranges.py │ │ │ ├── raw_data.py │ │ │ ├── references.py │ │ │ ├── struct.py │ │ │ ├── subarchive.py │ │ │ └── vector.py │ │ └── structs │ │ │ ├── comments.py.1 │ │ │ ├── comments.py.2 │ │ │ ├── default_width.py │ │ │ ├── integers.py │ │ │ ├── namespaces.py │ │ │ └── unaligned.py │ ├── rust_expectations │ │ ├── archives │ │ │ ├── comments.rs.1 │ │ │ ├── empty.rs.1 │ │ │ ├── multivector.rs.1 │ │ │ ├── multivector.rs.2 │ │ │ ├── namespaces.rs.1 │ │ │ ├── ranges.rs.1 │ │ │ ├── raw_data.rs.1 │ │ │ ├── references.rs.1 │ │ │ ├── struct.rs.1 │ │ │ ├── subarchive.rs.1 │ │ │ └── vector.rs.1 │ │ ├── constants │ │ │ ├── comments.rs.1 │ │ │ ├── invalid_value.rs.1 │ │ │ ├── namespaces.rs.1 │ │ │ └── values.rs.1 │ │ ├── enums │ │ │ ├── comments.rs.1.1 │ │ │ ├── comments.rs.2.1 │ │ │ ├── default_width.rs.1 │ │ │ ├── implicit_values.rs.1 │ │ │ ├── namespaces.rs.1 │ │ │ ├── structs.rs.1 │ │ │ └── values.rs.1 │ │ ├── rustfmt.toml │ │ └── structs │ │ │ ├── comments.rs.1 │ │ │ ├── default_width.rs.1 │ │ │ ├── integers.rs.1 │ │ │ ├── namespaces.rs.1 │ │ │ └── unaligned.rs.1 │ ├── schemas.py │ ├── test_cpp_generator.py │ ├── test_dot_generator.py │ ├── test_flatdata_generator.py │ ├── test_go_generator.py │ ├── test_python_generator.py │ └── test_rust_generator.py │ └── tree │ ├── __init__.py │ ├── test_node.py │ ├── test_node_tree_builder.py │ ├── test_references.py │ ├── test_resolver.py │ ├── test_schema_resolution.py │ ├── test_syntax_tree.py │ └── test_syntax_tree_builder.py ├── flatdata-go ├── backward-compatibility-tests │ ├── Gopkg.lock │ ├── Gopkg.toml │ ├── LICENSE │ ├── Makefile │ ├── backward_compatibility_test.go │ ├── test_backward_compatibility.schema │ └── test_data.go └── flatdata │ ├── Gopkg.lock │ ├── Gopkg.toml │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── TODO.md │ ├── benchmarks_test.go │ ├── doc.go │ ├── memory_descriptor.go │ ├── reader.go │ ├── reader_test.go │ ├── resource.go │ ├── resource_test.go │ └── test_memory_descriptor.go ├── flatdata-py ├── .pylintrc ├── README.md ├── flatdata │ └── lib │ │ ├── __init__.py │ │ ├── archive.py │ │ ├── archive_builder.py │ │ ├── data_access.py │ │ ├── errors.py │ │ ├── file_resource_storage.py │ │ ├── file_resource_writer.py │ │ ├── flatdata_writer.py │ │ ├── inspector.py │ │ ├── resource_storage.py │ │ ├── resources.py │ │ ├── structure.py │ │ ├── tar_archive_resource_storage.py │ │ └── writer.py ├── inspector.py ├── pyproject.toml ├── requirements.txt ├── tests │ ├── common.py │ ├── test_archive_creation.py │ ├── test_archive_validation.py │ ├── test_backward_compatibility.py │ ├── test_data_access.py │ └── test_tar_resource_storage.py └── writer.py ├── flatdata-rs ├── .gitignore ├── Cargo.toml ├── README.md ├── ci │ └── coverage.sh ├── lib │ ├── Cargo.toml │ └── src │ │ ├── arrayview.rs │ │ ├── bytereader.rs │ │ ├── bytewriter.rs │ │ ├── error.rs │ │ ├── filestorage.rs │ │ ├── generator.rs │ │ ├── helper.rs │ │ ├── lib.rs │ │ ├── memory.rs │ │ ├── memstorage.rs │ │ ├── multiarrayview.rs │ │ ├── multivector.rs │ │ ├── rawdata.rs │ │ ├── storage.rs │ │ ├── structs.rs │ │ ├── tarstorage.rs │ │ ├── test │ │ ├── mod.rs │ │ ├── test.flatdata │ │ └── test_generated.rs │ │ └── vector.rs ├── rustfmt.toml └── tests │ ├── coappearances │ ├── Cargo.toml │ ├── assets │ │ ├── coappearances.flatdata │ │ ├── karenina.archive │ │ │ ├── Graph.archive │ │ │ ├── Graph.archive.schema │ │ │ ├── chapters │ │ │ ├── chapters.schema │ │ │ ├── edges │ │ │ ├── edges.schema │ │ │ ├── meta │ │ │ ├── meta.schema │ │ │ ├── statistics │ │ │ │ ├── Statistics.archive │ │ │ │ ├── Statistics.archive.schema │ │ │ │ ├── invariants │ │ │ │ ├── invariants.schema │ │ │ │ ├── vertex_degrees │ │ │ │ └── vertex_degrees.schema │ │ │ ├── strings │ │ │ ├── strings.schema │ │ │ ├── vertices │ │ │ ├── vertices.schema │ │ │ ├── vertices_data │ │ │ ├── vertices_data.schema │ │ │ ├── vertices_data_index │ │ │ └── vertices_data_index.schema │ │ ├── karenina.json │ │ └── karenina.tar │ ├── build.rs │ └── src │ │ ├── coappearances.rs │ │ └── lib.rs │ └── features │ ├── Cargo.toml │ ├── build.rs │ └── src │ ├── archives │ ├── empty.rs │ ├── mod.rs │ ├── multivector.rs │ ├── namespaces.rs │ ├── ranges.rs │ ├── raw_data.rs │ ├── references.rs │ ├── struct_in_archive.rs │ ├── subarchive.rs │ └── vector.rs │ ├── constants │ ├── invalid_value.rs │ ├── mod.rs │ ├── namespaces.rs │ └── values.rs │ ├── enums │ ├── mod.rs │ ├── namespaces.rs │ ├── structs.rs │ └── values.rs │ ├── lib.rs │ └── structs │ ├── integers.rs │ ├── mod.rs │ ├── namespaces.rs │ └── unaligned.rs ├── generator ├── inspector ├── lgtm.yml ├── test_cases ├── README.md ├── archives │ ├── comments.flatdata │ ├── empty.flatdata │ ├── multivector.flatdata │ ├── namespaces.flatdata │ ├── ranges.flatdata │ ├── raw_data.flatdata │ ├── references.flatdata │ ├── struct.flatdata │ ├── subarchive.flatdata │ └── vector.flatdata ├── constants │ ├── comments.flatdata │ ├── invalid_value.flatdata │ ├── namespaces.flatdata │ └── values.flatdata ├── enums │ ├── comments.flatdata │ ├── default_width.flatdata │ ├── implicit_values.flatdata │ ├── namespaces.flatdata │ ├── structs.flatdata │ └── values.flatdata └── structs │ ├── comments.flatdata │ ├── default_width.flatdata │ ├── integers.flatdata │ ├── namespaces.flatdata │ └── unaligned.flatdata └── writer /.clang-format: -------------------------------------------------------------------------------- 1 | # Clang-format v14 based configuration 2 | --- 3 | BasedOnStyle: Google 4 | Language: Cpp 5 | Standard: c++17 6 | AccessModifierOffset: -4 7 | AllowShortFunctionsOnASingleLine : None 8 | AllowShortIfStatementsOnASingleLine: Never 9 | AllowShortLoopsOnASingleLine: false 10 | AlwaysBreakAfterDefinitionReturnType: All 11 | BinPackParameters: false 12 | BreakBeforeBinaryOperators: All 13 | BreakBeforeBraces: Allman 14 | BreakBeforeTernaryOperators: true 15 | BreakConstructorInitializers: BeforeComma 16 | ColumnLimit: 100 17 | PackConstructorInitializers: BinPack 18 | IndentCaseLabels : false 19 | IndentWidth: 4 20 | PenaltyBreakComment: 60 21 | SortIncludes: Never 22 | SortUsingDeclarations: false 23 | SpacesInContainerLiterals: false 24 | SpacesInAngles: Always 25 | SpacesInParentheses: true 26 | SpaceInEmptyParentheses: true 27 | SpacesInSquareBrackets: true 28 | SpaceInEmptyBlock: false 29 | TabWidth: 4 30 | Cpp11BracedListStyle: false 31 | SpaceBeforeCpp11BracedList: false 32 | SpacesInCStyleCastParentheses: false 33 | BreakBeforeBraces: Custom 34 | BraceWrapping: 35 | AfterCaseLabel: true 36 | AfterClass: true 37 | AfterControlStatement: Always 38 | AfterEnum: true 39 | AfterFunction: true 40 | AfterNamespace: true 41 | AfterObjCDeclaration: true 42 | AfterStruct: true 43 | AfterUnion: true 44 | AfterExternBlock: true 45 | BeforeCatch: true 46 | BeforeElse: true 47 | BeforeLambdaBody: false 48 | BeforeWhile: false 49 | IndentBraces: false 50 | SplitEmptyFunction: true 51 | SplitEmptyRecord: true 52 | SplitEmptyNamespace: true 53 | ... 54 | -------------------------------------------------------------------------------- /.github/workflows/cpp.yml: -------------------------------------------------------------------------------- 1 | name: flatdata-cpp 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | workflow_dispatch: 8 | 9 | env: 10 | CARGO_TERM_COLORS: always 11 | 12 | jobs: 13 | GCC: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | debug-stats: ["", "-DWITH_DEBUG_DATA_ACCESS_STATISTICS=ON"] 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Dependencies 21 | run: sudo apt-get install python3-pip python3-setuptools libboost-filesystem-dev 22 | - name: Generator 23 | run: pip3 install ./flatdata-generator 24 | - name: Build and Test 25 | run: | 26 | CC=gcc CXX=g++ EXTRA_CMAKE_ARGS=${{ matrix.debug-stats }} flatdata-cpp/ci/build-and-test-cpp.sh 27 | Clang: 28 | runs-on: ubuntu-latest 29 | strategy: 30 | matrix: 31 | debug-stats: ["", "-DWITH_DEBUG_DATA_ACCESS_STATISTICS=ON"] 32 | steps: 33 | - uses: actions/checkout@v2 34 | - name: Dependencies 35 | run: sudo apt-get install python3-pip python3-setuptools libboost-filesystem-dev 36 | - name: Generator 37 | run: pip3 install ./flatdata-generator 38 | - name: Build and Test 39 | run: | 40 | CC=clang CXX=clang++ EXTRA_CMAKE_ARGS=${{ matrix.debug-stats }} flatdata-cpp/ci/build-and-test-cpp.sh 41 | -------------------------------------------------------------------------------- /.github/workflows/dot.yml: -------------------------------------------------------------------------------- 1 | name: flatdata-dot 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | workflow_dispatch: 8 | 9 | env: 10 | CARGO_TERM_COLORS: always 11 | 12 | jobs: 13 | Build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Dependencies 18 | run: sudo apt-get install graphviz 19 | - name: Generator 20 | run: pip3 install ./flatdata-generator 21 | - name: Build and Test 22 | run: | 23 | ci/dot_test_cases.sh 24 | -------------------------------------------------------------------------------- /.github/workflows/generator.yml: -------------------------------------------------------------------------------- 1 | name: flatdata-generator 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | workflow_dispatch: 8 | 9 | env: 10 | CARGO_TERM_COLORS: always 11 | 12 | jobs: 13 | Build: 14 | runs-on: ubuntu-20.04 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Install 18 | run: | 19 | cd flatdata-generator 20 | # runtime requirements 21 | pip install -r requirements.txt 22 | # CI requirements 23 | pip install nose pylint 24 | - name: Run tests 25 | run: | 26 | cd flatdata-generator 27 | python -m nose 28 | pip install . 29 | flatdata-generator --help -------------------------------------------------------------------------------- /.github/workflows/py.yml: -------------------------------------------------------------------------------- 1 | name: flatdata-py 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | workflow_dispatch: 8 | 9 | env: 10 | CARGO_TERM_COLORS: always 11 | 12 | jobs: 13 | Build: 14 | runs-on: ubuntu-20.04 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Install 18 | run: | 19 | pip install ./flatdata-generator 20 | cd flatdata-py 21 | # runtime requirements 22 | pip install -r requirements.txt 23 | # CI requirements 24 | pip install nose pylint 25 | - name: Run tests 26 | run: | 27 | cd flatdata-py 28 | python -m nose 29 | pip install . 30 | flatdata-inspector --help -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: flatdata-rs 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | workflow_dispatch: 8 | 9 | env: 10 | CARGO_TERM_COLORS: always 11 | 12 | jobs: 13 | Build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Dependencies 18 | run: sudo apt-get install python3-venv 19 | - name: Build 20 | run: | 21 | # use generator from source 22 | export FLATDATA_GENERATOR_PATH=${PWD}/flatdata-generator 23 | cd flatdata-rs 24 | cargo build --all-targets 25 | cargo build --all-targets --all-features 26 | - name: Run tests 27 | run: | 28 | # use generator from source 29 | export FLATDATA_GENERATOR_PATH=${PWD}/flatdata-generator 30 | cd flatdata-rs 31 | cargo test --all-targets 32 | cargo test --all-targets --all-features 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.pyc 2 | __pycache__ 3 | build 4 | venv* 5 | **/.vscode/** 6 | **/.idea/** 7 | **/*_generated.go 8 | **/coverage.out 9 | **/flatdata-fuzz.zip 10 | **/corpus/** 11 | **/dist/** 12 | *.egg-info 13 | .DS_Store 14 | *.bak 15 | -------------------------------------------------------------------------------- /ci/dot_test_cases.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | for x in $(find test_cases -name "*.flatdata") 6 | do 7 | echo $x 8 | ./generator -s $x -g dot -O test.dot 9 | dot -Tsvg -O test.dot 10 | echo Done 11 | done -------------------------------------------------------------------------------- /ci/lint.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | from pylint.lint import Run 4 | 5 | THRESHOLD = 6.00 6 | 7 | results = Run(['flatdata-py'], do_exit=False) 8 | score = results.linter.stats['global_note'] 9 | 10 | if score < THRESHOLD: 11 | print("pylint score below acceptable threshold of %.2f/10!" % THRESHOLD, file=sys.stderr) 12 | sys.exit(1) -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | Flatdata Usage Examples 2 | ======================= 3 | 4 | This folder contains examples of flatdata usage. Those are meant to show how 5 | to use serialization/deserialization APIs and different resource types available. 6 | 7 | Binary Layout Example 8 | --------------------- 9 | 10 | This example writes a simple not aligned data structure (23 bits long) to a flatdata vector. 11 | The structure is filled with ones and zeroes to make it easier to see how different fields are 12 | stored. 13 | 14 | Two structures are written to the output to show the structure alignment and padding. 15 | 16 | Coappearances 17 | ------------- 18 | 19 | This examples converts a graph of coappearances from json to flatdata. A graph of coappearances is 20 | an undirected graph where the vertices are characters from a book. An edge between two characters 21 | represents their appearance in the same scene. 22 | 23 | The idea of this example to show how to convert a nested data format to a flat representation. Further, the example introduces 24 | 25 | * all available data structures in flatdata, 26 | * a technique how to represent ranges with sentinels, and 27 | * representation of strings as raw blocks. 28 | 29 | The examples also contains a simple reader which dumps the flatdata archive to terminal. 30 | 31 | The data [karenina.json](coappearances/karenina.json) is based on characters coappearance in Leo Tolstoy's "_Anna 32 | Karenina_", compiled by [Donald Knuth][1]. 33 | 34 | [1]: https://www-cs-faculty.stanford.edu/~knuth/sgb.html 35 | -------------------------------------------------------------------------------- /examples/binary_layout.flatdata: -------------------------------------------------------------------------------- 1 | namespace binary_layout { 2 | 3 | struct UnalignedStructure { 4 | f0 : u8 : 4; 5 | f1 : u16 : 16; 6 | f2 : u8 : 3; 7 | } 8 | 9 | archive BinaryLayout { 10 | alignment_example : vector< UnalignedStructure >; 11 | } 12 | 13 | } // demo 14 | -------------------------------------------------------------------------------- /examples/fibonacci.flatdata: -------------------------------------------------------------------------------- 1 | namespace fib { 2 | struct Number { 3 | value : u64 : 64; 4 | } 5 | 6 | archive Fibonacci { 7 | numbers: vector< Number >; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/graph.flatdata: -------------------------------------------------------------------------------- 1 | namespace graph { 2 | /** 3 | * A vertex is point in a plane. 4 | */ 5 | struct Vertex { 6 | x : u32 : 16; 7 | y : u32 : 16; 8 | } 9 | 10 | /** 11 | * An edge connects two vertices by referencing their indexes. 12 | */ 13 | struct Edge { 14 | from_ref : u32 : 16; 15 | to_ref : u32 : 16; 16 | } 17 | 18 | archive Graph { 19 | vertices : vector< Vertex >; 20 | 21 | @explicit_reference( Edge.from_ref, vertices ) 22 | @explicit_reference( Edge.to_ref, vertices ) 23 | edges : vector< Edge >; 24 | } 25 | } // namespace graph -------------------------------------------------------------------------------- /flatdata-cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | project(flatdata-cpp) 3 | 4 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") 5 | include(flatdata/GenerateSource) 6 | 7 | set(CMAKE_CXX_STANDARD 17) 8 | 9 | find_package(Boost COMPONENTS system filesystem REQUIRED) 10 | find_package(Threads REQUIRED) 11 | 12 | file(GLOB FLATDATA_SOURCE 13 | "src/*.h" 14 | "src/*.inl" 15 | "src/*.cpp") 16 | 17 | add_library(flatdata STATIC ${FLATDATA_SOURCE}) 18 | 19 | set_target_properties(flatdata PROPERTIES POSITION_INDEPENDENT_CODE ON) 20 | 21 | if(WITH_DEBUG_DATA_ACCESS_STATISTICS) 22 | message(STATUS "WITH_DEBUG_DATA_ACCESS_STATISTICS enabled") 23 | target_compile_definitions(flatdata PUBLIC DEBUG_DATA_ACCESS_STATISTICS) 24 | endif() 25 | 26 | target_include_directories(flatdata 27 | PUBLIC $ 28 | PUBLIC $ 29 | PUBLIC ${Boost_INCLUDE_DIRS}) 30 | 31 | target_link_libraries(flatdata 32 | ${Boost_LIBRARIES} 33 | ${CMAKE_THREAD_LIBS_INIT}) 34 | 35 | enable_testing() 36 | add_subdirectory(test) 37 | add_subdirectory(benchmark) 38 | add_subdirectory(examples) -------------------------------------------------------------------------------- /flatdata-cpp/benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT ${UNIX}) 2 | return() 3 | endif() 4 | 5 | file(GLOB BENCHMARK_FLATDATA_SOURCES "*.cpp") 6 | 7 | flatdata_generate_source(generate_flatdata_benchmark_code 8 | ${CMAKE_CURRENT_SOURCE_DIR}/graph.flatdata 9 | ${CMAKE_CURRENT_BINARY_DIR}/generated/graph.hpp) 10 | 11 | add_executable(flatdata_benchmark ${BENCHMARK_FLATDATA_SOURCES}) 12 | add_dependencies(flatdata_benchmark generate_flatdata_benchmark_code) 13 | 14 | target_include_directories(flatdata_benchmark 15 | PRIVATE ${GTEST_INCLUDE_DIRS} 16 | PRIVATE ${Boost_INCLUDE_DIRS} 17 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated 18 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor) 19 | 20 | target_link_libraries(flatdata_benchmark 21 | flatdata) 22 | 23 | include(InstallTarget OPTIONAL RESULT_VARIABLE HAS_INSTALL_TARGET) 24 | if(HAS_INSTALL_TARGET) 25 | install_with_depends(flatdata_benchmark bin lib flatdata_benchmark_component) 26 | install_with_depends(run.py bin lib flatdata_benchmark_component) 27 | endif() 28 | 29 | set_property(TARGET flatdata_benchmark PROPERTY FOLDER "flatdata") 30 | -------------------------------------------------------------------------------- /flatdata-cpp/benchmark/Lookup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "GraphGenerator.h" 5 | 6 | /// Performance search for edges in the graph by their id. Essentially runs one binary search for 7 | /// each edge in the graph in each iteration. 8 | template < typename Graph > 9 | void 10 | lookup( const Graph& graph, uint32_t num_iterations ) 11 | { 12 | uint32_t num_buckets = sqrt( graph.node_count( ) ); 13 | std::mt19937 gen( 1337 ); 14 | std::uniform_int_distribution< uint32_t > dis( 0, num_buckets - 1 ); 15 | for ( uint32_t i = 0; i < num_iterations; i++ ) 16 | { 17 | std::vector< std::vector< std::pair< InternalId, ExternalId > > > buckets( num_buckets ); 18 | 19 | for ( uint32_t edge_index = 0; edge_index < graph.edge_count( ); edge_index++ ) 20 | { 21 | InternalId id{ edge_index }; 22 | auto edge = graph.edge( id ); 23 | buckets[ dis( gen ) ].emplace_back( id, edge.external_id( ) ); 24 | } 25 | uint32_t num_not_found = 0; 26 | for ( auto& bucket : buckets ) 27 | { 28 | for ( auto& ids : bucket ) 29 | { 30 | auto found = graph.find( ids.second ); 31 | if ( found.id( ).id != ids.first.id ) 32 | { 33 | num_not_found++; 34 | } 35 | } 36 | } 37 | std::cout << "Not found: " << num_not_found << std::endl; 38 | } 39 | } -------------------------------------------------------------------------------- /flatdata-cpp/benchmark/graph.flatdata: -------------------------------------------------------------------------------- 1 | namespace benchmark { 2 | 3 | // Each edge has: 4 | // * data 5 | // * a from node 6 | // * a to node 7 | struct EdgeData{ 8 | id: u64; 9 | from: u32; 10 | to: u32; 11 | length: u32; 12 | speed_pos: u8; 13 | speed_neg: u8; 14 | is_a: bool; 15 | is_b: bool; 16 | is_c: bool; 17 | is_d: bool; 18 | is_e_pos: bool; 19 | is_e_neg: bool; 20 | is_f_pos: bool; 21 | is_f_neg: bool; 22 | is_g_pos: bool; 23 | is_g_neg: bool; 24 | frc: u8: 3; 25 | } 26 | 27 | // Models an edge adjacent to a node 28 | // In addition to the id of the edge it stores the direction of the edge 29 | struct AdjacentEdge{ 30 | id: u32: 31; 31 | dir: u8: 1; 32 | } 33 | 34 | // Each node has a list of (directed) edges adjacent to it 35 | struct Node{ 36 | x: u32; 37 | y: u32; 38 | @range(adjacent_edges) 39 | first_adjacent_edge: u32; 40 | } 41 | 42 | // Models a graph consistent of nodes and edges, as well as their connectivity 43 | archive Graph { 44 | @explicit_reference( Node.first_adjacent_edge, adjacent_edges ) 45 | nodes: vector; 46 | 47 | @explicit_reference( AdjacentEdge.id, edge_data ) 48 | adjacent_edges: vector; 49 | 50 | @explicit_reference( EdgeData.from, nodes ) 51 | @explicit_reference( EdgeData.to, nodes ) 52 | edge_data: vector; 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /flatdata-cpp/benchmark/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import subprocess 4 | import re 5 | import pandas as pd 6 | 7 | expr_cpu_time = re.compile(r'CPU time \(ms\) = ([0-9.]+)') 8 | expr_memory = re.compile(r'Memory rusage peak \(kb\) = ([0-9]+)') 9 | 10 | def run(target, graph, nodes, runs): 11 | cmd = ['./flatdata_benchmark', target, graph, '--num-nodes', str(nodes)] 12 | if target != 'create': 13 | cmd += ['--num-runs', str(runs)] 14 | output = subprocess.check_output(cmd).decode('utf-8') 15 | try: 16 | cpu_time = float(expr_cpu_time.search(output).group(1)) 17 | memory_usage = int(expr_memory.search(output).group(1)) 18 | except Exception as e: 19 | print("{} in output {}".format(e, output)) 20 | return None 21 | return { 22 | 'target':target, 23 | 'graph':graph, 24 | 'nodes':nodes, 25 | 'cpu_time(s)':cpu_time, 26 | 'peak mem(kb)':memory_usage 27 | } 28 | 29 | if __name__ == "__main__": 30 | GRAPHS = ['struct', 'flatdata'] 31 | NUM_NODES = 20000000 32 | NUM_RUNS = 10 33 | 34 | results = [] 35 | for target in ['create', 'lookup', 'dijkstra', 'bfs']: 36 | for graph_name in GRAPHS: 37 | print("Executing {} on {}".format(target, graph_name)) 38 | result = run(target, graph_name, NUM_NODES, NUM_RUNS) 39 | results.append(result) 40 | 41 | print(pd.DataFrame(results).to_string()) 42 | -------------------------------------------------------------------------------- /flatdata-cpp/ci/Dockerfile: -------------------------------------------------------------------------------- 1 | # CI image for building with gcc and clang 2 | FROM alpine:latest 3 | 4 | RUN apk --no-cache add \ 5 | binutils \ 6 | boost-dev \ 7 | clang \ 8 | cmake \ 9 | doxygen \ 10 | g++ \ 11 | gfortran \ 12 | make \ 13 | musl-dev \ 14 | python3 \ 15 | && pip3 install \ 16 | breathe \ 17 | sphinx \ 18 | jinja2 \ 19 | nose \ 20 | pandas \ 21 | pyparsing 22 | 23 | -------------------------------------------------------------------------------- /flatdata-cpp/ci/build-and-test-cpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -ex 3 | mkdir build 4 | cd build 5 | cmake ../flatdata-cpp -DCMAKE_CXX_FLAGS="-Wall -pedantic -Wextra" $EXTRA_CMAKE_ARGS 6 | make -j$(nproc) 7 | make test ARGS="--verbose" 8 | -------------------------------------------------------------------------------- /flatdata-cpp/cmake/flatdata/GenerateSource.cmake: -------------------------------------------------------------------------------- 1 | set(FLATDATA_GENERATOR_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../flatdata-generator) 2 | 3 | # Generates sources from flatdata schema 4 | # 5 | # @param TARGET_NAME Name of custom target to generate header for schema 6 | # @param SCHEMA_FILENAME path to the flatdata schema 7 | # @param OUTPUT_FILENAME output filename. Generator is forced to output to the given file. 8 | # 9 | function(flatdata_generate_source TARGET_NAME SCHEMA_FILENAME OUTPUT_FILENAME) 10 | find_program(PYTHON3_EXECUTABLE NAMES python3 python36) 11 | if (NOT PYTHON3_EXECUTABLE) 12 | message(FATAL_ERROR "python3 NOT found.") 13 | endif() 14 | 15 | file(GLOB_RECURSE FLATDATA_GENERATOR_SOURCES ${FLATDATA_GENERATOR_PATH}/**/*.py) 16 | file(GLOB_RECURSE FLATDATA_GENERATOR_TEMPLATES ${FLATDATA_GENERATOR_PATH}/**/*.jinja2) 17 | 18 | add_custom_command( 19 | OUTPUT ${OUTPUT_FILENAME} 20 | COMMAND ${PYTHON3_EXECUTABLE} ${FLATDATA_GENERATOR_PATH}/generator.py 21 | --gen cpp 22 | --schema ${SCHEMA_FILENAME} 23 | --output-file ${OUTPUT_FILENAME} 24 | DEPENDS ${FLATDATA_GENERATOR_SOURCES} 25 | DEPENDS ${FLATDATA_GENERATOR_TEMPLATES} 26 | DEPENDS ${SCHEMA_FILENAME} 27 | WORKING_DIRECTORY ${GENERATOR_PATH} 28 | COMMENT "Generating sources from flatdata schema" 29 | ) 30 | add_custom_target(${TARGET_NAME} DEPENDS ${OUTPUT_FILENAME}) 31 | endfunction(flatdata_generate_source) 32 | -------------------------------------------------------------------------------- /flatdata-cpp/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | function (flatdata_make_example PATH) 2 | get_filename_component(EXAMPLE_DIR ${PATH} DIRECTORY) 3 | get_filename_component(EXAMPLE_NAME ${PATH} NAME) 4 | 5 | flatdata_generate_source(generate_flatdata_${EXAMPLE_NAME} 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../../examples/${PATH}.flatdata 7 | ${CMAKE_CURRENT_BINARY_DIR}/generated/${PATH}.hpp) 8 | 9 | add_executable(${EXAMPLE_NAME} ${PATH}.cpp) 10 | add_dependencies(${EXAMPLE_NAME} generate_flatdata_${EXAMPLE_NAME}) 11 | 12 | target_include_directories(${EXAMPLE_NAME} 13 | PRIVATE ${Boost_INCLUDE_DIRS} 14 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated/${EXAMPLE_DIR} 15 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor) 16 | 17 | target_link_libraries(${EXAMPLE_NAME} flatdata) 18 | endfunction(flatdata_make_example) 19 | 20 | flatdata_make_example(binary_layout) 21 | flatdata_make_example(fibonacci) 22 | flatdata_make_example(graph) 23 | flatdata_make_example(coappearances/coappearances) 24 | -------------------------------------------------------------------------------- /flatdata-cpp/examples/binary_layout.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #include "binary_layout.hpp" 7 | 8 | #include 9 | 10 | int 11 | main( int, const char** ) 12 | { 13 | std::shared_ptr< flatdata::MemoryResourceStorage > storage 14 | = flatdata::MemoryResourceStorage::create( ); 15 | auto builder = binary_layout::BinaryLayoutBuilder::open( storage ); 16 | 17 | flatdata::Vector< binary_layout::UnalignedStructure > alignment_example( 2 ); 18 | auto struct_0 = alignment_example[ 0 ]; 19 | struct_0.f0 = 0xF; 20 | struct_0.f1 = 0; 21 | struct_0.f2 = 0x07; 22 | 23 | auto struct_1 = alignment_example[ 1 ]; 24 | struct_1.f0 = 0; 25 | struct_1.f1 = 0xFFFF; 26 | struct_1.f2 = 0x0; 27 | 28 | builder.set_alignment_example( alignment_example ); 29 | 30 | std::cout << storage->hexdump( true ); 31 | std::cout << storage->bindump( false ); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/ArchiveBuilder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ResourceStorage.h" 9 | 10 | #include 11 | 12 | namespace flatdata 13 | { 14 | class ArchiveBuilder 15 | { 16 | public: 17 | virtual ~ArchiveBuilder( ) = default; 18 | 19 | /** 20 | * @brief Construct an uninitialized archive 21 | */ 22 | ArchiveBuilder( ) = default; 23 | 24 | /** 25 | * @brief ArchiveBuilder 26 | * @param storage 27 | */ 28 | explicit ArchiveBuilder( std::shared_ptr< flatdata::ResourceStorage > storage ); 29 | /** 30 | * @brief Returns archive name. Is implemented by the concrete archive instances. 31 | */ 32 | virtual const char* name( ) const = 0; 33 | 34 | /** 35 | * @brief Returns archive schema. Is implemented by the concrete archive instances. 36 | */ 37 | virtual const char* schema( ) const = 0; 38 | 39 | /** 40 | * @brief Returns true if archive is correctly loaded 41 | */ 42 | bool is_open( ) const; 43 | 44 | /** 45 | * @brief Returns true if archive is correctly loaded 46 | */ 47 | explicit operator bool( ) const; 48 | 49 | protected: 50 | bool initialize( ); 51 | flatdata::ResourceStorage& storage( ); 52 | const flatdata::ResourceStorage& storage( ) const; 53 | bool is_created( ) const; 54 | void check_created( ) const; 55 | 56 | private: 57 | std::shared_ptr< flatdata::ResourceStorage > m_storage; 58 | bool m_created = false; 59 | }; 60 | 61 | } // namespace flatdata 62 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/ArrayView.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "internal/ArrayViewIterator.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace flatdata 15 | { 16 | template < typename T > 17 | class ArrayView 18 | { 19 | public: 20 | using ConstValueType = typename T::AccessorType; 21 | using ConstStreamType = typename T::AccessorType::StreamType; 22 | using const_iterator = ArrayViewIterator< T >; 23 | 24 | public: 25 | explicit ArrayView( ConstStreamType data_begin = nullptr, ConstStreamType data_end = nullptr ); 26 | 27 | ConstValueType operator[]( size_t i ) const; 28 | const_iterator begin( ) const; 29 | const_iterator end( ) const; 30 | ConstStreamType data( ) const; 31 | 32 | ConstValueType front( ) const; 33 | ConstValueType back( ) const; 34 | 35 | ArrayView slice( size_t pos, size_t length ) const; 36 | ArrayView slice( std::pair< size_t /*start*/, size_t /*end*/ > range ) const; 37 | ArrayView slice_before( size_t pos ) const; 38 | ArrayView slice_after( size_t pos ) const; 39 | 40 | ArrayView skip( size_t count ) const; 41 | ArrayView skip_last( size_t count ) const; 42 | 43 | explicit operator bool( ) const; 44 | 45 | size_t size_in_bytes( ) const; 46 | size_t size( ) const; 47 | std::string describe( size_t nest_level = 0u ) const; 48 | 49 | bool empty( ) const; 50 | 51 | private: 52 | ArrayView( ConstStreamType data, size_t size ); 53 | 54 | ConstStreamType m_data; 55 | size_t m_size; 56 | }; 57 | 58 | } // namespace flatdata 59 | 60 | #include "internal/ArrayView.inl" 61 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/Copy.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace flatdata 12 | { 13 | /** 14 | * Utility function to copy the underlying data of a flatdata structure. 15 | * 16 | * Note: flatdata structures are handles to memory, in particular their copy operator just copies 17 | * the handle, and not the data. In the situation when the underlying data should be copied, this 18 | * function can be used. 19 | */ 20 | template < typename T > 21 | void 22 | copy_struct( T destination, typename T::AccessorType source ) 23 | { 24 | std::memcpy( destination.data( ), source.data( ), T::size_in_bytes( ) ); 25 | } 26 | } // namespace flatdata 27 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/Hash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace flatdata 12 | { 13 | /** 14 | * Hash function for a flatdata structure. 15 | * 16 | * Example: 17 | * 18 | * std::unordered_set< flatdata::SomeStruct, flatdata::Hash > set; 19 | * std::unordered_map< flatdata::SomeStruct, uint32_t, flatdata::Hash > map; 20 | * 21 | */ 22 | struct Hash 23 | { 24 | template < typename T > 25 | size_t 26 | operator( )( const T& value ) const 27 | { 28 | std::size_t hash = 0; 29 | auto data = value.data( ); 30 | auto size = value.size_in_bytes( ); 31 | for ( size_t i = 0; i < size; i++ ) 32 | { 33 | boost::hash_combine( hash, data[ i ] ); 34 | } 35 | 36 | return hash; 37 | } 38 | }; 39 | } // namespace flatdata 40 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/MemoryDescriptor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace flatdata 13 | { 14 | struct MemoryDescriptor 15 | { 16 | public: 17 | MemoryDescriptor( ) = default; 18 | MemoryDescriptor( const uint8_t* ptr, size_t size ) 19 | : m_ptr( ptr ) 20 | , m_size( size ) 21 | { 22 | } 23 | MemoryDescriptor( const char* ptr, size_t size ) 24 | : MemoryDescriptor( reinterpret_cast< const uint8_t* >( ptr ), size ) 25 | { 26 | } 27 | 28 | explicit operator bool( ) const 29 | { 30 | return m_ptr != nullptr; 31 | } 32 | 33 | std::string 34 | describe( size_t /*nest_level*/ = 0 ) const 35 | { 36 | std::ostringstream ss; 37 | if ( this->operator bool( ) ) 38 | { 39 | ss << "Raw data of size " << m_size; 40 | } 41 | else 42 | { 43 | ss << "Uninitialized Raw data"; 44 | } 45 | return ss.str( ); 46 | } 47 | 48 | const uint8_t* 49 | data( ) const 50 | { 51 | return m_ptr; 52 | } 53 | 54 | const char* 55 | char_ptr( ) const 56 | { 57 | return reinterpret_cast< const char* >( m_ptr ); 58 | } 59 | 60 | size_t 61 | size_in_bytes( ) const 62 | { 63 | return m_size; 64 | } 65 | 66 | size_t 67 | size( ) const 68 | { 69 | return m_size; 70 | } 71 | 72 | private: 73 | const uint8_t* m_ptr = nullptr; 74 | size_t m_size = 0; 75 | }; 76 | 77 | } // namespace flatdata 78 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/flatdata.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | /** 9 | * This is the main header file to include C++ Flatdata Library. 10 | * Please refer to README.md in the root of the library for more information on the usage. 11 | */ 12 | 13 | #include "Archive.h" 14 | #include "ArchiveBuilder.h" 15 | #include "ArrayView.h" 16 | #include "Copy.h" 17 | #include "ExternalVector.h" 18 | #include "FileResourceStorage.h" 19 | #include "Hash.h" 20 | #include "MemoryDescriptor.h" 21 | #include "MemoryResourceStorage.h" 22 | #include "MultiArrayView.h" 23 | #include "MultiVector.h" 24 | #include "ResourceStorage.h" 25 | #include "Struct.h" 26 | #include "TarArchiveResourceStorage.h" 27 | #include "Vector.h" 28 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/internal/ArchiveUtils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace flatdata 11 | { 12 | namespace internal 13 | { 14 | 15 | inline std::string 16 | signature_name( const std::string& archive_name ) 17 | { 18 | return archive_name + ".archive"; 19 | } 20 | 21 | } // namespace internal 22 | } // namespace flatdata 23 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/internal/Constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace flatdata 9 | { 10 | enum 11 | { 12 | PADDING_SIZE = 8 13 | }; 14 | 15 | } // namespace flatdata 16 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/internal/ResourceStorageCommon.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Writer.h" 9 | #include "Constants.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace flatdata 15 | { 16 | namespace resource_storage 17 | { 18 | using size_type = uint64_t; 19 | 20 | template < typename T > 21 | void 22 | write_to_stream( std::ostream& stream, T value ) 23 | { 24 | unsigned char data[ sizeof( T ) ] = { 0 }; 25 | Writer< T > writer{ data }; 26 | writer = value; 27 | stream.write( reinterpret_cast< const char* >( data ), sizeof( T ) ); 28 | } 29 | 30 | inline void 31 | write_padding( std::ostream& stream ) 32 | { 33 | char zero[ PADDING_SIZE ] = { 0 }; 34 | stream.write( zero, PADDING_SIZE ); 35 | } 36 | 37 | } // namespace resource_storage 38 | } // namespace flatdata 39 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/internal/TarReader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace flatdata 15 | { 16 | namespace internal 17 | { 18 | struct TarFileEntry 19 | { 20 | std::string name; 21 | size_t offset = 0; 22 | size_t size = 0; 23 | }; 24 | 25 | std::vector< TarFileEntry > read_tar_file_entries( MemoryDescriptor data ); 26 | } // namespace internal 27 | } // namespace flatdata 28 | -------------------------------------------------------------------------------- /flatdata-cpp/include/flatdata/internal/functional/Tagged.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #pragma once 7 | 8 | namespace flatdata 9 | { 10 | /// Tags a type with it's invalid value 11 | template < typename T, T INVALID_VALUE > 12 | class Tagged 13 | { 14 | }; 15 | } // namespace flatdata 16 | -------------------------------------------------------------------------------- /flatdata-cpp/src/ResourceStorage.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace flatdata 12 | { 13 | bool 14 | ResourceStorage::write_to_stream( const char* resource_name, 15 | const char* schema, 16 | const unsigned char* data, 17 | size_t size_in_bytes ) 18 | { 19 | auto stream = create_output_stream( resource_name ); 20 | resource_storage::write_to_stream( *stream, size_in_bytes ); 21 | stream->write( reinterpret_cast< const char* >( data ), size_in_bytes ); 22 | resource_storage::write_padding( *stream ); 23 | stream->flush( ); 24 | 25 | return static_cast< bool >( *stream ) && write_schema( resource_name, schema ); 26 | } 27 | 28 | } // namespace flatdata 29 | -------------------------------------------------------------------------------- /flatdata-cpp/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB TEST_FLATDATA_SOURCES "*.cpp" "../vendor/catch_amalgamated.cpp") 2 | 3 | flatdata_generate_source(generate_flatdata_test_code 4 | ${CMAKE_CURRENT_SOURCE_DIR}/test_structures.flatdata 5 | ${CMAKE_CURRENT_BINARY_DIR}/generated/test_structures.hpp) 6 | 7 | flatdata_generate_source(generate_flatdata_test_code2 8 | ${CMAKE_CURRENT_SOURCE_DIR}/test_structures2.flatdata 9 | ${CMAKE_CURRENT_BINARY_DIR}/generated/test_structures2.hpp) 10 | 11 | flatdata_generate_source(generate_flatdata_test_case_ranges 12 | ${CMAKE_CURRENT_SOURCE_DIR}/../../test_cases/archives/ranges.flatdata 13 | ${CMAKE_CURRENT_BINARY_DIR}/generated/ranges.hpp) 14 | 15 | add_executable(flatdata_test ${TEST_FLATDATA_SOURCES}) 16 | add_dependencies(flatdata_test generate_flatdata_test_code generate_flatdata_test_code2 generate_flatdata_test_case_ranges) 17 | 18 | target_include_directories(flatdata_test 19 | PRIVATE ${Boost_INCLUDE_DIRS} 20 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated 21 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor 22 | ) 23 | 24 | target_compile_definitions(flatdata_test PRIVATE CATCH_CONFIG_CONSOLE_WIDTH=120) 25 | 26 | target_link_libraries(flatdata_test 27 | flatdata 28 | ${CMAKE_THREAD_LIBS_INIT} 29 | ) 30 | 31 | add_test(NAME flatdata_test COMMAND flatdata_test) 32 | 33 | include(InstallTarget OPTIONAL RESULT_VARIABLE HAS_INSTALL_TARGET) 34 | if(HAS_INSTALL_TARGET) 35 | install_with_depends(flatdata_test bin lib flatdata_test_component) 36 | endif() 37 | 38 | set_property(TARGET flatdata_test PROPERTY FOLDER "flatdata") 39 | -------------------------------------------------------------------------------- /flatdata-cpp/test/FuncTraitsTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2018 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #include 7 | 8 | namespace flatdata 9 | { 10 | namespace functraits_test 11 | { 12 | void 13 | free_function( std::true_type ) 14 | { 15 | } 16 | 17 | void 18 | zero_arity_function( ) 19 | { 20 | } 21 | 22 | struct Functor 23 | { 24 | void 25 | operator( )( std::true_type, std::true_type ) 26 | { 27 | } 28 | }; 29 | 30 | static_assert( is_callable_with< decltype( free_function ), std::true_type >::value, 31 | "Free function is callable with its arguments" ); 32 | static_assert( !is_callable_with< decltype( free_function ), std::false_type >::value, 33 | "Free function is not callable with non-implicitly " 34 | "convertible arguments" ); 35 | static_assert( is_callable_with< decltype( zero_arity_function ) >::value, 36 | "Free function with zero arity is callable without arguments" ); 37 | static_assert( !is_callable_with< decltype( zero_arity_function ), std::true_type >::value, 38 | "Free function with zero arity is not callable with wrong arity" ); 39 | static_assert( is_callable_with< Functor, std::true_type, std::true_type >::value, 40 | "Functor is callable with its arguments" ); 41 | static_assert( !is_callable_with< Functor, std::true_type, std::false_type >::value, 42 | "Functor is not callable with non-implicitly convertible arguments" ); 43 | static_assert( !is_callable_with< Functor >::value, "Functor is not callable with wrong arity" ); 44 | } // namespace functraits_test 45 | } // namespace flatdata 46 | -------------------------------------------------------------------------------- /flatdata-cpp/test/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 HERE Europe B.V. 3 | * See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | #define CATCH_CONFIG_MAIN 7 | #include "catch_amalgamated.hpp" 8 | -------------------------------------------------------------------------------- /flatdata-cpp/test/test_structures2.flatdata: -------------------------------------------------------------------------------- 1 | namespace test_structures2 { 2 | 3 | struct AStruct { 4 | value : u64 : 8; 5 | } 6 | 7 | // A 1:1 copy of the same multivector as in test-structures, makes sure we do not have clashes in builtins 8 | archive SimpleResources { 9 | multivector_resource: multivector< 33, AStruct >; 10 | } 11 | 12 | } // namespace test_structures2 13 | -------------------------------------------------------------------------------- /flatdata-cpp/vendor/docopt/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Vladimir Keleshev, 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the Software 6 | without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to 9 | whom the Software is furnished to do so, subject to the 10 | following conditions: 11 | 12 | The above copyright notice and this permission notice shall 13 | be included in all copies or substantial portions of the 14 | Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 17 | KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 19 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /flatdata-generator/.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | max-line-length=120 3 | 4 | [MESSAGES CONTROL] 5 | disable=missing-docstring,line-too-long 6 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/generators/dot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | 6 | from flatdata.generator.tree.nodes.archive import Archive 7 | from . import BaseGenerator 8 | 9 | SCOPE_SEPARATOR = "__" 10 | DECORATION_BOUND = "__bound__" 11 | 12 | 13 | class DotGenerator(BaseGenerator): 14 | """Flatdata to DOT (graph description language) generator""" 15 | 16 | def __init__(self): 17 | BaseGenerator.__init__(self, "dot/dot.jinja2") 18 | 19 | def _populate_environment(self, env): 20 | env.autoescape = True 21 | 22 | def _field_value_type(field): 23 | type_name = field.type.name.replace("@@", ".").replace("@", ".") 24 | namespace_name = field.parent.parent.path 25 | if type_name.startswith(namespace_name): 26 | type_name = type_name[len(namespace_name):] 27 | if type_name.startswith("."): 28 | type_name = type_name[1:] 29 | 30 | return type_name 31 | 32 | env.filters["field_value_type"] = _field_value_type 33 | 34 | def supported_nodes(self): 35 | return [Archive] 36 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/cpp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/cpp/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/cpp/constant.jinja2: -------------------------------------------------------------------------------- 1 | {%- macro declaration(node) %} 2 | enum : {{ node.type|cpp_base_type}} 3 | { 4 | {% if node.doc %} 5 | {{- node.doc|cpp_doc }} 6 | {% endif %} 7 | {{ node.name }} = {{ node.value }}{{ node.type.annotation }} 8 | }; 9 | {%- endmacro %} 10 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/cpp/cpp.jinja2: -------------------------------------------------------------------------------- 1 | {% import "cpp/constant.jinja2" as constant %} 2 | {% import "cpp/enumeration.jinja2" as enumeration %} 3 | {% import "cpp/structure.jinja2" as structure %} 4 | {% import "cpp/archive.jinja2" as archive %} 5 | {% import "cpp/namespace.jinja2" as namespace %} 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | {% for node in nodes %} 15 | {{ namespace.opening(node) }} 16 | {%- if node|is_structure %} 17 | {{- structure.declaration(node) }} 18 | {%- elif node|is_enumeration %} 19 | {{- enumeration.declaration(node) }} 20 | {%- elif node|is_archive %} 21 | {{- archive.declaration(node) }} 22 | {%- elif node|is_constant %} 23 | {{- constant.declaration(node) }} 24 | {%- endif %} 25 | 26 | {{ namespace.closing(node) }} 27 | {% endfor %} 28 | 29 | // ------------------------------------------------------------------------------------------------- 30 | // -------------------------------------- Implementations ------------------------------------------ 31 | // ------------------------------------------------------------------------------------------------- 32 | 33 | {% for node in nodes if not node|is_constant %} 34 | {{ namespace.opening(node) }} 35 | {%- if node|is_structure %} 36 | {{- structure.definition(node, tree) }} 37 | {%- elif node|is_enumeration %} 38 | {{- enumeration.definition(node, tree) }} 39 | {%- elif node|is_archive %} 40 | {{- archive.definition(node, tree) }} 41 | {%- endif %} 42 | {{ namespace.closing(node) }} 43 | {% endfor %} 44 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/cpp/enumeration.jinja2: -------------------------------------------------------------------------------- 1 | {% macro declaration(enum) %} 2 | 3 | {% if enum.doc %} 4 | {{ enum.doc|cpp_doc }} 5 | {% endif %} 6 | enum class {{ enum.name }} : {{ enum.type|cpp_base_type }} 7 | { 8 | {% for value in enum.values %} 9 | {% if value.doc %} 10 | {{ value.doc|cpp_doc }} 11 | {% endif %} 12 | {{ value.name }} = {{ value.value }}{{ enum.type.annotation }}{{ "," if not loop.last }} 13 | {% endfor %} 14 | }; 15 | 16 | inline 17 | const char* to_string( {{ enum.name }} value ); 18 | 19 | {% endmacro %} 20 | 21 | {% macro definition(enum, tree) %} 22 | 23 | inline 24 | const char* to_string( {{ enum.name }} value ) 25 | { 26 | switch( value ) 27 | { 28 | {% for value in enum.values %} 29 | case {{ enum.name }}::{{ value.name }}: 30 | return "{{ enum.name }}::{{ value.name }}"; 31 | {% endfor %} 32 | default: 33 | // default needed since C++ allows storage of unknown values 34 | return "Unknown value of {{ enum.name }}"; 35 | } 36 | } 37 | 38 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/cpp/namespace.jinja2: -------------------------------------------------------------------------------- 1 | {% macro opening(node) %} 2 | {% for ns in node|namespaces %}namespace {{ ns.name }} { 3 | {% endfor %} 4 | {% endmacro %} 5 | 6 | {% macro closing(node) %} 7 | {% for ns in node|namespaces %}}{% endfor %} // namespace {{ node|namespaces|join(".", attribute="name") }} 8 | {% endmacro %} 9 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/dot/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/archive.jinja2: -------------------------------------------------------------------------------- 1 | {% import "dot/styles.jinja2" as styles %} 2 | 3 | {%- macro enter(tree, archive) %} 4 | subgraph cluster_{{ archive.path_with() }} 5 | { 6 | penwidth=1; 7 | color="{{ styles.color_archive_border }}"; 8 | fillcolor="{{ styles.color_archive_bg }}"; 9 | label=<{{ archive.name }}> 10 | 11 | {%- endmacro %} 12 | 13 | {%- macro exit(tree, archive) %} 14 | } 15 | {%- endmacro %} 16 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/dot.jinja2: -------------------------------------------------------------------------------- 1 | {% import "dot/render.jinja2" as render %} 2 | {% import "dot/references.jinja2" as refs %} 3 | {% import "dot/styles.jinja2" as styles %} 4 | 5 | digraph FlatdataDot 6 | { 7 | graph [splines=true, compound=false, rankdir=LR, rank=same, style=filled, fontsize="16", fontname="Courier New", penwidth=1, fontcolor="{{ styles.color_font_generic }}"] 8 | node [shape=none, margin=none, fontsize=9, fontname="Courier New"]; 9 | edge [style=solid, arrowsize=0.5, color="{{ styles.color_explicit_reference_fg }}", arrowtail="dot", dir="both"] 10 | 11 | {{ render.render_tree(tree) }} 12 | {{ refs.render_explicit_references(tree, nodes) }} 13 | } 14 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/namespace.jinja2: -------------------------------------------------------------------------------- 1 | {% import "dot/styles.jinja2" as styles %} 2 | 3 | {%- macro enter(tree, namespace) %} 4 | subgraph cluster_{{ namespace.path_with() }} 5 | { 6 | penwidth=0; 7 | fontcolor="{{ styles.color_font_generic }}"; 8 | fillcolor="{{ styles.color_namespace_bg }}"; 9 | label=<{{ namespace.name }}> 10 | {%- endmacro %} 11 | 12 | {%- macro exit(tree, namespace) %} 13 | } 14 | {% endmacro %} 15 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/references.jinja2: -------------------------------------------------------------------------------- 1 | {%- macro _render_edge(tree, origin, destination, ref) %} 2 | {% set dest_dot = destination.path_with() 3 | if destination.referenced_structures|length == 0 4 | else destination.path_with() + destination.referenced_structures[0].node.path_with() %} 5 | 6 | {% set origin_dot = origin.path_with() + ref.structure.node.path_with() %} 7 | {% set origin_port = 'port_' + origin.path_with() + ref.field.node.path_with() %} 8 | 9 | {{ origin_dot }}:{{ origin_port }} -> {{ dest_dot }} [lhead=cluster_{{ destination.path_with() }}]; 10 | {%- endmacro %} 11 | 12 | {%- macro _render_explicit_reference(tree, ref, resource) %} 13 | {% for origin in tree.binding_resources_or_self(resource) %} 14 | {% for destination in tree.binding_resources_or_self(ref.destination.node) %} 15 | {{ _render_edge(tree, origin, destination, ref) }} 16 | {% endfor %} 17 | {% endfor %} 18 | {%- endmacro %} 19 | 20 | {%- macro render_explicit_references(tree, nodes) %} 21 | {% for node in nodes if node|is_archive %} 22 | {% for resource in node.resources %} 23 | {% for ref in resource.explicit_references %} 24 | {{ _render_explicit_reference(tree, ref, resource) }} 25 | {% endfor %} 26 | {% endfor %} 27 | {% endfor %} 28 | {%- endmacro %} 29 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/render.jinja2: -------------------------------------------------------------------------------- 1 | {% import "dot/archive.jinja2" as archive %} 2 | {% import "dot/namespace.jinja2" as namespace %} 3 | {% import "dot/resource.jinja2" as resource %} 4 | 5 | {%- macro _enter_node(tree, node) -%} 6 | {% if node|is_namespace %} 7 | {{ namespace.enter(tree, node) }} 8 | {% elif node|is_archive %} 9 | {{ archive.enter(tree, node) }} 10 | {% elif node|is_resource %} 11 | {{ resource.enter(tree, node) }} 12 | {% endif %} 13 | {%- endmacro -%} 14 | 15 | {%- macro _exit_node(tree, node) -%} 16 | {% if node|is_namespace %} 17 | {{ namespace.exit(tree, node) }} 18 | {% elif node|is_archive %} 19 | {{ archive.exit(tree, node) }} 20 | {% elif node|is_resource %} 21 | {{ resource.exit(tree, node) }} 22 | {% endif %} 23 | {%- endmacro -%} 24 | 25 | {% macro _render_node_recursive(tree, node) %} 26 | {{ _enter_node(tree, node) }} 27 | 28 | {%- for node in node.children -%} 29 | {{- _render_node_recursive(tree, node) -}} 30 | {%- endfor -%} 31 | {{- _exit_node(tree, node) -}} 32 | {%- endmacro -%} 33 | 34 | {% macro render_tree(tree) %} 35 | {{- _render_node_recursive(tree, tree.root) -}} 36 | {% endmacro %} 37 | 38 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/resource.jinja2: -------------------------------------------------------------------------------- 1 | {% import "dot/styles.jinja2" as styles %} 2 | {% import "dot/structure.jinja2" as structure %} 3 | 4 | {%- macro enter(tree, resource) %} 5 | {% if not tree.is_bound_implicitly(resource) %} 6 | subgraph cluster_{{ resource.path_with() }} 7 | { 8 | label=<{{ resource.name }}
{{ resource.__class__.__name__ }}{% if resource.optional %}
optional{% endif %}
> 9 | penwidth=0; 10 | fontsize="9" 11 | fillcolor="{{ styles.color_resource_bg }}"; 12 | 13 | {# invisible node for cases with no types #} 14 | {% if not resource.referenced_structures %} 15 | {{ resource.path_with() }} [style=invisible, fixedsize="true", width="0", height="0", label=""]; 16 | {% endif %} 17 | 18 | {% for ref in resource.referenced_structures %} 19 | {{ structure.render(resource, tree, ref.node) }} 20 | {% endfor %} 21 | {% endif %} 22 | {%- endmacro %} 23 | 24 | {%- macro exit(tree, resource) %} 25 | {% if not tree.is_bound_implicitly(resource) %} 26 | } 27 | {% endif %} 28 | {%- endmacro %} 29 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/structure.jinja2: -------------------------------------------------------------------------------- 1 | {% import "dot/styles.jinja2" as styles %} 2 | 3 | {% macro render(resource, tree, struct) %} 4 | {{ resource.path_with() + struct.path_with() }} [label=< 5 | 6 | 7 | 10 | 11 | {% for field in struct.fields %} 12 | 13 | 16 | 17 | {% endfor %} 18 |
8 | {{ struct.name }} 9 |
14 | {{ field.name }}:{{ field | field_value_type }}:{{ field.type.width }} 15 |
>]; 19 | {% endmacro %} 20 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/dot/styles.jinja2: -------------------------------------------------------------------------------- 1 | {% set color_font_generic = "#516D7B" %} 2 | {% set color_archive_bg = "#EBF8FF" %} 3 | {% set color_archive_border = "#85D4FF" %} 4 | {% set color_namespace_bg = "#F7F7F7" %} 5 | {% set color_namespace_border = "#85D4FF" %} 6 | {% set color_resource_bg = "#C4E6F8" %} 7 | {% set color_resource_border = "#85D4FF" %} 8 | {% set color_structure_header_bg = "#257FAD" %} 9 | {% set color_structure_header_fg = color_archive_bg %} 10 | {% set color_structure_member_bg = color_archive_bg %} 11 | {% set color_structure_member_fg = color_font_generic %} 12 | {% set color_structure_member_type_fg = "#568C3B" %} 13 | {% set color_structure_member_width_fg = "#D22D72" %} 14 | {% set color_explicit_reference_fg = "#257FAD" %} 15 | {% set color_implicitly_bound_bg = "#D9F2FF" %} 16 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/flatdata/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/archive.jinja2: -------------------------------------------------------------------------------- 1 | {% import "flatdata/resource.jinja2" as resource %} 2 | 3 | {% macro declaration(archive) %} 4 | {% for b in archive.resources|bound_resources %} 5 | @bound_implicitly( {{ b.name }} : {% for r in b.children -%} 6 | {{ r.node.path_with(".") }}{{ ", " if not loop.last }} 7 | {%- endfor %} 8 | ) 9 | {% endfor %} 10 | archive {{ archive.name }} 11 | { 12 | {% for r in archive.resources|supported_resources %} 13 | {% for ref in r.explicit_references %} 14 | @explicit_reference( {{ ref.structure.node.path_with(".") }}.{{ ref.field.node.name }}, {{ ref.destination.node.path_with(".")}} ) 15 | {% endfor %} 16 | {% if r.optional %} 17 | @optional 18 | {% endif %} 19 | {{ r.name }} : {{ resource.resource_type(r) }}; 20 | {% endfor %} 21 | } 22 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/constant.jinja2: -------------------------------------------------------------------------------- 1 | {%- macro declaration(node) %} 2 | const {{ node.type.name }} {{ node.name }} = {{ node.value }}; 3 | {% endmacro %} 4 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/enumeration.jinja2: -------------------------------------------------------------------------------- 1 | {% macro declaration(enum) %} 2 | enum {{ enum.name }} : {{ enum.type.name }} : {{ enum.type.width }} 3 | { 4 | {% for value in enum.values | not_auto_generated %} 5 | {{ value.name }} = {{ value.value }}, 6 | {% endfor %} 7 | } 8 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/flatdata.jinja2: -------------------------------------------------------------------------------- 1 | {% import "flatdata/constant.jinja2" as constant %} 2 | {% import "flatdata/enumeration.jinja2" as enumeration %} 3 | {% import "flatdata/structure.jinja2" as structure %} 4 | {% import "flatdata/archive.jinja2" as archive %} 5 | {% import "flatdata/namespace.jinja2" as namespace %} 6 | {% for node in nodes | filter_builtin %} 7 | {{ namespace.opening(node) }} 8 | {%- if node|is_structure %} 9 | {{- structure.declaration(node) }} 10 | {%- elif node|is_enumeration %} 11 | {{- enumeration.declaration(node) }} 12 | {%- elif node|is_archive %} 13 | {{- archive.declaration(node) }} 14 | {%- elif node|is_constant %} 15 | {{- constant.declaration(node) }} 16 | {%- endif %} 17 | {{ namespace.closing(node) }} 18 | {% endfor %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/namespace.jinja2: -------------------------------------------------------------------------------- 1 | {% macro opening(node) %} 2 | {% for ns in node|namespaces %} 3 | namespace {{ ns.name }} { 4 | {% endfor %} 5 | {% endmacro %} 6 | 7 | {% macro closing(node) %} 8 | {% for ns in node|namespaces %} 9 | } 10 | {% endfor %} 11 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/resource.jinja2: -------------------------------------------------------------------------------- 1 | {%- macro resource_type(r) -%} 2 | {%- set type_params = r.referenced_structures|to_type_params -%} 3 | {%- if r|is_instance -%} 4 | {{ type_params }} 5 | {%- elif r|is_vector -%} 6 | vector< {{ type_params }} > 7 | {%- elif r|is_multivector -%} 8 | multivector< {{ r.width }}, {{ type_params }} > 9 | {%- elif r|is_raw_data -%} 10 | raw_data 11 | {%- elif r|is_archive_resource -%} 12 | archive {{ r.target.node.path_with(".") }} 13 | {%- else -%} 14 | {% raise "Unsupported resource type" %} 15 | {%- endif -%} 16 | {%- endmacro -%} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/flatdata/structure.jinja2: -------------------------------------------------------------------------------- 1 | {% macro declaration(struct) %} 2 | struct {{ struct.name }} 3 | { 4 | {% for field in struct.fields %} 5 | {% if field.range %} 6 | @range( {{ field.range }} ) 7 | {% endif %} 8 | {% for const_ref in field.const_value_refs %} 9 | @const( {{ const_ref.target }} ) 10 | {% endfor %} 11 | {% if field.invalid_value %} 12 | @optional( {{ field.invalid_value.target }} ) 13 | {% endif %} 14 | {{ field.name }} : {{field.type.name | field_type}} : {{ field.type.width }}; 15 | {% endfor %} 16 | } 17 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/go/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/go/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/go/base.jinja2: -------------------------------------------------------------------------------- 1 | {% macro generate(tree, nodes) %} 2 | ///////////////////////////////////////////////////////////////////////// 3 | // ATTENTION! 4 | // This code is automatically generated by flatdata generator. 5 | // Any modifications to this file will be lost upon next regeneration. 6 | ///////////////////////////////////////////////////////////////////////// 7 | package {{ tree.root.children[0].name }} 8 | 9 | import ( 10 | "bytes" 11 | "encoding/binary" 12 | "errors" 13 | "fmt" 14 | "log" 15 | {% if tree|contains_archive_resource %} 16 | "path/filepath" 17 | {% endif %} 18 | 19 | "github.com/heremaps/flatdata/flatdata-go/flatdata" 20 | ) 21 | 22 | const ( 23 | flatdataOffsetSizeInBytes uint = 8 24 | flatdataPaddingSizeInBytes uint = 8 25 | {% for node in nodes %} 26 | {% if node|is_structure %} 27 | {{ node.name|to_go_case(false) }}SizeInBytes = {{ node.size_in_bytes }} 28 | {% elif node|is_constant %} 29 | {{ node.name|to_go_case }} {{ node.type.name|type_mapping(node) }} = {{ node.value }} 30 | {% endif %} 31 | {% endfor %} 32 | ) 33 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/go/go.jinja2: -------------------------------------------------------------------------------- 1 | {% import "go/archive.jinja2" as go_archive %} 2 | {% import "go/vector.jinja2" as go_vector %} 3 | {% import "go/rawdata.jinja2" as go_rawdata %} 4 | {% import "go/instance.jinja2" as go_instance %} 5 | {% import "go/multivector.jinja2" as go_multivector %} 6 | {% import "go/base.jinja2" as go_base %} 7 | {% import "go/structure.jinja2" as go_struct %} 8 | {{ go_base.generate(tree, nodes) }} 9 | 10 | {% macro structure_definition(tree, struct) %} 11 | {{ go_struct.generate(tree, struct) }} 12 | {% endmacro %} 13 | 14 | {% macro archive_definition(tree, archive) %} 15 | {% for resource in archive.resources if not resource|is_bound_resource %} 16 | {% if resource|is_instance %} 17 | {{ go_instance.generate(tree, archive, resource) }} 18 | {% elif resource|is_vector %} 19 | {{ go_vector.generate(tree, archive, resource) }} 20 | {% elif resource|is_raw_data %} 21 | {{ go_rawdata.generate(tree, archive, resource) }} 22 | {% elif resource|is_multivector %} 23 | {{ go_multivector.generate(tree, archive, resource) }} 24 | {% endif %} 25 | {% endfor %} 26 | {{ go_archive.generate(tree, archive) }} 27 | {% endmacro %} 28 | 29 | {% for node in nodes %} 30 | {%- if node|is_structure %} 31 | {{- structure_definition(tree, node) }} 32 | {%- elif node|is_archive %} 33 | {{- archive_definition(tree, node) }} 34 | {% endif %} 35 | {% endfor %} 36 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/go/rawdata.jinja2: -------------------------------------------------------------------------------- 1 | {% macro generate(tree, archive, resource) %} 2 | type {{ archive.name|to_go_case }}{{ resource.name|to_go_case }}RawData struct { 3 | descriptor flatdata.MemoryDescriptor 4 | IsOptional bool 5 | IsOpen bool 6 | } 7 | 8 | func (v *{{ archive.name|to_go_case }}{{ resource.name|to_go_case }}RawData) GetValue() []byte { 9 | data := make([]byte, v.GetSize()) 10 | _, err := v.descriptor.ReadAt(data, 8) 11 | if err != nil { 12 | return make([]byte, 0) 13 | } 14 | return data 15 | } 16 | 17 | func (v *{{ archive.name|to_go_case }}{{ resource.name|to_go_case }}RawData) GetSize() int { 18 | size := make([]byte, 8) 19 | _, err := v.descriptor.ReadAt(size, 0) 20 | if err != nil { 21 | return 0 22 | } 23 | return int(binary.LittleEndian.Uint64(size)) 24 | } 25 | 26 | func (v *{{ archive.name|to_go_case }}{{ resource.name|to_go_case }}RawData) Close() { 27 | v.descriptor.Close() 28 | v.IsOpen = false 29 | } 30 | 31 | func (v *{{ archive.name|to_go_case }}{{ resource.name|to_go_case }}RawData) GetSizeInBytes() int { 32 | return v.descriptor.Len() 33 | } 34 | 35 | func (v *{{ archive.name|to_go_case }}{{ resource.name|to_go_case }}RawData) ToString() string { 36 | return fmt.Sprintf(`{"container_type": "RawData", "size": %d, "size_in_bytes": %d, "element_types": []}`, v.GetSize(), v.GetSizeInBytes()) 37 | } 38 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/go/structure.jinja2: -------------------------------------------------------------------------------- 1 | {% macro generate(tree, struct) %} 2 | {{ struct|to_go_doc}} 3 | type {{ struct.name|to_go_case }} struct { 4 | descriptor flatdata.MemoryDescriptor 5 | position int 6 | } 7 | 8 | {% for field in struct.fields %} 9 | func (v *{{ struct.name|to_go_case }}) Get{{ field.name|to_go_case }}() {{ field.type.name|type_mapping_with_bool }} { 10 | {% if field.doc %} 11 | {{ field|to_go_doc|indent(8) }} 12 | {% endif %} 13 | elementSizeInBits := uint({{ field.type.width }}) 14 | elementOffset := uint({{ field.offset }}) 15 | result := flatdata.Read(v.descriptor, (uint(v.position)*8)+elementOffset, elementSizeInBits, {{ field.type.is_signed|lower }}) 16 | {% if field.type.name|is_bool %} 17 | return result == 1 18 | {% else %} 19 | return {{ field.type.name|type_mapping_with_bool }}(result) 20 | {% endif %} 21 | } 22 | 23 | {% endfor %} 24 | 25 | func (v *{{ struct.name|to_go_case }}) ToString() string { 26 | buffer := bytes.Buffer{} 27 | buffer.WriteString(fmt.Sprintf(`{"name": "{{ struct.name }}", "position": %d, "attributes": {`, v.position)) 28 | if v.descriptor != nil { 29 | {% for field in struct.fields %} 30 | buffer.WriteString(fmt.Sprintf(`"{{ field.name }}": %v`, {% if field.type.name|is_bool %}v.Get{{ field.name|to_go_case }}(){% else %}v.Get{{ field.name|to_go_case }}(){% endif %})) 31 | {% if loop.length != loop.index %} 32 | buffer.WriteString(",") 33 | {% endif %} 34 | {% endfor %} 35 | } 36 | buffer.WriteString("}}") 37 | return buffer.String() 38 | } 39 | {% endmacro %} -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/py/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/py/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/rust/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/templates/rust/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/rust/constant.jinja2: -------------------------------------------------------------------------------- 1 | {%- macro declaration(node) %} 2 | 3 | {% if node.doc %} 4 | {{ node.doc | rust_doc }} 5 | {% endif %} 6 | pub const {{ node.name | camel_to_snake_case | upper }}: {{ node.type.name }} = {{ node.value | format_numeric_literal }}; 7 | {%- endmacro %} 8 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/rust/enumeration.jinja2: -------------------------------------------------------------------------------- 1 | {%- macro declaration(enum) %} 2 | 3 | {%- if enum.doc %} 4 | {{ enum.doc | rust_doc }} 5 | {% endif %} 6 | #[derive(Debug, PartialEq, Eq)] 7 | #[repr({{ enum.type.name }})] 8 | pub enum {{ enum.name }} { 9 | {% for value in enum.values %} 10 | {% if value.doc %} 11 | {{ value.doc | rust_doc }} 12 | {% endif %} 13 | {% if value.auto_generated %} 14 | #[doc(hidden)] 15 | {% endif %} 16 | {{ value.name | snake_to_upper_camel_case }} = {{ value.value | format_numeric_literal }}, 17 | {% endfor %} 18 | } 19 | 20 | impl flatdata::helper::Int for {{ enum.name }} { 21 | const IS_SIGNED: bool = {{ enum.type.is_signed | lower }}; 22 | } 23 | {%- endmacro %} 24 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/templates/rust/index.jinja2: -------------------------------------------------------------------------------- 1 | {% import "rust/structure.jinja2" as structure %} 2 | {% macro declaration(index) %} 3 | 4 | {# multivector index structs #} 5 | {{ structure.declaration(index) }} 6 | 7 | impl flatdata::IndexStruct for {{index.name}} { 8 | #[inline] 9 | fn range(&self) -> std::ops::Range { 10 | let range = self.range(); 11 | range.start as usize..range.end as usize 12 | } 13 | 14 | #[inline] 15 | fn set_index(&mut self, value: usize) { 16 | self.set_value(value as u64); 17 | } 18 | } 19 | {% endmacro %} 20 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/tree/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/helpers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/tree/helpers/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/helpers/enumtype.py: -------------------------------------------------------------------------------- 1 | from .basictype import BasicType 2 | 3 | 4 | class EnumType: 5 | def __init__(self, name, basic_type): 6 | assert not BasicType.is_basic_type(name), "%r is no valid enum name" % name 7 | self._name = name 8 | self._type = basic_type 9 | 10 | @property 11 | def name(self): 12 | return self._name 13 | 14 | @property 15 | def width(self): 16 | return self._type.width 17 | 18 | @property 19 | def annotation(self): 20 | return self._type.annotation 21 | 22 | @property 23 | def is_signed(self): 24 | return self._type.is_signed 25 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/flatdata/generator/tree/nodes/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/explicit_reference.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.node import Node 2 | from flatdata.generator.tree.nodes.references import ResourceReference, FieldReference, StructureReference 3 | 4 | 5 | class ExplicitReference(Node): 6 | def __init__(self, name, properties=None): 7 | super().__init__(name=name, properties=properties) 8 | 9 | @staticmethod 10 | def create(properties): 11 | destination = properties.destination 12 | field = Node.jointwo(properties.source_type, properties.source_field) 13 | result = ExplicitReference( 14 | name="er_{field}_{destination}".format(field=field.replace(Node.PATH_SEPARATOR, '_'), 15 | destination=destination.replace( 16 | Node.PATH_SEPARATOR, '_')), 17 | properties=properties) 18 | result.insert(ResourceReference(name=destination)) 19 | result.insert(FieldReference(name=field)) 20 | result.insert(StructureReference(name=properties.source_type)) 21 | return result 22 | 23 | 24 | @property 25 | def destination(self): 26 | result = self.children_like(ResourceReference) 27 | assert len(result) == 1 28 | return result[0] 29 | 30 | @property 31 | def field(self): 32 | result = self.children_like(FieldReference) 33 | assert len(result) == 1 34 | return result[0] 35 | 36 | @property 37 | def structure(self): 38 | result = self.children_like(StructureReference) 39 | assert len(result) == 1 40 | return result[0] 41 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/resources/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import ResourceBase 2 | from .archive import Archive 3 | from .multivector import Multivector 4 | from .instance import Instance 5 | from .rawdata import RawData 6 | from .vector import Vector 7 | from .bound_resource import BoundResource 8 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/resources/archive.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.references import ArchiveReference 2 | from .base import ResourceBase 3 | 4 | 5 | class Archive(ResourceBase): 6 | def __init__(self, name, properties=None, target=None): 7 | super().__init__(name=name, properties=properties) 8 | self._target = target 9 | 10 | @staticmethod 11 | def create(properties): 12 | return Archive(name=properties.name, 13 | properties=properties, 14 | target=properties.type.archive.name) 15 | 16 | @property 17 | def target(self): 18 | targets = self.children_like(ArchiveReference) 19 | assert len(targets) == 1 20 | return targets[0] 21 | 22 | def create_references(self): 23 | return [ArchiveReference(name=self._target)] 24 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/resources/bound_resource.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.references import ResourceReference 2 | from .base import ResourceBase 3 | 4 | 5 | class BoundResource(ResourceBase): 6 | def __init__(self, name, properties=None, resources=None): 7 | super().__init__(name=name, properties=properties) 8 | self._resources = resources 9 | 10 | @staticmethod 11 | def create(properties): 12 | return BoundResource(name=properties.name, 13 | properties=properties, 14 | resources=[r for r in properties.resources]) 15 | 16 | def create_references(self): 17 | return [ResourceReference(name=r) for r in self._resources] 18 | 19 | @property 20 | def referenced_structures(self): 21 | return [s for r in self.children_like(ResourceReference) for s in 22 | r.node.referenced_structures] 23 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/resources/instance.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.references import StructureReference 2 | from .base import ResourceBase 3 | 4 | 5 | class Instance(ResourceBase): 6 | def __init__(self, name, properties=None, resource_type=None): 7 | super().__init__(name=name, properties=properties) 8 | self._type = resource_type 9 | 10 | @staticmethod 11 | def create(properties): 12 | return Instance(name=properties.name, 13 | properties=properties, 14 | resource_type=properties.type.object.type) 15 | 16 | def create_references(self): 17 | return [StructureReference(name=self._type)] 18 | 19 | @property 20 | def type(self): 21 | return self._type 22 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/resources/rawdata.py: -------------------------------------------------------------------------------- 1 | from .base import ResourceBase 2 | 3 | 4 | class RawData(ResourceBase): 5 | def __init__(self, name, properties=None): 6 | super(RawData, self).__init__(name=name, properties=properties) 7 | 8 | @staticmethod 9 | def create(properties): 10 | return RawData(name=properties.name, properties=properties) 11 | 12 | def create_references(self): 13 | return [] 14 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/resources/vector.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.references import StructureReference 2 | from .base import ResourceBase 3 | 4 | 5 | class Vector(ResourceBase): 6 | def __init__(self, name, properties=None, type=None): 7 | super().__init__(name=name, properties=properties) 8 | self._type = type 9 | 10 | @staticmethod 11 | def create(properties): 12 | return Vector(name=properties.name, 13 | properties=properties, 14 | type=properties.type.vector.type) 15 | 16 | def create_references(self): 17 | return [StructureReference(name=self._type)] 18 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/root.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.node import Node 2 | 3 | 4 | class Root(Node): 5 | def __init__(self): 6 | super().__init__(name="__root_node_name_is_empty__", properties=None) 7 | self._name = "" 8 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/trivial/__init__.py: -------------------------------------------------------------------------------- 1 | from .constant import Constant 2 | from .field import Field 3 | from .namespace import Namespace 4 | from .structure import Structure 5 | from .enumeration import Enumeration 6 | from .enumeration_value import EnumerationValue 7 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/trivial/constant.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.node import Node 2 | from flatdata.generator.tree.helpers.basictype import BasicType 3 | from flatdata.generator.tree.errors import InvalidConstantValueError 4 | 5 | class Constant(Node): 6 | def __init__(self, name, properties=None): 7 | super().__init__(name=name, properties=properties) 8 | if properties: 9 | self._value = int(properties.value, 0) 10 | if self.type.bits_required(self.value) > self.type.width: 11 | raise InvalidConstantValueError(name=name, value=self.value) 12 | 13 | @staticmethod 14 | def create(properties, definition): 15 | result = Constant(name=properties.name, properties=properties) 16 | return result 17 | 18 | @property 19 | def type(self): 20 | return BasicType(self._properties.type) 21 | 22 | @property 23 | def doc(self): 24 | return self._properties.doc 25 | 26 | @property 27 | def value(self): 28 | return self._value 29 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/trivial/enumeration_value.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.node import Node 2 | 3 | class EnumerationValue(Node): 4 | def __init__(self, name, value, auto_generated, properties=None): 5 | super().__init__(name=name, properties=properties) 6 | self._value = value 7 | self._auto_generated = auto_generated 8 | 9 | @staticmethod 10 | def create(properties, value): 11 | result = EnumerationValue(name=properties.name, properties=properties, value=value, auto_generated=False) 12 | return result 13 | 14 | @property 15 | def doc(self): 16 | return self._properties.doc 17 | 18 | @property 19 | def value(self): 20 | return self._value 21 | 22 | @property 23 | def auto_generated(self): 24 | return self._auto_generated 25 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/trivial/namespace.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | 6 | from flatdata.generator.tree.nodes.node import Node 7 | 8 | 9 | class Namespace(Node): 10 | def __init__(self, name, properties=None): 11 | super().__init__(name=name, properties=properties) 12 | -------------------------------------------------------------------------------- /flatdata-generator/flatdata/generator/tree/nodes/trivial/structure.py: -------------------------------------------------------------------------------- 1 | from flatdata.generator.tree.nodes.node import Node 2 | from .field import Field 3 | 4 | 5 | class Structure(Node): 6 | def __init__(self, name, properties=None): 7 | """ 8 | Use to instantiate empty structure. 9 | No special properties are evaluated. 10 | 11 | :param name: name 12 | :param properties: properties. can be missing. 13 | """ 14 | super().__init__(name=name, properties=properties) 15 | 16 | @staticmethod 17 | def create(properties, definition): 18 | result = Structure(name=properties.name, properties=properties) 19 | 20 | for field in properties.fields: 21 | result.insert(Field.create(properties=field)) 22 | return result 23 | 24 | @property 25 | def has_range(self): 26 | return any(f for f in self.fields if f.range) 27 | 28 | @property 29 | def doc(self): 30 | return self._properties.doc 31 | 32 | @property 33 | def size_in_bits(self): 34 | return self._size_in_bits 35 | 36 | @size_in_bits.setter 37 | def size_in_bits(self, value): 38 | self._size_in_bits = value 39 | 40 | @property 41 | def size_in_bytes(self): 42 | return (self._size_in_bits + 7) // 8 43 | 44 | @property 45 | def fields(self): 46 | return self.children_like(Field) 47 | -------------------------------------------------------------------------------- /flatdata-generator/generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | ''' 3 | Dummy launcher script since it doesn't feel very natural 4 | to run a module with `python3 -m flatdata.generator.app` 5 | ''' 6 | from flatdata.generator import app as generator 7 | 8 | if __name__ == "__main__": 9 | generator.main() 10 | -------------------------------------------------------------------------------- /flatdata-generator/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [project] 6 | name = "flatdata-generator" 7 | version = "0.4.6" 8 | description = "Generate source code for C++, Rust, Go or Python from a Flatdata schema file" 9 | readme = "README.md" 10 | authors = [ 11 | { name = "Flatdata Developers" }, 12 | ] 13 | classifiers = [ 14 | "License :: OSI Approved :: Apache Software License", 15 | "Operating System :: OS Independent", 16 | "Programming Language :: Python :: 3", 17 | ] 18 | dependencies = [ 19 | "jinja2>=2.2", 20 | "pyparsing>=2.0", 21 | ] 22 | 23 | [project.scripts] 24 | flatdata-generator = "flatdata.generator.app:main" 25 | 26 | [project.urls] 27 | Homepage = "https://github.com/heremaps/flatdata" 28 | 29 | [tool.hatch.build.targets.sdist] 30 | include = [ 31 | "/flatdata", 32 | ] 33 | 34 | [tool.hatch.build.targets.wheel] 35 | packages = ["flatdata"] 36 | -------------------------------------------------------------------------------- /flatdata-generator/requirements.txt: -------------------------------------------------------------------------------- 1 | pyparsing>=2.0 2 | jinja2>=2.10 3 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/assertions.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | 6 | import re 7 | import difflib 8 | 9 | from flatdata.generator.tree.builder import build_ast 10 | 11 | def unify_whitespace(value): 12 | removed_trailing = re.sub(r"\s+$", "", value) 13 | return re.sub(r"\s+", " ", removed_trailing) 14 | 15 | def diff(a, b): 16 | return "\n".join(difflib.unified_diff(a.split("\n"), b.split("\n"))) 17 | 18 | def generate_and_assert_in(definition, generator, *expectations, unexpected_items=None): 19 | tree = build_ast(definition=definition) 20 | contents = generator().render(tree) 21 | contents_unified = unify_whitespace(contents) 22 | 23 | assert expectations or unexpected_items, "No expectations specified" 24 | for expectation in expectations: 25 | expectation_unified = unify_whitespace(expectation) 26 | assert expectation_unified in contents_unified, "\nDetected change:\n========== DIFF ===========\n%s" % diff(expectation, contents) 27 | 28 | if unexpected_items: 29 | for unexpected_item in unexpected_items: 30 | unexpected_item_unified = unify_whitespace(unexpected_item) 31 | assert not unexpected_item_unified in contents_unified, "\n*Did find:\n%s\n========== IN GENERATED CODE ===========\n%s" % (unexpected_item, contents) 32 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/comments.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/cpp_expectations/archives/comments.h -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/empty.h: -------------------------------------------------------------------------------- 1 | class A : public flatdata::Archive 2 | { 3 | public: 4 | /// Archive schema 5 | static const char* schema_definition( ); 6 | /// Archive name 7 | static const char* name_definition( ); 8 | 9 | public: 10 | /** 11 | * Create and open archive at path. 12 | * In case opening fails, is_open() or operator bool() returns false. 13 | * 14 | * @sa is_open 15 | * @sa operator bool() 16 | */ 17 | static A open( std::shared_ptr< flatdata::ResourceStorage > storage ); 18 | A( ) = default; 19 | 20 | 21 | const char* name( ) const override; 22 | const char* schema( ) const override; 23 | 24 | private: 25 | explicit A( std::shared_ptr< flatdata::ResourceStorage > storage ); 26 | 27 | bool load_contents( ) override; 28 | void describe_resources( std::ostream& stream, size_t nest_level ) const override; 29 | 30 | private: 31 | }; 32 | 33 | class ABuilder : public flatdata::ArchiveBuilder 34 | { 35 | public: 36 | /// Creates Archive builder 37 | static ABuilder open( std::shared_ptr< flatdata::ResourceStorage > storage ); 38 | /// Archive schema 39 | static const char* schema_definition( ); 40 | 41 | public: /// Common methods 42 | ABuilder( ) = default; 43 | const char* name( ) const override; 44 | const char* schema( ) const override; 45 | 46 | public: /// Resources 47 | 48 | 49 | private: 50 | ABuilder( std::shared_ptr< flatdata::ResourceStorage > storage ); 51 | 52 | }; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/multivector.h.1: -------------------------------------------------------------------------------- 1 | using DataType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >; 2 | const DataType& data( ) const; 3 | 4 | using OptionalDataType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >; 5 | const boost::optional< OptionalDataType >& optional_data( ) const; 6 | 7 | using DataU64IndexType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >; 8 | const DataU64IndexType& data_u64_index( ) const; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/multivector.h.2: -------------------------------------------------------------------------------- 1 | using DataType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >; 2 | using DataReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >; 3 | DataType start_data( ); 4 | 5 | using OptionalDataType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >; 6 | using OptionalDataReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >; 7 | OptionalDataType start_optional_data( ); 8 | 9 | using DataU64IndexType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >; 10 | using DataU64IndexReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >; 11 | DataU64IndexType start_data_u64_index( ); -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/raw_data.h.1: -------------------------------------------------------------------------------- 1 | using DataType = flatdata::MemoryDescriptor; 2 | const DataType& data( ) const; 3 | 4 | using OptionalDataType = flatdata::MemoryDescriptor; 5 | const boost::optional< OptionalDataType >& optional_data( ) const; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/raw_data.h.2: -------------------------------------------------------------------------------- 1 | using DataType = flatdata::MemoryDescriptor; 2 | using DataReaderType = flatdata::MemoryDescriptor; 3 | bool set_data( DataReaderType data ); 4 | 5 | using OptionalDataType = flatdata::MemoryDescriptor; 6 | using OptionalDataReaderType = flatdata::MemoryDescriptor; 7 | bool set_optional_data( OptionalDataReaderType data ); -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/struct.h.1: -------------------------------------------------------------------------------- 1 | using DataType = ::n::S; 2 | const DataType& data( ) const; 3 | 4 | using OptionalDataType = ::n::S; 5 | const boost::optional< OptionalDataType >& optional_data( ) const; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/struct.h.2: -------------------------------------------------------------------------------- 1 | using DataType = ::n::S; 2 | using DataReaderType = ::n::S; 3 | bool set_data( DataReaderType data ); 4 | 5 | using OptionalDataType = ::n::S; 6 | using OptionalDataReaderType = ::n::S; 7 | bool set_optional_data( OptionalDataReaderType data ); -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/subarchive.h.1: -------------------------------------------------------------------------------- 1 | using DataType = ::n::X; 2 | const DataType& data( ) const; 3 | 4 | using OptionalDataType = ::n::X; 5 | const boost::optional< OptionalDataType >& optional_data( ) const; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/subarchive.h.2: -------------------------------------------------------------------------------- 1 | using DataType = ::n::XBuilder; 2 | DataType& data( ); 3 | using OptionalDataType = ::n::XBuilder; 4 | OptionalDataType& optional_data( ); -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/vector.h.1: -------------------------------------------------------------------------------- 1 | using DataType = flatdata::ArrayView< ::n::S >; 2 | const DataType& data( ) const; 3 | 4 | using OptionalDataType = flatdata::ArrayView< ::n::S >; 5 | const boost::optional< OptionalDataType >& optional_data( ) const; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/archives/vector.h.2: -------------------------------------------------------------------------------- 1 | using DataType = flatdata::ExternalVector< ::n::S >; 2 | using DataReaderType = flatdata::ArrayView< ::n::S >; 3 | DataType start_data( ); 4 | bool set_data( DataReaderType data ); 5 | 6 | using OptionalDataType = flatdata::ExternalVector< ::n::S >; 7 | using OptionalDataReaderType = flatdata::ArrayView< ::n::S >; 8 | OptionalDataType start_optional_data( ); 9 | bool set_optional_data( OptionalDataReaderType data ); -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.1: -------------------------------------------------------------------------------- 1 | enum : uint32_t 2 | { 3 | // This is a comment about foo 4 | FOO = 0UL 5 | }; 6 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/constants/comments.h.2: -------------------------------------------------------------------------------- 1 | enum : uint64_t 2 | { 3 | /* 4 | * This is a comment about bar 5 | */ 6 | BAR = 0ULL 7 | }; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/constants/invalid_value.h: -------------------------------------------------------------------------------- 1 | template< template < typename, int, int, int > class Member > 2 | union BarTemplate 3 | { 4 | using InvalidZeroType = Member< flatdata::Tagged< int8_t, ::n::INVALID_ZERO >, 0, 8, 3 >; 5 | InvalidZeroType invalid_zero; 6 | using InvalidMinIntType = Member< flatdata::Tagged< int8_t, ::n::INVALID_MIN_INT >, 8, 8, 3 >; 7 | InvalidMinIntType invalid_min_int; 8 | using InvalidMaxIntType = Member< flatdata::Tagged< int8_t, ::n::INVALID_MAX_INT >, 16, 8, 3 >; 9 | InvalidMaxIntType invalid_max_int; 10 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/constants/namespaces.h: -------------------------------------------------------------------------------- 1 | namespace n { 2 | enum : int8_t 3 | { 4 | FOO = 0 5 | }; 6 | } // namespace n 7 | 8 | namespace n { 9 | enum : int8_t 10 | { 11 | FOO2 = 10 12 | }; 13 | } // namespace n 14 | 15 | namespace m { 16 | enum : int8_t 17 | { 18 | FOO = 1 19 | }; 20 | } // namespace m 21 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.1: -------------------------------------------------------------------------------- 1 | // This is a comment about Foo 2 | enum class Foo : uint64_t 3 | { 4 | // This is a comment about Foo.a 5 | A = 0ULL, 6 | // This is a comment about Foo.b 7 | B = 1ULL 8 | }; 9 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/comments.h.2: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a comment about Bar 3 | */ 4 | enum class Bar : uint64_t 5 | { 6 | /* 7 | * This is a comment about Bar.a 8 | */ 9 | A = 0ULL, 10 | /* 11 | * This is a comment about Bar.b 12 | */ 13 | B = 1ULL 14 | }; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/default_width.h: -------------------------------------------------------------------------------- 1 | template< template < typename, int, int, int > class Member > 2 | union StructEnumI8Template 3 | { 4 | using FType = Member< ::n::EnumI8, 0, 1, 1 >; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/implicit_values.h: -------------------------------------------------------------------------------- 1 | enum class Enum1 : uint16_t 2 | { 3 | // = 0 4 | VALUE_1 = 0, 5 | // = 3 6 | VALUE_2 = 3, 7 | // = 4 8 | VALUE_3 = 4, 9 | // = 1 10 | VALUE_4 = 1, 11 | // = 2 12 | VALUE_5 = 2, 13 | UNKNOWN_VALUE_5 = 5, 14 | UNKNOWN_VALUE_6 = 6, 15 | UNKNOWN_VALUE_7 = 7 16 | }; 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/namespaces.h.1: -------------------------------------------------------------------------------- 1 | namespace n { 2 | 3 | template< template < typename, int, int, int > class Member > 4 | union FooTemplate 5 | { 6 | using FType = Member< ::a::Bar, 0, 1, 1 >; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/namespaces.h.2: -------------------------------------------------------------------------------- 1 | namespace m { 2 | 3 | template< template < typename, int, int, int > class Member > 4 | union FooTemplate 5 | { 6 | using FType = Member< ::b::Bar, 0, 1, 1 >; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/structs.h.1: -------------------------------------------------------------------------------- 1 | enum class EnumI8 : int8_t 2 | { 3 | VALUE = 0, 4 | UNKNOWN_VALUE_MINUS_1 = -1 5 | }; 6 | 7 | inline 8 | const char* to_string( EnumI8 value ); -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/enums/structs.h.2: -------------------------------------------------------------------------------- 1 | template< template < typename, int, int, int > class Member > 2 | union StructEnumI8Template 3 | { 4 | using FType = Member< ::n::EnumI8, 0, 1, 1 >; 5 | FType f; 6 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/structs/comments.h.1: -------------------------------------------------------------------------------- 1 | // This is a comment about Foo 2 | template< template < typename, int, int, int > class Member > 3 | union FooTemplate -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/structs/comments.h.2: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a comment about Bar 3 | */ 4 | template< template < typename, int, int, int > class Member > 5 | union BarTemplate -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/structs/default_width.h: -------------------------------------------------------------------------------- 1 | template< template < typename, int, int, int > class Member > 2 | union U8Template 3 | { 4 | using FType = Member< uint8_t, 0, 8, 1 >; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/structs/namespaces.h.1: -------------------------------------------------------------------------------- 1 | namespace n { 2 | 3 | template< template < typename, int, int, int > class Member > 4 | union FooTemplate -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/structs/namespaces.h.2: -------------------------------------------------------------------------------- 1 | namespace m { 2 | 3 | template< template < typename, int, int, int > class Member > 4 | union FooTemplate -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/cpp_expectations/structs/unaligned.h: -------------------------------------------------------------------------------- 1 | template< template < typename, int, int, int > class Member > 2 | union U8Template 3 | { 4 | using PaddingType = Member< uint64_t, 0, 3, 1 >; 5 | PaddingType padding; 6 | using FType = Member< uint8_t, 3, 5, 1 >; 7 | FType f; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/comments.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/archives/comments.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/empty.dot: -------------------------------------------------------------------------------- 1 | digraph FlatdataDot 2 | { 3 | graph [splines=true, compound=false, rankdir=LR, rank=same, style=filled, fontsize="16", fontname="Courier New", penwidth=1, fontcolor="#516D7B"] 4 | node [shape=none, margin=none, fontsize=9, fontname="Courier New"]; 5 | edge [style=solid, arrowsize=0.5, color="#257FAD", arrowtail="dot", dir="both"] 6 | 7 | subgraph cluster__n 8 | { 9 | penwidth=0; 10 | fontcolor="#516D7B"; 11 | fillcolor="#F7F7F7"; 12 | label=<n> 13 | subgraph cluster__n_A 14 | { 15 | penwidth=1; 16 | color="#85D4FF"; 17 | fillcolor="#EBF8FF"; 18 | label=<A> 19 | } 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/ranges.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/archives/ranges.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/raw_data.dot: -------------------------------------------------------------------------------- 1 | subgraph cluster__n 2 | { 3 | penwidth=0; 4 | fontcolor="#516D7B"; 5 | fillcolor="#F7F7F7"; 6 | label=<n> 7 | subgraph cluster__n_A 8 | { 9 | penwidth=1; 10 | color="#85D4FF"; 11 | fillcolor="#EBF8FF"; 12 | label=<A> 13 | subgraph cluster__n_A_data 14 | { 15 | label=<data
RawData> 16 | penwidth=0; 17 | fontsize="9" 18 | fillcolor="#C4E6F8"; 19 | 20 | _n_A_data [style=invisible, fixedsize="true", width="0", height="0", label=""]; 21 | 22 | 23 | } 24 | 25 | subgraph cluster__n_A_optional_data 26 | { 27 | label=<optional_data
RawData
optional
> 28 | penwidth=0; 29 | fontsize="9" 30 | fillcolor="#C4E6F8"; 31 | 32 | _n_A_optional_data [style=invisible, fixedsize="true", width="0", height="0", label=""]; 33 | 34 | 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/struct.dot: -------------------------------------------------------------------------------- 1 | subgraph cluster__n 2 | { 3 | penwidth=0; 4 | fontcolor="#516D7B"; 5 | fillcolor="#F7F7F7"; 6 | label=<n> 7 | subgraph cluster__n_A 8 | { 9 | penwidth=1; 10 | color="#85D4FF"; 11 | fillcolor="#EBF8FF"; 12 | label=<A> 13 | subgraph cluster__n_A_data 14 | { 15 | label=<data
Instance> 16 | penwidth=0; 17 | fontsize="9" 18 | fillcolor="#C4E6F8"; 19 | 20 | 21 | _n_A_data_n_S [label=< 22 | 23 | 24 | 27 | 28 | 29 | 32 | 33 |
25 | S 26 |
30 | x:u64:64 31 |
>]; 34 | 35 | 36 | } 37 | 38 | subgraph cluster__n_A_optional_data 39 | { 40 | label=<optional_data
Instance
optional
> 41 | penwidth=0; 42 | fontsize="9" 43 | fillcolor="#C4E6F8"; 44 | 45 | 46 | _n_A_optional_data_n_S [label=< 47 | 48 | 49 | 52 | 53 | 54 | 57 | 58 |
50 | S 51 |
55 | x:u64:64 56 |
>]; 59 | 60 | 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/subarchive.dot: -------------------------------------------------------------------------------- 1 | subgraph cluster__n 2 | { 3 | penwidth=0; 4 | fontcolor="#516D7B"; 5 | fillcolor="#F7F7F7"; 6 | label=<n> 7 | subgraph cluster__n_X 8 | { 9 | penwidth=1; 10 | color="#85D4FF"; 11 | fillcolor="#EBF8FF"; 12 | label=<X> 13 | subgraph cluster__n_X_payload 14 | { 15 | label=<payload
RawData> 16 | penwidth=0; 17 | fontsize="9" 18 | fillcolor="#C4E6F8"; 19 | 20 | _n_X_payload [style=invisible, fixedsize="true", width="0", height="0", label=""]; 21 | 22 | 23 | } 24 | 25 | } 26 | subgraph cluster__n_A 27 | { 28 | penwidth=1; 29 | color="#85D4FF"; 30 | fillcolor="#EBF8FF"; 31 | label=<A> 32 | subgraph cluster__n_A_data 33 | { 34 | label=<data
Archive> 35 | penwidth=0; 36 | fontsize="9" 37 | fillcolor="#C4E6F8"; 38 | 39 | _n_A_data [style=invisible, fixedsize="true", width="0", height="0", label=""]; 40 | 41 | 42 | } 43 | 44 | subgraph cluster__n_A_optional_data 45 | { 46 | label=<optional_data
Archive
optional
> 47 | penwidth=0; 48 | fontsize="9" 49 | fillcolor="#C4E6F8"; 50 | 51 | _n_A_optional_data [style=invisible, fixedsize="true", width="0", height="0", label=""]; 52 | 53 | 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/archives/vector.dot: -------------------------------------------------------------------------------- 1 | subgraph cluster__n 2 | { 3 | penwidth=0; 4 | fontcolor="#516D7B"; 5 | fillcolor="#F7F7F7"; 6 | label=<n> 7 | subgraph cluster__n_A 8 | { 9 | penwidth=1; 10 | color="#85D4FF"; 11 | fillcolor="#EBF8FF"; 12 | label=<A> 13 | subgraph cluster__n_A_data 14 | { 15 | label=<data
Vector> 16 | penwidth=0; 17 | fontsize="9" 18 | fillcolor="#C4E6F8"; 19 | 20 | 21 | _n_A_data_n_S [label=< 22 | 23 | 24 | 27 | 28 | 29 | 32 | 33 |
25 | S 26 |
30 | x:u64:64 31 |
>]; 34 | 35 | 36 | } 37 | 38 | subgraph cluster__n_A_optional_data 39 | { 40 | label=<optional_data
Vector
optional
> 41 | penwidth=0; 42 | fontsize="9" 43 | fillcolor="#C4E6F8"; 44 | 45 | 46 | _n_A_optional_data_n_S [label=< 47 | 48 | 49 | 52 | 53 | 54 | 57 | 58 |
50 | S 51 |
55 | x:u64:64 56 |
>]; 59 | 60 | 61 | } 62 | 63 | } 64 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/constants/comments.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/constants/comments.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/constants/invalid_value.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/constants/invalid_value.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/constants/namespaces.dot: -------------------------------------------------------------------------------- 1 | digraph FlatdataDot 2 | { 3 | graph [splines=true, compound=false, rankdir=LR, rank=same, style=filled, fontsize="16", fontname="Courier New", penwidth=1, fontcolor="#516D7B"] 4 | node [shape=none, margin=none, fontsize=9, fontname="Courier New"]; 5 | edge [style=solid, arrowsize=0.5, color="#257FAD", arrowtail="dot", dir="both"] 6 | 7 | subgraph cluster__n 8 | { 9 | penwidth=0; 10 | fontcolor="#516D7B"; 11 | fillcolor="#F7F7F7"; 12 | label=<n> 13 | } 14 | 15 | subgraph cluster__m 16 | { 17 | penwidth=0; 18 | fontcolor="#516D7B"; 19 | fillcolor="#F7F7F7"; 20 | label=<m> 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/constants/values.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/constants/values.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/enums/comments.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/enums/comments.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/enums/default_width.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/enums/default_width.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/enums/implicit_values.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/enums/implicit_values.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/enums/namespaces.dot: -------------------------------------------------------------------------------- 1 | digraph FlatdataDot 2 | { 3 | graph [splines=true, compound=false, rankdir=LR, rank=same, style=filled, fontsize="16", fontname="Courier New", penwidth=1, fontcolor="#516D7B"] 4 | node [shape=none, margin=none, fontsize=9, fontname="Courier New"]; 5 | edge [style=solid, arrowsize=0.5, color="#257FAD", arrowtail="dot", dir="both"] 6 | 7 | subgraph cluster__a 8 | { 9 | penwidth=0; 10 | fontcolor="#516D7B"; 11 | fillcolor="#F7F7F7"; 12 | label=<a> 13 | } 14 | 15 | subgraph cluster__b 16 | { 17 | penwidth=0; 18 | fontcolor="#516D7B"; 19 | fillcolor="#F7F7F7"; 20 | label=<b> 21 | } 22 | 23 | subgraph cluster__n 24 | { 25 | penwidth=0; 26 | fontcolor="#516D7B"; 27 | fillcolor="#F7F7F7"; 28 | label=<n> 29 | } 30 | 31 | subgraph cluster__m 32 | { 33 | penwidth=0; 34 | fontcolor="#516D7B"; 35 | fillcolor="#F7F7F7"; 36 | label=<m> 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/enums/structs.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/enums/structs.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/enums/values.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/enums/values.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/structs/comments.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/structs/comments.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/structs/default_width.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/structs/default_width.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/structs/integers.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/structs/integers.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/structs/namespaces.dot: -------------------------------------------------------------------------------- 1 | digraph FlatdataDot 2 | { 3 | graph [splines=true, compound=false, rankdir=LR, rank=same, style=filled, fontsize="16", fontname="Courier New", penwidth=1, fontcolor="#516D7B"] 4 | node [shape=none, margin=none, fontsize=9, fontname="Courier New"]; 5 | edge [style=solid, arrowsize=0.5, color="#257FAD", arrowtail="dot", dir="both"] 6 | 7 | subgraph cluster__n 8 | { 9 | penwidth=0; 10 | fontcolor="#516D7B"; 11 | fillcolor="#F7F7F7"; 12 | label=<n> 13 | } 14 | 15 | subgraph cluster__m 16 | { 17 | penwidth=0; 18 | fontcolor="#516D7B"; 19 | fillcolor="#F7F7F7"; 20 | label=<m> 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/dot_expectations/structs/unaligned.dot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/dot_expectations/structs/unaligned.dot -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/comments.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | archive Foo 3 | { 4 | bar : raw_data; 5 | } 6 | } 7 | 8 | namespace n { 9 | archive Bar 10 | { 11 | foo : raw_data; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/empty.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | archive A 3 | { 4 | } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/multivector.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct S 3 | { 4 | x : u64 : 64; 5 | } 6 | } 7 | 8 | namespace n { 9 | struct T 10 | { 11 | x : u64 : 64; 12 | } 13 | } 14 | 15 | namespace n { 16 | archive A 17 | { 18 | data : multivector< 8, .n.S, .n.T >; 19 | @optional 20 | optional_data : multivector< 16, .n.S, .n.T >; 21 | data_u64_index : multivector< 64, .n.S, .n.T >; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct S 3 | { 4 | x : u64 : 64; 5 | } 6 | } 7 | 8 | namespace n { 9 | archive X 10 | { 11 | payload : raw_data; 12 | } 13 | } 14 | 15 | namespace m { 16 | struct S 17 | { 18 | x : u64 : 64; 19 | } 20 | } 21 | 22 | namespace m { 23 | archive X 24 | { 25 | payload : raw_data; 26 | } 27 | } 28 | 29 | namespace a { 30 | archive A 31 | { 32 | single : .n.S; 33 | list : vector< .m.S >; 34 | multi : multivector< 32, .n.S >; 35 | inner : archive .n.X; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/ranges.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct S 3 | { 4 | x : u64 : 64; 5 | @range( y_range ) 6 | first_y : u32 : 14; 7 | } 8 | } 9 | 10 | namespace n { 11 | archive A 12 | { 13 | data : vector< .n.S >; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/raw_data.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | archive A 3 | { 4 | data : raw_data; 5 | @optional 6 | optional_data : raw_data; 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/references.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct S 3 | { 4 | x : u32 : 32; 5 | } 6 | } 7 | 8 | namespace n { 9 | struct R 10 | { 11 | ref : u32 : 8; 12 | ref2 : u32 : 4; 13 | } 14 | } 15 | 16 | namespace n { 17 | @bound_implicitly( all_lists : .n.A.list1, .n.A.list2, .n.A.multilist1 ) 18 | archive A 19 | { 20 | @optional 21 | list1 : vector< .n.S >; 22 | list2 : vector< .n.S >; 23 | @optional 24 | multilist1 : multivector< 32, .n.S >; 25 | multilist2 : multivector< 32, .n.S >; 26 | @optional 27 | raw1 : raw_data; 28 | raw2 : raw_data; 29 | @explicit_reference( .n.R.ref, .n.A.list1 ) 30 | @explicit_reference( .n.R.ref2, .n.A.list1 ) 31 | @explicit_reference( .n.R.ref2, .n.A.list2 ) 32 | @explicit_reference( .n.R.ref2, .n.A.multilist1 ) 33 | @explicit_reference( .n.R.ref2, .n.A.multilist2 ) 34 | @explicit_reference( .n.R.ref2, .n.A.raw1 ) 35 | @explicit_reference( .n.R.ref2, .n.A.raw2 ) 36 | refs : vector< .n.R >; 37 | @explicit_reference( .n.R.ref, .n.A.list1 ) 38 | multirefs : multivector< 32, .n.R >; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/struct.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct S 3 | { 4 | x : u64 : 64; 5 | } 6 | } 7 | 8 | namespace n { 9 | archive A 10 | { 11 | data : .n.S; 12 | @optional 13 | optional_data : .n.S; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/subarchive.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | archive X 3 | { 4 | payload : raw_data; 5 | } 6 | } 7 | 8 | namespace n { 9 | archive A 10 | { 11 | data : archive .n.X; 12 | @optional 13 | optional_data : archive .n.X; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/archives/vector.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct S 3 | { 4 | x : u64 : 64; 5 | } 6 | } 7 | 8 | namespace n { 9 | archive A 10 | { 11 | data : vector< .n.S >; 12 | @optional 13 | optional_data : vector< .n.S >; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/constants/comments.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | const u32 FOO = 0; 3 | } 4 | 5 | namespace n { 6 | const u64 BAR = 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/constants/invalid_value.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | const i8 INVALID_ZERO = 0; 3 | } 4 | 5 | namespace n { 6 | const i8 INVALID_MIN_INT = -128; 7 | } 8 | 9 | namespace n { 10 | const i8 INVALID_MAX_INT = 127; 11 | } 12 | 13 | namespace n { 14 | struct Bar 15 | { 16 | @optional( .n.INVALID_ZERO ) 17 | invalid_zero : i8 : 8; 18 | @optional( .n.INVALID_MIN_INT ) 19 | invalid_min_int : i8 : 8; 20 | @optional( .n.INVALID_MAX_INT ) 21 | invalid_max_int : i8 : 8; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/constants/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | const i8 FOO = 0; 3 | } 4 | 5 | namespace n { 6 | const i8 FOO2 = 10; 7 | } 8 | 9 | namespace m { 10 | const i8 FOO = 1; 11 | } 12 | 13 | namespace m { 14 | struct Bar 15 | { 16 | @const( .m.FOO ) 17 | foo1 : i8 : 8; 18 | @const( .n.FOO ) 19 | foo2 : i8 : 8; 20 | @const( .m.FOO ) 21 | foo3 : i8 : 8; 22 | @optional( .m.FOO ) 23 | bar1 : i8 : 8; 24 | @optional( .n.FOO ) 25 | bar2 : i8 : 8; 26 | @optional( .m.FOO ) 27 | bar3 : i8 : 8; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/enums/comments.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | enum Foo : u64 : 1 3 | { 4 | A = 0, 5 | B = 1, 6 | } 7 | } 8 | 9 | namespace n { 10 | enum Bar : u64 : 1 11 | { 12 | A = 0, 13 | B = 1, 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/enums/default_width.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | enum EnumI8 : i8 : 1 3 | { 4 | VALUE = 0, 5 | } 6 | } 7 | 8 | namespace n { 9 | struct StructEnumI8 10 | { 11 | f : .n.EnumI8 : 1; 12 | } 13 | } 14 | 15 | namespace n { 16 | enum EnumU8 : u8 : 1 17 | { 18 | VALUE = 0, 19 | } 20 | } 21 | 22 | namespace n { 23 | struct StructEnumU8 24 | { 25 | f : .n.EnumU8 : 1; 26 | } 27 | } 28 | 29 | namespace n { 30 | enum EnumI16 : i16 : 1 31 | { 32 | VALUE = 0, 33 | } 34 | } 35 | 36 | namespace n { 37 | struct StructEnumI16 38 | { 39 | f : .n.EnumI16 : 1; 40 | } 41 | } 42 | 43 | namespace n { 44 | enum EnumU16 : u16 : 1 45 | { 46 | VALUE = 0, 47 | } 48 | } 49 | 50 | namespace n { 51 | struct StructEnumU16 52 | { 53 | f : .n.EnumU16 : 1; 54 | } 55 | } 56 | 57 | namespace n { 58 | enum EnumI32 : i32 : 1 59 | { 60 | VALUE = 0, 61 | } 62 | } 63 | 64 | namespace n { 65 | struct StructEnumI32 66 | { 67 | f : .n.EnumI32 : 1; 68 | } 69 | } 70 | 71 | namespace n { 72 | enum EnumU32 : u32 : 1 73 | { 74 | VALUE = 0, 75 | } 76 | } 77 | 78 | namespace n { 79 | struct StructEnumU32 80 | { 81 | f : .n.EnumU32 : 1; 82 | } 83 | } 84 | 85 | namespace n { 86 | enum EnumI64 : i64 : 1 87 | { 88 | VALUE = 0, 89 | } 90 | } 91 | 92 | namespace n { 93 | struct StructEnumI64 94 | { 95 | f : .n.EnumI64 : 1; 96 | } 97 | } 98 | 99 | namespace n { 100 | enum EnumU64 : u64 : 1 101 | { 102 | VALUE = 0, 103 | } 104 | } 105 | 106 | namespace n { 107 | struct StructEnumU64 108 | { 109 | f : .n.EnumU64 : 1; 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/enums/implicit_values.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | enum Enum1 : u16 : 3 3 | { 4 | VALUE_1 = 0, 5 | VALUE_2 = 3, 6 | VALUE_3 = 4, 7 | VALUE_4 = 1, 8 | VALUE_5 = 2, 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/enums/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | namespace a { 2 | enum Bar : u8 : 1 3 | { 4 | VALUE = 0, 5 | } 6 | } 7 | 8 | namespace b { 9 | enum Bar : u8 : 1 10 | { 11 | VALUE = 0, 12 | } 13 | } 14 | 15 | namespace n { 16 | struct Foo 17 | { 18 | f : .a.Bar : 1; 19 | } 20 | } 21 | 22 | namespace m { 23 | struct Foo 24 | { 25 | f : .b.Bar : 1; 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/enums/structs.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | enum EnumI8 : i8 : 1 3 | { 4 | VALUE = 0, 5 | } 6 | } 7 | 8 | namespace n { 9 | struct StructEnumI8 10 | { 11 | f : .n.EnumI8 : 1; 12 | } 13 | } 14 | 15 | namespace n { 16 | enum EnumU8 : u8 : 1 17 | { 18 | VALUE = 0, 19 | } 20 | } 21 | 22 | namespace n { 23 | struct StructEnumU8 24 | { 25 | f : .n.EnumU8 : 1; 26 | } 27 | } 28 | 29 | namespace n { 30 | enum EnumI16 : i16 : 1 31 | { 32 | VALUE = 0, 33 | } 34 | } 35 | 36 | namespace n { 37 | struct StructEnumI16 38 | { 39 | f : .n.EnumI16 : 1; 40 | } 41 | } 42 | 43 | namespace n { 44 | enum EnumU16 : u16 : 1 45 | { 46 | VALUE = 0, 47 | } 48 | } 49 | 50 | namespace n { 51 | struct StructEnumU16 52 | { 53 | f : .n.EnumU16 : 1; 54 | } 55 | } 56 | 57 | namespace n { 58 | enum EnumI32 : i32 : 1 59 | { 60 | VALUE = 0, 61 | } 62 | } 63 | 64 | namespace n { 65 | struct StructEnumI32 66 | { 67 | f : .n.EnumI32 : 1; 68 | } 69 | } 70 | 71 | namespace n { 72 | enum EnumU32 : u32 : 1 73 | { 74 | VALUE = 0, 75 | } 76 | } 77 | 78 | namespace n { 79 | struct StructEnumU32 80 | { 81 | f : .n.EnumU32 : 1; 82 | } 83 | } 84 | 85 | namespace n { 86 | enum EnumI64 : i64 : 1 87 | { 88 | VALUE = 0, 89 | } 90 | } 91 | 92 | namespace n { 93 | struct StructEnumI64 94 | { 95 | f : .n.EnumI64 : 1; 96 | } 97 | } 98 | 99 | namespace n { 100 | enum EnumU64 : u64 : 1 101 | { 102 | VALUE = 0, 103 | } 104 | } 105 | 106 | namespace n { 107 | struct StructEnumU64 108 | { 109 | f : .n.EnumU64 : 1; 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/enums/values.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | enum EnumI8 : i8 : 8 3 | { 4 | FOO_I8_NEG = -128, 5 | FOO_I8_POS = 127, 6 | FOO_I8_ZERO = 0, 7 | FOO_I8_NEG_HEX = -127, 8 | FOO_I8_POS_HEX = 126, 9 | FOO_I8_ONE_HEX = 1, 10 | } 11 | } 12 | 13 | namespace n { 14 | enum EnumU8 : u8 : 8 15 | { 16 | FOO_U8_POS = 255, 17 | FOO_U8_ZERO = 0, 18 | FOO_U8_POS_HEX = 254, 19 | FOO_U8_ONE_HEX = 1, 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/structs/comments.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct Foo 3 | { 4 | a : u64 : 64; 5 | b : u64 : 64; 6 | } 7 | } 8 | 9 | namespace n { 10 | struct Bar 11 | { 12 | a : u64 : 64; 13 | b : u64 : 64; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/structs/default_width.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct U8 3 | { 4 | f : u8 : 8; 5 | } 6 | } 7 | 8 | namespace n { 9 | struct I8 10 | { 11 | f : i8 : 8; 12 | } 13 | } 14 | 15 | namespace n { 16 | struct U16 17 | { 18 | f : u16 : 16; 19 | } 20 | } 21 | 22 | namespace n { 23 | struct I16 24 | { 25 | f : i16 : 16; 26 | } 27 | } 28 | 29 | namespace n { 30 | struct U32 31 | { 32 | f : u32 : 32; 33 | } 34 | } 35 | 36 | namespace n { 37 | struct I32 38 | { 39 | f : i32 : 32; 40 | } 41 | } 42 | 43 | namespace n { 44 | struct U64 45 | { 46 | f : u64 : 64; 47 | } 48 | } 49 | 50 | namespace n { 51 | struct I64 52 | { 53 | f : i64 : 64; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/structs/integers.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct U8 3 | { 4 | f : u8 : 8; 5 | } 6 | } 7 | 8 | namespace n { 9 | struct I8 10 | { 11 | f : i8 : 8; 12 | } 13 | } 14 | 15 | namespace n { 16 | struct U16 17 | { 18 | f : u16 : 16; 19 | } 20 | } 21 | 22 | namespace n { 23 | struct I16 24 | { 25 | f : i16 : 16; 26 | } 27 | } 28 | 29 | namespace n { 30 | struct U32 31 | { 32 | f : u32 : 32; 33 | } 34 | } 35 | 36 | namespace n { 37 | struct I32 38 | { 39 | f : i32 : 32; 40 | } 41 | } 42 | 43 | namespace n { 44 | struct U64 45 | { 46 | f : u64 : 64; 47 | } 48 | } 49 | 50 | namespace n { 51 | struct I64 52 | { 53 | f : i64 : 64; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/structs/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct Foo 3 | { 4 | f : u32 : 32; 5 | } 6 | } 7 | 8 | namespace m { 9 | struct Foo 10 | { 11 | f : u32 : 32; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/flatdata_expectations/structs/unaligned.flatdata: -------------------------------------------------------------------------------- 1 | namespace n { 2 | struct U8 3 | { 4 | padding : u64 : 3; 5 | f : u8 : 5; 6 | } 7 | } 8 | 9 | namespace n { 10 | struct I8 11 | { 12 | padding : u64 : 3; 13 | f : i8 : 5; 14 | } 15 | } 16 | 17 | namespace n { 18 | struct U16 19 | { 20 | padding : u64 : 3; 21 | f : u16 : 13; 22 | } 23 | } 24 | 25 | namespace n { 26 | struct I16 27 | { 28 | padding : u64 : 3; 29 | f : i16 : 13; 30 | } 31 | } 32 | 33 | namespace n { 34 | struct U32 35 | { 36 | padding : u64 : 3; 37 | f : u32 : 29; 38 | } 39 | } 40 | 41 | namespace n { 42 | struct I32 43 | { 44 | padding : u64 : 3; 45 | f : i32 : 29; 46 | } 47 | } 48 | 49 | namespace n { 50 | struct U64 51 | { 52 | padding : u64 : 3; 53 | f : u64 : 61; 54 | } 55 | } 56 | 57 | namespace n { 58 | struct I64 59 | { 60 | padding : u64 : 3; 61 | f : i64 : 61; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/archives/comments.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/go_expectations/archives/comments.go -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/archives/empty.go: -------------------------------------------------------------------------------- 1 | type AArchive struct { 2 | IsOptional bool 3 | IsOpen bool 4 | } 5 | 6 | func (v *AArchive) Close() { 7 | } 8 | 9 | func (v *AArchive) GetSizeInBytes() int { 10 | var size int 11 | return size 12 | } 13 | 14 | func (v *AArchive) ToString() string { 15 | buffer := bytes.Buffer{} 16 | buffer.WriteString(fmt.Sprintf(`{"name": "A", "container_type": "Archive", "size_in_bytes": %d, "resources": [`, v.GetSizeInBytes())) 17 | buffer.WriteString("]}") 18 | return buffer.String() 19 | } 20 | 21 | func OpenAArchive(resource flatdata.ResourceStorage) (*AArchive, error) { 22 | v := &AArchive{} 23 | // Initialize resources 24 | // Add resources to archive 25 | return v, nil 26 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/archives/references.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/go_expectations/archives/references.go -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/constants/comments.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/go_expectations/constants/comments.go -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/constants/values.go: -------------------------------------------------------------------------------- 1 | package n 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "errors" 7 | "fmt" 8 | "log" 9 | 10 | "github.com/heremaps/flatdata/flatdata-go/flatdata" 11 | ) 12 | 13 | const ( 14 | flatdataOffsetSizeInBytes uint = 8 15 | flatdataPaddingSizeInBytes uint = 8 16 | FooI8Neg int8 = -128 17 | FooI8Pos int8 = 127 18 | FooI8Zero int8 = 0 19 | FooI8NegHex int8 = -128 20 | FooI8PosHex int8 = 127 21 | FooI8ZeroHex int8 = 0 22 | FooU8Pos uint8 = 255 23 | FooU8Zero uint8 = 0 24 | FooU8PosHex uint8 = 255 25 | FooU8ZeroHex uint8 = 0 26 | FooI16Neg int16 = -32768 27 | FooI16Pos int16 = 32767 28 | FooI16Zero int16 = 0 29 | FooI16NegHex int16 = -32768 30 | FooI16PosHex int16 = 32767 31 | FooI16ZeroHex int16 = 0 32 | FooU16Pos uint16 = 65535 33 | FooU16Zero uint16 = 0 34 | FooU16PosHex uint16 = 65535 35 | FooU16ZeroHex uint16 = 0 36 | FooI32Neg int32 = -2147483648 37 | FooI32Pos int32 = 2147483647 38 | FooI32Zero int32 = 0 39 | FooI32NegHex int32 = -2147483648 40 | FooI32PosHex int32 = 2147483647 41 | FooI32ZeroHex int32 = 0 42 | FooU32Pos uint32 = 4294967295 43 | FooU32Zero uint32 = 0 44 | FooU32PosHex uint32 = 4294967295 45 | FooU32ZeroHex uint32 = 0 46 | FooI64Neg int64 = -9223372036854775808 47 | FooI64Pos int64 = 9223372036854775807 48 | FooI64Zero int64 = 0 49 | FooI64NegHex int64 = -9223372036854775808 50 | FooI64PosHex int64 = 9223372036854775807 51 | FooI64ZeroHex int64 = 0 52 | FooU64Pos uint64 = 18446744073709551615 53 | FooU64Zero uint64 = 0 54 | FooU64PosHex uint64 = 18446744073709551615 55 | FooU64ZeroHex uint64 = 0 56 | ) 57 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/structs/comments.go.1: -------------------------------------------------------------------------------- 1 | // // This is a comment about Foo 2 | type Foo struct { 3 | descriptor flatdata.MemoryDescriptor 4 | position int 5 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/structs/comments.go.2: -------------------------------------------------------------------------------- 1 | // /* 2 | // * This is a comment about Bar 3 | // */ 4 | type Bar struct { 5 | descriptor flatdata.MemoryDescriptor 6 | position int 7 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/go_expectations/structs/default_width.go: -------------------------------------------------------------------------------- 1 | const ( 2 | flatdataOffsetSizeInBytes uint = 8 3 | flatdataPaddingSizeInBytes uint = 8 4 | u8SizeInBytes = 1 5 | i8SizeInBytes = 1 6 | u16SizeInBytes = 2 7 | i16SizeInBytes = 2 8 | u32SizeInBytes = 4 9 | i32SizeInBytes = 4 10 | u64SizeInBytes = 8 11 | i64SizeInBytes = 8 12 | ) -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/archives/empty.py: -------------------------------------------------------------------------------- 1 | class n_A(flatdata.archive.Archive): 2 | _SCHEMA = """namespace n { 3 | archive A 4 | { 5 | } 6 | } 7 | 8 | """ 9 | _NAME = "A" 10 | _RESOURCES = { 11 | "A.archive" : flatdata.archive.ResourceSignature( 12 | container=flatdata.resources.RawData, 13 | initializer=None, 14 | schema=_SCHEMA, 15 | is_optional=False, 16 | doc="Archive signature"), 17 | } 18 | 19 | def __init__(self, resource_storage): 20 | flatdata.archive.Archive.__init__(self, resource_storage) -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/archives/raw_data.py: -------------------------------------------------------------------------------- 1 | class n_A(flatdata.archive.Archive): 2 | _SCHEMA = """namespace n { 3 | archive A 4 | { 5 | data : raw_data; 6 | @optional 7 | optional_data : raw_data; 8 | } 9 | } 10 | 11 | """ 12 | _DATA_SCHEMA = """namespace n { 13 | archive A 14 | { 15 | data : raw_data; 16 | } 17 | } 18 | 19 | """ 20 | _DATA_DOC = """""" 21 | _OPTIONAL_DATA_SCHEMA = """namespace n { 22 | archive A 23 | { 24 | @optional 25 | optional_data : raw_data; 26 | } 27 | } 28 | 29 | """ 30 | _OPTIONAL_DATA_DOC = """""" 31 | _NAME = "A" 32 | _RESOURCES = { 33 | "A.archive" : flatdata.archive.ResourceSignature( 34 | container=flatdata.resources.RawData, 35 | initializer=None, 36 | schema=_SCHEMA, 37 | is_optional=False, 38 | doc="Archive signature"), 39 | "data": flatdata.archive.ResourceSignature(container=flatdata.resources.RawData, 40 | initializer=None, 41 | schema=_DATA_SCHEMA, 42 | is_optional=False, 43 | doc=_DATA_DOC), 44 | "optional_data": flatdata.archive.ResourceSignature(container=flatdata.resources.RawData, 45 | initializer=None, 46 | schema=_OPTIONAL_DATA_SCHEMA, 47 | is_optional=True, 48 | doc=_OPTIONAL_DATA_DOC), 49 | } 50 | 51 | def __init__(self, resource_storage): 52 | flatdata.archive.Archive.__init__(self, resource_storage) 53 | 54 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/archives/references.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/py_expectations/archives/references.py -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/structs/comments.py.1: -------------------------------------------------------------------------------- 1 | # This is a comment about Foo 2 | class n_Foo(flatdata.structure.Structure): 3 | """// This is a comment about Foo""" 4 | _SCHEMA = """namespace n { -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/structs/comments.py.2: -------------------------------------------------------------------------------- 1 | # This is a comment about Foo 2 | class n_Foo(flatdata.structure.Structure): 3 | """// This is a comment about Foo""" -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/structs/default_width.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/generators/py_expectations/structs/default_width.py -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/py_expectations/structs/namespaces.py: -------------------------------------------------------------------------------- 1 | class n_Foo(flatdata.structure.Structure): 2 | """""" 3 | _SCHEMA = """namespace n { 4 | struct Foo 5 | { 6 | f : u32 : 32; 7 | } 8 | } 9 | 10 | """ 11 | _NAME = "n_Foo" 12 | _SIZE_IN_BITS = 32 13 | _SIZE_IN_BYTES = 4 14 | _FIELDS = { 15 | "f": flatdata.structure.FieldSignature(offset=0, width=32, is_signed=False, dtype="u4"), 16 | } 17 | _FIELD_KEYS = { 18 | "f", 19 | } 20 | 21 | class m_Foo(flatdata.structure.Structure): 22 | """""" 23 | _SCHEMA = """namespace m { 24 | struct Foo 25 | { 26 | f : u32 : 32; 27 | } 28 | } 29 | 30 | """ 31 | _NAME = "m_Foo" 32 | _SIZE_IN_BITS = 32 33 | _SIZE_IN_BYTES = 4 34 | _FIELDS = { 35 | "f": flatdata.structure.FieldSignature(offset=0, width=32, is_signed=False, dtype="u4"), 36 | } 37 | _FIELD_KEYS = { 38 | "f", 39 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/archives/empty.rs.1: -------------------------------------------------------------------------------- 1 | #[derive(Clone)] 2 | pub struct A { 3 | _storage: flatdata::StorageHandle, 4 | } 5 | 6 | impl A { 7 | fn signature_name(archive_name: &str) -> String { 8 | format!("{}.archive", archive_name) 9 | } 10 | 11 | } 12 | 13 | impl ::std::fmt::Debug for A { 14 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { 15 | f.debug_struct("A") 16 | .finish() 17 | } 18 | } 19 | 20 | impl A { 21 | pub fn open(storage: flatdata::StorageHandle) 22 | -> ::std::result::Result 23 | { 24 | #[allow(unused_imports)] 25 | use flatdata::SliceExt; 26 | #[allow(unused_variables)] 27 | use flatdata::ResourceStorageError as Error; 28 | // extend lifetime since Rust cannot know that we reference a cache here 29 | #[allow(unused_variables)] 30 | let extend = |x : Result<&[u8], Error>| -> Result<&'static [u8], Error> {x.map(|x| unsafe{std::mem::transmute(x)})}; 31 | 32 | storage.read(&Self::signature_name("A"), schema::a::A)?; 33 | 34 | 35 | Ok(Self { 36 | _storage: storage, 37 | }) 38 | } 39 | } 40 | 41 | /// Builder for creating [`A`] archives. 42 | /// 43 | ///[`A`]: struct.A.html 44 | #[derive(Clone, Debug)] 45 | pub struct ABuilder { 46 | storage: flatdata::StorageHandle 47 | } 48 | 49 | 50 | impl ABuilder { 51 | pub fn new( 52 | storage: flatdata::StorageHandle, 53 | ) -> Result { 54 | flatdata::create_archive("A", schema::a::A, &storage)?; 55 | Ok(Self { storage }) 56 | } 57 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/constants/comments.rs.1: -------------------------------------------------------------------------------- 1 | // This is a comment about foo 2 | pub const FOO: u32 = 0; 3 | 4 | /// This is a comment about bar 5 | pub const BAR: u64 = 0; -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/constants/namespaces.rs.1: -------------------------------------------------------------------------------- 1 | pub mod n { 2 | #[allow(unused_imports)] 3 | use flatdata::{flatdata_read_bytes, flatdata_write_bytes}; 4 | 5 | 6 | pub const FOO: i8 = 0; 7 | 8 | pub const FOO2: i8 = 10; 9 | 10 | #[doc(hidden)] 11 | pub mod schema { 12 | } 13 | } 14 | 15 | #[allow(missing_docs)] 16 | pub mod m { 17 | #[allow(unused_imports)] 18 | use flatdata::{flatdata_read_bytes, flatdata_write_bytes}; 19 | 20 | 21 | pub const FOO: i8 = 1; 22 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/enums/comments.rs.1.1: -------------------------------------------------------------------------------- 1 | // This is a comment about Foo 2 | #[derive(Debug, PartialEq, Eq)] 3 | #[repr(u64)] 4 | pub enum Foo { 5 | // This is a comment about Foo.a 6 | A = 0, 7 | // This is a comment about Foo.b 8 | B = 1, 9 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/enums/comments.rs.2.1: -------------------------------------------------------------------------------- 1 | /// This is a comment about Bar 2 | #[derive(Debug, PartialEq, Eq)] 3 | #[repr(u64)] 4 | pub enum Bar { 5 | /// This is a comment about Bar.a 6 | A = 0, 7 | /// This is a comment about Bar.b 8 | B = 1, 9 | } -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/enums/implicit_values.rs.1: -------------------------------------------------------------------------------- 1 | #[derive(Debug, PartialEq, Eq)] 2 | #[repr(u16)] 3 | pub enum Enum1 { 4 | // = 0 5 | Value1 = 0, 6 | // = 3 7 | Value2 = 3, 8 | // = 4 9 | Value3 = 4, 10 | // = 1 11 | Value4 = 1, 12 | // = 2 13 | Value5 = 2, 14 | #[doc(hidden)] 15 | UnknownValue5 = 5, 16 | #[doc(hidden)] 17 | UnknownValue6 = 6, 18 | #[doc(hidden)] 19 | UnknownValue7 = 7, 20 | } 21 | 22 | impl flatdata::helper::Int for Enum1 { 23 | const IS_SIGNED: bool = false; 24 | } 25 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/rust_expectations/rustfmt.toml: -------------------------------------------------------------------------------- 1 | disable_all_formatting = true 2 | ignore = [ 3 | ".", 4 | "*" 5 | ] -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/schemas.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | NUM_TEST_CASES = 25 4 | 5 | def schemas_and_expectations(generator, extension): 6 | """ 7 | Retrieves list of test cases filenames and generates corresponding expectation filenames 8 | generator: one of the supported generator: `rust`, `cpp`, `flatdata`, `dot`, `rust`, `go 9 | extension: extension of the expectation files for this generator, e.g. `.h` for `cpp` 10 | """ 11 | result = list() 12 | basedir = os.path.dirname(__file__) 13 | test_dir = os.path.normpath(os.path.join( 14 | basedir, '..', '..', '..', 'test_cases')) 15 | for path, _subdirs, files in os.walk(test_dir): 16 | for name in files: 17 | if os.path.splitext(name)[1] == '.flatdata': 18 | relpath = os.path.relpath(path, test_dir) 19 | test_relpath = os.path.join(relpath, name) 20 | expectation_filename = os.path.splitext( 21 | test_relpath)[0]+'.' + extension 22 | expecation_path = os.path.join( 23 | basedir, generator + '_expectations', expectation_filename) 24 | result.append((os.path.join(path, name), expecation_path)) 25 | assert len(result) == NUM_TEST_CASES, "Did not find expected number of test cases in " + test_dir 26 | return result 27 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/test_cpp_generator.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2019 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | import glob 6 | 7 | from flatdata.generator.generators.cpp import CppGenerator 8 | from .assertions import generate_and_assert_in 9 | from .schemas import schemas_and_expectations 10 | 11 | def generate_and_compare(test_case): 12 | with open(test_case[0], 'r') as test_file: 13 | test = test_file.read() 14 | 15 | expectations = list() 16 | for file in glob.glob(test_case[1] + '*'): 17 | with open(file, 'r') as expectation_file: 18 | expectations.append(expectation_file.read()) 19 | 20 | generate_and_assert_in(test, CppGenerator, *expectations) 21 | 22 | def test_against_expectations(): 23 | for x in schemas_and_expectations(generator='cpp', extension='h'): 24 | yield generate_and_compare, x 25 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/test_dot_generator.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | import glob 6 | 7 | from flatdata.generator.generators.dot import DotGenerator 8 | from .assertions import generate_and_assert_in 9 | from .schemas import schemas_and_expectations 10 | 11 | def test_structures_outside_of_archives_are_not_represented(): 12 | unexpected_lines = [ 13 | "_n_S" 14 | ] 15 | generate_and_assert_in(""" 16 | namespace n{ 17 | struct S { 18 | f : u64 : 3; 19 | } 20 | } 21 | """, DotGenerator, *[], unexpected_items=unexpected_lines) 22 | 23 | def generate_and_compare(test_case): 24 | with open(test_case[0], 'r') as test_file: 25 | test = test_file.read() 26 | 27 | expectations = list() 28 | for file in glob.glob(test_case[1] + '*'): 29 | with open(file, 'r') as expectation_file: 30 | expectations.append(expectation_file.read()) 31 | 32 | generate_and_assert_in(test, DotGenerator, *expectations) 33 | 34 | def test_against_expectations(): 35 | for x in schemas_and_expectations(generator='dot', extension='dot'): 36 | yield generate_and_compare, x -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/test_flatdata_generator.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2018 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | from nose.tools import assert_equal 6 | 7 | from flatdata.generator.generators.flatdata import FlatdataGenerator 8 | from flatdata.generator.tree.builder import build_ast 9 | from .schemas import schemas_and_expectations 10 | 11 | def generate_and_compare(test_case): 12 | with open(test_case[0], 'r') as test_file: 13 | test = test_file.read() 14 | with open(test_case[1], 'r') as expectation_file: 15 | expectation = expectation_file.read() 16 | tree = build_ast(definition=test) 17 | contents = FlatdataGenerator().render(tree) 18 | assert_equal.__self__.maxDiff = None 19 | assert_equal(expectation, contents, test_case) 20 | 21 | def test_against_expectations(): 22 | for i in schemas_and_expectations(generator='flatdata', extension='flatdata'): 23 | yield generate_and_compare, i 24 | 25 | def test_normalization_is_fixed_point(): 26 | for i in schemas_and_expectations(generator='flatdata', extension='flatdata'): 27 | yield generate_and_compare, (i[1], i[1]) 28 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/test_go_generator.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | import glob 6 | 7 | from flatdata.generator.generators.go import GoGenerator 8 | from .assertions import generate_and_assert_in 9 | from .schemas import schemas_and_expectations 10 | 11 | from nose.plugins.skip import SkipTest 12 | 13 | 14 | def generate_and_compare(test_case): 15 | with open(test_case[0], 'r') as test_file: 16 | test = test_file.read() 17 | 18 | expectations = list() 19 | for file in glob.glob(test_case[1] + '*'): 20 | with open(file, 'r') as expectation_file: 21 | expectations.append(expectation_file.read()) 22 | 23 | generate_and_assert_in(test, GoGenerator, *expectations) 24 | 25 | 26 | def skip(test_case): 27 | raise SkipTest("Test %s is skipped" % test_case[0]) 28 | 29 | 30 | def test_against_expectations(): 31 | for x in schemas_and_expectations(generator='go', extension='go'): 32 | # Go does not yet support namespaces, enums, ranges, or constants, skip those tests 33 | if "enums" not in x[0] and "constants" not in x[0] and "namespaces" not in x[0] and "ranges" not in x[0]: 34 | yield generate_and_compare, x 35 | else: 36 | yield skip, x 37 | -------------------------------------------------------------------------------- /flatdata-generator/tests/generators/test_python_generator.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | import glob 6 | 7 | from flatdata.generator.generators.python import PythonGenerator 8 | from .assertions import generate_and_assert_in 9 | from .schemas import schemas_and_expectations 10 | 11 | from nose.plugins.skip import SkipTest 12 | 13 | def generate_and_compare(test_case): 14 | with open(test_case[0], 'r') as test_file: 15 | test = test_file.read() 16 | 17 | expectations = list() 18 | for file in glob.glob(test_case[1] + '*'): 19 | with open(file, 'r') as expectation_file: 20 | expectations.append(expectation_file.read()) 21 | 22 | generate_and_assert_in(test, PythonGenerator, *expectations) 23 | 24 | def skip(test_case): 25 | raise SkipTest("Test %s is skipped" % test_case[0]) 26 | 27 | def test_against_expectations(): 28 | for x in schemas_and_expectations(generator='py', extension='py'): 29 | # Python does not yet support enums or constants, skip those tests 30 | if "enums" not in x[0] and "constants" not in x[0]: 31 | yield generate_and_compare, x 32 | else: 33 | yield skip, x -------------------------------------------------------------------------------- /flatdata-generator/tests/tree/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-generator/tests/tree/__init__.py -------------------------------------------------------------------------------- /flatdata-generator/tests/tree/test_references.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | 6 | import sys 7 | 8 | sys.path.insert(0, "..") 9 | from nose.tools import assert_equal, assert_raises 10 | import flatdata.generator.tree.nodes.references as refs 11 | 12 | 13 | def test_reference_name_is_at_prefixed_and_at_separated(): 14 | assert_equal("@foo@bar@baz", refs.TypeReference(name="foo.bar.baz").name) 15 | -------------------------------------------------------------------------------- /flatdata-go/backward-compatibility-tests/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/davecgh/go-spew" 6 | packages = ["spew"] 7 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 8 | version = "v1.1.0" 9 | 10 | [[projects]] 11 | name = "github.com/pmezard/go-difflib" 12 | packages = ["difflib"] 13 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 14 | version = "v1.0.0" 15 | 16 | [[projects]] 17 | name = "github.com/stretchr/testify" 18 | packages = ["assert"] 19 | revision = "b91bfb9ebec76498946beb6af7c0230c7cc7ba6c" 20 | version = "v1.2.0" 21 | 22 | [solve-meta] 23 | analyzer-name = "dep" 24 | analyzer-version = 1 25 | inputs-digest = "0a81cdd8b28938307cd5d3941bfdb99c2b2a04aac9c0cb95558335aaab9ea4bd" 26 | solver-name = "gps-cdcl" 27 | solver-version = 1 28 | -------------------------------------------------------------------------------- /flatdata-go/backward-compatibility-tests/Gopkg.toml: -------------------------------------------------------------------------------- 1 | 2 | # Gopkg.toml example 3 | # 4 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 5 | # for detailed Gopkg.toml documentation. 6 | # 7 | # required = ["github.com/user/thing/cmd/thing"] 8 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 9 | # 10 | # [[constraint]] 11 | # name = "github.com/user/project" 12 | # version = "1.0.0" 13 | # 14 | # [[constraint]] 15 | # name = "github.com/user/project2" 16 | # branch = "dev" 17 | # source = "github.com/myfork/project2" 18 | # 19 | # [[override]] 20 | # name = "github.com/x/y" 21 | # version = "2.4.0" 22 | 23 | ignored = ["github.com/heremaps/flatdata/flatdata-go/flatdata"] 24 | 25 | [[constraint]] 26 | name = "github.com/stretchr/testify" 27 | version = "1.2.0" 28 | 29 | [prune] 30 | go-tests = true 31 | non-go = true 32 | unused-packages = true -------------------------------------------------------------------------------- /flatdata-go/backward-compatibility-tests/LICENSE: -------------------------------------------------------------------------------- 1 | ../../LICENSE -------------------------------------------------------------------------------- /flatdata-go/backward-compatibility-tests/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all run-ci clean lint test deps generate 2 | 3 | all: clean generate lint test 4 | 5 | run-ci: deps lint test 6 | 7 | deps: 8 | @echo "Install dependencies..." 9 | dep ensure 10 | 11 | clean: 12 | @echo "Cleanup..." 13 | find . -maxdepth 1 -type f -name "*_generated.go" -delete 14 | 15 | lint: 16 | @echo "Run linters..." 17 | go fmt $$(go list ./... | grep -v /vendor/) 18 | go vet $$(go list ./... | grep -v /vendor/) 19 | golint $$(go list ./... | grep -v /vendor/) | grep -v _generated.go; test $$? -eq 1 20 | 21 | generate: 22 | $$GOPATH/src/github.com/heremaps/flatdata/generator -v -g go \ 23 | -s test_backward_compatibility.schema \ 24 | -O test_backward_compatibility_generated.go 25 | 26 | test: 27 | @echo "Run tests..." 28 | go test -v $$(go list ./... | grep -v /vendor/) 29 | -------------------------------------------------------------------------------- /flatdata-go/backward-compatibility-tests/test_backward_compatibility.schema: -------------------------------------------------------------------------------- 1 | namespace backwardcompatibility { 2 | struct SimpleStruct { 3 | a : u32 : 32; 4 | b : u32 : 32; 5 | } 6 | struct SignedStruct { 7 | a : i16 : 5; 8 | b : u32 : 32; 9 | c : i32 : 7; 10 | d : u32 : 32; 11 | } 12 | archive BackwardCompatibilityTest { 13 | resource_a: SignedStruct; 14 | resource_b: vector< SignedStruct >; 15 | resource_c: multivector< 33, SimpleStruct, SignedStruct >; 16 | resource_d: raw_data; 17 | } 18 | } -------------------------------------------------------------------------------- /flatdata-go/flatdata/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/davecgh/go-spew" 6 | packages = ["spew"] 7 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 8 | version = "v1.1.0" 9 | 10 | [[projects]] 11 | name = "github.com/pmezard/go-difflib" 12 | packages = ["difflib"] 13 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 14 | version = "v1.0.0" 15 | 16 | [[projects]] 17 | name = "github.com/stretchr/testify" 18 | packages = ["assert"] 19 | revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" 20 | version = "v1.1.4" 21 | 22 | [[projects]] 23 | branch = "master" 24 | name = "golang.org/x/exp" 25 | packages = ["mmap"] 26 | revision = "a05f2c1e93dc0743a12c519ef35f386b8c095d91" 27 | 28 | [solve-meta] 29 | analyzer-name = "dep" 30 | analyzer-version = 1 31 | inputs-digest = "a5ddb58f3872e6eea2c321f0b14d3501778db7da54ce27f2ef3265978b3c645e" 32 | solver-name = "gps-cdcl" 33 | solver-version = 1 34 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/Gopkg.toml: -------------------------------------------------------------------------------- 1 | 2 | # Gopkg.toml example 3 | # 4 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 5 | # for detailed Gopkg.toml documentation. 6 | # 7 | # required = ["github.com/user/thing/cmd/thing"] 8 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 9 | # 10 | # [[constraint]] 11 | # name = "github.com/user/project" 12 | # version = "1.0.0" 13 | # 14 | # [[constraint]] 15 | # name = "github.com/user/project2" 16 | # branch = "dev" 17 | # source = "github.com/myfork/project2" 18 | # 19 | # [[override]] 20 | # name = "github.com/x/y" 21 | # version = "2.4.0" 22 | 23 | 24 | [[constraint]] 25 | name = "github.com/stretchr/testify" 26 | version = "1.1.4" 27 | 28 | [[constraint]] 29 | branch = "master" 30 | name = "golang.org/x/exp" 31 | 32 | [prune] 33 | go-tests = true 34 | non-go = true 35 | unused-packages = true 36 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/LICENSE: -------------------------------------------------------------------------------- 1 | ../../LICENSE -------------------------------------------------------------------------------- /flatdata-go/flatdata/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all run-ci lint test bench deps 2 | 3 | all: lint test bench 4 | 5 | run-ci: deps all 6 | 7 | deps: 8 | @echo "Install dependencies..." 9 | dep ensure 10 | 11 | lint: 12 | @echo "Run linters..." 13 | go fmt $$(go list ./... | grep -v /vendor/) 14 | go vet $$(go list ./... | grep -v /vendor/) 15 | golint -set_exit_status $$(go list ./... | grep -v /vendor/) 16 | 17 | test: 18 | @echo "Run tests..." 19 | go test -v $$(go list ./... | grep -v /vendor/) 20 | 21 | bench: 22 | @echo "Run benchmarks..." 23 | go test -bench=. 24 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/README.md: -------------------------------------------------------------------------------- 1 | # flatdata-go 2 | Common library for flatdata Go implementation 3 | 4 | ### Requirements 5 | Library requires Go 1.9 and higher. 6 | 7 | ### Dependencies 8 | Use [**dep**](https://github.com/golang/dep) to properly add `flatdata-go` to your project. 9 | Otherwise, you can always install dependencies manually: 10 | ``` 11 | go get -u golang.org/x/exp/mmap 12 | go get -u github.com/stretchr/testify 13 | ``` 14 | 15 | ### Tests and coverage 16 | Run tests and show coverage info 17 | ``` 18 | go test -v -race ./... -coverprofile=coverage.out 19 | ``` 20 | 21 | Open coverage in browser 22 | ``` 23 | go tool cover -html=coverage.out 24 | ``` 25 | 26 | ### Benchmarks 27 | ``` 28 | go test -bench=. 29 | ``` 30 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/TODO.md: -------------------------------------------------------------------------------- 1 | Some todos for the golang implementation: 2 | 3 | - [x] Working multivector implementation. 4 | - [ ] Reader example: C++ is writing, golang is reading. All resource types + optional. 5 | - [x] Schema validation on archive opening. 6 | - [x] Port backward compatibility tests. 7 | - [x] Tests in CI. 8 | - [ ] Writer. 9 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/benchmarks_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | package flatdata 7 | 8 | import ( 9 | "testing" 10 | 11 | "math/rand" 12 | ) 13 | 14 | const arraySize = 8192 15 | 16 | func BenchmarkFileResourceReadUnsigned(b *testing.B) { 17 | runBenchmarkOnFileResource(false, b) 18 | } 19 | 20 | func BenchmarkFileResourceReadSigned(b *testing.B) { 21 | runBenchmarkOnFileResource(true, b) 22 | } 23 | 24 | func runBenchmarkOnFileResource(signed bool, b *testing.B) { 25 | b.StopTimer() 26 | 27 | handle := &TestMemoryDescriptor{Array: generateRandomByteArray()} 28 | 29 | b.StartTimer() 30 | 31 | for n := 0; n < b.N; n++ { 32 | Read(handle, 4092, 64, signed) 33 | } 34 | } 35 | 36 | func generateRandomByteArray() []byte { 37 | bytes := make([]byte, arraySize) 38 | rand.Read(bytes) 39 | return bytes 40 | } 41 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | // Package flatdata represents Go implementation for Flatdata 7 | package flatdata 8 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/memory_descriptor.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | package flatdata 7 | 8 | import "io" 9 | 10 | // MemoryDescriptor represents internal low level data access 11 | type MemoryDescriptor interface { 12 | io.ReaderAt 13 | Close() error 14 | Len() int 15 | At(i int) byte 16 | } 17 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/reader.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | package flatdata 7 | 8 | import "math" 9 | 10 | var signBits []uint 11 | 12 | func init() { 13 | signBits = make([]uint, 64) 14 | for i := 0; i < 64; i++ { 15 | signBits[i] = uint(math.Exp2(float64(i))) 16 | } 17 | } 18 | 19 | // Read allows to read data from flatdata memory layout 20 | func Read(descriptor MemoryDescriptor, offset, size uint, signed bool) int { 21 | currentIndex := offset / 8 22 | currentByte := uint(descriptor.At(int(currentIndex))) 23 | bitsLeft := size 24 | localOffset := offset % 8 25 | var result uint 26 | 27 | if localOffset != 0 { 28 | result = currentByte >> localOffset 29 | if bitsLeft <= (8 - localOffset) { 30 | result &= (1 << bitsLeft) - 1 31 | return int(result) 32 | } 33 | bitsLeft -= 8 - localOffset 34 | currentIndex++ 35 | currentByte = uint(descriptor.At(int(currentIndex))) 36 | } 37 | 38 | for bitsLeft >= 8 { 39 | temp := currentByte 40 | temp <<= size - bitsLeft 41 | result |= temp 42 | 43 | bitsLeft -= 8 44 | currentIndex++ 45 | currentByte = uint(descriptor.At(int(currentIndex))) 46 | } 47 | 48 | if bitsLeft != 0 { 49 | temp := currentByte & ((1 << bitsLeft) - 1) 50 | temp <<= size - bitsLeft 51 | result |= temp 52 | } 53 | 54 | if signed { 55 | return int((result & (signBits[size-1] - 1)) - (result & signBits[size-1])) 56 | } 57 | 58 | return int(result) 59 | } 60 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/resource_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | package flatdata 7 | 8 | import ( 9 | "testing" 10 | 11 | "github.com/stretchr/testify/assert" 12 | ) 13 | 14 | func TestOpenNonExistingFileResourceShouldReturnError(t *testing.T) { 15 | r := NewFileResourceStorage("non_existing_archive") 16 | _, _, err := r.GetMemoryDescriptor("non_existing_resource") 17 | assert.EqualError(t, err, ErrorCantAccessResource, "Should return error for an non-existing resource") 18 | } 19 | -------------------------------------------------------------------------------- /flatdata-go/flatdata/test_memory_descriptor.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | */ 5 | 6 | package flatdata 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | ) 12 | 13 | // TestMemoryDescriptor implements MemoryDescriptor interface with reading date from []byte for internal usage 14 | type TestMemoryDescriptor struct { 15 | Array []byte 16 | } 17 | 18 | // ReadAt number of bytes equal to p starting from offset off 19 | func (b *TestMemoryDescriptor) ReadAt(p []byte, off int64) (n int, err error) { 20 | if off < 0 || int64(len(b.Array)) < off { 21 | return 0, fmt.Errorf("invalid offset %d", off) 22 | } 23 | n = copy(p, b.Array[off:]) 24 | if n < len(p) { 25 | return n, io.EOF 26 | } 27 | return n, nil 28 | } 29 | 30 | // Close should close memory descriptor 31 | func (b *TestMemoryDescriptor) Close() error { 32 | return nil 33 | } 34 | 35 | // Len returns length of internal byte array 36 | func (b *TestMemoryDescriptor) Len() int { 37 | return len(b.Array) 38 | } 39 | 40 | // At return byte on position i 41 | func (b *TestMemoryDescriptor) At(i int) byte { 42 | return b.Array[i] 43 | } 44 | -------------------------------------------------------------------------------- /flatdata-py/.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | max-line-length=120 3 | 4 | [MESSAGES CONTROL] 5 | disable=missing-docstring,line-too-long 6 | -------------------------------------------------------------------------------- /flatdata-py/flatdata/lib/__init__.py: -------------------------------------------------------------------------------- 1 | from . import structure 2 | from . import resources 3 | from . import archive 4 | from . import archive_builder 5 | from . import file_resource_writer 6 | from . import errors 7 | from . import resource_storage 8 | from . import flatdata_writer 9 | -------------------------------------------------------------------------------- /flatdata-py/flatdata/lib/file_resource_storage.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2017 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | 6 | import mmap 7 | import os 8 | 9 | from .errors import MissingResourceError 10 | 11 | 12 | class FileResourceStorage: 13 | """ 14 | Resource storage based on memory-mapped files. 15 | """ 16 | 17 | @staticmethod 18 | def memory_map(filename): 19 | """ 20 | Memory maps given file. Introduced to be able to swap mmap implementations. 21 | :param filename: 22 | :return: file-like object for memory mapped file. 23 | """ 24 | opened_file = open(filename, 'r') 25 | return mmap.mmap(opened_file.fileno(), 0, access=mmap.ACCESS_READ) 26 | 27 | def __init__(self, path): 28 | self.path = path 29 | 30 | def get(self, key, is_optional=False): 31 | filename = os.path.join(self.path, key) 32 | if not os.path.exists(filename): 33 | if not is_optional: 34 | raise MissingResourceError(key) 35 | else: 36 | return None 37 | 38 | if os.path.isfile(filename): 39 | return self.memory_map(filename) 40 | 41 | return FileResourceStorage(filename) 42 | 43 | def ls(self): 44 | return os.listdir(self.path) 45 | -------------------------------------------------------------------------------- /flatdata-py/flatdata/lib/file_resource_writer.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (c) 2021 HERE Europe B.V. 3 | See the LICENSE file in the root of this project for license details. 4 | ''' 5 | 6 | import os 7 | from flatdata.lib.errors import ArchivePathNotProvidedError, FileNameNotProvided 8 | 9 | class FileResourceWriter: 10 | ''' 11 | This is a factory class which will create instance of FileResourceWriter for 12 | resource. This class directly writes to disc on a file. 13 | ''' 14 | def __init__(self): 15 | '''Create instance of FileResourceWriter''' 16 | self._file = None 17 | 18 | @staticmethod 19 | def create_instance(): 20 | '''Static method to create instances and gives this class a factory like behaviour''' 21 | return FileResourceWriter() 22 | 23 | def open(self, name, file_path): 24 | ''' 25 | Opens a file for writing. It will also create directory if it is not present. 26 | 27 | :raises FileNameNotProvided 28 | :raises ArchivePathNotProvidedError 29 | :param name(str): name of file 30 | :param file_path(str): file path 31 | ''' 32 | if not name: 33 | raise FileNameNotProvided() 34 | 35 | if not file_path: 36 | raise ArchivePathNotProvidedError() 37 | 38 | file_name = os.path.join(file_path, name) 39 | if not os.path.exists(file_path): 40 | os.mkdir(file_path) 41 | 42 | self._file = open(file_name, 'wb') 43 | 44 | def write(self, data): 45 | '''Write data to file''' 46 | if data: 47 | self._file.write(data) 48 | 49 | def close(self): 50 | '''Flush data and close file''' 51 | self._file.flush() 52 | self._file.close() 53 | -------------------------------------------------------------------------------- /flatdata-py/inspector.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from flatdata.lib import inspector 3 | inspector.main() 4 | -------------------------------------------------------------------------------- /flatdata-py/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [project] 6 | name = "flatdata-py" 7 | version = "0.4.7" 8 | description = "Python 3 implementation of Flatdata" 9 | readme = "README.md" 10 | authors = [ 11 | { name = "Flatdata Developers" }, 12 | ] 13 | classifiers = [ 14 | "License :: OSI Approved :: Apache Software License", 15 | "Operating System :: OS Independent", 16 | "Programming Language :: Python :: 3", 17 | ] 18 | dependencies = [ 19 | "flatdata-generator==0.4.6", 20 | "numpy", 21 | "pandas", 22 | ] 23 | 24 | [project.optional-dependencies] 25 | inspector = [ 26 | "IPython", 27 | ] 28 | 29 | [project.scripts] 30 | flatdata-inspector = "flatdata.lib.inspector:main[inspector]" 31 | flatdata-writer = "flatdata.lib.writer:main[writer]" 32 | 33 | [project.urls] 34 | Homepage = "https://github.com/heremaps/flatdata" 35 | 36 | [tool.hatch.build.targets.sdist] 37 | include = [ 38 | "/flatdata", 39 | ] 40 | 41 | [tool.hatch.build.targets.wheel] 42 | packages = ["flatdata"] 43 | -------------------------------------------------------------------------------- /flatdata-py/requirements.txt: -------------------------------------------------------------------------------- 1 | flatdata-generator==0.4.6 2 | numpy 3 | pandas 4 | -------------------------------------------------------------------------------- /flatdata-py/tests/test_tar_resource_storage.py: -------------------------------------------------------------------------------- 1 | from common import * 2 | from flatdata.generator.engine import Engine 3 | from flatdata.lib.tar_archive_resource_storage import TarArchiveResourceStorage 4 | 5 | from nose.tools import eq_ 6 | import tarfile 7 | import tempfile 8 | import os 9 | 10 | 11 | def check_signed_struct(s): 12 | eq_(-0x1, s.a) 13 | eq_(0x01234567, s.b) 14 | eq_(-0x28, s.c) 15 | eq_(0, s.d) 16 | 17 | 18 | def test_tar_resource_storage(): 19 | module = Engine(INSTANCE_TEST_SCHEMA).render_python_module() 20 | valid_data = { 21 | "Archive.archive": ARCHIVE_SIGNATURE_PAYLOAD, 22 | "Archive.archive.schema": module.backward_compatibility_Archive.schema().encode(), 23 | "resource": RESOURCE_PAYLOAD, 24 | "resource.schema": module.backward_compatibility_Archive.resource_schema('resource').encode() 25 | } 26 | 27 | with tempfile.TemporaryDirectory() as tmpdir: 28 | archive_path = os.path.join(tmpdir, "archive.tar") 29 | cwd = os.getcwd() 30 | os.chdir(tmpdir) 31 | tar = tarfile.open(archive_path, "w") 32 | for key, value in valid_data.items(): 33 | with open(os.path.join(tmpdir, key), "wb") as file: 34 | file.write(value) 35 | tar.add(key) 36 | tar.close() 37 | os.chdir(cwd) 38 | 39 | archive = module.backward_compatibility_Archive(TarArchiveResourceStorage.create(archive_path)) 40 | check_signed_struct(archive.resource) 41 | -------------------------------------------------------------------------------- /flatdata-py/writer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from flatdata.lib import writer 3 | writer.main() 4 | -------------------------------------------------------------------------------- /flatdata-rs/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /flatdata-rs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | 3 | members = [ 4 | "lib", 5 | "tests/features", 6 | "tests/coappearances", 7 | ] 8 | -------------------------------------------------------------------------------- /flatdata-rs/ci/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Usage: 4 | # ./coverage 5 | # 6 | # Run kcov on the tests, and merge the results. 7 | # 8 | # Environment variables: 9 | # TRAVIS_JOB_ID - id for coveralls, defaults to none 10 | # KCOV - path to kcov, defaults to 'kcov' 11 | 12 | [ -n "$TRAVIS_JOB_ID" ] && COVERALLS_ID="--coveralls-id=$TRAVIS_JOB_ID" 13 | [ -z "$KCOV" ] && KCOV=kcov 14 | 15 | # Rebuild tests with dead code included, and get a list of the filenames. 16 | export RUSTFLAGS="-C link-dead-code" 17 | TEST_FILES=$(cargo test 2>&1 >/dev/null | awk '/^ Running target\/debug\// { print $2 }') 18 | 19 | KCOV_OPTS="--verify --exclude-pattern=/.cargo --include-path $(pwd)" 20 | OUT_DIR=target/kcov 21 | 22 | for f in $TEST_FILES; do 23 | "$KCOV" $KCOV_OPTS "$OUT_DIR" $f 24 | done 25 | "$KCOV" --merge $KCOV_OPTS $COVERALLS_ID "$OUT_DIR" "$OUT_DIR" 26 | -------------------------------------------------------------------------------- /flatdata-rs/lib/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flatdata" 3 | version = "0.5.8" 4 | authors = ["boxdot ", "Christian Vetter ", "Gabriel Féron "] 5 | license = "Apache-2.0" 6 | description = "Rust implementation of flatdata" 7 | repository = "https://github.com/heremaps/flatdata" 8 | keywords = ["serialization", "flatdata", "mmap"] 9 | categories = ["encoding"] 10 | readme = "../README.md" 11 | edition = "2018" 12 | 13 | [dependencies] 14 | diff = "0.1.11" 15 | memmap2 = "0.9.4" 16 | tar = { version = "0.4.38", optional = true } 17 | walkdir = "2.2.9" 18 | 19 | [package.metadata.docs.rs] 20 | all-features = true 21 | -------------------------------------------------------------------------------- /flatdata-rs/lib/src/helper.rs: -------------------------------------------------------------------------------- 1 | //! Module which contains internal helper traits. 2 | 3 | /// Helper trait which defines a constant for an integer type whether it is signed. 4 | pub trait Int { 5 | /// `true` if the implementing type is signed, otherwise `false`. 6 | const IS_SIGNED: bool; 7 | } 8 | 9 | impl Int for bool { 10 | const IS_SIGNED: bool = false; 11 | } 12 | 13 | impl Int for i8 { 14 | const IS_SIGNED: bool = true; 15 | } 16 | 17 | impl Int for u8 { 18 | const IS_SIGNED: bool = false; 19 | } 20 | 21 | impl Int for i16 { 22 | const IS_SIGNED: bool = true; 23 | } 24 | 25 | impl Int for u16 { 26 | const IS_SIGNED: bool = false; 27 | } 28 | 29 | impl Int for i32 { 30 | const IS_SIGNED: bool = true; 31 | } 32 | 33 | impl Int for u32 { 34 | const IS_SIGNED: bool = false; 35 | } 36 | 37 | impl Int for i64 { 38 | const IS_SIGNED: bool = true; 39 | } 40 | 41 | impl Int for u64 { 42 | const IS_SIGNED: bool = false; 43 | } 44 | -------------------------------------------------------------------------------- /flatdata-rs/lib/src/memory.rs: -------------------------------------------------------------------------------- 1 | pub type SizeType = u64; 2 | #[doc(hidden)] 3 | pub const PADDING_SIZE: usize = 8; 4 | -------------------------------------------------------------------------------- /flatdata-rs/lib/src/test/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test structures and archives used in unit tests of the library. 2 | //! 3 | //! The test structs are generated from the underlying flatdata file. 4 | //! However, to make it easier to understand the unit tests, the 5 | //! generated code is checked in and is not generated on the fly. 6 | //! Whenever the generator changes this code should be updated manually 7 | //! and checked in. 8 | //! 9 | //! Generate it by using the following command from the `flatdata-rs` 10 | //! folder: 11 | //! 12 | //! ```shell 13 | //! ../generator -g rust -s lib/src/test/test.flatdata -O lib/src/test/test_generated.rs && \ 14 | //! sed -i.bak -e s/flatdata::/crate::/g lib/src/test/test_generated.rs 15 | //! ``` 16 | //! 17 | 18 | // TODO: Implement missing docs 19 | // TODO: Implement missing debugs 20 | #![allow(dead_code, missing_debug_implementations, missing_docs)] 21 | 22 | include!("test_generated.rs"); 23 | 24 | pub use test::*; 25 | -------------------------------------------------------------------------------- /flatdata-rs/lib/src/test/test.flatdata: -------------------------------------------------------------------------------- 1 | namespace test { 2 | 3 | enum E : u32 : 1 { 4 | Value, 5 | } 6 | 7 | struct A { 8 | x : u32 : 16; 9 | y : u32 : 16; 10 | e : E : 1; 11 | } 12 | 13 | struct B { 14 | id : u32 : 16; 15 | } 16 | 17 | struct R { 18 | @range(x) 19 | first_x : u32 : 16; 20 | y : u32 : 16; 21 | } 22 | 23 | archive S { 24 | data: A; 25 | } 26 | 27 | archive X { 28 | data: vector; 29 | } 30 | 31 | archive Y { 32 | data: vector; 33 | } 34 | 35 | archive Z { 36 | ab: multivector<16, A, B>; 37 | } 38 | 39 | archive W { 40 | blob: raw_data; 41 | } 42 | 43 | } // namespace test 44 | -------------------------------------------------------------------------------- /flatdata-rs/rustfmt.toml: -------------------------------------------------------------------------------- 1 | reorder_imports = true 2 | reorder_modules = true 3 | merge_imports = true 4 | format_doc_comments = true 5 | wrap_comments = true 6 | 7 | ignore = [ 8 | "lib/src/lib.rs", 9 | ] 10 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flatdata_tests_coappearances" 3 | version = "0.1.0" 4 | authors = ["boxdot ", "Christian Vetter "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [dependencies] 9 | flatdata = { path = "../../lib" } 10 | 11 | [build-dependencies] 12 | flatdata = { path = "../../lib" } 13 | 14 | [features] 15 | tar = ["flatdata/tar"] 16 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/coappearances.flatdata: -------------------------------------------------------------------------------- 1 | ../../../../examples/coappearances/coappearances.flatdata -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/Graph.archive: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/chapters: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-rs/tests/coappearances/assets/karenina.archive/chapters -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/chapters.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Chapter 3 | { 4 | major : u8 : 4; 5 | minor : u8 : 7; 6 | } 7 | } 8 | 9 | namespace coappearances { 10 | archive Graph 11 | { 12 | chapters : vector< .coappearances.Chapter >; 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/edges: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-rs/tests/coappearances/assets/karenina.archive/edges -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/edges.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Coappearance 3 | { 4 | a_ref : u32 : 16; 5 | b_ref : u32 : 16; 6 | count : u32 : 16; 7 | @range( chapters_range ) 8 | first_chapter_ref : u32 : 16; 9 | } 10 | } 11 | 12 | namespace coappearances { 13 | archive Graph 14 | { 15 | @explicit_reference( .coappearances.Coappearance.a_ref, .coappearances.Graph.vertices ) 16 | @explicit_reference( .coappearances.Coappearance.b_ref, .coappearances.Graph.vertices ) 17 | @explicit_reference( .coappearances.Coappearance.first_chapter_ref, .coappearances.Graph.chapters ) 18 | edges : vector< .coappearances.Coappearance >; 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/meta: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/meta.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Meta 3 | { 4 | title_ref : u32 : 32; 5 | author_ref : u32 : 32; 6 | } 7 | } 8 | 9 | namespace coappearances { 10 | archive Graph 11 | { 12 | @explicit_reference( .coappearances.Meta.title_ref, .coappearances.Graph.strings ) 13 | @explicit_reference( .coappearances.Meta.author_ref, .coappearances.Graph.strings ) 14 | meta : .coappearances.Meta; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/statistics/Statistics.archive: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/statistics/Statistics.archive.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Invariants 3 | { 4 | max_degree : u32 : 16; 5 | max_degree_ref : u32 : 16; 6 | min_degree : u32 : 16; 7 | min_degree_ref : u32 : 16; 8 | num_connected_components : u32 : 16; 9 | } 10 | } 11 | 12 | namespace coappearances { 13 | struct Degree 14 | { 15 | value : u32 : 16; 16 | } 17 | } 18 | 19 | namespace coappearances { 20 | @bound_implicitly( characters : .coappearances.Graph.vertices, .coappearances.Statistics.vertex_degrees ) 21 | archive Statistics 22 | { 23 | invariants : .coappearances.Invariants; 24 | vertex_degrees : vector< .coappearances.Degree >; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/statistics/invariants: -------------------------------------------------------------------------------- 1 | 2 | G.  -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/statistics/invariants.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Invariants 3 | { 4 | max_degree : u32 : 16; 5 | max_degree_ref : u32 : 16; 6 | min_degree : u32 : 16; 7 | min_degree_ref : u32 : 16; 8 | num_connected_components : u32 : 16; 9 | } 10 | } 11 | 12 | namespace coappearances { 13 | archive Statistics 14 | { 15 | invariants : .coappearances.Invariants; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/statistics/vertex_degrees: -------------------------------------------------------------------------------- 1 |  + ( , 2 |  G  3 |  4 |  2 / 5 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/statistics/vertex_degrees.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Degree 3 | { 4 | value : u32 : 16; 5 | } 6 | } 7 | 8 | namespace coappearances { 9 | archive Statistics 10 | { 11 | vertex_degrees : vector< .coappearances.Degree >; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/strings.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | archive Graph 3 | { 4 | strings : raw_data; 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/vertices: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-rs/tests/coappearances/assets/karenina.archive/vertices -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/vertices.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Character 3 | { 4 | name_ref : u32 : 32; 5 | } 6 | } 7 | 8 | namespace coappearances { 9 | archive Graph 10 | { 11 | @explicit_reference( .coappearances.Character.name_ref, .coappearances.Graph.strings ) 12 | vertices : vector< .coappearances.Character >; 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/vertices_data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-rs/tests/coappearances/assets/karenina.archive/vertices_data -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/vertices_data.schema: -------------------------------------------------------------------------------- 1 | namespace coappearances { 2 | struct Nickname 3 | { 4 | ref : u32 : 32; 5 | } 6 | } 7 | 8 | namespace coappearances { 9 | struct Description 10 | { 11 | ref : u32 : 32; 12 | } 13 | } 14 | 15 | namespace coappearances { 16 | struct UnaryRelation 17 | { 18 | kind_ref : u32 : 32; 19 | to_ref : u32 : 16; 20 | } 21 | } 22 | 23 | namespace coappearances { 24 | struct BinaryRelation 25 | { 26 | kind_ref : u32 : 32; 27 | to_a_ref : u32 : 16; 28 | to_b_ref : u32 : 16; 29 | } 30 | } 31 | 32 | namespace coappearances { 33 | archive Graph 34 | { 35 | @explicit_reference( .coappearances.Nickname.ref, .coappearances.Graph.strings ) 36 | @explicit_reference( .coappearances.Description.ref, .coappearances.Graph.strings ) 37 | @explicit_reference( .coappearances.UnaryRelation.kind_ref, .coappearances.Graph.strings ) 38 | @explicit_reference( .coappearances.UnaryRelation.to_ref, .coappearances.Graph.vertices ) 39 | @explicit_reference( .coappearances.BinaryRelation.kind_ref, .coappearances.Graph.strings ) 40 | @explicit_reference( .coappearances.BinaryRelation.to_a_ref, .coappearances.Graph.vertices ) 41 | @explicit_reference( .coappearances.BinaryRelation.to_b_ref, .coappearances.Graph.vertices ) 42 | vertices_data : multivector< 32, .coappearances.Nickname, .coappearances.Description, .coappearances.UnaryRelation, .coappearances.BinaryRelation >; 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/vertices_data_index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-rs/tests/coappearances/assets/karenina.archive/vertices_data_index -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.archive/vertices_data_index.schema: -------------------------------------------------------------------------------- 1 | index(namespace coappearances { 2 | struct Nickname 3 | { 4 | ref : u32 : 32; 5 | } 6 | } 7 | 8 | namespace coappearances { 9 | struct Description 10 | { 11 | ref : u32 : 32; 12 | } 13 | } 14 | 15 | namespace coappearances { 16 | struct UnaryRelation 17 | { 18 | kind_ref : u32 : 32; 19 | to_ref : u32 : 16; 20 | } 21 | } 22 | 23 | namespace coappearances { 24 | struct BinaryRelation 25 | { 26 | kind_ref : u32 : 32; 27 | to_a_ref : u32 : 16; 28 | to_b_ref : u32 : 16; 29 | } 30 | } 31 | 32 | namespace coappearances { 33 | archive Graph 34 | { 35 | @explicit_reference( .coappearances.Nickname.ref, .coappearances.Graph.strings ) 36 | @explicit_reference( .coappearances.Description.ref, .coappearances.Graph.strings ) 37 | @explicit_reference( .coappearances.UnaryRelation.kind_ref, .coappearances.Graph.strings ) 38 | @explicit_reference( .coappearances.UnaryRelation.to_ref, .coappearances.Graph.vertices ) 39 | @explicit_reference( .coappearances.BinaryRelation.kind_ref, .coappearances.Graph.strings ) 40 | @explicit_reference( .coappearances.BinaryRelation.to_a_ref, .coappearances.Graph.vertices ) 41 | @explicit_reference( .coappearances.BinaryRelation.to_b_ref, .coappearances.Graph.vertices ) 42 | vertices_data : multivector< 32, .coappearances.Nickname, .coappearances.Description, .coappearances.UnaryRelation, .coappearances.BinaryRelation >; 43 | } 44 | } 45 | 46 | ) -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.json: -------------------------------------------------------------------------------- 1 | ../../../../examples/coappearances/karenina.json -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/assets/karenina.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heremaps/flatdata/192c3095c19ef3888269d96e8b34ddb181948418/flatdata-rs/tests/coappearances/assets/karenina.tar -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | flatdata::generate( 3 | "assets/coappearances.flatdata", 4 | &std::env::var("OUT_DIR").unwrap(), 5 | ) 6 | .expect("generator failed"); 7 | } 8 | -------------------------------------------------------------------------------- /flatdata-rs/tests/coappearances/src/coappearances.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/coappearances.rs")); 4 | 5 | pub use coappearances::*; 6 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flatdata_tests_features" 3 | version = "0.1.0" 4 | authors = ["Christian Vetter "] 5 | edition = "2018" 6 | publish = false 7 | 8 | [dependencies] 9 | flatdata = { path = "../../lib" } 10 | 11 | [build-dependencies] 12 | flatdata = { path = "../../lib" } 13 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | flatdata::generate("../../../test_cases", &std::env::var("OUT_DIR").unwrap()) 3 | .expect("generator failed"); 4 | } 5 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/empty.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/archives/empty.rs")); 4 | 5 | #[cfg(test)] 6 | fn is_sync(_t: T) {} 7 | 8 | #[test] 9 | fn test() { 10 | let storage = flatdata::MemoryResourceStorage::new("/my_test"); 11 | 12 | let builder = n::ABuilder::new(storage.clone()).expect("Failed to create builder"); 13 | std::mem::drop(builder); 14 | 15 | let archive = n::A::open(storage).expect("Failed to open archive"); 16 | 17 | is_sync(archive); 18 | } 19 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod empty; 2 | pub mod multivector; 3 | pub mod namespaces; 4 | pub mod ranges; 5 | pub mod raw_data; 6 | pub mod references; 7 | pub mod struct_in_archive; 8 | pub mod subarchive; 9 | pub mod vector; 10 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/namespaces.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/archives/namespaces.rs")); 4 | 5 | #[test] 6 | fn compilation() { 7 | // just check that symbols exists and everything compiles 8 | type A = a::A; 9 | } 10 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/ranges.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/archives/ranges.rs")); 4 | 5 | #[test] 6 | fn test() { 7 | let storage = flatdata::MemoryResourceStorage::new("/my_test"); 8 | 9 | let mut data = flatdata::Vector::::new(); 10 | for x in 10..600 { 11 | let next = data.grow(); 12 | next.set_x(x); 13 | next.set_first_y(x as u32 * 10); 14 | } 15 | assert_eq!(600 - 10, data.len()); 16 | 17 | let builder = n::ABuilder::new(storage.clone()).expect("Failed to create builder"); 18 | builder 19 | .set_data(&data.as_view()) 20 | .expect("Failed to set data"); 21 | 22 | let archive = n::A::open(storage).expect("Failed to open archive"); 23 | let data = archive.data(); 24 | assert_eq!(599 - 10, data.len()); 25 | for x in (10..599).enumerate() { 26 | assert_eq!(data[x.0].x(), x.1); 27 | assert_eq!( 28 | data[x.0].y_range(), 29 | (x.1 as u32 * 10..(x.1 as u32 + 1) * 10) 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/raw_data.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/archives/raw_data.rs")); 4 | 5 | #[test] 6 | fn test() { 7 | for &set_optional in &[false, true] { 8 | let storage = flatdata::MemoryResourceStorage::new("/my_test"); 9 | 10 | let builder = n::ABuilder::new(storage.clone()).expect("Failed to create builder"); 11 | builder.set_data(b"My Data").expect("Failed to set data"); 12 | 13 | if set_optional { 14 | builder 15 | .set_optional_data(b"My Other Data") 16 | .expect("Failed to set optional data"); 17 | } 18 | 19 | let archive = n::A::open(storage).expect("Failed to open archive"); 20 | assert_eq!(archive.data().as_bytes(), b"My Data"); 21 | if set_optional { 22 | assert_eq!( 23 | archive 24 | .optional_data() 25 | .expect("Optional data missing") 26 | .as_bytes(), 27 | b"My Other Data" 28 | ); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/struct_in_archive.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/archives/struct.rs")); 4 | 5 | #[test] 6 | fn test() { 7 | for &set_optional in &[false, true] { 8 | let storage = flatdata::MemoryResourceStorage::new("/my_test"); 9 | 10 | let builder = n::ABuilder::new(storage.clone()).expect("Failed to create builder"); 11 | let mut data = n::S::new(); 12 | data.set_x(14); 13 | builder.set_data(&data).expect("Failed to set data"); 14 | 15 | if set_optional { 16 | let mut optional_data = n::S::new(); 17 | optional_data.set_x(16); 18 | builder 19 | .set_optional_data(&optional_data) 20 | .expect("Failed to set optional data"); 21 | } 22 | 23 | let archive = n::A::open(storage).expect("Failed to open archive"); 24 | assert_eq!(archive.data().x(), 14); 25 | if set_optional { 26 | assert_eq!( 27 | archive.optional_data().expect("Optional data missing").x(), 28 | 16 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/archives/vector.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/archives/vector.rs")); 4 | 5 | #[test] 6 | fn test() { 7 | for &set_optional in &[false, true] { 8 | let storage = flatdata::MemoryResourceStorage::new("/my_test"); 9 | 10 | let mut data = flatdata::Vector::::new(); 11 | for x in 10..600 { 12 | data.grow().set_x(x); 13 | } 14 | 15 | let builder = n::ABuilder::new(storage.clone()).expect("Failed to create builder"); 16 | builder 17 | .set_data(&data.as_view()) 18 | .expect("Failed to set data"); 19 | 20 | if set_optional { 21 | let mut optional_data = builder 22 | .start_optional_data() 23 | .expect("Failed to start optional data"); 24 | for x in 10..600 { 25 | optional_data 26 | .grow() 27 | .expect("Failed to grow optional data") 28 | .set_x(x); 29 | } 30 | optional_data 31 | .close() 32 | .expect("Failed to close optional data"); 33 | } 34 | 35 | let archive = n::A::open(storage).expect("Failed to open archive"); 36 | let data = archive.data(); 37 | for x in (10..600).enumerate() { 38 | assert_eq!(data[x.0].x(), x.1); 39 | } 40 | if set_optional { 41 | let data = archive.optional_data().expect("Optional data not found"); 42 | for x in (10..600).enumerate() { 43 | assert_eq!(data[x.0].x(), x.1); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/constants/invalid_value.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/constants/invalid_value.rs")); 4 | 5 | #[test] 6 | fn values() { 7 | let mut data = n::Bar::new(); 8 | 9 | data.set_invalid_zero(10); 10 | assert_eq!(data.invalid_zero(), Some(10)); 11 | 12 | data.set_invalid_zero(0); 13 | assert_eq!(data.invalid_zero(), None); 14 | 15 | data.invset_alid_min_int(10); 16 | assert_eq!(data.invalid_min_int(), Some(10)); 17 | 18 | data.invset_alid_min_int(-128); 19 | assert_eq!(data.invalid_min_int(), None); 20 | 21 | data.invset_alid_max_int(10); 22 | assert_eq!(data.invalid_max_int(), Some(10)); 23 | 24 | data.invset_alid_max_int(127); 25 | assert_eq!(data.invalid_max_int(), None); 26 | } 27 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/constants/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod namespaces; 2 | pub mod values; 3 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/constants/namespaces.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/constants/namespaces.rs")); 4 | 5 | #[test] 6 | fn values_in_namespace() { 7 | assert_eq!(n::FOO, 0); 8 | assert_eq!(m::FOO, 1); 9 | } 10 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/enums/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod namespaces; 2 | pub mod structs; 3 | pub mod values; 4 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/enums/namespaces.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/enums/namespaces.rs")); 4 | 5 | #[test] 6 | fn values_in_namespaces() { 7 | assert_eq!(a::Bar::Value as i32, 0); 8 | assert_eq!(b::Bar::Value as i32, 0); 9 | 10 | let a = n::Foo::new(); 11 | assert_eq!(a.f(), a::Bar::Value); 12 | 13 | let b = m::Foo::new(); 14 | assert_eq!(b.f(), b::Bar::Value); 15 | } 16 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/enums/structs.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/enums/structs.rs")); 4 | 5 | #[test] 6 | fn enums_in_structs() { 7 | let mut value = n::StructEnumI8::new(); 8 | value.set_f(n::EnumI8::Value); 9 | assert_eq!(value.f(), n::EnumI8::Value); 10 | 11 | let mut value = n::StructEnumU8::new(); 12 | value.set_f(n::EnumU8::Value); 13 | assert_eq!(value.f(), n::EnumU8::Value); 14 | 15 | let mut value = n::StructEnumI16::new(); 16 | value.set_f(n::EnumI16::Value); 17 | assert_eq!(value.f(), n::EnumI16::Value); 18 | 19 | let mut value = n::StructEnumU16::new(); 20 | value.set_f(n::EnumU16::Value); 21 | assert_eq!(value.f(), n::EnumU16::Value); 22 | 23 | let mut value = n::StructEnumI32::new(); 24 | value.set_f(n::EnumI32::Value); 25 | assert_eq!(value.f(), n::EnumI32::Value); 26 | 27 | let mut value = n::StructEnumU32::new(); 28 | value.set_f(n::EnumU32::Value); 29 | assert_eq!(value.f(), n::EnumU32::Value); 30 | 31 | let mut value = n::StructEnumI64::new(); 32 | value.set_f(n::EnumI64::Value); 33 | assert_eq!(value.f(), n::EnumI64::Value); 34 | 35 | let mut value = n::StructEnumU64::new(); 36 | value.set_f(n::EnumU64::Value); 37 | assert_eq!(value.f(), n::EnumU64::Value); 38 | } 39 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/enums/values.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/enums/values.rs")); 4 | 5 | #[test] 6 | fn values() { 7 | assert_eq!(n::EnumI8::FooI8Neg as i8, -128); 8 | assert_eq!(n::EnumI8::FooI8Pos as i8, 127); 9 | assert_eq!(n::EnumI8::FooI8Zero as i8, 0); 10 | assert_eq!(n::EnumI8::FooI8NegHex as i8, -0x7f); 11 | assert_eq!(n::EnumI8::FooI8PosHex as i8, 0x7e); 12 | assert_eq!(n::EnumI8::FooI8OneHex as i8, 0x1); 13 | assert_eq!(n::EnumI8::UnknownValueMinus1 as i8, -1); 14 | assert_eq!(n::EnumI8::UnknownValue2 as i8, 2); 15 | 16 | assert_eq!(n::EnumU8::FooU8Pos as u8, 255); 17 | assert_eq!(n::EnumU8::FooU8Zero as u8, 0); 18 | assert_eq!(n::EnumU8::FooU8PosHex as u8, 0xfe); 19 | assert_eq!(n::EnumU8::FooU8OneHex as u8, 0x1); 20 | assert_eq!(n::EnumU8::UnknownValue2 as i8, 2); 21 | } 22 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg(test)] 2 | 3 | pub mod archives; 4 | pub mod constants; 5 | pub mod enums; 6 | pub mod structs; 7 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/structs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod integers; 2 | pub mod namespaces; 3 | pub mod unaligned; 4 | -------------------------------------------------------------------------------- /flatdata-rs/tests/features/src/structs/namespaces.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | include!(concat!(env!("OUT_DIR"), "/structs/namespaces.rs")); 4 | 5 | #[test] 6 | fn proper_namespaces() { 7 | // just check that this compiles 8 | type X = n::Foo; 9 | type Y = m::Foo; 10 | } 11 | -------------------------------------------------------------------------------- /generator: -------------------------------------------------------------------------------- 1 | flatdata-generator/generator.py -------------------------------------------------------------------------------- /inspector: -------------------------------------------------------------------------------- 1 | ./flatdata-py/inspector.py -------------------------------------------------------------------------------- /lgtm.yml: -------------------------------------------------------------------------------- 1 | extraction: 2 | cpp: 3 | prepare: # Customizable step used by all languages. 4 | packages: 5 | - python3-pip 6 | - python3-setuptools 7 | - libboost-filesystem-dev 8 | after_prepare: # Customizable step used by all languages. 9 | - pip3 install ./flatdata-generator 10 | configure: # Customizable step used only by C/C++ extraction. 11 | command: 12 | - mkdir build 13 | - cd build 14 | - cmake ../flatdata-cpp -DCMAKE_CXX_FLAGS="-Wall -pedantic -Wextra" 15 | index: # Customizable step used by all languages. 16 | build_command: 17 | - cd build 18 | - make -j$(nproc) -------------------------------------------------------------------------------- /test_cases/README.md: -------------------------------------------------------------------------------- 1 | ## Flatdata compatibility test cases 2 | 3 | This folder organizes test case schemas by feature (combination). 4 | These test cases are used: 5 | * to test compliance of the code generators 6 | * to test compliance of the language implementations 7 | 8 | ### Organization 9 | 10 | Each test contains: 11 | * a short description on what it should be used to test 12 | * a schema file -------------------------------------------------------------------------------- /test_cases/archives/comments.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that comments get attached to the corresponding constant 2 | */ 3 | namespace n{ 4 | // This is a comment about foo 5 | archive Foo { 6 | // this is a comment about foo.bar 7 | bar : raw_data; 8 | } 9 | 10 | /* 11 | * This is a comment about Bar 12 | */ 13 | archive Bar { 14 | /* 15 | * this is a comment about bar.foo 16 | */ 17 | foo : raw_data; 18 | } 19 | } -------------------------------------------------------------------------------- /test_cases/archives/empty.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that empty archives work 2 | */ 3 | namespace n{ 4 | archive A { 5 | } 6 | } -------------------------------------------------------------------------------- /test_cases/archives/multivector.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a multivector can be stored/read in archives 2 | */ 3 | namespace n{ 4 | struct S { 5 | x : u64; 6 | } 7 | 8 | struct T { 9 | x : u64; 10 | } 11 | 12 | archive A { 13 | data : multivector< 8, S, T >; 14 | 15 | @optional 16 | optional_data : multivector< 16, S, T >; 17 | 18 | data_u64_index : multivector< 64, S, T >; 19 | } 20 | } -------------------------------------------------------------------------------- /test_cases/archives/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a namespaces are resolved properly 2 | * Note that same-name structs are not supported in the same multivector, even if in different namespaces 3 | */ 4 | namespace n{ 5 | struct S { 6 | x : u64; 7 | } 8 | 9 | archive X { 10 | payload : raw_data; 11 | } 12 | } 13 | 14 | namespace m { 15 | struct S { 16 | x : u64; 17 | } 18 | 19 | archive X { 20 | payload : raw_data; 21 | } 22 | } 23 | 24 | namespace a { 25 | archive A { 26 | single : .n.S; 27 | list : vector< .m.S >; 28 | multi : multivector< 32, .n.S >; 29 | inner : archive .n.X; 30 | } 31 | } -------------------------------------------------------------------------------- /test_cases/archives/ranges.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a vector can contain ranges 2 | */ 3 | namespace n{ 4 | struct S { 5 | x : u64; 6 | @range(y_range) 7 | first_y : u32 : 14; 8 | } 9 | 10 | archive A { 11 | data : vector< S >; 12 | } 13 | } -------------------------------------------------------------------------------- /test_cases/archives/raw_data.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that raw data can be stored/read in archives 2 | */ 3 | namespace n{ 4 | archive A { 5 | data : raw_data; 6 | 7 | @optional 8 | optional_data : raw_data; 9 | } 10 | } -------------------------------------------------------------------------------- /test_cases/archives/references.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a resources can be annotated with references 2 | * R.ref should limit the size of resources to 2^8, and R.ref2 even further to 2^4 3 | */ 4 | namespace n{ 5 | struct S { 6 | x : u32; 7 | } 8 | 9 | struct R { 10 | ref : u32 : 8; 11 | ref2 : u32 : 4; 12 | } 13 | 14 | @bound_implicitly( all_lists : list1, list2, multilist1) 15 | archive A { 16 | @optional 17 | list1 : vector< S >; 18 | list2 : vector< S >; 19 | @optional 20 | multilist1 : multivector< 32, S >; 21 | multilist2 : multivector< 32, S >; 22 | @optional 23 | raw1 : raw_data; 24 | raw2 : raw_data; 25 | 26 | @explicit_reference( R.ref, list1 ) 27 | @explicit_reference( R.ref2, list1 ) 28 | @explicit_reference( R.ref2, list2 ) 29 | @explicit_reference( R.ref2, multilist1 ) 30 | @explicit_reference( R.ref2, multilist2 ) 31 | @explicit_reference( R.ref2, raw1 ) 32 | @explicit_reference( R.ref2, raw2 ) 33 | refs : vector< R >; 34 | 35 | @explicit_reference( R.ref, list1 ) 36 | multirefs : multivector< 32, R >; 37 | } 38 | } -------------------------------------------------------------------------------- /test_cases/archives/struct.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a single struct can be stored/read in archives 2 | */ 3 | namespace n{ 4 | struct S { 5 | x : u64; 6 | } 7 | 8 | archive A { 9 | data : S; 10 | 11 | @optional 12 | optional_data : S; 13 | } 14 | } -------------------------------------------------------------------------------- /test_cases/archives/subarchive.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a subarchive can be stored/read in archives 2 | */ 3 | namespace n{ 4 | archive X { 5 | payload : raw_data; 6 | } 7 | 8 | archive A { 9 | data : archive X; 10 | 11 | @optional 12 | optional_data : archive X; 13 | } 14 | } -------------------------------------------------------------------------------- /test_cases/archives/vector.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that a vector can be stored/read in archives 2 | */ 3 | namespace n{ 4 | struct S { 5 | x : u64; 6 | } 7 | 8 | archive A { 9 | data : vector< S >; 10 | 11 | @optional 12 | optional_data : vector< S >; 13 | } 14 | } -------------------------------------------------------------------------------- /test_cases/constants/comments.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that comments get attached to the corresponding constant 2 | */ 3 | namespace n{ 4 | // This is a comment about foo 5 | const u32 FOO = 0; 6 | 7 | /* 8 | * This is a comment about bar 9 | */ 10 | const u64 BAR = 0; 11 | } -------------------------------------------------------------------------------- /test_cases/constants/invalid_value.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests fields with invalid values are handles properly 2 | */ 3 | namespace n{ 4 | const i8 INVALID_ZERO = 0; 5 | const i8 INVALID_MIN_INT = -128; 6 | const i8 INVALID_MAX_INT = 127; 7 | 8 | struct Bar { 9 | @optional( INVALID_ZERO ) 10 | invalid_zero : i8; 11 | @optional( INVALID_MIN_INT ) 12 | invalid_min_int : i8; 13 | @optional( INVALID_MAX_INT ) 14 | invalid_max_int : i8; 15 | } 16 | } -------------------------------------------------------------------------------- /test_cases/constants/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that symbols are properly separated into namespaces 2 | */ 3 | namespace n{ 4 | const i8 FOO = 0; 5 | const i8 FOO2 = 10; 6 | } 7 | 8 | namespace m{ 9 | const i8 FOO = 1; 10 | 11 | struct Bar { 12 | @const( FOO ) 13 | foo1 : i8; 14 | @const( .n.FOO ) 15 | foo2 : i8; 16 | @const( .m.FOO ) 17 | foo3 : i8; 18 | @optional( FOO ) 19 | bar1 : i8; 20 | @optional( .n.FOO ) 21 | bar2 : i8; 22 | @optional( .m.FOO ) 23 | bar3 : i8; 24 | } 25 | } -------------------------------------------------------------------------------- /test_cases/enums/comments.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that comments get attached to the corresponding constant 2 | */ 3 | namespace n{ 4 | // This is a comment about Foo 5 | enum Foo : u64 : 1 { 6 | // This is a comment about Foo.a 7 | A = 0, 8 | 9 | // This is a comment about Foo.b 10 | B = 1, 11 | } 12 | 13 | /* 14 | * This is a comment about Bar 15 | */ 16 | enum Bar : u64 : 1 { 17 | /* 18 | * This is a comment about Bar.a 19 | */ 20 | A = 0, 21 | 22 | /* 23 | * This is a comment about Bar.b 24 | */ 25 | B = 1, 26 | } 27 | } -------------------------------------------------------------------------------- /test_cases/enums/default_width.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that fields have a default width independent of the underlying type 2 | */ 3 | namespace n{ 4 | enum EnumI8 : i8 : 1 { 5 | VALUE = 0, 6 | } 7 | 8 | struct StructEnumI8 { 9 | f : EnumI8; 10 | } 11 | 12 | enum EnumU8 : u8 : 1 { 13 | VALUE = 0, 14 | } 15 | 16 | struct StructEnumU8 { 17 | f : EnumU8; 18 | } 19 | 20 | enum EnumI16 : i16 : 1 { 21 | VALUE = 0, 22 | } 23 | 24 | struct StructEnumI16 { 25 | f : EnumI16; 26 | } 27 | 28 | enum EnumU16 : u16 : 1 { 29 | VALUE = 0, 30 | } 31 | 32 | struct StructEnumU16 { 33 | f : EnumU16; 34 | } 35 | 36 | enum EnumI32 : i32 : 1 { 37 | VALUE = 0, 38 | } 39 | 40 | struct StructEnumI32 { 41 | f : EnumI32; 42 | } 43 | 44 | enum EnumU32 : u32 : 1 { 45 | VALUE = 0, 46 | } 47 | 48 | struct StructEnumU32 { 49 | f : EnumU32; 50 | } 51 | 52 | enum EnumI64 : i64 : 1 { 53 | VALUE = 0, 54 | } 55 | 56 | struct StructEnumI64 { 57 | f : EnumI64; 58 | } 59 | 60 | enum EnumU64 : u64 : 1 { 61 | VALUE = 0, 62 | } 63 | 64 | struct StructEnumU64 { 65 | f : EnumU64; 66 | } 67 | } -------------------------------------------------------------------------------- /test_cases/enums/implicit_values.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that an enumeration can contain implicit values 2 | */ 3 | namespace n{ 4 | enum Enum1 : u16 : 3 { 5 | // = 0 6 | VALUE_1, 7 | // = 3 8 | VALUE_2 = 3, 9 | // = 4 10 | VALUE_3, 11 | // = 1 12 | VALUE_4 = 1, 13 | // = 2 14 | VALUE_5 15 | } 16 | } -------------------------------------------------------------------------------- /test_cases/enums/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that symbols are properly separated into namespaces 2 | */ 3 | namespace a{ 4 | enum Bar : u8 : 1 { 5 | VALUE = 0, 6 | } 7 | } 8 | 9 | namespace b{ 10 | enum Bar : u8 : 1 { 11 | VALUE = 0, 12 | } 13 | } 14 | 15 | namespace n{ 16 | struct Foo { 17 | f : .a.Bar : 1; 18 | } 19 | } 20 | 21 | namespace m{ 22 | struct Foo { 23 | f : .b.Bar : 1; 24 | } 25 | } -------------------------------------------------------------------------------- /test_cases/enums/structs.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that enums work in structs 2 | */ 3 | namespace n{ 4 | enum EnumI8 : i8 : 1 { 5 | VALUE = 0, 6 | } 7 | 8 | struct StructEnumI8 { 9 | f : EnumI8 : 1; 10 | } 11 | 12 | enum EnumU8 : u8 : 1 { 13 | VALUE = 0, 14 | } 15 | 16 | struct StructEnumU8 { 17 | f : EnumU8 : 1; 18 | } 19 | 20 | enum EnumI16 : i16 : 1 { 21 | VALUE = 0, 22 | } 23 | 24 | struct StructEnumI16 { 25 | f : EnumI16 : 1; 26 | } 27 | 28 | enum EnumU16 : u16 : 1 { 29 | VALUE = 0, 30 | } 31 | 32 | struct StructEnumU16 { 33 | f : EnumU16 : 1; 34 | } 35 | 36 | enum EnumI32 : i32 : 1 { 37 | VALUE = 0, 38 | } 39 | 40 | struct StructEnumI32 { 41 | f : EnumI32 : 1; 42 | } 43 | 44 | enum EnumU32 : u32 : 1 { 45 | VALUE = 0, 46 | } 47 | 48 | struct StructEnumU32 { 49 | f : EnumU32 : 1; 50 | } 51 | 52 | enum EnumI64 : i64 : 1 { 53 | VALUE = 0, 54 | } 55 | 56 | struct StructEnumI64 { 57 | f : EnumI64 : 1; 58 | } 59 | 60 | enum EnumU64 : u64 : 1 { 61 | VALUE = 0, 62 | } 63 | 64 | struct StructEnumU64 { 65 | f : EnumU64 : 1; 66 | } 67 | } -------------------------------------------------------------------------------- /test_cases/enums/values.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that varies ways of assigning values to the different types works properly 2 | * MIN, MAX and 0 are assigned to test that the resulting enum can hold the full range 3 | * Undefined values are generated, and can be used. 4 | */ 5 | namespace n{ 6 | enum EnumI8 : i8 { 7 | FOO_I8_NEG = -128, 8 | FOO_I8_POS = 127, 9 | FOO_I8_ZERO = 0, 10 | FOO_I8_NEG_HEX = -0x7f, 11 | FOO_I8_POS_HEX = 0x7e, 12 | FOO_I8_ONE_HEX = 0x1, 13 | } 14 | 15 | enum EnumU8 : u8 { 16 | FOO_U8_POS = 255, 17 | FOO_U8_ZERO = 0, 18 | FOO_U8_POS_HEX = 0xfe, 19 | FOO_U8_ONE_HEX = 0x1, 20 | } 21 | } -------------------------------------------------------------------------------- /test_cases/structs/comments.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that comments get attached to the corresponding constant 2 | */ 3 | namespace n{ 4 | // This is a comment about Foo 5 | struct Foo { 6 | // This is a comment about Foo.a 7 | a : u64 : 64; 8 | 9 | // This is a comment about Foo.b 10 | b : u64 : 64; 11 | } 12 | 13 | /* 14 | * This is a comment about Bar 15 | */ 16 | struct Bar { 17 | /* 18 | * This is a comment about Bar.a 19 | */ 20 | a : u64 : 64; 21 | 22 | /* 23 | * This is a comment about Bar.b 24 | */ 25 | b : u64 : 64; 26 | } 27 | } -------------------------------------------------------------------------------- /test_cases/structs/default_width.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that fields have a default with based on the underlying type 2 | * Tests should test the expected structure size 3 | * Tests should try assigning min/max/random values to these and reading them again 4 | */ 5 | namespace n{ 6 | struct U8 { 7 | f : u8; 8 | } 9 | 10 | struct I8 { 11 | f : i8; 12 | } 13 | 14 | struct U16 { 15 | f : u16 ; 16 | } 17 | 18 | struct I16 { 19 | f : i16 ; 20 | } 21 | 22 | struct U32 { 23 | f : u32 ; 24 | } 25 | 26 | struct I32 { 27 | f : i32 ; 28 | } 29 | 30 | struct U64 { 31 | f : u64 ; 32 | } 33 | 34 | struct I64 { 35 | f : i64 ; 36 | } 37 | } -------------------------------------------------------------------------------- /test_cases/structs/integers.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that varies integral types work in structures 2 | * Tests should test the expected structure size 3 | * Tests should try assigning min/max/random values to these and reading them again 4 | */ 5 | namespace n{ 6 | struct U8 { 7 | f : u8 : 8; 8 | } 9 | 10 | struct I8 { 11 | f : i8 : 8; 12 | } 13 | 14 | struct U16 { 15 | f : u16 : 16; 16 | } 17 | 18 | struct I16 { 19 | f : i16 : 16; 20 | } 21 | 22 | struct U32 { 23 | f : u32 : 32; 24 | } 25 | 26 | struct I32 { 27 | f : i32 : 32; 28 | } 29 | 30 | struct U64 { 31 | f : u64 : 64; 32 | } 33 | 34 | struct I64 { 35 | f : i64 : 64; 36 | } 37 | } -------------------------------------------------------------------------------- /test_cases/structs/namespaces.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that symbols are properly separated into namespaces 2 | */ 3 | namespace n{ 4 | struct Foo { 5 | f : u32 : 32; 6 | } 7 | } 8 | 9 | namespace m{ 10 | struct Foo { 11 | f : u32 : 32; 12 | } 13 | } -------------------------------------------------------------------------------- /test_cases/structs/unaligned.flatdata: -------------------------------------------------------------------------------- 1 | /* This test tests that fields with misaligned offsets and less than full width work 2 | * Tests should test the expected structure size 3 | * Tests should try assigning min/max/random values to these and reading them again 4 | */ 5 | namespace n{ 6 | struct U8 { 7 | padding : u64 : 3; 8 | f : u8 : 5; 9 | } 10 | 11 | struct I8 { 12 | padding : u64 : 3; 13 | f : i8 : 5; 14 | } 15 | 16 | struct U16 { 17 | padding : u64 : 3; 18 | f : u16 : 13; 19 | } 20 | 21 | struct I16 { 22 | padding : u64 : 3; 23 | f : i16 : 13; 24 | } 25 | 26 | struct U32 { 27 | padding : u64 : 3; 28 | f : u32 : 29; 29 | } 30 | 31 | struct I32 { 32 | padding : u64 : 3; 33 | f : i32 : 29; 34 | } 35 | 36 | struct U64 { 37 | padding : u64 : 3; 38 | f : u64 : 61; 39 | } 40 | 41 | struct I64 { 42 | padding : u64 : 3; 43 | f : i64 : 61; 44 | } 45 | } -------------------------------------------------------------------------------- /writer: -------------------------------------------------------------------------------- 1 | flatdata-py/writer.py --------------------------------------------------------------------------------