Schema.prototype.compile = function(proto) { if (!proto) proto = this.messages.toJSON() if (typeof proto === 'string' && proto[0] === '{') proto = JSON.parse(proto) var self = this var opts = { encodings: { json: json() } } this.names = [] this.proto = proto this.messages = protobuf(proto, opts) this.fields = this.messages.toJSON().messages[0].fields this.fields.forEach(function(m) { if (m.name === 'blobs') self.blobs = protobuf('message Row { optional '+m.type+' blobs = '+m.tag+'; }', opts).Row self.names.push(m.name) }) debug('compiling schema (%d fields)', this.fields.length) }
var proto = function(sch) { return protobuf(sch, {encodings:{json:json()}}).Row }