Class: HTTPX::Transcoder::GRPCEncoding::Deflater

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/httpx/plugins/grpc/grpc_encoding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, compressed:) ⇒ Deflater

Returns a new instance of Deflater.



11
12
13
14
15
# File 'lib/httpx/plugins/grpc/grpc_encoding.rb', line 11

def initialize(body, compressed:)
  @content_type = body.content_type
  @body = BodyReader.new(body)
  @compressed = compressed
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



9
10
11
# File 'lib/httpx/plugins/grpc/grpc_encoding.rb', line 9

def content_type
  @content_type
end

Instance Method Details

#bytesizeObject



17
18
19
20
21
# File 'lib/httpx/plugins/grpc/grpc_encoding.rb', line 17

def bytesize
  return @body.bytesize if @body.respond_to?(:bytesize)

  Float::INFINITY
end

#read(length = nil, outbuf = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/httpx/plugins/grpc/grpc_encoding.rb', line 23

def read(length = nil, outbuf = nil)
  buf = @body.read(length, outbuf)

  return unless buf

  compressed_flag = @compressed ? 1 : 0

  buf = outbuf if outbuf

  buf.prepend([compressed_flag, buf.bytesize].pack("CL>"))
  buf
end