Skip to content

timostamm/protobuf-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d709ae4 · Mar 28, 2025
Mar 13, 2025
Mar 28, 2025
Mar 13, 2025
Sep 4, 2020
Apr 24, 2023
May 4, 2023
Sep 4, 2020
Mar 28, 2025
Mar 12, 2025
May 4, 2023
Mar 15, 2025
Mar 19, 2025
Jul 31, 2023
Mar 12, 2025

Repository files navigation

protobuf-ts npm

Protocol buffers and RPC for Node.js and the Web Browser. Pure TypeScript.

For the following .proto file:

syntax = "proto3";

message Person {
    string name = 1;
    uint64 id = 2;
    int32 years = 3;
    optional bytes data = 5;
}

protobuf-ts generates code that can be used like this:

let pete: Person = {
    name: "pete", 
    id: 123n, // it's a bigint
    years: 30
    // data: new Uint8Array([0xDE, 0xAD, 0xBE, 0xEF]);
};

let bytes = Person.toBinary(pete);
pete = Person.fromBinary(bytes);

pete = Person.fromJsonString('{"name":"pete", "id":"123", "years": 30}')

What are protocol buffers?

Protocol buffers is an interface definition language and binary serialization format.
Data structures defined in .proto files are platform-independent and can be used in many languages.
To learn more about the capabilities, please check the official language guide.

Quickstart

  • npm install @protobuf-ts/plugin

    installs the plugin and the compiler "protoc"

  • download the example file msg-readme.proto and place it into a protos/ directory

  • npx protoc --ts_out . --proto_path protos protos/msg-readme.proto

    generates msg-readme.ts
    if your protoc version asks for it, add the flag "--experimental_allow_proto3_optional"

Features

Read the MANUAL to learn more.

Copyright

Support

Buy Me A Coffee