Git Product home page Git Product logo

pbf-loader's Introduction

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.

pbf-loader's People

Contributors

pago avatar jjangga0214 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.