{"name":"pbf","version":"3.0.3","description":"a low-level, lightweight protocol buffers implementation in JavaScript","main":"index.js","scripts":{"test":"eslint index.js compile.js test/*.js bench/bench-tiles.js bin/pbf && tap test/*.test.js","cov":"tap test/*.test.js --cov --coverage-report=html","build-min":"mkdirp dist && browserify index.js -s Pbf | uglifyjs -c warnings=false -m > dist/pbf.js","build-dev":"mkdirp dist && browserify index.js -d -s Pbf > dist/pbf-dev.js","prepublish":"npm run build-dev && npm run build-min"},"bin":{"pbf":"bin/pbf"},"repository":{"type":"git","url":"git+ssh://git@github.com/mapbox/pbf.git"},"keywords":["protocol","buffer","pbf","protobuf","binary","format","serialization","encoder","decoder"],"author":{"name":"Konstantin Kaefer"},"license":"BSD-3-Clause","bugs":{"url":"https://github.com/mapbox/pbf/issues"},"homepage":"https://github.com/mapbox/pbf","dependencies":{"ieee754":"^1.1.6","resolve-protobuf-schema":"^2.0.0"},"devDependencies":{"benchmark":"^2.1.0","browserify":"^13.0.1","eslint":"^3.0.0","eslint-config-mourner":"^2.0.1","mkdirp":"^0.5.1","protocol-buffers":"^3.1.6","tap":"^6.1.1","tile-stats-runner":"^1.0.0","uglify-js":"^2.6.2"},"eslintConfig":{"extends":"mourner","rules":{"space-before-function-paren":[2,"never"],"key-spacing":0,"no-empty":0,"global-require":0}},"gitHead":"20d9164c18b5c8af5ac875c999cee9b1ec34a9ba","_id":"pbf@3.0.3","_shasum":"7cd0aea17aa789426469c9878169b3a23a7f801f","_from":".","_npmVersion":"3.10.9","_nodeVersion":"7.1.0","_npmUser":{"name":"mourner","email":"agafonkin@gmail.com"},"dist":{"shasum":"7cd0aea17aa789426469c9878169b3a23a7f801f","tarball":"http://registry-npm.ywwl.com/pbf/download/pbf-3.0.3.tgz","integrity":"sha512-jQDoyj46CV2+m0dBQpmEK5fA9a/Rwhp0EbcbPI1VPe0tUOHOT1R+jJRxFQLcWo+Ac7642DlwMlmGhaP/6LFDPA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHyX3F11g544uQVdMMGrowSdxhQ/qXt934ySPfqbDSvgAiA754Z6ao1Xf8gf9b0n0xRE4WdLuLJZuOrxzurvm+lJEA=="}],"size":230746,"noattachment":false,"key":"/pbf/-/pbf-3.0.3.tgz"},"maintainers":[{"name":"aaronlidman","email":"aaronlidman@gmail.com"},{"name":"ansis","email":"ansis.brammanis@gmail.com"},{"name":"camilleanne","email":"camille@mapbox.com"},{"name":"dthompson","email":"dthompson@gmail.com"},{"name":"gretacb","email":"carol@mapbox.com"},{"name":"ianshward","email":"ian@mapbox.com"},{"name":"ingalls","email":"nicholas.ingalls@gmail.com"},{"name":"jfirebaugh","email":"john.firebaugh@gmail.com"},{"name":"kkaefer","email":"kkaefer@gmail.com"},{"name":"mapbox-admin","email":"accounts@mapbox.com"},{"name":"miccolis","email":"jeff@miccolis.net"},{"name":"mikemorris","email":"michael.patrick.morris@gmail.com"},{"name":"morganherlocker","email":"morgan.herlocker@gmail.com"},{"name":"mourner","email":"agafonkin@gmail.com"},{"name":"rclark","email":"ryan.clark.j@gmail.com"},{"name":"springmeyer","email":"dane@mapbox.com"},{"name":"tmcw","email":"tom@macwright.org"},{"name":"tristen","email":"tristen.brown@gmail.com"},{"name":"willwhite","email":"will@mapbox.com"},{"name":"yhahn","email":"young@mapbox.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/pbf-3.0.3.tgz_1479127894613_0.18303250498138368"},"directories":{},"readme":"# pbf\n\n[![build status](https://secure.travis-ci.org/mapbox/pbf.svg)](http://travis-ci.org/mapbox/pbf) [![Coverage Status](https://coveralls.io/repos/mapbox/pbf/badge.svg)](https://coveralls.io/r/mapbox/pbf)\n\nA low-level, fast, ultra-lightweight (3KB gzipped) JavaScript library for decoding and encoding [protocol buffers](https://developers.google.com/protocol-buffers), a compact binary format for structured data serialization. Works both in Node and the browser. Supports lazy decoding and detailed customization of the reading/writing code.\n\n## Performance\n\nThis library is extremely fast — much faster than native `JSON.parse`/`JSON.stringify`\nand the [protocol-buffers](https://github.com/mafintosh/protocol-buffers) module.\nHere's a result from running a real-world benchmark on Node v6.5\n(decoding and encoding a sample of 439 vector tiles, 22.6 MB total):\n\n- **pbf** decode: 387ms, or 57 MB/s\n- **pbf** encode: 396ms, or 56 MB/s\n- **protocol-buffers** decode: 837ms, or 26 MB/s\n- **protocol-buffers** encode: 4197ms, or 5 MB/s\n- **JSON.parse**: 1540ms, or 125 MB/s (parsing an equivalent 77.5 MB JSON file)\n- **JSON.stringify**: 607ms, or 49 MB/s\n\n## Examples\n\n#### Using Compiled Code\n\nInstall `pbf` and compile a JavaScript module from a `.proto` file:\n\n```bash\n$ npm install -g pbf\n$ pbf example.proto > example.js\n```\n\nThen read and write objects using the module like this:\n\n```js\nvar Pbf = require('pbf');\nvar Example = require('./example.js').Example;\n\n// read\nvar pbf = new Pbf(buffer);\nvar obj = Example.read(pbf);\n\n// write\nvar pbf = new Pbf();\nExample.write(obj, pbf);\nvar buffer = pbf.finish();\n```\n\nAlternatively, you can compile a module directly in the code:\n\n```js\nvar compile = require('pbf/compile');\nvar schema = require('protocol-buffers-schema');\n\nvar proto = schema.parse(fs.readFileSync('example.proto'));\nvar Test = compile(proto).Test;\n```\n\nIf you use `webpack` as your module bundler, you can use [pbf-loader](https://github.com/trivago/pbf-loader)\nto load .proto files directly. It returns a compiled module ready to be used.\n\nGiven you already configured your `webpack.config.js`, the code above would look like:\n```js\nvar Pbf = require('pbf');\nvar proto = require('./example.proto');\n\nvar Test = proto.Test;\n```\n\n#### Custom Reading\n\n```js\nvar data = new Pbf(buffer).readFields(readData, {});\n\nfunction readData(tag, data, pbf) {\n    if (tag === 1) data.name = pbf.readString();\n    else if (tag === 2) data.version = pbf.readVarint();\n    else if (tag === 3) data.layer = pbf.readMessage(readLayer, {});\n}\nfunction readLayer(tag, layer, pbf) {\n    if (tag === 1) layer.name = pbf.readString();\n    else if (tag === 3) layer.size = pbf.readVarint();\n}\n```\n\n#### Custom Writing\n\n```js\nvar pbf = new Pbf();\nwriteData(data, pbf);\nvar buffer = pbf.finish();\n\nfunction writeData(data, pbf) {\n    pbf.writeStringField(1, data.name);\n    pbf.writeVarintField(2, data.version);\n    pbf.writeMessage(3, writeLayer, data.layer);\n}\nfunction writeLayer(layer, pbf) {\n    pbf.writeStringField(1, layer.name);\n    pbf.writeVarintField(2, layer.size);\n}\n```\n\n## Install\n\nNode and Browserify:\n\n```bash\nnpm install pbf\n```\n\nMaking a browser build:\n\n```bash\nnpm install\nnpm run build-dev # dist/pbf-dev.js (development build)\nnpm run build-min # dist/pbf.js (minified production build)\n```\n\nCDN link: https://unpkg.com/pbf@3.0.5/dist/pbf.js\n\n## API\n\nCreate a `Pbf` object, optionally given a `Buffer` or `Uint8Array` as input data:\n\n```js\n// parse a pbf file from disk in Node\nvar pbf = new Pbf(fs.readFileSync('data.pbf'));\n\n// parse a pbf file in a browser after an ajax request with responseType=\"arraybuffer\"\nvar pbf = new Pbf(new Uint8Array(xhr.response));\n```\n\n`Pbf` object properties:\n\n```js\npbf.length; // length of the underlying buffer\npbf.pos; // current offset for reading or writing\n```\n\n#### Reading\n\nRead a sequence of fields:\n\n```js\npbf.readFields(function (tag) {\n    if (tag === 1) pbf.readVarint();\n    else if (tag === 2) pbf.readString();\n    else ...\n});\n```\n\nIt optionally accepts an object that will be passed to the reading function for easier construction of decoded data,\nand also passes the `Pbf` object as a third argument:\n\n```js\nvar result = pbf.readFields(callback, {})\n\nfunction callback(tag, result, pbf) {\n    if (tag === 1) result.id = pbf.readVarint();\n}\n```\n\nTo read an embedded message, use `pbf.readMessage(fn[, obj])` (in the same way as `read`).\n\nRead values:\n\n```js\nvar value = pbf.readVarint();\nvar str = pbf.readString();\nvar numbers = pbf.readPackedVarint();\n```\n\nFor lazy or partial decoding, simply save the position instead of reading a value,\nthen later set it back to the saved value and read:\n\n```js\nvar fooPos = -1;\npbf.readFields(function (tag) {\n    if (tag === 1) fooPos = pbf.pos;\n});\n...\npbf.pos = fooPos;\npbf.readMessage(readFoo);\n```\n\nScalar reading methods:\n\n* `readVarint(isSigned)` (pass `true` if you expect negative varints)\n* `readSVarint()`\n* `readFixed32()`\n* `readFixed64()`\n* `readSFixed32()`\n* `readSFixed64()`\n* `readBoolean()`\n* `readFloat()`\n* `readDouble()`\n* `readString()`\n* `readBytes()`\n* `skip(value)`\n\nPacked reading methods:\n\n* `readPackedVarint(arr, isSigned)` (appends read items to `arr`)\n* `readPackedSVarint(arr)`\n* `readPackedFixed32(arr)`\n* `readPackedFixed64(arr)`\n* `readPackedSFixed32(arr)`\n* `readPackedSFixed64(arr)`\n* `readPackedBoolean(arr)`\n* `readPackedFloat(arr)`\n* `readPackedDouble(arr)`\n\n#### Writing\n\nWrite values:\n\n```js\npbf.writeVarint(123);\npbf.writeString(\"Hello world\");\n```\n\nWrite an embedded message:\n\n```js\npbf.writeMessage(1, writeObj, obj);\n\nfunction writeObj(obj, pbf) {\n    pbf.writeStringField(obj.name);\n    pbf.writeVarintField(obj.version);\n}\n```\n\nField writing methods:\n\n* `writeVarintField(tag, val)`\n* `writeSVarintField(tag, val)`\n* `writeFixed32Field(tag, val)`\n* `writeFixed64Field(tag, val)`\n* `writeSFixed32Field(tag, val)`\n* `writeSFixed64Field(tag, val)`\n* `writeBooleanField(tag, val)`\n* `writeFloatField(tag, val)`\n* `writeDoubleField(tag, val)`\n* `writeStringField(tag, val)`\n* `writeBytesField(tag, buffer)`\n\nPacked field writing methods:\n\n* `writePackedVarint(tag, val)`\n* `writePackedSVarint(tag, val)`\n* `writePackedSFixed32(tag, val)`\n* `writePackedSFixed64(tag, val)`\n* `writePackedBoolean(tag, val)`\n* `writePackedFloat(tag, val)`\n* `writePackedDouble(tag, val)`\n\nScalar writing methods:\n\n* `writeVarint(val)`\n* `writeSVarint(val)`\n* `writeSFixed32(val)`\n* `writeSFixed64(val)`\n* `writeBoolean(val)`\n* `writeFloat(val)`\n* `writeDouble(val)`\n* `writeString(val)`\n* `writeBytes(buffer)`\n\nMessage writing methods:\n\n* `writeMessage(tag, fn[, obj])`\n* `writeRawMessage(fn[, obj])`\n\nMisc methods:\n\n* `realloc(minBytes)` - pad the underlying buffer size to accommodate the given number of bytes;\n   note that the size increases exponentially, so it won't necessarily equal the size of data written\n* `finish()` - make the current buffer ready for reading and return the data as a buffer slice\n* `destroy()` - dispose the buffer\n\nFor an example of a real-world usage of the library, see [vector-tile-js](https://github.com/mapbox/vector-tile-js).\n\n\n## Proto Schema to JavaScript\n\nIf installed globally, `pbf` provides a binary that compiles `proto` files into JavaScript modules. Usage:\n\n```bash\n$ pbf <proto_path> [--no-write] [--no-read] [--browser]\n```\n\nThe `--no-write` and `--no-read` switches remove corresponding code in the output.\nThe `--browser` switch makes the module work in browsers instead of Node.\n\nThe resulting module exports each message by name with the following methods:\n\n* `read(pbf)` - decodes an object from the given `Pbf` instance\n* `write(obj, pbf)` - encodes an object into the given `Pbf` instance (usually empty)\n\nThe resulting code is clean and simple, so feel free to customize it.\n\n## Changelog\n\n#### 3.2.1 (Oct 11, 2019)\n\n- Significantly improved performance when decoding large strings in the browser.\n\n#### 3.2.0 (Mar 11, 2019)\n\n- Improved decoding to be able to parse repeated fields even if they were specified as packed, and vise versa.\n- Improved packed encoding to skip empty arrays (previously, it would write a tag).\n- Fixed an off-by-one data corruption bug when writing a message larger than 0x10000000 bytes.\n\n#### 3.1.0 (Sep 27, 2017)\n\n- Added support for Protocol Buffer 3 [maps](https://developers.google.com/protocol-buffers/docs/proto3#maps) to proto compiler.\n\n#### 3.0.5 (Nov 30, 2016)\n\n- Fixed an error appearing in some versions of IE11 and old Android browsers.\n\n#### 3.0.4 (Nov 14, 2016)\n\n- Fixed compiling repeated packed enum fields.\n\n#### 3.0.3 (Nov 14, 2016)\n\n- Fixed a regression that broke compiling repeated enum fields with defaults.\n\n#### 3.0.2 (Sep 30, 2016)\n\n- Fixed a regression that broke decoding of packed fields with a tag that didn't fit into one byte.\n\n#### 3.0.1 (Sep 20, 2016)\n\n- Fixed a regression that broke encoding of long strings.\n\n#### 3.0.0 (Aug 30, 2016)\n\nThis release include tons of compatibility/robustness fixes, and a more reliable Node implementation. Decoding performance is expected to get up to ~15% slower than v2.0 in Node (browsers are unaffected), but encoding got faster by ~15% in return.\n\n##### Encoder/decoder\n\n- **Breaking**: changed Node implementation to use `Uint8Array` instead of `Buffer` internally (and produce corresponding result on `finish()`), making it fully match the browser implementation for consistency and simplicity.\n- Fixed `writeVarint` to write `0` when given `NaN` or other non-number to avoid producing a broken Protobuf message.\n- Changed `readPacked*` methods signature to accept an optional `arr` argument to append the results to (to support messages with repeated fields that mix packed/non-packed encoding).\n- Added an optional `isSigned` argument to `readVarint` that enables proper reading of negative varints.\n- Deprecated `readVarint64()` (it still works, but it's recommended to be changed to `readVarint(true)`).\n- Faster string encoding.\n\n##### Proto compiler\n\n- **Breaking:** Full support for defaults field values (both implicit and explicit); they're now included in the decoded JSON objects.\n- Fixed reading of repeated fields with mixed packed/non-packed encoding for compatibility.\n- Fixed proto3 compiler to use packed by default for repeated scalar fields.\n- Fixed reading of negative varint types.\n- Fixed packed fields to decode into `[]` if they're not present.\n- Fixed nested message references handling.\n- Fixed `packed=false` being interpreted as packed.\n- Added a comment to generated code with pbf version number.\n\n#### 2.0.1 (May 28, 2016)\n\n- Fixed a regression with `writeVarint` that affected certain numbers.\n\n#### 2.0.0 (May 28, 2016)\n\n- Significantly improved the proto compiler, which now produces a much safer reading/writing code.\n- Added the ability to compile a read/write module from a protobuf schema directly in the code.\n- Proto compiler: fixed name resolutions and collisions in schemas with nested messages.\n- Proto compiler: fixed broken top-level enums.\n\n#### 1.3.7 (May 28, 2016)\n\n- Fixed a regression with `writeVarint` that affected certain numbers.\n\n#### 1.3.6 (May 27, 2016)\n\n- Improved read and write performance (both ~15% faster).\n- Improved generated code for default values.\n\n#### 1.3.5 (Oct 5, 2015)\n\n- Added support for `syntax` keyword proto files (by updating `resolve-protobuf-schema` dependency).\n\n#### 1.3.4 (Jul 31, 2015)\n\n- Added `writeRawMessage` method for writing a message without a tag, useful for creating pbfs with multiple top-level messages.\n\n#### 1.3.2 (Mar 5, 2015)\n\n- Added `readVarint64` method for proper decoding of negative `int64`-encoded values.\n\n#### 1.3.1 (Feb 20, 2015)\n\n- Fixed pbf proto compile tool generating broken writing code.\n\n#### 1.3.0 (Feb 5, 2015)\n\n- Added `pbf` binary that compiles `.proto` files into `Pbf`-based JavaScript modules.\n\n#### 1.2.0 (Jan 5, 2015)\n\n##### Breaking API changes\n\n- Changed `writeMessage` signature to `(tag, fn, obj)` (see example in the docs)\n  for a huge encoding performance improvement.\n- Replaced `readPacked` and `writePacked` methods that accept type as a string\n  with `readPackedVarint`, etc. for each type (better performance and simpler API).\n\n##### Improvements\n\n- 5x faster encoding in Node (vector tile benchmark).\n- 40x faster encoding and 3x faster decoding in the browser (vector tile benchmark).\n\n#### 1.1.4 (Jan 2, 2015)\n\n- Significantly improved `readPacked` and `writePacked` performance (the tile reading benchmark is now 70% faster).\n\n#### 1.1.3 (Dec 26, 2014)\n\nBrings tons of improvements and fixes over the previous version (`0.0.2`).\nBasically makes the library complete.\n\n##### Improvements\n\n- Improved performance of both reading and writing.\n- Made the browser build 3 times smaller.\n- Added convenience `readFields` and `readMessage` methods for a much easier reading API.\n- Added reading methods: `readFloat`, `readBoolean`, `readSFixed32`, `readSFixed64`.\n- Added writing methods: `writeUInt64`, `writeSFixed32`, `writeSFixed64`.\n- Improved `readDouble` and `readString` to use native Buffer methods under Node.\n- Improved `readString` and `writeString` to use HTML5 `TextEncoder` and `TextDecoder` where available.\n- Made `Pbf` `buffer` argument optional.\n- Added extensive docs and examples in the readme.\n- Added an extensive test suite that brings test coverage up to 100%.\n\n##### Breaking API changes\n\n- Renamed `readBuffer`/`writeBuffer` to `readBytes`/`writeBytes`.\n- Renamed `readUInt32`/`writeUInt32` to `readFixed32`/`writeFixed32`, etc.\n- Renamed `writeTaggedVarint` to `writeVarintField`, etc.\n- Changed `writePacked` signature from `(type, tag, items)` to `(tag, type, items)`.\n\n##### Bugfixes\n\n- Fixed `readVarint` to handle varints bigger than 6 bytes.\n- Fixed `readSVarint` to handle number bigger than `2^30`.\n- Fixed `writeVarint` failing on some integers.\n- Fixed `writeVarint` not throwing an error on numbers that are too big.\n- Fixed `readUInt64` always failing.\n- Fixed writing to an empty buffer always failing.\n","publish_time":1479127895244,"_cnpm_publish_time":1479127895244,"dist-tags":{"latest":"5.2.0"}}