]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/iot-gateway/node_modules/protocol-buffers/index.js
Initial commit
[apps/tidep0084.git] / example / iot-gateway / node_modules / protocol-buffers / index.js
1 var schema = require('protocol-buffers-schema')
2 var compile = require('./compile')
4 module.exports = function (proto, opts) {
5   if (!opts) opts = {}
6   if (!proto) throw new Error('Pass in a .proto string or a protobuf-schema parsed object')
8   var sch = (typeof proto === 'object' && !Buffer.isBuffer(proto)) ? proto : schema.parse(proto)
10   // to not make toString,toJSON enumarable we make a fire-and-forget prototype
11   var Messages = function () {
12     var self = this
14     compile(sch, opts.encodings || {}).forEach(function (m) {
15       self[m.name] = m.values || m
16     })
17   }
19   Messages.prototype.toString = function () {
20     return schema.stringify(sch)
21   }
23   Messages.prototype.toJSON = function () {
24     return sch
25   }
27   return new Messages()
28 }