This article shows how to setup protojs and test it on Ubuntu.
Clone the repository from github first:
sudo -s
cd /usr/src
git clone https://github.com/sirikata/protojs.git
Compile it.
curl is required.install it using 'apt-get install curl'.
cd protojs
./bootstrap.sh (This will download antlr-3.2 from antlr.org)
make
After a while, I got pbj binary. It's a protojs compiler.
Add the following into ~/.bashrc file
export PBJ_HOME=/usr/src/protojs
export PATH=$PBJ_HOME:$PATH
source ~/.bashrc
Let's use it. I have a folder tree looks like so:
proto/
├── input
│ └── group.proto
└── output
├── c++
└── js
4 directories, 1 file
I defined a group.proto for generating C++ and JavaScript files.
package freebird;
message group {
required string id = 1;
required string name = 2;
required string description = 3;
required string device_number = 4;
}
In proto folder, execute the following command to generate js file:
pbj input/group.proto output/js/group.js
group.js 's content:
"use strict";
/** @suppress {duplicate}*/var freebird;
if (typeof(freebird)=="undefined") {freebird = {};}
freebird.group = PROTO.Message("freebird.group",{
id: {
options: {},
multiplicity: PROTO.required,
type: function(){return PROTO.string;},
id: 1
},
name: {
options: {},
multiplicity: PROTO.required,
type: function(){return PROTO.string;},
id: 2
},
description: {
options: {},
multiplicity: PROTO.required,
type: function(){return PROTO.string;},
id: 3
},
device_number: {
options: {},
multiplicity: PROTO.required,
type: function(){return PROTO.string;},
id: 4
}});
1 comment:
Hi, I have been trying to get this working on windows, I installed Cygwin. however it keeps on failing.
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: no acceptable C compiler found in $PATH
Can you upload the generated pbj executable, I should be able to use it directly to parse the .proto files in to js classes.
I suppose for serialization/deserialization I should be able to integrate the existing packages uploaded on github.
Thanks in advance.
Post a Comment