About protobuf JavaScript version

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.