Class: GrpcKit::Transport::ServerTransport

Inherits:
Object
  • Object
show all
Includes:
Packable
Defined in:
lib/grpc_kit/transport/server_transport.rb

Instance Method Summary collapse

Methods included from Packable

#pack, #unpack, #unpacker

Constructor Details

#initialize(control_queue, stream) ⇒ ServerTransport

Returns a new instance of ServerTransport.

Parameters:



12
13
14
15
# File 'lib/grpc_kit/transport/server_transport.rb', line 12

def initialize(control_queue, stream)
  @control_queue = control_queue
  @stream = stream
end

Instance Method Details

#end_writevoid

This method returns an undefined value.



59
60
61
# File 'lib/grpc_kit/transport/server_transport.rb', line 59

def end_write
  @stream.end_write
end

#read_data(last: false) ⇒ nil, Array<Boolean,Integer,String>

Returns nil when closed, tuple of Length-Prefixed-Message.

Parameters:

  • last (Boolean) (defaults to: false)

Returns:

  • (nil, Array<Boolean,Integer,String>)

    nil when closed, tuple of Length-Prefixed-Message



40
41
42
43
44
45
46
47
48
49
# File 'lib/grpc_kit/transport/server_transport.rb', line 40

def read_data(last: false)
  data_in_buffer = unpack(nil)
  return data_in_buffer if data_in_buffer
  loop do
    data = recv_data(last: last)
    return nil unless data
    message = unpack(data)
    return message if message
  end
end

#recv_headersHash<String,String>

Returns:

  • (Hash<String,String>)


64
65
66
# File 'lib/grpc_kit/transport/server_transport.rb', line 64

def recv_headers
  @stream.headers
end

#start_response(headers) ⇒ void

This method returns an undefined value.

Parameters:

  • headers (Hash<String, String>)


19
20
21
22
# File 'lib/grpc_kit/transport/server_transport.rb', line 19

def start_response(headers)
  @control_queue.submit_response(@stream.stream_id, headers)
  send_data
end

#submit_headers(headers) ⇒ void

This method returns an undefined value.

Parameters:

  • headers (Hash<String, String>)


26
27
28
# File 'lib/grpc_kit/transport/server_transport.rb', line 26

def submit_headers(headers)
  @control_queue.submit_headers(@stream.stream_id, headers)
end

#write_data(buf, last: false) ⇒ void

This method returns an undefined value.

Parameters:

  • buf (String)
  • last (Boolean) (defaults to: false)


33
34
35
36
# File 'lib/grpc_kit/transport/server_transport.rb', line 33

def write_data(buf, last: false)
  @stream.write_send_data(pack(buf), last: last)
  send_data
end

#write_trailers(trailer) ⇒ void

This method returns an undefined value.

Parameters:

  • trailer (Hash<String, String>)


53
54
55
56
# File 'lib/grpc_kit/transport/server_transport.rb', line 53

def write_trailers(trailer)
  @stream.write_trailers_data(trailer)
  send_data
end