Skip to content

Instantly share code, notes, and snippets.

@henridf
Last active May 29, 2024 22:08
Show Gist options
  • Select an option

  • Save henridf/704c1c812f04a502c1c26f77a739090b to your computer and use it in GitHub Desktop.

Select an option

Save henridf/704c1c812f04a502c1c26f77a739090b to your computer and use it in GitHub Desktop.

Revisions

  1. henridf revised this gist Mar 28, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,7 @@ message LabelMatcher {
    Then any of the following text snippets are valid input to `protoc --encode`

    #### `LabelMatcher`:

    ```
    type: EQ
    name: "foo"
    @@ -51,7 +52,7 @@ type: EQ, name: "foo", value: "bar"
    ```
    type: EQ;name: "foo";value: "bar"
    ```

    (Note the absence of outer curly braces!)


    #### `Query`:
  2. henridf revised this gist Mar 28, 2018. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -54,10 +54,27 @@ type: EQ;name: "foo";value: "bar"



    #### `Query`:


    ```
    start_timestamp_ms: 0
    end_timestamp_ms: 100
    matchers: [{type: EQ; name: "bla"; value: 'val'}]
    ```

    ```
    start_timestamp_ms: 0
    end_timestamp_ms: 100
    matchers: [
    {
    type: EQ
    name: "bla"
    value: 'val'
    }
    ]
    ```



  3. henridf revised this gist Mar 28, 2018. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,13 @@ Here are a few examples based on some quick experimentation (as opposed to looki
    Assume the following proto def (coming from [prometheus](https://github.com/prometheus/prometheus/blob/master/prompb/types.proto)):

    ```proto
    message Query {
    required int64 start_timestamp_ms = 1;
    required int64 end_timestamp_ms = 2;
    repeated prometheus.LabelMatcher matchers = 3;
    }
    message LabelMatcher {
    enum Type {
    EQ = 0;
    @@ -30,7 +37,7 @@ message LabelMatcher {

    Then any of the following text snippets are valid input to `protoc --encode`


    #### `LabelMatcher`:
    ```
    type: EQ
    name: "foo"
  4. henridf revised this gist Mar 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ Here is the relevant snippet from `protoc --help`:

    Here are a few examples based on some quick experimentation (as opposed to looking at whatever parsing/grammar is used by protoc itself... which would probably have taken a bit more than the few minutes for the experiments below).

    Assume the following proto def (coming from [prometheus](https://github.com/prometheus/prometheus/blob/master/prompb/types.proto):
    Assume the following proto def (coming from [prometheus](https://github.com/prometheus/prometheus/blob/master/prompb/types.proto)):

    ```proto
    message LabelMatcher {
  5. henridf revised this gist Mar 28, 2018. 1 changed file with 2 additions and 8 deletions.
    10 changes: 2 additions & 8 deletions protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ message LabelMatcher {
    }
    ```

    Then any of the following text is valid input to `protoc --encode`
    Then any of the following text snippets are valid input to `protoc --encode`


    ```
    @@ -38,7 +38,7 @@ value: "bar"
    ```

    ```
    type: EQ,name: "foo",value: "bar"
    type: EQ, name: "foo", value: "bar"
    ```

    ```
    @@ -54,9 +54,3 @@ type: EQ;name: "foo";value: "bar"









  6. henridf revised this gist Mar 28, 2018. 1 changed file with 52 additions and 0 deletions.
    52 changes: 52 additions & 0 deletions protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -8,3 +8,55 @@ Here is the relevant snippet from `protoc --help`:
    to standard output. The message type must
    be defined in PROTO_FILES or their imports.
    ```


    Here are a few examples based on some quick experimentation (as opposed to looking at whatever parsing/grammar is used by protoc itself... which would probably have taken a bit more than the few minutes for the experiments below).

    Assume the following proto def (coming from [prometheus](https://github.com/prometheus/prometheus/blob/master/prompb/types.proto):

    ```proto
    message LabelMatcher {
    enum Type {
    EQ = 0;
    NEQ = 1;
    RE = 2;
    NRE = 3;
    }
    Type type = 1;
    string name = 2;
    string value = 3;
    }
    ```

    Then any of the following text is valid input to `protoc --encode`


    ```
    type: EQ
    name: "foo"
    value: "bar"
    ```

    ```
    type: EQ,name: "foo",value: "bar"
    ```

    ```
    type: EQ;name: "foo";value: "bar"
    ```
















  7. henridf created this gist Mar 28, 2018.
    10 changes: 10 additions & 0 deletions protoc-encode.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    I needed to quickly encode a protobuf from the command-line, and while I pretty much immediately came across `protoc --encode` as the obvious solution, I did not find much documentation on the input textual syntax.


    Here is the relevant snippet from `protoc --help`:
    ```text
    --encode=MESSAGE_TYPE Read a text-format message of the given type
    from standard input and write it in binary
    to standard output. The message type must
    be defined in PROTO_FILES or their imports.
    ```