Skip to content

Protons custom options

Alex Potsides edited this page Oct 23, 2023 · 3 revisions

Protons supports some custom options to control how messages are decoded.

limit

The limit option allows you to limit the size of decoded maps and repeated fields.

In the following example any message with more than 10 instances of repeatedField in it's serialized form will cause an error to be thrown on decode:

syntax = "proto3";

import "protons-rutime/options.proto";

message Message {
  repeated string repeatedField = 1 [(protons.options).limit = 10];
}

Similarly the following example will cause decoding of any message with more than 10 map entries for mapField to error:

syntax = "proto3";

import "protons-rutime/options.proto";

message Message {
  map<string, string> mapField = 1 [(protons.options).limit = 10];
}

Editor setup

To validate these options during development you may need to configure your editor to add additional paths to protoc.

For example if you are using the vscode-proto3 plugin with VSCode add the following configuration to allow resolving protons-rutime/options.proto from your project's node_modules folder:

{
  "protoc": {
    "options": [
        "--proto_path=${workspaceRoot}/node_modules"
    ]
  }
}

Other plugins may require other options.

Clone this wiki locally