Reprinted Please note: http://blog.csdn.net/herm_lib/article/details/8580917
I found several JS versions of protobuf, two officially recommended ones:
- Protobuf-JS: http://code.google.com/p/protobuf-js/
- Protojs: http://github.com/sirikata/protojs
The previous half-finished product is not counted and cannot be used. Many other features are not supported.
Accidentally found the protobuf JS version of Google closure library. It's strange that this is not officially recommended. js has never been used before, and closure is unknown. It worked hard.
Closure protobuf JS supports generating proto files in the form of plugin.
Closure Library: http://code.google.com/p/closure-library/downloads/list
Protobuf-plugin-closure: http://code.google.com/p/protobuf-plugin-closure/source/checkout
To compile JS plugin, follow these steps:
1. Download the entire protobuf and compile the protoc and various lib libraries.
2. generate two supported proto files
./Protoc-I./JS/protobuf/JS/-I./src -- cpp_out =./JS/protobuf/JS/./JS/protobuf/JS/javascript_package.proto
./Protoc-I./JS/protobuf/JS/-I./src -- cpp_out =./JS/protobuf/JS/./JS/protobuf/JS/int64_encoding.proto
3. Compile the plug-in
G ++-I. /src-I. /JS /. /src/Google/protobuf/Compiler/plugin. pb. cc. /src/Google/protobuf/Compiler/plugin. cc. /JS/protobuf/JS/code_generator.cc. /JS/protobuf/JS/protoc_gen_js.cc. /javascript_package.pb.cc. /JS/protobuf/JS/int64_encoding.pb.cc/home/users/h/Hu/huangrg/protobuf-2.4.1/src /. libs/libprotobuf. A
/Home/users/h/Hu/huangrg/protobuf-2.4.1/src/. libs/libprotoc. A-o./JS/protoc-gen-js-lpthread
4. Test test. Proto.
. /Protoc -- plugin =. /protoc-gen-js-I .. /-I .. /.. /src/-I. /JS -- js_out =. /JS -- cpp_out =. /Js. /JS/test. PROTO
Note that the source code resource of protobuf-plugin-closure is related to the entire protobuf path.
Installing http://github.com/sirikata/protojs
The protojs contains README, which describes the installation method.
1. Run./Bootstrap. Sh.
Failed to download antlr-3.2.jar and another C Runtime Library. Open Bootstrap. SH and change the download connection:
Http://www.antlr.org/...... change to: http://www.antlr3.org /......
2. Make. Java support is required. you can install Java without Java.