npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ipfn/protons

v1.2.0

Published

Protocol Buffers for Node.js without compiliation

Downloads

24

Readme

protons

Dependency Status Travis CI

Protocol Buffers for Node.js and the browser without compilation, eval and default values.

Forked from dignifiedquire/protons to remove usage of default values.

> npm install @ipfn/protons

Usage

Assuming the following test.proto file exists

enum FOO {
  BAR = 1;
}

message Test {
  required float num  = 1;
  required string payload = 2;
}

message AnotherOne {
  repeated FOO list = 1;
}

Use the above proto file to encode/decode messages by doing

const protons = require('protons')

// pass a proto file as a buffer/string or pass a parsed protobuf-schema object
const messages = protons(fs.readFileSync('test.proto'))

const buf = messages.Test.encode({
  num: 42,
  payload: 'hello world'
})

console.log(buf) // should print a buffer

To decode a message use Test.decode

const obj = messages.Test.decode(buf)
console.log(obj) // should print an object similar to above

Enums are accessed in the same way as messages

const buf = messages.AnotherOne.encode({
  list: [
    messages.FOO.BAR
  ]
})

Nested emums are accessed as properties on the corresponding message

const buf = message.SomeMessage.encode({
  list: [
    messages.SomeMessage.NESTED_ENUM.VALUE
  ]
})

See the Google Protocol Buffers docs for more information about the available types etc.

Performance

This module is pretty fast.

You can run the benchmarks yourself by doing npm run bench.

On my Macbook Pro it gives the following results

JSON (encode) x 516,087 ops/sec ±6.68% (73 runs sampled)
JSON (decode) x 534,339 ops/sec ±1.79% (89 runs sampled)
JSON(encode + decode) x 236,625 ops/sec ±5.42% (81 runs sampled)
protocol-buffers (encode) x 385,121 ops/sec ±3.89% (82 runs sampled)
protocol-buffers (decode) x 945,545 ops/sec ±2.39% (86 runs sampled)
protocol-buffers(encode + decode) x 279,605 ops/sec ±2.83% (86 runs sampled)
npm (encode) x 377,625 ops/sec ±3.15% (84 runs sampled)
npm (decode) x 948,428 ops/sec ±3.59% (87 runs sampled)
npm(encode + decode) x 251,929 ops/sec ±2.91% (81 runs sampled)
local (encode) x 373,376 ops/sec ±6.90% (66 runs sampled)
local (decode) x 1,770,870 ops/sec ±1.50% (83 runs sampled)
local(encode + decode) x 322,507 ops/sec ±2.82% (79 runs sampled)

Note that JSON parsing/serialization in node is a native function that is really fast.

Leveldb encoding compatibility

Compiled protocol buffers messages are valid levelup encodings. This means you can pass them as valueEncoding and keyEncoding.

const level = require('level')
const db = level('db')

db.put('hello', {payload:'world'}, {valueEncoding:messages.Test}, (err) => {
  db.get('hello', {valueEncoding:messages.Test}, (err, message) => {
    console.log(message)
  })
})

License

MIT