Skip to content

Instantly share code, notes, and snippets.

@bom-d-van
Last active March 26, 2023 17:22
Show Gist options
  • Select an option

  • Save bom-d-van/1d4c16385eefb3d89d33f158c8ca77e4 to your computer and use it in GitHub Desktop.

Select an option

Save bom-d-van/1d4c16385eefb3d89d33f158c8ca77e4 to your computer and use it in GitHub Desktop.

Revisions

  1. bom-d-van revised this gist Mar 12, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions nc-protoc.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Using nc and protoc as protobuf client and server

    Inspiration: [Linux and Unix nc command](www.computerhope.com/unix/nc.htm)

    Example protobuf definition:

    ```proto
  2. bom-d-van revised this gist Mar 12, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion nc-protoc.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,8 @@ protoc --encode=Person \
    name: "John Doe"
    email: "[email protected]"
    id: 43
    phone {number: "1010"} phone {number: "0101"}
    phone {number: "1010"}
    phone {number: "0101"}
    ' \
    | nc 127.0.0.1 8080
    ```
  3. bom-d-van revised this gist Mar 12, 2017. 1 changed file with 19 additions and 3 deletions.
    22 changes: 19 additions & 3 deletions nc-protoc.md
    Original file line number Diff line number Diff line change
    @@ -39,19 +39,35 @@ protoc --encode=Person \
    ## Listening on 127.0.0.1:8080 for a TCP protobuf request

    ```sh
    nc -l -p 8080 -c | protoc --decode=Person foo.proto
    nc -l -p 8080 -c \
    | protoc --decode=Person foo.proto
    ```

    ## Server/Client in action

    sever:

    ```sh
    protoc --encode=Person foo.proto <<<'name: "John Doe" email: "[email protected]" id: 42' | nc -l -p 8080 -c | protoc --decode=Person foo.proto
    protoc --encode=Person \
    foo.proto <<<'
    name: "John Doe"
    email: "[email protected]"
    id: 42
    ' \
    | nc -l -p 8080 -c \
    | protoc --decode=Person foo.proto
    ```

    client:

    ```sh
    protoc --encode=Person foo.proto <<<'name: "John Doe" email: "[email protected]" id: 43 phone {number: "1010"}' | nc 127.0.0.1 8080 | protoc --decode=Person foo.proto
    protoc --encode=Person \
    foo.proto <<<'
    name: "John Doe"
    email: "[email protected]"
    id: 43
    phone {number: "1010"}
    ' \
    | nc 127.0.0.1 8080 \
    | protoc --decode=Person foo.proto
    ```
  4. bom-d-van created this gist Mar 12, 2017.
    57 changes: 57 additions & 0 deletions nc-protoc.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    # Using nc and protoc as protobuf client and server

    Example protobuf definition:

    ```proto
    message Person {
    required string name = 1;
    required int32 id = 2;
    optional string email = 3;
    enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
    }
    message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
    }
    repeated PhoneNumber phone = 4;
    }
    ```

    ## Send a protobuf TCP request to 127.0.0.1:8080

    ```sh
    protoc --encode=Person \
    foo.proto <<<'
    name: "John Doe"
    email: "[email protected]"
    id: 43
    phone {number: "1010"} phone {number: "0101"}
    ' \
    | nc 127.0.0.1 8080
    ```

    ## Listening on 127.0.0.1:8080 for a TCP protobuf request

    ```sh
    nc -l -p 8080 -c | protoc --decode=Person foo.proto
    ```

    ## Server/Client in action

    sever:

    ```sh
    protoc --encode=Person foo.proto <<<'name: "John Doe" email: "[email protected]" id: 42' | nc -l -p 8080 -c | protoc --decode=Person foo.proto
    ```

    client:

    ```sh
    protoc --encode=Person foo.proto <<<'name: "John Doe" email: "[email protected]" id: 43 phone {number: "1010"}' | nc 127.0.0.1 8080 | protoc --decode=Person foo.proto
    ```