pbf-loader

1.1.0 • Public • Published

Webpack loader for .proto files

Installation

npm install pbf-loader

Usage

see example for sample implementation.

Given your webpack.config.js like this:

module.exports = {
    module: {
        loaders: [
            {
                test: /\.proto$/,
                loader: "pbf-loader"
            }
        ]
    }
}

Instead of:

const Pbf = require('pbf'); 
const compile = require('pbf/compile');
const fs = require('fs');
const schema = require('protocol-buffers-schema');
 
const data = 'somestring';
const proto = schema.parse(fs.readFileSync('./test.proto'));
const test = compile(proto).test; // assuming message definition: message test {}

using this webpack loader, simply require your .proto file like this:

const proto = require('./index.proto');
const Pbf = require('pbf');
 
const data = "somestring"; // data that you want to write;
 
const schema = proto.test; // accessing the message definition
const pbf = new Pbf();
 
// now you can write data to your pbf with pbf.writeMessage etc.
pbf.writeString(data);
const buffer = pbf.finish();
// now you can read back your message using schema.read(new Pbf(buffer))

You can refer to index.proto for how the .proto file looks like.

Test

Assuming you already did npm install, you can:

npm test

License

This project is released under the terms of the Apache 2.0 license.

Readme

Keywords

none

Package Sidebar

Install

npm i pbf-loader

Weekly Downloads

158

Version

1.1.0

License

Apache 2.0

Last publish

Collaborators

  • bitwre