Class: GrpcKit::Transport::Packable::Unpacker
- Inherits:
-
Object
- Object
- GrpcKit::Transport::Packable::Unpacker
- Defined in:
- lib/grpc_kit/transport/packable.rb
Constant Summary collapse
- PREFIX_SIZE =
Compressed-Flag (1 byte) + Message-Length (4 Bytes)
5
Instance Method Summary collapse
- #data_exist? ⇒ Boolean
- #feed(data) ⇒ void
-
#initialize ⇒ Unpacker
constructor
A new instance of Unpacker.
- #read ⇒ nil, Array<Boolean, Integer, String>
Constructor Details
#initialize ⇒ Unpacker
Returns a new instance of Unpacker.
30 31 32 |
# File 'lib/grpc_kit/transport/packable.rb', line 30 def initialize @data = +''.b end |
Instance Method Details
#data_exist? ⇒ Boolean
35 36 37 |
# File 'lib/grpc_kit/transport/packable.rb', line 35 def data_exist? !@data.empty? end |
#feed(data) ⇒ void
This method returns an undefined value.
41 42 43 |
# File 'lib/grpc_kit/transport/packable.rb', line 41 def feed(data) @data << data end |
#read ⇒ nil, Array<Boolean, Integer, String>
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/grpc_kit/transport/packable.rb', line 46 def read return nil if @data.bytesize < PREFIX_SIZE prefix = @data.byteslice(0, PREFIX_SIZE) compressed, length = prefix.unpack('CN') return nil if (@data.bytesize-PREFIX_SIZE) < length d = @data.freeze data = d.byteslice(PREFIX_SIZE, length) @data = d.byteslice(PREFIX_SIZE + length, d.bytesize) [compressed == 1, length, data] end |