Class: GrpcKit::Transport::SendBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/transport/send_buffer.rb

Instance Method Summary collapse

Constructor Details

#initializeSendBuffer

Returns a new instance of SendBuffer.



6
7
8
9
# File 'lib/grpc_kit/transport/send_buffer.rb', line 6

def initialize
  @buffer = nil
  @end_write = false
end

Instance Method Details

#end_writeObject



21
22
23
# File 'lib/grpc_kit/transport/send_buffer.rb', line 21

def end_write
  @end_write = true
end

#end_write?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/grpc_kit/transport/send_buffer.rb', line 25

def end_write?
  @end_write
end

#read(size) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/grpc_kit/transport/send_buffer.rb', line 29

def read(size)
  if @buffer.nil?
    return false
  end

  data = @buffer.slice!(0, size)
  if !data.empty?
    data
  elsif end_write?
    nil # EOF
  else
    false # deferred
  end
end

#write(data, last: false) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/grpc_kit/transport/send_buffer.rb', line 11

def write(data, last: false)
  end_write if last

  if @buffer
    @buffer << data
  else
    @buffer = data
  end
end