sirikata / protojs Goto Github PK
View Code? Open in Web Editor NEWThis project forked from danielrh/protojs
Protobuf implementation in javascript
Home Page: http://sirikata.com
License: Other
This project forked from danielrh/protojs
Protobuf implementation in javascript
Home Page: http://sirikata.com
License: Other
Protojs is a BSD-licensed protocol buffer library written in JavaScript. http://github.com/sirikata/protojs NOTE: If you're starting a new project, we recommend newer, better supported and maintained options, e.g. https://github.com/dcodeIO/ProtoBuf.js ==== Features: * Fast compiler using ANTLR * Packed field + 2.3.0 autodetection * Full Unicode support (decoding surrogate pairs above 0xffff) * Getters+setters for error checking (and fallback if not supported) * Enums and nested messages * 32-bit and 64-bit floating points * Serializing/deserializing to base64 or array of int * PBJ datatypes (uuid, vector, quaternion, normal) defined in pbj.js ==== Bugs or missing features: * Does not enforce "required", acts the same as "optional" * Default values are not used * Setting a field in a sub-message will not cause the sub-message to be serialized, as the python parser worked before 2.3.0 * It is not possible to serialize to binary string in a cross-browser way, because Javascript uses unicode strings. However, the Stream class can be extended for specific applications * No support for extensions or services * Not compatible with older versions of protobufs ==== Building protojs: The build process is tested on Linux, and should work also on mac or cygwin: First, run "./bootstrap.sh" This script downloads antlr-3.2 from antlr.org. Now, run "make" Builds the "pbj" compiler and a test file from protocol/ into output/ If you want to use the makefile you can put your own .proto files into protocol/. You can also run the pbj file with "pbj input.proto output.proto" If you want to build a directory full of protocol files, run it with "make INPUTDIR=/path/to/protocol". You can optionally specify OUTPUTDIR if you don't want them to go to output. ==== Using the javascript library: The javascript library is intended to be as similar as possible to python protocol buffers. If you have declared the package Example.Test, and made a message called HelloWorld, you can create a message with: var mymsg = new Example.Test.HelloWorld; mymsg.field1 = "value1"; mymsg.inner_msg.field2 = 5; var newmsg = mymsg.repeated_msg.push(); newmsg.field2 = 6; newmsg.field3.push(1) newmsg.field3.push(2) newmsg.field3.push(3) To serialize the message, you must create an instance of a class that extends PROTO.Stream. var serialized = new PROTO.Base64Stream; mymsg.SerializeToStream(serialized); document.write(serialized.getString()); Note that the function names are ParseFromStream and SerializeToStream, not ParseFromString or ParseFromArray as in python or C++. This is because javascript strings are encoded in UTF-16 and cannot handle binary data. ==== Reporting bugs: Send mail to Patrick Horn <[email protected]>, or find me at irc.freenode.net #sirikata If you have a cool feature to add, feel free to fork the project.
http://www.antlr.org/download/C/libantlr3c-3.2.tar.gz
description The requested resource (/download/C/libantlr3c-3.2.tar.gz) is not available.
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [pbj] Error 1
e.g. where pbj would fail
message XMLNotification {
required string message = 1;
}
When compiling the script with the google closure tools, the following warnings occur:
inc\third_party\protobuf.js:1175: WARNING - Comparison again NaN is always false. Did you mean isNaN()?
if (n == NaN) {
^
inc\third_party\protobuf.js:1188: WARNING - Comparison again NaN is always false. Did you mean isNaN()?
if (n == NaN) {
^
inc\third_party\protobuf.js:1339: WARNING - Comparison again NaN is always false. Did you mean isNaN()?
if (n == NaN) {
^
According to the compiler, isNaN should be used in this code.
can you package this as a nodejs module?
The definition of PROTO.DefineProperty calls PROTO.warn on lines 83 and 87 of protobuf.js. However, PROTO.warn is not defined until line 118. If a browser like IE8 does not support DefineProperty, then it will attempt to call PROTO.warn before it's defined.
With this proto file:
package Test; message MyTest { enum MyTestEnum { ZERO = 0 ; ONE = 1 ; } optional MyTestEnum value = 2 [default = ZERO]; }
...I get this JS output:
"use strict"; /** @suppress {duplicate}*/var Test; if (typeof(Test)=="undefined") {Test = {};} Test.MyTest = PROTO.Message("Test.MyTest",{ MyTestEnum: PROTO.Enum("Test.MyTest.MyTestEnum",{ ZERO :0, ONE :1 }), value: { options: {default_value:Test.MyTest.MyTestEnum.ZERO}, multiplicity: PROTO.optional, type: function(){return Test.MyTest.MyTestEnum;}, id: 2 }});
...which produces (in Firefox):
TypeError: Test.MyTest is undefined
...and in Chrome:
Uncaught TypeError: Cannot read property 'MyTestEnum' of undefined
...in both cases, the offending line is:
options: {default_value:Test.MyTest.MyTestEnum.ZERO},
...changing the default value from the enum "ZERO" to a literal value of "0" fixes the problem.
This .proto file works fine in at least three other protobuf systems - so I presume that it's legal.
for pbj file , if I delete the line
"package ProtoJSTest.PB;"
for the generated file :"Test.pbj.js"
there are many javascript errors
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.