コード例 #1
0
ファイル: schema.js プロジェクト: 14mmm/dat
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)
}
コード例 #2
0
ファイル: read-streams.js プロジェクト: 6a68/dat
var proto = function(sch) {
  return protobuf(sch, {encodings:{json:json()}}).Row
}