title: Unbuffered bidirectional data streaming with gRPC: how to get the size of the client-side buffer?
body: <p>I am streaming data from a server to a client and I would like the server not to read and send more data than the client's buffer size.</p>
  
  <p>Given:</p>
  
  <pre><code>service StreamService {
    rpc Stream(stream Buffer) returns (stream Buffer);
  }
  
  message Buffer {
    bytes data = 1;
  }
  </code></pre>
  
  <p>My client's program basically looks like: </p>
  
  <pre><code>func ReadFromServer(stream StreamService_StreamClient, buf []byte) (n int, err error) {
    // I actually don't need more than len(buf)...
    // How could I send len(buf) while stream is bidirectional...?
    buffer, err := stream.Recv()
    if err != nil {
       return 0,  err
    }
    n = copy(buf, buffer.Data)
    // buf could also be smaller than buffer.Data...
    return n, nil
  }
  </code></pre>
  
  <p>So how could I send <code>len(buf)</code> while the RPC's stream is bidirectional, i.e. the send direction is used by another independent stream of data? Note that I don't use client or server-side buffering to avoid loosing data when one of them is terminated (my data-source is an I/O).</p>