flatbuffer的实现和用法。需要一些建议

时间:2016-02-12 06:57:11

标签: client-server response flatbuffers

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

2 个答案:

答案 0 :(得分:1)

了解如何使用flatbuffer以及了解有关flatbuffers vs JSON的更多信息的最佳方法之一。 (How to use 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.

答案 1 :(得分:0)

是的,FlatBuffers消息通常比等效的JSON小很多,并且访问速度会更快。