1

flatbuffer 可以用于服务器客户端通信吗?以前我使用的是 JSON,但是您认为 flatbuffer 是否对于来自服务器的响应大到足以在到达客户端时产生一些延迟的通信有用。如果不推荐使用flatbuffer,那么我可以使用哪个?是否有任何库可以减少服务器响应的大小并将其发送到客户端以进行高效快速的通信?

4

2 回答 2

1

学习如何使用 flatbuffer 以及了解更多关于 flatbuffers 与 JSON 的最佳方式之一。(如何使用 FlatBuffers?

FlatBuffer Android 示例应用程序

当我们将它与 json 进行比较时,这个应用程序显示了平面缓冲区的工作速度。

如何开始使用 flatBuffer

$ git clone https://github.com/google/flatbuffers.git

$ cd flatbuffers

* Run the command on the basis of your platform

$ cmake -G "Unix Makefiles"
$ cmake -G "Visual Studio 10"
$ cmake -G "Xcode"

* now build for your platform as usual. This should result in a flatc executable
* Now create your schema file with extension .fbs. Guide to write a schema can be found [here]("https://google.github.io/flatbuffers/flatbuffers_guide_writing_schema.html").And also have your sample json file.

$ ./flatc -j -b schema.fbs sample.json

* This will create few java file and one bin file. Java files are like model(POJO for flatBuffer) of your json.Place the java files in your application package and bin file in raw folder(bin file is only for testing as it is converted to byte that is to be passed to flatbuffer for testing).
* Now we have to get flatbuffer jar file.

$ cd flatbuffers
$ cd java
$ mvn install
This will download all the dependencies.
$ cd target

* Here we will get the flatbuffers-java-1.3.0-SNAPSHOT.jar file that we have to put it in your libs folder of android project.
* For rest you can see my (https://github.com/amitshekhariitbhu/FlatBuffer).

## Major steps:
* Prepare your schema.fbs.
* Have a sample json.
* Build flatBuffer google project to generate your java files to be used in main application.
* Generate java files.
于 2016-07-09T16:03:31.783 回答
0

是的,FlatBuffers 消息通常比等效的 JSON 小很多,而且访问起来会更快。

于 2016-02-12T07:33:49.323 回答