~jgillis/flatbuffers-read-writing

03cc0b3fe74f60885264a2a4795fda037bb597c7 — Joris Gillis 4 years ago cb89a4c
Setting up FlatBuffers
5 files changed, 81 insertions(+), 35 deletions(-)

A README.md
M pom.xml
A src/main/fbs/person.fbs
M src/main/java/com/example/flatbuffers/FlatbuffersApplication.java
D src/test/java/com/example/flatbuffers/FlatbuffersApplicationTests.java
A README.md => README.md +8 -0
@@ 0,0 1,8 @@
# FlatBuffers Example project

Example project to explore FlatBuffers.

## Development

Note that the version of `flatc` has to match the version of the `flatbuffers-java` library in 
`pom.xml`. 
\ No newline at end of file

M pom.xml => pom.xml +56 -16
@@ 16,33 16,73 @@

    <properties>
        <java.version>14</java.version>
        <fbs.sources>${basedir}/src/main/fbs</fbs.sources>
        <fbs.generated.sources>${project.build.directory}/generated-sources/java</fbs.generated.sources>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
            <groupId>com.google.flatbuffers</groupId>
            <artifactId>flatbuffers-java</artifactId>
            <version>1.12.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>${java.version}</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>generate-sources</phase>
                    </execution>
                </executions>
                <configuration>
                    <executable>/usr/local/bin/flatc</executable>
                    <workingDirectory>${fbs.sources}</workingDirectory>
                    <arguments>
                        <argument>--grpc</argument>
                        <argument>--java</argument>
                        <argument>--gen-mutable</argument>
                        <argument>-o</argument>
                        <argument>${fbs.generated.sources}</argument>
                        <argument>person.fbs</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.10</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${fbs.generated.sources}</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>


A src/main/fbs/person.fbs => src/main/fbs/person.fbs +16 -0
@@ 0,0 1,16 @@
namespace com.example.flatbuffers.model;

table Person {
    firstName:string;
    lastName:string;
    age:int;
}

table Address {
    street:string;
    streetNumber:int;
    city:string;
    postalCode:short;
}

root_type Person;
\ No newline at end of file

M src/main/java/com/example/flatbuffers/FlatbuffersApplication.java => src/main/java/com/example/flatbuffers/FlatbuffersApplication.java +1 -6
@@ 1,13 1,8 @@
package com.example.flatbuffers;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FlatbuffersApplication {

    public static void main(String[] args) {
        SpringApplication.run(FlatbuffersApplication.class, args);
    }

    }
}

D src/test/java/com/example/flatbuffers/FlatbuffersApplicationTests.java => src/test/java/com/example/flatbuffers/FlatbuffersApplicationTests.java +0 -13
@@ 1,13 0,0 @@
package com.example.flatbuffers;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class FlatbuffersApplicationTests {

    @Test
    void contextLoads() {
    }

}