maxspan
maxspan

Reputation: 14177

Converting Protobuf schema inside javascript into separate proto definition file

I am having the below javascript content which I want to convert to protobuf file (.proto file). I want to know how to save it as proto file. JS file

 {
        package: null,
        syntax: "proto2",
        messages: [{
            name: "Msg",
            syntax: "proto2",
            fields: [{
                rule: "optional",
                type: "Commands",
                name: "command_number",
                id: 1
            }, {
                rule: "optional",
                type: "bytes",
                name: "data",
                id: 2
            }, {
                rule: "optional",
                type: "int32",
                name: "time",
                id: 3
            }],
 enums: [{
            name: "Commands",
            syntax: "proto2",
            values: [{
                name: "chart_create_session",
                id: 0
            }, {
                name: "chart_delete_session",
                id: 1
            }, {
                name: "resolve_symbol",
                id: 2
            }, {
                name: "create_series",
                id: 3
            }
}]
}]
    }

Upvotes: 1

Views: 349

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063338

yes onetime thing

In that case:

syntax = "proto2";

message Msg {
    optional Commands command_number = 1;
    optional bytes data = 2;
    optional int32 time = 3;
}
enum Commands {
    chart_create_session = 0;
    chart_delete_session = 1;
    resolve_symbol = 2;
    create_series = 3;
}

 message chart_create_session {
    optional string session = 1;
    optional string parameters = 2;
}

Upvotes: 1

Related Questions