1.0.10 • Published 6 years ago

@netrunner/pbf-ts v1.0.10

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

pbf-ts

Creates interface schema and encoder/decoder for protobuf.

The CLI is very simple:

pbfts [source dir] [target dir] file1.proto file2.proto ...

After parsing the protobuf schema the program will create an interface, a encoder and a decoder for every message schema.

# src/myfile.proto
message Point {
    required uint32 x = 1;
    required uint32 y = 2;
    optional uint32 z = 3;
}

It creates a file with the name of the message:

pbfts ./src ./lib myfile.proto
# => ./lib/Point.ts
export interface PointSchema {
    x: number;
    y: number;
    z?: number;
}
export const Point = {
    encode(obj: PointSchema): Buffer { ... },
    decode(buf: Buffer | Uint8Array): PointSchema { ... }
};

You can also use the writer functions in your own code:

import { writeSchemaFile, writeSchemaFileSync } from "@netrunner/pbf-ts";

const pbfData = `
message User {
    required uint32 id = 1;
    required string name = 2;
    required bytes salt = 3;
    optional bytes hash = 4;
}
message Post {
    required uint32 id = 1;
    required uint32 user_id = 2;
    required string title = 3;
    required string description = 4;
}
`;

// synchronous file creation
writeSchemaFileSync(pbfData, {
    // // default options
    // indent: '    ',
    // suffix: 'Schema',
    // lineBreak: '\n',
    // writeDir: './'
});
// => User.ts
// => Post.ts

(async () => {
    // asynchronous file creation
    await writeSchemaFile(pbfData, {
        // // default options
        // indent: '    ',
        // suffix: 'Schema',
        // lineBreak: '\n',
        // writeDir: './'
    });
    // => User.ts
    // => Post.ts
});
1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago