平面缓冲区实现和使用.需要一些建议



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

学习如何

使用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.

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

最新更新