-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Home
dcode edited this page Oct 24, 2013
·
101 revisions
ProtoBuf.js is a Protocol Buffers implementation on top of ByteBuffer.js including a .proto parser, reflection, message class building and simple encoding and decoding in plain JavaScript. There is no compilation step required, it's super easy to use and it works out of the box on .proto files.
FAQ:
- Why ProtoBuf.js instead of, let's say, JSON?
- How to validate / decode / reverse engineer a protobuf buffer by hand?
npm install protobufjs
var ProtoBuf = require("protobufjs");
...
Requires ByteBuffer.js. Optionally depends on Long.js for long (int64) support. If you do not require long support, you can skip the Long.js config. Require.js example:
require.config({
...
"paths": {
"Long": "/path/to/Long.js",
"ByteBuffer": "/path/to/ByteBuffer.js",
"ProtoBuf": "/path/to/ProtoBuf.js"
},
...
});
require(["ProtoBuf"], function(ProtoBuf) {
...
});
Or as a module dependency:
define("MyModule", ["ProtoBuf"], function(ProtoBuf) {
...
});
Requires ByteBuffer.js. Optionally depends on Long.js for long (int64) support. If you do not require long support, you can skip the Long.js include.
<script src="Long.min.js"></script>
<script src="ByteBuffer.min.js"></script>
<script src="ProtoBuf.min.js"></script>
var ProtoBuf = dcodeIO.ProtoBuf;
...
Now, everything is set up and ready to go.