Rantanen / protoc-gen-constructors

Utilities for generating consistent constructors for protobuf types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protoc-gen-constructors

Generating constructors for Protobuf messages

Building

$ cargo build

Running

OUTLANG=java && protoc \
    --plugin=target/debug/protoc-gen-${OUTLANG}_constructors \
    --${OUTLANG}_out=out_dir \
    --${OUTLANG}_constructors_out=input.spec:out_dir \
    input.proto

The LANG_out and LANG_constructors_outpaths must be equal. The LANG_constructors_out also needs the constructor specification as a parameter.

Constructor specification format

package foo.bar

message MyMessage {

    // Creates a text message.
    CreateMessage(
        // The text value to use for the message.
        string msg
    ) {
        text = msg
    }
    
    // Creates a text message with category.
    CreateMessageWithCategory(
        // The message category ID.
        int category,
        
        // The text value to use for the message.
        string msg
    ) {
        category = category
        text = msg
    }
}

About

Utilities for generating consistent constructors for protobuf types


Languages

Language:Rust 92.6%Language:JavaScript 3.9%Language:Java 2.0%Language:Python 1.5%