Class: GrpcKit::Transport::Packable::Unpacker
- Inherits:
-
Object
- Object
- GrpcKit::Transport::Packable::Unpacker
- Defined in:
- lib/grpc_kit/transport/packable.rb
Constant Summary collapse
- METADATA_SIZE =
Compressed bytes(1 Byte) + length bytes(4 Bytes)
5
Instance Method Summary collapse
- #feed(data) ⇒ Object
-
#initialize ⇒ Unpacker
constructor
A new instance of Unpacker.
- #read ⇒ Object
- #readable? ⇒ Boolean
Constructor Details
#initialize ⇒ Unpacker
Returns a new instance of Unpacker.
34 35 36 37 |
# File 'lib/grpc_kit/transport/packable.rb', line 34 def initialize @i = 0 @data = nil end |
Instance Method Details
#feed(data) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/grpc_kit/transport/packable.rb', line 43 def feed(data) if @data @data << data else @data = data end end |
#read ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/grpc_kit/transport/packable.rb', line 51 def read = @data.slice!(0, METADATA_SIZE) c, size = .unpack('CN') # TODO: more efficient code data = @data.slice!(0, size) [c != 0, size, data] end |
#readable? ⇒ Boolean
39 40 41 |
# File 'lib/grpc_kit/transport/packable.rb', line 39 def readable? @data && !@data.empty? end |