Class: Arf::RPC::Request

Inherits:
BaseMessage show all
Defined in:
lib/arf/rpc/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMessage

#decode_bytes, #decode_string, #decode_uint16, encode, #encode_bytes, #encode_string, #encode_uint16, has_metadata, has_status, has_streaming, #initialize, initialize_from, kind, message_by_kind, register

Constructor Details

This class inherits a constructor from Arf::RPC::BaseMessage

Instance Attribute Details

#methodObject

Returns the value of attribute method.



9
10
11
# File 'lib/arf/rpc/request.rb', line 9

def method
  @method
end

#paramsObject

Returns the value of attribute params.



9
10
11
# File 'lib/arf/rpc/request.rb', line 9

def params
  @params
end

#serviceObject

Returns the value of attribute service.



9
10
11
# File 'lib/arf/rpc/request.rb', line 9

def service
  @service
end

Instance Method Details

#decode(data) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/arf/rpc/request.rb', line 27

def decode(data)
  @service = decode_string(data)
  @method = decode_string(data)
  flags = data.readbyte
  @streaming = !flags.nobits?((0x01 << 0x00))
  @metadata = Metadata.new.decode(data)
  params_len = decode_uint16(data)
  @params = []
  params_len.times { @params << Proto.decode(data) }
end

#encodeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/arf/rpc/request.rb', line 11

def encode
  flags = 0x00
  flags |= (0x01 << 0x00) if streaming?

  params = @params.map { Proto.encode(_1) }

  IO::Buffer.new
    .write_raw(encode_string(@service))
    .write_raw(encode_string(@method))
    .write(flags)
    .write_raw(@metadata.encode)
    .write_raw(encode_uint16(params.length))
    .write_raw(params.join)
    .string
end