Class: GrpcKit::Streams::Stream
- Inherits:
-
Object
- Object
- GrpcKit::Streams::Stream
- Includes:
- Rpcs::Packable
- Defined in:
- lib/grpc_kit/streams/stream.rb
Instance Method Summary collapse
-
#initialize(protobuf:, session:, stream:) ⇒ Stream
constructor
A new instance of Stream.
- #recv(last: false) ⇒ Object
- #send(last: false) ⇒ Object
Constructor Details
#initialize(protobuf:, session:, stream:) ⇒ Stream
Returns a new instance of Stream.
8 9 10 11 12 |
# File 'lib/grpc_kit/streams/stream.rb', line 8 def initialize(protobuf:, session:, stream:) @protobuf = protobuf @session = session @stream = stream end |
Instance Method Details
#recv(last: false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grpc_kit/streams/stream.rb', line 19 def recv(last: false) data = unpack(read(last: last)) unless data raise StopIteration end compressed, size, buf = *data unless size == buf.size raise "inconsistent data: #{buf}" end if compressed raise 'compress option is unsupported' end @protobuf.decode(buf) end |
#send(last: false) ⇒ Object
14 15 16 17 |
# File 'lib/grpc_kit/streams/stream.rb', line 14 def send(last: false) req = @protobuf.encode(data) @stream.write_send_data(pack(req), last: last) end |