Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const fs = require('fs');
- const Pbf = require('pbf')
- const csv = require('./csv')
- const kLinePbfFile = __dirname + '/line.pbf';
- const kLineCsvFile = __dirname + '/line.csv';
- const kLineToWrite = { node_from: 1, node_to: 2, speed: 3 };
- function main() {
- spawn(function* (resume) {
- const outPbf = new Pbf();
- csv.Line.write(kLineToWrite, outPbf);
- const outBuf = outPbf.finish();
- yield fs.writeFile(kLinePbfFile, outBuf, resume);
- const inBuf = yield fs.readFile(kLinePbfFile, resume);
- const inPbf = new Pbf(inBuf);
- const roundtrip = csv.Line.read(inPbf);
- console.log(roundtrip);
- });
- spawn(function* (resume) {
- const pbf = new Pbf(new Buffer(0));
- pbf.writeVarint(42);
- const buf = pbf.finish();
- console.log(buf);
- const rbuf = new Buffer([0x2a, 0xff, 0xff, 0xff, 0xff]);
- const rpbf = new Pbf(rbuf);
- const len = rpbf.readVarint();
- console.log(len);
- });
- }
- function spawn(generator) {
- let it = generator(function (err, data) {
- if (err) it.throw(err);
- return it.next(data);
- });
- it.next();
- }
- if (require.main === module) { main(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement