├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── idl │ └── fbs │ │ ├── v1.0.fbs │ │ └── v2.0.fbs ├── java │ └── org │ │ └── horiga │ │ └── study │ │ └── springboot │ │ └── flatbuffers │ │ ├── Application.java │ │ ├── FlatBuffersHttpMessageConverter.java │ │ ├── FlatBuffersMessage.java │ │ ├── FlatBuffersMessageProtocolException.java │ │ ├── controller │ │ └── APIController.java │ │ ├── model │ │ └── ResponseMessage.java │ │ ├── protocol │ │ └── messages │ │ │ ├── Demo.java │ │ │ ├── Error.java │ │ │ ├── Friends.java │ │ │ ├── FriendsAnswer.java │ │ │ ├── Me.java │ │ │ ├── MessagePlaceholderKeyValuePair.java │ │ │ ├── PagerCondition.java │ │ │ ├── Score.java │ │ │ ├── TextMessage.java │ │ │ ├── Token.java │ │ │ ├── TokenAnswer.java │ │ │ ├── User.java │ │ │ ├── UserAnswer.java │ │ │ └── v2 │ │ │ ├── Error.java │ │ │ ├── Friends.java │ │ │ ├── MessageId.java │ │ │ ├── Pager.java │ │ │ ├── Person.java │ │ │ ├── Request.java │ │ │ ├── RequestBody.java │ │ │ ├── Response.java │ │ │ ├── ResponseBody.java │ │ │ └── Token.java │ │ └── util │ │ └── Utils.java └── resources │ └── application.properties └── test └── java ├── FbTest.java ├── FbTest2.java └── WebIntegrationTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Reference : https://github.com/github/gitignore 2 | 3 | # ------------------------------ 4 | # Java.gitignore 5 | # ------------------------------ 6 | *.class 7 | 8 | # Mobile Tools for Java (J2ME) 9 | .mtj.tmp/ 10 | 11 | # Package Files # 12 | *.jar 13 | *.war 14 | *.ear 15 | 16 | # ------------------------------ 17 | # Maven.gitignore 18 | # ------------------------------ 19 | target/ 20 | pom.xml.tag 21 | pom.xml.releaseBackup 22 | pom.xml.next 23 | release.properties 24 | 25 | # ------------------------------ 26 | # Global/Eclipse.gitignore 27 | # ------------------------------ 28 | *.pydevproject 29 | .metadata 30 | .gradle 31 | bin/ 32 | tmp/ 33 | *.tmp 34 | *.bak 35 | *.swp 36 | *~.nib 37 | local.properties 38 | .settings/ 39 | .loadpath 40 | 41 | # External tool builders 42 | .externalToolBuilders/ 43 | 44 | # Locally stored "Eclipse launch configurations" 45 | *.launch 46 | 47 | # CDT-specific 48 | .cproject 49 | 50 | # PDT-specific 51 | .buildpath 52 | 53 | # sbteclipse plugin 54 | .target 55 | 56 | # TeXlipse plugin 57 | .texlipse 58 | 59 | # ------------------------------ 60 | # LINEGAME local 61 | # ------------------------------ 62 | .classpath 63 | .project 64 | .springBeans 65 | /repository/ 66 | /logs/ 67 | 68 | # ------------------------------ 69 | # OS generated files 70 | # ------------------------------ 71 | .DS_Store 72 | .DS_Store? 73 | ._* 74 | .Spotlight-V100 75 | .Trashes 76 | Icon? 77 | ehthumbs.db 78 | Thumbs.db 79 | 80 | .idea 81 | *.iml 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-flatbuffers 2 | 3 | > Google [FlatBuffers](https://google.github.io/flatbuffers/) with [spring-boot](http://projects.spring.io/spring-boot/) HTTP server demo 4 | 5 | - Compile FlatBuffers scheme in Java 6 | 7 | ```bash 8 | /usr/local/bin/flatc -j -o src/main/java src/main/idl/fbs/v1.0.fbs 9 | ``` 10 | 11 | - FlatBuffersHttpMessageConverter 12 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | org.horiga.study 7 | springboot-flatbuffers 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | springboot-flatbuffers 12 | The demo spring-boot with Google's FlatBuffers 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.2.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | org.horiga.study.springboot.flatbuffers.Application 24 | 9.2.9.v20150224 25 | 1.8 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-tomcat 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-jetty 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-starter-actuator 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | 64 | com.google.flatbuffers 65 | flatbuffers-java 66 | 1.2.0-SNAPSHOT 67 | 68 | 69 | 70 | com.fasterxml.jackson.module 71 | jackson-module-afterburner 72 | 2.4.0 73 | 74 | 75 | com.fasterxml.jackson.datatype 76 | jackson-datatype-jsr310 77 | 2.4.5 78 | 79 | 80 | 81 | com.google.guava 82 | guava 83 | 18.0 84 | 85 | 86 | 87 | org.projectlombok 88 | lombok 89 | 1.14.8 90 | provided 91 | 92 | 93 | 94 | com.ning 95 | async-http-client 96 | 1.9.31 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | org.springframework.boot 105 | spring-boot-maven-plugin 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/main/idl/fbs/v1.0.fbs: -------------------------------------------------------------------------------- 1 | namespace org.horiga.study.springboot.flatbuffers.protocol.messages; 2 | 3 | table Demo { 4 | point: short; 5 | score: double; 6 | flags: bool = false; 7 | } 8 | 9 | table Token { 10 | id: int; 11 | accessToken: string; 12 | created: long; 13 | } 14 | 15 | table PagerCondition { 16 | start: int; 17 | count: int; 18 | filterBy: string; 19 | filterValue: string; 20 | } 21 | 22 | // fetch @me 23 | table Me { 24 | token: Token; 25 | } 26 | 27 | table User { 28 | token: Token; 29 | ids: [string]; 30 | } 31 | 32 | table Friends { 33 | token: Token; 34 | condition: PagerCondition; 35 | } 36 | 37 | table Score { 38 | mi: int = 2; 39 | factor: string; 40 | score: double; 41 | } 42 | 43 | table MessagePlaceholderKeyValuePair { 44 | key: string; 45 | value: string; 46 | } 47 | 48 | table TextMessage { 49 | id: string; 50 | to: [string]; 51 | placeholders: [MessagePlaceholderKeyValuePair]; 52 | } 53 | 54 | // response 55 | table Error { 56 | code: string; 57 | message: string; 58 | } 59 | 60 | table TokenAnswer { 61 | token: Token; 62 | expired: long; 63 | } 64 | 65 | table UserAnswer { 66 | displayName: string; 67 | mid: string; 68 | pictureUrl: string; 69 | } 70 | 71 | table FriendsAnswer { 72 | total: int; 73 | start: int; 74 | count: int; 75 | members: [User]; 76 | } 77 | -------------------------------------------------------------------------------- /src/main/idl/fbs/v2.0.fbs: -------------------------------------------------------------------------------- 1 | namespace org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 2 | 3 | enum MessageId: int { 4 | OK = 0, FAILED, TOKEN, PERSON, FRIENDS 5 | } 6 | 7 | union RequestBody { 8 | Pager 9 | } 10 | 11 | union ResponseBody { 12 | Error, Person, Friends 13 | } 14 | 15 | table Token { 16 | token: string; 17 | } 18 | 19 | table Error { 20 | code: int; 21 | detail: string; 22 | } 23 | 24 | table Request { 25 | msg: MessageId; 26 | token: Token; 27 | body: RequestBody; 28 | } 29 | 30 | table Response { 31 | msg: MessageId; 32 | body: ResponseBody; 33 | } 34 | 35 | table Person { 36 | userId: string; 37 | displayName: string; 38 | thumbnail: string; 39 | } 40 | 41 | table Pager { 42 | offset: int; 43 | limit: int; 44 | } 45 | 46 | table Friends { 47 | total: int; 48 | offset: int; 49 | limit: int; 50 | entity: [Person]; 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/Application.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.databind.DeserializationFeature; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.fasterxml.jackson.databind.SerializationFeature; 7 | import com.fasterxml.jackson.datatype.jsr310.JSR310Module; 8 | import com.fasterxml.jackson.module.afterburner.AfterburnerModule; 9 | import com.google.common.collect.Maps; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.eclipse.jetty.server.HttpConnectionFactory; 12 | import org.horiga.study.springboot.flatbuffers.protocol.messages.Me; 13 | import org.horiga.study.springboot.flatbuffers.protocol.messages.Score; 14 | import org.springframework.boot.SpringApplication; 15 | import org.springframework.boot.autoconfigure.SpringBootApplication; 16 | import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; 17 | import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.http.converter.HttpMessageConverter; 20 | import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | import java.util.stream.Stream; 26 | 27 | @SpringBootApplication 28 | @Slf4j 29 | public class Application extends WebMvcConfigurerAdapter { 30 | 31 | public static void main(String[] args) { 32 | SpringApplication.run(Application.class, args); 33 | } 34 | 35 | @Bean 36 | ObjectMapper objectMapper() { 37 | ObjectMapper mapper = new ObjectMapper(); 38 | mapper.registerModules(new AfterburnerModule(), new JSR310Module()); 39 | mapper.enable(SerializationFeature.INDENT_OUTPUT); 40 | mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); 41 | mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); 42 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 43 | mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 44 | return mapper; 45 | } 46 | 47 | @Bean 48 | FlatBuffersHttpMessageConverter flatBuffersHttpMessageConverter() { 49 | try { 50 | Map repo = Maps.newHashMap(); 51 | repo.put("1", new FlatBuffersMessage("1", Me.class)); 52 | repo.put("2", new FlatBuffersMessage("2", Score.class)); 53 | 54 | return new FlatBuffersHttpMessageConverter(repo); 55 | } catch (Exception e) { 56 | throw new RuntimeException(e); 57 | } 58 | } 59 | 60 | @Override 61 | public void configureMessageConverters(List> converters) { 62 | converters.add(flatBuffersHttpMessageConverter()); 63 | } 64 | 65 | @Override 66 | public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { 67 | configurer.defaultContentType(FlatBuffersHttpMessageConverter.X_FLATBUFFERS); 68 | } 69 | 70 | // Withdraw Server header directives. 71 | @Bean 72 | JettyServerCustomizer jettyServerCustomizer() { 73 | return server -> { 74 | Stream.of(server.getConnectors()) 75 | .flatMap(conn -> conn.getConnectionFactories().stream()) 76 | .flatMap(f -> (f instanceof HttpConnectionFactory) ? 77 | Stream.of((HttpConnectionFactory) f) : Stream.empty()) 78 | .forEach(f -> f.getHttpConfiguration().setSendServerVersion(false)); 79 | }; 80 | } 81 | 82 | @Bean 83 | JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory( 84 | JettyServerCustomizer[] customizer 85 | ) { 86 | JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(); 87 | factory.addServerCustomizers(customizer); 88 | return factory; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/FlatBuffersHttpMessageConverter.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers; 2 | 3 | import com.google.flatbuffers.Table; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.http.HttpInputMessage; 6 | import org.springframework.http.HttpOutputMessage; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.converter.AbstractHttpMessageConverter; 9 | import org.springframework.http.converter.HttpMessageNotReadableException; 10 | import org.springframework.http.converter.HttpMessageNotWritableException; 11 | import org.springframework.util.StreamUtils; 12 | 13 | import java.io.ByteArrayOutputStream; 14 | import java.io.IOException; 15 | import java.nio.ByteBuffer; 16 | import java.nio.charset.Charset; 17 | import java.util.Map; 18 | import java.util.Objects; 19 | 20 | /** 21 | * 22 | */ 23 | @Slf4j 24 | public class FlatBuffersHttpMessageConverter extends AbstractHttpMessageConverter { 25 | 26 | public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); 27 | 28 | public static final MediaType X_FLATBUFFERS = new MediaType("application", "x-fb", DEFAULT_CHARSET); 29 | 30 | public static final String X_FLATBUFFERS_MESSAGE_ID = "X-FBS-MessageId"; 31 | 32 | protected final Map messageRepository; 33 | 34 | public FlatBuffersHttpMessageConverter(Map messageRepository) { 35 | super(X_FLATBUFFERS); 36 | this.messageRepository = messageRepository; 37 | } 38 | 39 | @Override 40 | protected boolean supports(Class clazz) { 41 | return Table.class.isAssignableFrom(clazz); 42 | } 43 | 44 | @Override 45 | protected Table readInternal(Class clazz, HttpInputMessage inputMessage) 46 | throws IOException, HttpMessageNotReadableException { 47 | 48 | final String messageId = inputMessage.getHeaders().getFirst(X_FLATBUFFERS_MESSAGE_ID); 49 | log.debug("Request.messageId: {}", messageId); 50 | 51 | if(Objects.isNull(messageId) || 52 | !messageRepository.containsKey(messageId)) { 53 | throw new HttpMessageNotReadableException("Unknown message protocol identifier"); 54 | } 55 | 56 | final long contentLength = inputMessage.getHeaders().getContentLength(); 57 | final ByteArrayOutputStream out = 58 | new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); 59 | StreamUtils.copy(inputMessage.getBody(), out); 60 | 61 | return messageRepository.get(messageId).build(ByteBuffer.wrap(out.toByteArray())); 62 | } 63 | 64 | @Override 65 | protected void writeInternal(Table message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { 66 | setFlatBuffersResponseHeaders(message, outputMessage); 67 | 68 | final byte[] dst = new byte[getContentLength(message, X_FLATBUFFERS).intValue()]; 69 | message.getByteBuffer().get(dst); 70 | 71 | StreamUtils.copy(dst, outputMessage.getBody()); 72 | } 73 | 74 | @Override 75 | protected Long getContentLength(Table table, MediaType contentType) throws IOException { 76 | final ByteBuffer buf = table.getByteBuffer(); 77 | return (long) (buf.limit() - buf.position()); 78 | } 79 | 80 | private void setFlatBuffersResponseHeaders(final Table message, final HttpOutputMessage outputMessage) { 81 | // debug 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/FlatBuffersMessage.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.flatbuffers.Table; 5 | import lombok.Getter; 6 | import lombok.ToString; 7 | 8 | import java.lang.reflect.Method; 9 | import java.nio.ByteBuffer; 10 | 11 | @Getter 12 | @ToString(callSuper = false, includeFieldNames = true) 13 | public class FlatBuffersMessage { 14 | 15 | private final String id; 16 | 17 | private final Class klass; 18 | 19 | private final Method buildMethod; 20 | 21 | public FlatBuffersMessage(String id, Class klass) throws Exception { 22 | this.id = id; 23 | this.klass = klass; 24 | final Method m = klass.getMethod("getRootAs" + klass.getSimpleName(), ByteBuffer.class); 25 | Preconditions.checkArgument(m != null, "This message is not FlatBuffers message"); 26 | this.buildMethod = m; 27 | } 28 | 29 | public Table build(final ByteBuffer bytes) 30 | throws FlatBuffersMessageProtocolException { 31 | try { 32 | return (Table) this.buildMethod.invoke(klass, bytes); 33 | } catch (Exception e) { 34 | throw new FlatBuffersMessageProtocolException("Unavailable flatbuffers message.", e); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/FlatBuffersMessageProtocolException.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Created by horiga on 2015/09/12. 7 | */ 8 | public class FlatBuffersMessageProtocolException extends IOException { 9 | 10 | public FlatBuffersMessageProtocolException() { 11 | super(); 12 | } 13 | 14 | public FlatBuffersMessageProtocolException(String message) { 15 | super(message); 16 | } 17 | 18 | public FlatBuffersMessageProtocolException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/controller/APIController.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers.controller; 2 | 3 | import com.google.flatbuffers.FlatBufferBuilder; 4 | import com.google.flatbuffers.Table; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.horiga.study.springboot.flatbuffers.protocol.messages.Me; 7 | import org.horiga.study.springboot.flatbuffers.protocol.messages.UserAnswer; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.concurrent.Callable; 14 | 15 | @RestController 16 | @Slf4j 17 | public class APIController { 18 | 19 | @RequestMapping(value = "/api", method = RequestMethod.POST) 20 | public Callable
onMessage( 21 | @RequestBody Table message 22 | ) { 23 | 24 | // test 25 | if (message instanceof Me) { 26 | log.info("accessToken:{}", ((Me) message).token().accessToken()); 27 | log.info("id :{}", ((Me) message).token().id()); 28 | log.info("created :{}", ((Me) message).token().created()); 29 | } 30 | 31 | return () -> { 32 | FlatBufferBuilder fbb = new FlatBufferBuilder(0); 33 | fbb.finish(UserAnswer.createUserAnswer(fbb, 34 | fbb.createString("Hiroyuki Horigami"), 35 | fbb.createString("12345"), 36 | fbb.createString("//scontent-nrt1-1.xx.fbcdn.net/hphotos-xpa1/t31.0-8/891598_504258659637103_960802615_o.jpg"))); 37 | UserAnswer resultMessage = UserAnswer.getRootAsUserAnswer(UserAnswer.getRootAsUserAnswer(fbb.dataBuffer()).getByteBuffer()); 38 | return resultMessage; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/model/ResponseMessage.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers.model; 2 | 3 | import com.google.flatbuffers.Table; 4 | import lombok.Getter; 5 | import lombok.ToString; 6 | import lombok.experimental.Builder; 7 | 8 | @Builder 9 | @Getter 10 | @ToString(callSuper = false, includeFieldNames = false) 11 | public class ResponseMessage { 12 | final Integer messageId; 13 | final Table table; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/Demo.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Demo extends Table { 12 | public static Demo getRootAsDemo(ByteBuffer _bb) { return getRootAsDemo(_bb, new Demo()); } 13 | public static Demo getRootAsDemo(ByteBuffer _bb, Demo obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Demo __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public short point() { int o = __offset(4); return o != 0 ? bb.getShort(o + bb_pos) : 0; } 17 | public double score() { int o = __offset(6); return o != 0 ? bb.getDouble(o + bb_pos) : 0; } 18 | public boolean flags() { int o = __offset(8); return o != 0 ? 0!=bb.get(o + bb_pos) : false; } 19 | 20 | public static int createDemo(FlatBufferBuilder builder, 21 | short point, 22 | double score, 23 | boolean flags) { 24 | builder.startObject(3); 25 | Demo.addScore(builder, score); 26 | Demo.addPoint(builder, point); 27 | Demo.addFlags(builder, flags); 28 | return Demo.endDemo(builder); 29 | } 30 | 31 | public static void startDemo(FlatBufferBuilder builder) { builder.startObject(3); } 32 | public static void addPoint(FlatBufferBuilder builder, short point) { builder.addShort(0, point, 0); } 33 | public static void addScore(FlatBufferBuilder builder, double score) { builder.addDouble(1, score, 0); } 34 | public static void addFlags(FlatBufferBuilder builder, boolean flags) { builder.addBoolean(2, flags, false); } 35 | public static int endDemo(FlatBufferBuilder builder) { 36 | int o = builder.endObject(); 37 | return o; 38 | } 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/Error.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Error extends Table { 12 | public static Error getRootAsError(ByteBuffer _bb) { return getRootAsError(_bb, new Error()); } 13 | public static Error getRootAsError(ByteBuffer _bb, Error obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Error __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public String code() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 17 | public ByteBuffer codeAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 18 | public String message() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 19 | public ByteBuffer messageAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 20 | 21 | public static int createError(FlatBufferBuilder builder, 22 | int code, 23 | int message) { 24 | builder.startObject(2); 25 | Error.addMessage(builder, message); 26 | Error.addCode(builder, code); 27 | return Error.endError(builder); 28 | } 29 | 30 | public static void startError(FlatBufferBuilder builder) { builder.startObject(2); } 31 | public static void addCode(FlatBufferBuilder builder, int codeOffset) { builder.addOffset(0, codeOffset, 0); } 32 | public static void addMessage(FlatBufferBuilder builder, int messageOffset) { builder.addOffset(1, messageOffset, 0); } 33 | public static int endError(FlatBufferBuilder builder) { 34 | int o = builder.endObject(); 35 | return o; 36 | } 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/Friends.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Friends extends Table { 12 | public static Friends getRootAsFriends(ByteBuffer _bb) { return getRootAsFriends(_bb, new Friends()); } 13 | public static Friends getRootAsFriends(ByteBuffer _bb, Friends obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Friends __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public Token token() { return token(new Token()); } 17 | public Token token(Token obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 18 | public PagerCondition condition() { return condition(new PagerCondition()); } 19 | public PagerCondition condition(PagerCondition obj) { int o = __offset(6); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 20 | 21 | public static int createFriends(FlatBufferBuilder builder, 22 | int token, 23 | int condition) { 24 | builder.startObject(2); 25 | Friends.addCondition(builder, condition); 26 | Friends.addToken(builder, token); 27 | return Friends.endFriends(builder); 28 | } 29 | 30 | public static void startFriends(FlatBufferBuilder builder) { builder.startObject(2); } 31 | public static void addToken(FlatBufferBuilder builder, int tokenOffset) { builder.addOffset(0, tokenOffset, 0); } 32 | public static void addCondition(FlatBufferBuilder builder, int conditionOffset) { builder.addOffset(1, conditionOffset, 0); } 33 | public static int endFriends(FlatBufferBuilder builder) { 34 | int o = builder.endObject(); 35 | return o; 36 | } 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/FriendsAnswer.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class FriendsAnswer extends Table { 12 | public static FriendsAnswer getRootAsFriendsAnswer(ByteBuffer _bb) { return getRootAsFriendsAnswer(_bb, new FriendsAnswer()); } 13 | public static FriendsAnswer getRootAsFriendsAnswer(ByteBuffer _bb, FriendsAnswer obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public FriendsAnswer __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int total() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public int start() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 18 | public int count() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 19 | public User members(int j) { return members(new User(), j); } 20 | public User members(User obj, int j) { int o = __offset(10); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; } 21 | public int membersLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; } 22 | 23 | public static int createFriendsAnswer(FlatBufferBuilder builder, 24 | int total, 25 | int start, 26 | int count, 27 | int members) { 28 | builder.startObject(4); 29 | FriendsAnswer.addMembers(builder, members); 30 | FriendsAnswer.addCount(builder, count); 31 | FriendsAnswer.addStart(builder, start); 32 | FriendsAnswer.addTotal(builder, total); 33 | return FriendsAnswer.endFriendsAnswer(builder); 34 | } 35 | 36 | public static void startFriendsAnswer(FlatBufferBuilder builder) { builder.startObject(4); } 37 | public static void addTotal(FlatBufferBuilder builder, int total) { builder.addInt(0, total, 0); } 38 | public static void addStart(FlatBufferBuilder builder, int start) { builder.addInt(1, start, 0); } 39 | public static void addCount(FlatBufferBuilder builder, int count) { builder.addInt(2, count, 0); } 40 | public static void addMembers(FlatBufferBuilder builder, int membersOffset) { builder.addOffset(3, membersOffset, 0); } 41 | public static int createMembersVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } 42 | public static void startMembersVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } 43 | public static int endFriendsAnswer(FlatBufferBuilder builder) { 44 | int o = builder.endObject(); 45 | return o; 46 | } 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/Me.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Me extends Table { 12 | public static Me getRootAsMe(ByteBuffer _bb) { return getRootAsMe(_bb, new Me()); } 13 | public static Me getRootAsMe(ByteBuffer _bb, Me obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Me __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public Token token() { return token(new Token()); } 17 | public Token token(Token obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 18 | 19 | public static int createMe(FlatBufferBuilder builder, 20 | int token) { 21 | builder.startObject(1); 22 | Me.addToken(builder, token); 23 | return Me.endMe(builder); 24 | } 25 | 26 | public static void startMe(FlatBufferBuilder builder) { builder.startObject(1); } 27 | public static void addToken(FlatBufferBuilder builder, int tokenOffset) { builder.addOffset(0, tokenOffset, 0); } 28 | public static int endMe(FlatBufferBuilder builder) { 29 | int o = builder.endObject(); 30 | return o; 31 | } 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/MessagePlaceholderKeyValuePair.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class MessagePlaceholderKeyValuePair extends Table { 12 | public static MessagePlaceholderKeyValuePair getRootAsMessagePlaceholderKeyValuePair(ByteBuffer _bb) { return getRootAsMessagePlaceholderKeyValuePair(_bb, new MessagePlaceholderKeyValuePair()); } 13 | public static MessagePlaceholderKeyValuePair getRootAsMessagePlaceholderKeyValuePair(ByteBuffer _bb, MessagePlaceholderKeyValuePair obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public MessagePlaceholderKeyValuePair __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public String key() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 17 | public ByteBuffer keyAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 18 | public String value() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 19 | public ByteBuffer valueAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 20 | 21 | public static int createMessagePlaceholderKeyValuePair(FlatBufferBuilder builder, 22 | int key, 23 | int value) { 24 | builder.startObject(2); 25 | MessagePlaceholderKeyValuePair.addValue(builder, value); 26 | MessagePlaceholderKeyValuePair.addKey(builder, key); 27 | return MessagePlaceholderKeyValuePair.endMessagePlaceholderKeyValuePair(builder); 28 | } 29 | 30 | public static void startMessagePlaceholderKeyValuePair(FlatBufferBuilder builder) { builder.startObject(2); } 31 | public static void addKey(FlatBufferBuilder builder, int keyOffset) { builder.addOffset(0, keyOffset, 0); } 32 | public static void addValue(FlatBufferBuilder builder, int valueOffset) { builder.addOffset(1, valueOffset, 0); } 33 | public static int endMessagePlaceholderKeyValuePair(FlatBufferBuilder builder) { 34 | int o = builder.endObject(); 35 | return o; 36 | } 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/PagerCondition.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class PagerCondition extends Table { 12 | public static PagerCondition getRootAsPagerCondition(ByteBuffer _bb) { return getRootAsPagerCondition(_bb, new PagerCondition()); } 13 | public static PagerCondition getRootAsPagerCondition(ByteBuffer _bb, PagerCondition obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public PagerCondition __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int start() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public int count() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 18 | public String filterBy() { int o = __offset(8); return o != 0 ? __string(o + bb_pos) : null; } 19 | public ByteBuffer filterByAsByteBuffer() { return __vector_as_bytebuffer(8, 1); } 20 | public String filterValue() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; } 21 | public ByteBuffer filterValueAsByteBuffer() { return __vector_as_bytebuffer(10, 1); } 22 | 23 | public static int createPagerCondition(FlatBufferBuilder builder, 24 | int start, 25 | int count, 26 | int filterBy, 27 | int filterValue) { 28 | builder.startObject(4); 29 | PagerCondition.addFilterValue(builder, filterValue); 30 | PagerCondition.addFilterBy(builder, filterBy); 31 | PagerCondition.addCount(builder, count); 32 | PagerCondition.addStart(builder, start); 33 | return PagerCondition.endPagerCondition(builder); 34 | } 35 | 36 | public static void startPagerCondition(FlatBufferBuilder builder) { builder.startObject(4); } 37 | public static void addStart(FlatBufferBuilder builder, int start) { builder.addInt(0, start, 0); } 38 | public static void addCount(FlatBufferBuilder builder, int count) { builder.addInt(1, count, 0); } 39 | public static void addFilterBy(FlatBufferBuilder builder, int filterByOffset) { builder.addOffset(2, filterByOffset, 0); } 40 | public static void addFilterValue(FlatBufferBuilder builder, int filterValueOffset) { builder.addOffset(3, filterValueOffset, 0); } 41 | public static int endPagerCondition(FlatBufferBuilder builder) { 42 | int o = builder.endObject(); 43 | return o; 44 | } 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/Score.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Score extends Table { 12 | public static Score getRootAsScore(ByteBuffer _bb) { return getRootAsScore(_bb, new Score()); } 13 | public static Score getRootAsScore(ByteBuffer _bb, Score obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Score __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int mi() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 2; } 17 | public String factor() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 18 | public ByteBuffer factorAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 19 | public double score() { int o = __offset(8); return o != 0 ? bb.getDouble(o + bb_pos) : 0; } 20 | 21 | public static int createScore(FlatBufferBuilder builder, 22 | int mi, 23 | int factor, 24 | double score) { 25 | builder.startObject(3); 26 | Score.addScore(builder, score); 27 | Score.addFactor(builder, factor); 28 | Score.addMi(builder, mi); 29 | return Score.endScore(builder); 30 | } 31 | 32 | public static void startScore(FlatBufferBuilder builder) { builder.startObject(3); } 33 | public static void addMi(FlatBufferBuilder builder, int mi) { builder.addInt(0, mi, 2); } 34 | public static void addFactor(FlatBufferBuilder builder, int factorOffset) { builder.addOffset(1, factorOffset, 0); } 35 | public static void addScore(FlatBufferBuilder builder, double score) { builder.addDouble(2, score, 0); } 36 | public static int endScore(FlatBufferBuilder builder) { 37 | int o = builder.endObject(); 38 | return o; 39 | } 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/TextMessage.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class TextMessage extends Table { 12 | public static TextMessage getRootAsTextMessage(ByteBuffer _bb) { return getRootAsTextMessage(_bb, new TextMessage()); } 13 | public static TextMessage getRootAsTextMessage(ByteBuffer _bb, TextMessage obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public TextMessage __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public String id() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 17 | public ByteBuffer idAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 18 | public String to(int j) { int o = __offset(6); return o != 0 ? __string(__vector(o) + j * 4) : null; } 19 | public int toLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } 20 | public MessagePlaceholderKeyValuePair placeholders(int j) { return placeholders(new MessagePlaceholderKeyValuePair(), j); } 21 | public MessagePlaceholderKeyValuePair placeholders(MessagePlaceholderKeyValuePair obj, int j) { int o = __offset(8); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; } 22 | public int placeholdersLength() { int o = __offset(8); return o != 0 ? __vector_len(o) : 0; } 23 | 24 | public static int createTextMessage(FlatBufferBuilder builder, 25 | int id, 26 | int to, 27 | int placeholders) { 28 | builder.startObject(3); 29 | TextMessage.addPlaceholders(builder, placeholders); 30 | TextMessage.addTo(builder, to); 31 | TextMessage.addId(builder, id); 32 | return TextMessage.endTextMessage(builder); 33 | } 34 | 35 | public static void startTextMessage(FlatBufferBuilder builder) { builder.startObject(3); } 36 | public static void addId(FlatBufferBuilder builder, int idOffset) { builder.addOffset(0, idOffset, 0); } 37 | public static void addTo(FlatBufferBuilder builder, int toOffset) { builder.addOffset(1, toOffset, 0); } 38 | public static int createToVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } 39 | public static void startToVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } 40 | public static void addPlaceholders(FlatBufferBuilder builder, int placeholdersOffset) { builder.addOffset(2, placeholdersOffset, 0); } 41 | public static int createPlaceholdersVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } 42 | public static void startPlaceholdersVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } 43 | public static int endTextMessage(FlatBufferBuilder builder) { 44 | int o = builder.endObject(); 45 | return o; 46 | } 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/Token.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Token extends Table { 12 | public static Token getRootAsToken(ByteBuffer _bb) { return getRootAsToken(_bb, new Token()); } 13 | public static Token getRootAsToken(ByteBuffer _bb, Token obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Token __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int id() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public String accessToken() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 18 | public ByteBuffer accessTokenAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 19 | public long created() { int o = __offset(8); return o != 0 ? bb.getLong(o + bb_pos) : 0; } 20 | 21 | public static int createToken(FlatBufferBuilder builder, 22 | int id, 23 | int accessToken, 24 | long created) { 25 | builder.startObject(3); 26 | Token.addCreated(builder, created); 27 | Token.addAccessToken(builder, accessToken); 28 | Token.addId(builder, id); 29 | return Token.endToken(builder); 30 | } 31 | 32 | public static void startToken(FlatBufferBuilder builder) { builder.startObject(3); } 33 | public static void addId(FlatBufferBuilder builder, int id) { builder.addInt(0, id, 0); } 34 | public static void addAccessToken(FlatBufferBuilder builder, int accessTokenOffset) { builder.addOffset(1, accessTokenOffset, 0); } 35 | public static void addCreated(FlatBufferBuilder builder, long created) { builder.addLong(2, created, 0); } 36 | public static int endToken(FlatBufferBuilder builder) { 37 | int o = builder.endObject(); 38 | return o; 39 | } 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/TokenAnswer.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class TokenAnswer extends Table { 12 | public static TokenAnswer getRootAsTokenAnswer(ByteBuffer _bb) { return getRootAsTokenAnswer(_bb, new TokenAnswer()); } 13 | public static TokenAnswer getRootAsTokenAnswer(ByteBuffer _bb, TokenAnswer obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public TokenAnswer __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public Token token() { return token(new Token()); } 17 | public Token token(Token obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 18 | public long expired() { int o = __offset(6); return o != 0 ? bb.getLong(o + bb_pos) : 0; } 19 | 20 | public static int createTokenAnswer(FlatBufferBuilder builder, 21 | int token, 22 | long expired) { 23 | builder.startObject(2); 24 | TokenAnswer.addExpired(builder, expired); 25 | TokenAnswer.addToken(builder, token); 26 | return TokenAnswer.endTokenAnswer(builder); 27 | } 28 | 29 | public static void startTokenAnswer(FlatBufferBuilder builder) { builder.startObject(2); } 30 | public static void addToken(FlatBufferBuilder builder, int tokenOffset) { builder.addOffset(0, tokenOffset, 0); } 31 | public static void addExpired(FlatBufferBuilder builder, long expired) { builder.addLong(1, expired, 0); } 32 | public static int endTokenAnswer(FlatBufferBuilder builder) { 33 | int o = builder.endObject(); 34 | return o; 35 | } 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/User.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class User extends Table { 12 | public static User getRootAsUser(ByteBuffer _bb) { return getRootAsUser(_bb, new User()); } 13 | public static User getRootAsUser(ByteBuffer _bb, User obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public User __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public Token token() { return token(new Token()); } 17 | public Token token(Token obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 18 | public String ids(int j) { int o = __offset(6); return o != 0 ? __string(__vector(o) + j * 4) : null; } 19 | public int idsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; } 20 | 21 | public static int createUser(FlatBufferBuilder builder, 22 | int token, 23 | int ids) { 24 | builder.startObject(2); 25 | User.addIds(builder, ids); 26 | User.addToken(builder, token); 27 | return User.endUser(builder); 28 | } 29 | 30 | public static void startUser(FlatBufferBuilder builder) { builder.startObject(2); } 31 | public static void addToken(FlatBufferBuilder builder, int tokenOffset) { builder.addOffset(0, tokenOffset, 0); } 32 | public static void addIds(FlatBufferBuilder builder, int idsOffset) { builder.addOffset(1, idsOffset, 0); } 33 | public static int createIdsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } 34 | public static void startIdsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } 35 | public static int endUser(FlatBufferBuilder builder) { 36 | int o = builder.endObject(); 37 | return o; 38 | } 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/UserAnswer.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class UserAnswer extends Table { 12 | public static UserAnswer getRootAsUserAnswer(ByteBuffer _bb) { return getRootAsUserAnswer(_bb, new UserAnswer()); } 13 | public static UserAnswer getRootAsUserAnswer(ByteBuffer _bb, UserAnswer obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public UserAnswer __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public String displayName() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 17 | public ByteBuffer displayNameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 18 | public String mid() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 19 | public ByteBuffer midAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 20 | public String pictureUrl() { int o = __offset(8); return o != 0 ? __string(o + bb_pos) : null; } 21 | public ByteBuffer pictureUrlAsByteBuffer() { return __vector_as_bytebuffer(8, 1); } 22 | 23 | public static int createUserAnswer(FlatBufferBuilder builder, 24 | int displayName, 25 | int mid, 26 | int pictureUrl) { 27 | builder.startObject(3); 28 | UserAnswer.addPictureUrl(builder, pictureUrl); 29 | UserAnswer.addMid(builder, mid); 30 | UserAnswer.addDisplayName(builder, displayName); 31 | return UserAnswer.endUserAnswer(builder); 32 | } 33 | 34 | public static void startUserAnswer(FlatBufferBuilder builder) { builder.startObject(3); } 35 | public static void addDisplayName(FlatBufferBuilder builder, int displayNameOffset) { builder.addOffset(0, displayNameOffset, 0); } 36 | public static void addMid(FlatBufferBuilder builder, int midOffset) { builder.addOffset(1, midOffset, 0); } 37 | public static void addPictureUrl(FlatBufferBuilder builder, int pictureUrlOffset) { builder.addOffset(2, pictureUrlOffset, 0); } 38 | public static int endUserAnswer(FlatBufferBuilder builder) { 39 | int o = builder.endObject(); 40 | return o; 41 | } 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Error.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Error extends Table { 12 | public static Error getRootAsError(ByteBuffer _bb) { return getRootAsError(_bb, new Error()); } 13 | public static Error getRootAsError(ByteBuffer _bb, Error obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Error __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int code() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public String detail() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 18 | public ByteBuffer detailAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 19 | 20 | public static int createError(FlatBufferBuilder builder, 21 | int code, 22 | int detail) { 23 | builder.startObject(2); 24 | Error.addDetail(builder, detail); 25 | Error.addCode(builder, code); 26 | return Error.endError(builder); 27 | } 28 | 29 | public static void startError(FlatBufferBuilder builder) { builder.startObject(2); } 30 | public static void addCode(FlatBufferBuilder builder, int code) { builder.addInt(0, code, 0); } 31 | public static void addDetail(FlatBufferBuilder builder, int detailOffset) { builder.addOffset(1, detailOffset, 0); } 32 | public static int endError(FlatBufferBuilder builder) { 33 | int o = builder.endObject(); 34 | return o; 35 | } 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Friends.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Friends extends Table { 12 | public static Friends getRootAsFriends(ByteBuffer _bb) { return getRootAsFriends(_bb, new Friends()); } 13 | public static Friends getRootAsFriends(ByteBuffer _bb, Friends obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Friends __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int total() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public int offset() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 18 | public int limit() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 19 | public Person entity(int j) { return entity(new Person(), j); } 20 | public Person entity(Person obj, int j) { int o = __offset(10); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null; } 21 | public int entityLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; } 22 | 23 | public static int createFriends(FlatBufferBuilder builder, 24 | int total, 25 | int offset, 26 | int limit, 27 | int entity) { 28 | builder.startObject(4); 29 | Friends.addEntity(builder, entity); 30 | Friends.addLimit(builder, limit); 31 | Friends.addOffset(builder, offset); 32 | Friends.addTotal(builder, total); 33 | return Friends.endFriends(builder); 34 | } 35 | 36 | public static void startFriends(FlatBufferBuilder builder) { builder.startObject(4); } 37 | public static void addTotal(FlatBufferBuilder builder, int total) { builder.addInt(0, total, 0); } 38 | public static void addOffset(FlatBufferBuilder builder, int offset) { builder.addInt(1, offset, 0); } 39 | public static void addLimit(FlatBufferBuilder builder, int limit) { builder.addInt(2, limit, 0); } 40 | public static void addEntity(FlatBufferBuilder builder, int entityOffset) { builder.addOffset(3, entityOffset, 0); } 41 | public static int createEntityVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } 42 | public static void startEntityVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } 43 | public static int endFriends(FlatBufferBuilder builder) { 44 | int o = builder.endObject(); 45 | return o; 46 | } 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/MessageId.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | public final class MessageId { 6 | private MessageId() { } 7 | public static final int OK = 0; 8 | public static final int FAILED = 1; 9 | public static final int TOKEN = 2; 10 | public static final int PERSON = 3; 11 | public static final int FRIENDS = 4; 12 | 13 | private static final String[] names = { "OK", "FAILED", "TOKEN", "PERSON", "FRIENDS", }; 14 | 15 | public static String name(int e) { return names[e]; } 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Pager.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Pager extends Table { 12 | public static Pager getRootAsPager(ByteBuffer _bb) { return getRootAsPager(_bb, new Pager()); } 13 | public static Pager getRootAsPager(ByteBuffer _bb, Pager obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Pager __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int offset() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public int limit() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 18 | 19 | public static int createPager(FlatBufferBuilder builder, 20 | int offset, 21 | int limit) { 22 | builder.startObject(2); 23 | Pager.addLimit(builder, limit); 24 | Pager.addOffset(builder, offset); 25 | return Pager.endPager(builder); 26 | } 27 | 28 | public static void startPager(FlatBufferBuilder builder) { builder.startObject(2); } 29 | public static void addOffset(FlatBufferBuilder builder, int offset) { builder.addInt(0, offset, 0); } 30 | public static void addLimit(FlatBufferBuilder builder, int limit) { builder.addInt(1, limit, 0); } 31 | public static int endPager(FlatBufferBuilder builder) { 32 | int o = builder.endObject(); 33 | return o; 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Person.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Person extends Table { 12 | public static Person getRootAsPerson(ByteBuffer _bb) { return getRootAsPerson(_bb, new Person()); } 13 | public static Person getRootAsPerson(ByteBuffer _bb, Person obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Person __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public String userId() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 17 | public ByteBuffer userIdAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 18 | public String displayName() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; } 19 | public ByteBuffer displayNameAsByteBuffer() { return __vector_as_bytebuffer(6, 1); } 20 | public String thumbnail() { int o = __offset(8); return o != 0 ? __string(o + bb_pos) : null; } 21 | public ByteBuffer thumbnailAsByteBuffer() { return __vector_as_bytebuffer(8, 1); } 22 | 23 | public static int createPerson(FlatBufferBuilder builder, 24 | int userId, 25 | int displayName, 26 | int thumbnail) { 27 | builder.startObject(3); 28 | Person.addThumbnail(builder, thumbnail); 29 | Person.addDisplayName(builder, displayName); 30 | Person.addUserId(builder, userId); 31 | return Person.endPerson(builder); 32 | } 33 | 34 | public static void startPerson(FlatBufferBuilder builder) { builder.startObject(3); } 35 | public static void addUserId(FlatBufferBuilder builder, int userIdOffset) { builder.addOffset(0, userIdOffset, 0); } 36 | public static void addDisplayName(FlatBufferBuilder builder, int displayNameOffset) { builder.addOffset(1, displayNameOffset, 0); } 37 | public static void addThumbnail(FlatBufferBuilder builder, int thumbnailOffset) { builder.addOffset(2, thumbnailOffset, 0); } 38 | public static int endPerson(FlatBufferBuilder builder) { 39 | int o = builder.endObject(); 40 | return o; 41 | } 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Request.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Request extends Table { 12 | public static Request getRootAsRequest(ByteBuffer _bb) { return getRootAsRequest(_bb, new Request()); } 13 | public static Request getRootAsRequest(ByteBuffer _bb, Request obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Request __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int msg() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public Token token() { return token(new Token()); } 18 | public Token token(Token obj) { int o = __offset(6); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 19 | public byte bodyType() { int o = __offset(8); return o != 0 ? bb.get(o + bb_pos) : 0; } 20 | public Table body(Table obj) { int o = __offset(10); return o != 0 ? __union(obj, o) : null; } 21 | 22 | public static int createRequest(FlatBufferBuilder builder, 23 | int msg, 24 | int token, 25 | byte body_type, 26 | int body) { 27 | builder.startObject(4); 28 | Request.addBody(builder, body); 29 | Request.addToken(builder, token); 30 | Request.addMsg(builder, msg); 31 | Request.addBodyType(builder, body_type); 32 | return Request.endRequest(builder); 33 | } 34 | 35 | public static void startRequest(FlatBufferBuilder builder) { builder.startObject(4); } 36 | public static void addMsg(FlatBufferBuilder builder, int msg) { builder.addInt(0, msg, 0); } 37 | public static void addToken(FlatBufferBuilder builder, int tokenOffset) { builder.addOffset(1, tokenOffset, 0); } 38 | public static void addBodyType(FlatBufferBuilder builder, byte bodyType) { builder.addByte(2, bodyType, 0); } 39 | public static void addBody(FlatBufferBuilder builder, int bodyOffset) { builder.addOffset(3, bodyOffset, 0); } 40 | public static int endRequest(FlatBufferBuilder builder) { 41 | int o = builder.endObject(); 42 | return o; 43 | } 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/RequestBody.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | public final class RequestBody { 6 | private RequestBody() { } 7 | public static final byte NONE = 0; 8 | public static final byte Pager = 1; 9 | 10 | private static final String[] names = { "NONE", "Pager", }; 11 | 12 | public static String name(int e) { return names[e]; } 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Response.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Response extends Table { 12 | public static Response getRootAsResponse(ByteBuffer _bb) { return getRootAsResponse(_bb, new Response()); } 13 | public static Response getRootAsResponse(ByteBuffer _bb, Response obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Response __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public int msg() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; } 17 | public byte bodyType() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; } 18 | public Table body(Table obj) { int o = __offset(8); return o != 0 ? __union(obj, o) : null; } 19 | 20 | public static int createResponse(FlatBufferBuilder builder, 21 | int msg, 22 | byte body_type, 23 | int body) { 24 | builder.startObject(3); 25 | Response.addBody(builder, body); 26 | Response.addMsg(builder, msg); 27 | Response.addBodyType(builder, body_type); 28 | return Response.endResponse(builder); 29 | } 30 | 31 | public static void startResponse(FlatBufferBuilder builder) { builder.startObject(3); } 32 | public static void addMsg(FlatBufferBuilder builder, int msg) { builder.addInt(0, msg, 0); } 33 | public static void addBodyType(FlatBufferBuilder builder, byte bodyType) { builder.addByte(1, bodyType, 0); } 34 | public static void addBody(FlatBufferBuilder builder, int bodyOffset) { builder.addOffset(2, bodyOffset, 0); } 35 | public static int endResponse(FlatBufferBuilder builder) { 36 | int o = builder.endObject(); 37 | return o; 38 | } 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/ResponseBody.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | public final class ResponseBody { 6 | private ResponseBody() { } 7 | public static final byte NONE = 0; 8 | public static final byte Error = 1; 9 | public static final byte Person = 2; 10 | public static final byte Friends = 3; 11 | 12 | private static final String[] names = { "NONE", "Error", "Person", "Friends", }; 13 | 14 | public static String name(int e) { return names[e]; } 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/protocol/messages/v2/Token.java: -------------------------------------------------------------------------------- 1 | // automatically generated, do not modify 2 | 3 | package org.horiga.study.springboot.flatbuffers.protocol.messages.v2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Token extends Table { 12 | public static Token getRootAsToken(ByteBuffer _bb) { return getRootAsToken(_bb, new Token()); } 13 | public static Token getRootAsToken(ByteBuffer _bb, Token obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public Token __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public String token() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 17 | public ByteBuffer tokenAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 18 | 19 | public static int createToken(FlatBufferBuilder builder, 20 | int token) { 21 | builder.startObject(1); 22 | Token.addToken(builder, token); 23 | return Token.endToken(builder); 24 | } 25 | 26 | public static void startToken(FlatBufferBuilder builder) { builder.startObject(1); } 27 | public static void addToken(FlatBufferBuilder builder, int tokenOffset) { builder.addOffset(0, tokenOffset, 0); } 28 | public static int endToken(FlatBufferBuilder builder) { 29 | int o = builder.endObject(); 30 | return o; 31 | } 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/org/horiga/study/springboot/flatbuffers/util/Utils.java: -------------------------------------------------------------------------------- 1 | package org.horiga.study.springboot.flatbuffers.util; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | import java.nio.ByteBuffer; 6 | 7 | @Slf4j 8 | public final class Utils { 9 | 10 | 11 | public static ByteBuffer hex(ByteBuffer bb, String message) { 12 | StringBuilder sb = new StringBuilder(); 13 | int n = 1; 14 | for (byte b : bb.array()) { 15 | String s = Integer.toHexString(0xff & b); 16 | if (s.length() == 1) { 17 | sb.append("0"); 18 | } 19 | sb.append(s); 20 | sb.append(n%8==0 ? "\n" : " "); 21 | n++; 22 | 23 | } 24 | log.info("\n>>>>>>>>> [{}] - pos:{}, limit:{}, cap:{}\n{}\n<<<<<<<<< [{}]", 25 | message, bb.position(), bb.limit(), bb.capacity(), sb.toString(), message); 26 | return bb; 27 | } 28 | 29 | public static ByteBuffer hex(ByteBuffer bb) { 30 | hex(bb, "to hex"); 31 | return bb; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horiga/springboot-flatbuffers/1614b229686461ca6e2ff6d4be1cc8badffb4f15/src/main/resources/application.properties -------------------------------------------------------------------------------- /src/test/java/FbTest.java: -------------------------------------------------------------------------------- 1 | import com.google.flatbuffers.FlatBufferBuilder; 2 | import com.google.flatbuffers.Table; 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.horiga.study.springboot.flatbuffers.protocol.messages.User; 5 | import org.horiga.study.springboot.flatbuffers.protocol.messages.UserAnswer; 6 | import org.junit.Test; 7 | 8 | import java.lang.reflect.Method; 9 | import java.nio.ByteBuffer; 10 | 11 | @Slf4j 12 | public class FbTest { 13 | 14 | @Test 15 | public void simple() throws Exception { 16 | 17 | Method[] declaredMethods = User.class.getDeclaredMethods(); 18 | 19 | for( Method m : declaredMethods) { 20 | log.debug("name:{}", m.getName()); 21 | } 22 | 23 | log.debug(">> User.class.getName:{}",User.class.getName()); 24 | log.debug(">> User.class.getTypeName:{}",User.class.getTypeName()); 25 | log.debug(">> User.class.getSimpleName:{}", User.class.getSimpleName()); 26 | 27 | //Method enclosingMethod = FUser.class.getEnclosingMethod(); 28 | //log.debug("Enclosing method.name:{}", enclosingMethod.getName()); 29 | Class klass = User.class; 30 | 31 | Method m = klass.getMethod("getRootAs" + klass.getSimpleName(), ByteBuffer.class); 32 | 33 | } 34 | 35 | @Test 36 | public void test_fbb() { 37 | 38 | // test 39 | FlatBufferBuilder fbb = new FlatBufferBuilder(0); 40 | fbb.finish(UserAnswer.createUserAnswer(fbb, 41 | fbb.createString("Hiroyuki Horigami"), 42 | fbb.createString("12345"), 43 | fbb.createString("//scontent-nrt1-1.xx.fbcdn.net/hphotos-xpa1/t31.0-8/891598_504258659637103_960802615_o.jpg"))); 44 | 45 | UserAnswer answer = UserAnswer.getRootAsUserAnswer(fbb.dataBuffer()); 46 | 47 | log.debug("displayName:{}, mid:{}, pictureUrl:{}", 48 | answer.displayName(), answer.mid(), answer.pictureUrl()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/FbTest2.java: -------------------------------------------------------------------------------- 1 | import com.google.flatbuffers.Table; 2 | import org.horiga.study.springboot.flatbuffers.protocol.messages.v2.Token; 3 | import org.horiga.study.springboot.flatbuffers.protocol.messages.v2.MessageId; 4 | import org.horiga.study.springboot.flatbuffers.protocol.messages.v2.Pager; 5 | import org.horiga.study.springboot.flatbuffers.protocol.messages.v2.Request; 6 | import org.horiga.study.springboot.flatbuffers.protocol.messages.v2.RequestBody; 7 | import org.horiga.study.springboot.flatbuffers.util.Utils; 8 | import org.junit.Test; 9 | 10 | import com.google.flatbuffers.FlatBufferBuilder; 11 | 12 | import lombok.extern.slf4j.Slf4j; 13 | 14 | import java.nio.ByteBuffer; 15 | 16 | @Slf4j 17 | public class FbTest2 { 18 | 19 | 20 | @Test 21 | public void fbs_union() { 22 | 23 | try { 24 | 25 | // 26 | // - serialize 27 | // 28 | 29 | FlatBufferBuilder fbb = new FlatBufferBuilder(0); 30 | 31 | // Pager 32 | int offset = 1; 33 | int limit = 100; 34 | int offsetPager = Pager.createPager(fbb, offset, limit); 35 | 36 | // Token 37 | int offsetToken = Token.createToken(fbb, fbb.createString("this-is-v2-message-token")); 38 | 39 | // Request 40 | Request.startRequest(fbb); 41 | Request.addMsg(fbb, MessageId.TOKEN); 42 | Request.addToken(fbb, offsetToken); 43 | Request.addBodyType(fbb, RequestBody.Pager); 44 | Request.addBody(fbb, offsetPager); 45 | fbb.finish(Request.endRequest(fbb)); 46 | 47 | ByteBuffer buffer = fbb.dataBuffer(); 48 | Utils.hex(buffer, "in serialize"); 49 | 50 | 51 | // 52 | // - deserialize process. 53 | // 54 | 55 | Request deserialize = Request.getRootAsRequest(buffer); 56 | Utils.hex(deserialize.getByteBuffer(), "out deserialize"); 57 | Pager pager = (Pager)deserialize.body(new Pager()); 58 | 59 | log.info("msg_id : {}", deserialize.msg()); 60 | log.info("token : {}", deserialize.token().token()); 61 | log.info("body_type: {}", RequestBody.name(deserialize.bodyType())); 62 | log.info("body : pager.limit:{}, pager.offset:{}", pager.limit(), pager.offset()); 63 | 64 | } catch (Exception e) { 65 | log.error("Failed to flatbuffers SerDe!!", e); 66 | 67 | 68 | } 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/WebIntegrationTest.java: -------------------------------------------------------------------------------- 1 | import com.google.flatbuffers.FlatBufferBuilder; 2 | import com.ning.http.client.AsyncHttpClient; 3 | import com.ning.http.client.AsyncHttpClientConfig; 4 | import com.ning.http.client.Response; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.horiga.study.springboot.flatbuffers.Application; 7 | import org.horiga.study.springboot.flatbuffers.FlatBuffersHttpMessageConverter; 8 | import org.horiga.study.springboot.flatbuffers.protocol.messages.Me; 9 | import org.horiga.study.springboot.flatbuffers.protocol.messages.Token; 10 | import org.horiga.study.springboot.flatbuffers.protocol.messages.UserAnswer; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.boot.test.SpringApplicationConfiguration; 17 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 18 | import org.springframework.test.web.servlet.MockMvc; 19 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 20 | import org.springframework.web.context.WebApplicationContext; 21 | 22 | import java.nio.ByteBuffer; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | @Slf4j 26 | @RunWith(SpringJUnit4ClassRunner.class) 27 | @SpringApplicationConfiguration(classes = Application.class) 28 | @org.springframework.boot.test.WebIntegrationTest("server.port=18080") 29 | public class WebIntegrationTest { 30 | 31 | @Autowired 32 | WebApplicationContext wac; 33 | 34 | private MockMvc mockMvc; 35 | 36 | @Before 37 | public void setUp() { 38 | mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); 39 | } 40 | 41 | @Autowired 42 | FlatBuffersHttpMessageConverter flatBuffersHttpMessageConverter; 43 | 44 | @After 45 | public void tearDown() { 46 | } 47 | 48 | @Test 49 | public void test_flatbuffers_simple() throws Exception { 50 | 51 | AsyncHttpClient httpclient = new AsyncHttpClient( 52 | new AsyncHttpClientConfig.Builder().setRequestTimeout(3000).build()); 53 | 54 | final Response res = httpclient.preparePost("http://localhost:18080/api") 55 | .addHeader("Content-Type", "application/x-fb") 56 | .addHeader("X-FBS-MessageId", "1") 57 | .setBody(me().array()) 58 | .setBodyEncoding("UTF-8") 59 | .execute() 60 | .get(3000, TimeUnit.MILLISECONDS); 61 | 62 | log.info("res.contentType:{}", res.getContentType()); 63 | log.info("res.status: {}", res.getStatusCode()); 64 | 65 | UserAnswer answer = UserAnswer.getRootAsUserAnswer(res.getResponseBodyAsByteBuffer()); 66 | 67 | httpclient.close(); 68 | 69 | log.info("answer.displayName:{}", answer.displayName()); 70 | log.info("answer.mid:{}", answer.mid()); 71 | log.info("answer.pictureUrl:{}", answer.pictureUrl()); 72 | 73 | } 74 | 75 | private static ByteBuffer me() throws Exception { 76 | 77 | FlatBufferBuilder fbb = new FlatBufferBuilder(0); 78 | 79 | int accessTokenOffset = fbb.createString("ThisIsAccessToken"); 80 | 81 | Token.startToken(fbb); 82 | Token.addId(fbb, 123); 83 | Token.addAccessToken(fbb, accessTokenOffset); 84 | Token.addCreated(fbb, System.currentTimeMillis()); 85 | int tokenOffset = Token.endToken(fbb); 86 | 87 | Me.startMe(fbb); 88 | Me.addToken(fbb, tokenOffset); 89 | int offset = Me.endMe(fbb); 90 | fbb.finish(offset); 91 | 92 | return ByteBuffer.wrap(fbb.sizedByteArray()); 93 | } 94 | } 95 | --------------------------------------------------------------------------------