Class: GrpcKit::Transport::Packable::Unpacker

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeUnpacker


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


41
42
43
# File 'lib/grpc_kit/transport/packable.rb', line 41

def feed(data)
  @data << data
end

#readnil, Array<Boolean, Integer, String>


46
47
48
49
50
51
52
53
54
55
# File 'lib/grpc_kit/transport/packable.rb', line 46

def read
  return nil if @data.empty?

  d = @data.freeze
   = d.byteslice(0, )
  c, size = .unpack('CN')
  data = @data.byteslice(, size)
  @data = @data.byteslice( + size, @data.bytesize)
  [c != 0, size, data]
end