0.3.2 • Published 4 years ago

@wirelineio/codec-protobuf v0.3.2

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
4 years ago

Wireline Codec Protobuf

CircleCI npm version

Codec for protobuf to use in libraries that follows the valueEncoding API of leveldb, like hypercore.

Requirement

CodecProtobuf only works with protocol-buffers since it's the only module that allows you to encode/decode type bytes to Buffer giving you the benefit of building universal apps working in Node and the Browser. (Most of the current bundle tooling for the Browser implements Buffer).

Install

$ npm install @wirelineio/codec-protobuf protocol-buffers

Usage

syntax = "proto3";

message Task {
  required string id = 1;
  string value = 2;
}
import protobuf from 'protocol-buffers';
import hypercore from 'hypercore';
import codecProtobuf from '@wirelineio/codec-protobuf';

const root = protobuf(fs.readFileSync('schema.proto'))

const codec = codecProtobuf(root);

const obj = { type: 'Task', message: { id: 'task-0', value: 'test' } };

const buffer = codec.encode(obj);

codec.decode(buffer); // { type: 'Task', message: { id: 'task-0', value: 'test' } }

// It's compatible with the valueEncoding option of hypercore
const feed = hypercore('./log', { valueEncoding: codec });

feed.append(obj, () => {
  feed.head(console.log) // { type: 'Task', message: { id: 'task-0', value: 'test' } }
});
0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

5 years ago

0.2.23

5 years ago

0.2.22

5 years ago

0.2.21

5 years ago

0.2.20

5 years ago

0.2.19

5 years ago

0.2.18

5 years ago

0.2.18-beta.0

5 years ago

0.2.17

5 years ago

0.2.17-alpha.1

5 years ago

0.2.17-alpha.0

5 years ago

0.2.16

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.9-beta.2

5 years ago

0.2.9-beta.1

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.2.0-alpha.2

5 years ago

0.2.0-alpha.1

5 years ago

0.2.0-alpha.0

5 years ago

0.1.36

5 years ago

0.1.34

5 years ago

0.1.33

5 years ago

0.1.21

5 years ago

0.1.18

5 years ago

0.1.14

5 years ago

0.1.14-alpha.5

5 years ago

0.1.14-alpha.4

5 years ago

0.1.14-alpha.3

5 years ago

0.1.14-alpha.2

5 years ago

0.1.14-alpha.1

5 years ago

0.1.14-alpha.0

5 years ago