class HTTPX::Transcoder::GRPCEncoding::Inflater

  1. lib/httpx/plugins/grpc/grpc_encoding.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. call

Public Class methods

new(response)
[show source]
   # File lib/httpx/plugins/grpc/grpc_encoding.rb
40 def initialize(response)
41   @response = response
42   @grpc_encodings = nil
43 end

Public Instance methods

call(message, &blk)
[show source]
   # File lib/httpx/plugins/grpc/grpc_encoding.rb
45 def call(message, &blk)
46   data = "".b
47 
48   until message.empty?
49     compressed, size = message.unpack("CL>")
50 
51     encoded_data = message.byteslice(5..size + 5 - 1)
52 
53     if compressed == 1
54       grpc_encodings.reverse_each do |encoding|
55         decoder = @response.body.class.initialize_inflater_by_encoding(encoding, @response, bytesize: encoded_data.bytesize)
56         encoded_data = decoder.call(encoded_data)
57 
58         blk.call(encoded_data) if blk
59 
60         data << encoded_data
61       end
62     else
63       blk.call(encoded_data) if blk
64 
65       data << encoded_data
66     end
67 
68     message = message.byteslice((size + 5)..-1)
69   end
70 
71   data
72 end