Пример #1
0
EncodeSuite.prototype.__pbf = function (args) {
  var parts = args.split(':');
  var proto = pbSchema.parse(fs.readFileSync(parts[0]));
  var message = pbCompile(proto)[parts[1]];
  var val = this.getValue(true);
  return function () {
    var pbf = new Pbf();
    message.write(val, pbf);
    var buf = pbf.finish();
    if (!buf.length) {
      throw new Error();
    }
  };
};
Пример #2
0
module.exports = function(json, proto, opts) {
  if (!opts.syntax) opts.syntax = '2';
  const replaceWith = `syntax = "proto${opts.syntax}";\n\npackage vector_tile;`;

  let proto_schema, protoString;
  if (!proto) throw new Error('Please provide the proto file or version to generate this buffer from');
  if (MVT_SPEC_VERSIONS.indexOf(proto) > -1) {
    protoString = replace(proto, 'package vector_tile;', replaceWith);
    proto_schema = schema.parse(protoString);
  } else {
    protoString = proto.replace('package vector_tile;', replaceWith);
    proto_schema = schema.parse(protoString);
  }

  const mvt = Compile(proto_schema);
  const pbf = new Pbf();
  mvt.Tile.write(json, pbf);
  return new Buffer(pbf.finish());
};