grpc_kit 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GrpcKit
4
- module Streams
5
- class Stream
6
- include GrpcKit::Rpcs::Packable
7
-
8
- def initialize(protobuf:, session:, stream:)
9
- @protobuf = protobuf
10
- @session = session
11
- @stream = stream
12
- end
13
-
14
- def send(last: false)
15
- req = @protobuf.encode(data)
16
- @stream.write_send_data(pack(req), last: last)
17
- end
18
-
19
- def recv(last: false)
20
- data = unpack(read(last: last))
21
-
22
- unless data
23
- raise StopIteration
24
- end
25
-
26
- compressed, size, buf = *data
27
-
28
- unless size == buf.size
29
- raise "inconsistent data: #{buf}"
30
- end
31
-
32
- if compressed
33
- raise 'compress option is unsupported'
34
- end
35
-
36
- @protobuf.decode(buf)
37
- end
38
-
39
- private
40
-
41
- def read(last: false)
42
- loop do
43
- data = @stream.read_recv_data(last: last)
44
- if data.empty?
45
- if @stream.end_read?
46
- return nil
47
- end
48
-
49
- @session.run_once
50
- redo
51
- end
52
-
53
- return data
54
- end
55
- end
56
- end
57
- end
58
- end