Class: Arf::RPC::Response
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
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
10
11
12
|
# File 'lib/arf/rpc/response.rb', line 10
def params
@params
end
|
Instance Method Details
#decode(data) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/arf/rpc/response.rb', line 29
def decode(data)
@status = decode_uint16(data)
flags = data.readbyte
@streaming = !flags.nobits?((0x01 << 0x00))
@metadata = Metadata.new.decode(data)
len = decode_uint16(data)
@params = []
len.times { @params << Proto.decode(data) }
end
|
#encode ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/arf/rpc/response.rb', line 12
def encode
flags = 0x00
flags |= (0x01 << 0x00) if streaming?
params = @params.map { Proto.encode(_1) }
IO::Buffer.new
.write_raw(encode_uint16(@status))
.write(flags)
.write_raw(@metadata.encode)
.write_raw(encode_uint16(params.length))
.write_raw(params.join)
.string
end
|
#ok? ⇒ Boolean
27
|
# File 'lib/arf/rpc/response.rb', line 27
def ok? = status == :ok
|
#result ⇒ Object
39
40
41
42
43
|
# File 'lib/arf/rpc/response.rb', line 39
def result
return @params if status == :ok
raise Status::BadStatus.new(@status, @metadata.get("arf-status-description"))
end
|