Does Protobuf support Tuples?

Viewed 1219

I would like to stream a string tuple from a grpc Server.

I can't seem to find a clever way (if there is any) that this can be done. Have any of you had any luck with tuples in Protobuf?

Additional information:

I am using F#, and would like something corresponding

string * string
1 Answers

What library are you using? I had no problem doing it with protobuf-net.Grpc. My service looks like this:

member __.SubscribeTupleAsync() =
    asyncSeq {
        while true do
            let time = DateTime.Now
            yield string time.Minute, string time.Second
            do! Async.Sleep 1000
    } |> AsyncSeq.toAsyncEnum

And my client looks like this:

use http = GrpcChannel.ForAddress("http://localhost:10042")
let client = http.CreateGrpcService<ITimeService>()
async {
    for (min, sec) in client.SubscribeTupleAsync() |> AsyncSeq.ofAsyncEnum do
        printfn "%s, %s" min sec
} |> Async.RunSynchronously

The contract is:

[<ServiceContract>]
type ITimeService =
    abstract member SubscribeTupleAsync : unit -> IAsyncEnumerable<string * string>

The .proto file is:

syntax = "proto3";
package ProtobufCommon;
import "google/protobuf/empty.proto";

message Tuple_String_String {
   string Item1 = 1;
   string Item2 = 2;
}
service TimeService {
   rpc SubscribeTuple (.google.protobuf.Empty) returns (stream Tuple_String_String);
}

And the output on the client is:

3, 26
3, 27
3, 28
3, 29
3, 30
3, 31
3, 32
3, 33
3, 34
3, 35
...
Related