krpc 0.3.2 → 0.4.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/krpc.gemspec +6 -6
- data/lib/krpc.rb +2 -2
- data/lib/krpc/client.rb +54 -48
- data/lib/krpc/connection.rb +38 -33
- data/lib/krpc/core_extensions.rb +3 -3
- data/lib/krpc/decoder.rb +13 -20
- data/lib/krpc/doc.rb +29 -30
- data/lib/krpc/encoder.rb +19 -31
- data/lib/krpc/error.rb +2 -1
- data/lib/krpc/gen.rb +36 -37
- data/lib/krpc/krpc.pb.rb +87 -26
- data/lib/krpc/procedure_name_parser.rb +47 -0
- data/lib/krpc/protobuf_extensions.rb +22 -1
- data/lib/krpc/protobuf_utils.rb +28 -31
- data/lib/krpc/service.rb +44 -67
- data/lib/krpc/streaming.rb +30 -30
- data/lib/krpc/types.rb +73 -154
- data/lib/krpc/version.rb +8 -1
- metadata +17 -16
- data/lib/krpc/attributes.rb +0 -80
data/lib/krpc/krpc.pb.rb
CHANGED
@@ -4,7 +4,30 @@
|
|
4
4
|
require 'google/protobuf'
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_message "krpc.schema.ConnectionRequest" do
|
8
|
+
optional :type, :enum, 1, "krpc.schema.ConnectionRequest.Type"
|
9
|
+
optional :client_name, :string, 2
|
10
|
+
optional :client_identifier, :bytes, 3
|
11
|
+
end
|
12
|
+
add_enum "krpc.schema.ConnectionRequest.Type" do
|
13
|
+
value :RPC, 0
|
14
|
+
value :STREAM, 1
|
15
|
+
end
|
16
|
+
add_message "krpc.schema.ConnectionResponse" do
|
17
|
+
optional :status, :enum, 1, "krpc.schema.ConnectionResponse.Status"
|
18
|
+
optional :message, :string, 2
|
19
|
+
optional :client_identifier, :bytes, 3
|
20
|
+
end
|
21
|
+
add_enum "krpc.schema.ConnectionResponse.Status" do
|
22
|
+
value :OK, 0
|
23
|
+
value :MALFORMED_MESSAGE, 1
|
24
|
+
value :TIMEOUT, 2
|
25
|
+
value :WRONG_TYPE, 3
|
26
|
+
end
|
7
27
|
add_message "krpc.schema.Request" do
|
28
|
+
repeated :calls, :message, 1, "krpc.schema.ProcedureCall"
|
29
|
+
end
|
30
|
+
add_message "krpc.schema.ProcedureCall" do
|
8
31
|
optional :service, :string, 1
|
9
32
|
optional :procedure, :string, 2
|
10
33
|
repeated :arguments, :message, 3, "krpc.schema.Argument"
|
@@ -14,18 +37,19 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
14
37
|
optional :value, :bytes, 2
|
15
38
|
end
|
16
39
|
add_message "krpc.schema.Response" do
|
17
|
-
optional :
|
18
|
-
|
19
|
-
optional :error, :string, 3
|
20
|
-
optional :has_return_value, :bool, 4
|
21
|
-
optional :return_value, :bytes, 5
|
40
|
+
optional :error, :string, 1
|
41
|
+
repeated :results, :message, 2, "krpc.schema.ProcedureResult"
|
22
42
|
end
|
23
|
-
add_message "krpc.schema.
|
24
|
-
|
43
|
+
add_message "krpc.schema.ProcedureResult" do
|
44
|
+
optional :error, :string, 1
|
45
|
+
optional :value, :bytes, 2
|
25
46
|
end
|
26
|
-
add_message "krpc.schema.
|
27
|
-
|
28
|
-
|
47
|
+
add_message "krpc.schema.StreamUpdate" do
|
48
|
+
repeated :results, :message, 1, "krpc.schema.StreamResult"
|
49
|
+
end
|
50
|
+
add_message "krpc.schema.StreamResult" do
|
51
|
+
optional :id, :uint64, 1
|
52
|
+
optional :result, :message, 2, "krpc.schema.ProcedureResult"
|
29
53
|
end
|
30
54
|
add_message "krpc.schema.Services" do
|
31
55
|
repeated :services, :message, 1, "krpc.schema.Service"
|
@@ -40,16 +64,13 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
40
64
|
add_message "krpc.schema.Procedure" do
|
41
65
|
optional :name, :string, 1
|
42
66
|
repeated :parameters, :message, 2, "krpc.schema.Parameter"
|
43
|
-
optional :
|
44
|
-
optional :
|
45
|
-
repeated :attributes, :string, 5
|
46
|
-
optional :documentation, :string, 6
|
67
|
+
optional :return_type, :message, 3, "krpc.schema.Type"
|
68
|
+
optional :documentation, :string, 4
|
47
69
|
end
|
48
70
|
add_message "krpc.schema.Parameter" do
|
49
71
|
optional :name, :string, 1
|
50
|
-
optional :type, :
|
51
|
-
optional :
|
52
|
-
optional :default_value, :bytes, 4
|
72
|
+
optional :type, :message, 2, "krpc.schema.Type"
|
73
|
+
optional :default_value, :bytes, 3
|
53
74
|
end
|
54
75
|
add_message "krpc.schema.Class" do
|
55
76
|
optional :name, :string, 1
|
@@ -65,9 +86,43 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
65
86
|
optional :value, :int32, 2
|
66
87
|
optional :documentation, :string, 3
|
67
88
|
end
|
89
|
+
add_message "krpc.schema.Type" do
|
90
|
+
optional :code, :enum, 1, "krpc.schema.Type.TypeCode"
|
91
|
+
optional :service, :string, 2
|
92
|
+
optional :name, :string, 3
|
93
|
+
repeated :types, :message, 4, "krpc.schema.Type"
|
94
|
+
end
|
95
|
+
add_enum "krpc.schema.Type.TypeCode" do
|
96
|
+
value :NONE, 0
|
97
|
+
value :DOUBLE, 1
|
98
|
+
value :FLOAT, 2
|
99
|
+
value :SINT32, 3
|
100
|
+
value :SINT64, 4
|
101
|
+
value :UINT32, 5
|
102
|
+
value :UINT64, 6
|
103
|
+
value :BOOL, 7
|
104
|
+
value :STRING, 8
|
105
|
+
value :BYTES, 9
|
106
|
+
value :CLASS, 100
|
107
|
+
value :ENUMERATION, 101
|
108
|
+
value :PROCEDURE_CALL, 200
|
109
|
+
value :STREAM, 201
|
110
|
+
value :STATUS, 202
|
111
|
+
value :SERVICES, 203
|
112
|
+
value :TUPLE, 300
|
113
|
+
value :LIST, 301
|
114
|
+
value :SET, 302
|
115
|
+
value :DICTIONARY, 303
|
116
|
+
end
|
117
|
+
add_message "krpc.schema.Tuple" do
|
118
|
+
repeated :items, :bytes, 1
|
119
|
+
end
|
68
120
|
add_message "krpc.schema.List" do
|
69
121
|
repeated :items, :bytes, 1
|
70
122
|
end
|
123
|
+
add_message "krpc.schema.Set" do
|
124
|
+
repeated :items, :bytes, 1
|
125
|
+
end
|
71
126
|
add_message "krpc.schema.Dictionary" do
|
72
127
|
repeated :entries, :message, 1, "krpc.schema.DictionaryEntry"
|
73
128
|
end
|
@@ -75,11 +130,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
75
130
|
optional :key, :bytes, 1
|
76
131
|
optional :value, :bytes, 2
|
77
132
|
end
|
78
|
-
add_message "krpc.schema.
|
79
|
-
|
80
|
-
end
|
81
|
-
add_message "krpc.schema.Tuple" do
|
82
|
-
repeated :items, :bytes, 1
|
133
|
+
add_message "krpc.schema.Stream" do
|
134
|
+
optional :id, :uint64, 1
|
83
135
|
end
|
84
136
|
add_message "krpc.schema.Status" do
|
85
137
|
optional :version, :string, 1
|
@@ -106,11 +158,17 @@ end
|
|
106
158
|
|
107
159
|
module KRPC
|
108
160
|
module PB
|
161
|
+
ConnectionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.ConnectionRequest").msgclass
|
162
|
+
ConnectionRequest::Type = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.ConnectionRequest.Type").enummodule
|
163
|
+
ConnectionResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.ConnectionResponse").msgclass
|
164
|
+
ConnectionResponse::Status = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.ConnectionResponse.Status").enummodule
|
109
165
|
Request = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Request").msgclass
|
166
|
+
ProcedureCall = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.ProcedureCall").msgclass
|
110
167
|
Argument = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Argument").msgclass
|
111
168
|
Response = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Response").msgclass
|
112
|
-
|
113
|
-
|
169
|
+
ProcedureResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.ProcedureResult").msgclass
|
170
|
+
StreamUpdate = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.StreamUpdate").msgclass
|
171
|
+
StreamResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.StreamResult").msgclass
|
114
172
|
Services = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Services").msgclass
|
115
173
|
Service = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Service").msgclass
|
116
174
|
Procedure = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Procedure").msgclass
|
@@ -118,11 +176,14 @@ module KRPC
|
|
118
176
|
Class = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Class").msgclass
|
119
177
|
Enumeration = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Enumeration").msgclass
|
120
178
|
EnumerationValue = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.EnumerationValue").msgclass
|
179
|
+
Type = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Type").msgclass
|
180
|
+
Type::TypeCode = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Type.TypeCode").enummodule
|
181
|
+
Tuple = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Tuple").msgclass
|
121
182
|
List = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.List").msgclass
|
183
|
+
Set = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Set").msgclass
|
122
184
|
Dictionary = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Dictionary").msgclass
|
123
185
|
DictionaryEntry = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.DictionaryEntry").msgclass
|
124
|
-
|
125
|
-
Tuple = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Tuple").msgclass
|
186
|
+
Stream = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Stream").msgclass
|
126
187
|
Status = Google::Protobuf::DescriptorPool.generated_pool.lookup("krpc.schema.Status").msgclass
|
127
188
|
end
|
128
189
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'krpc/error'
|
2
|
+
|
3
|
+
module KRPC
|
4
|
+
module ProcedureNameParser
|
5
|
+
|
6
|
+
def self.parse(proc_name)
|
7
|
+
parts = proc_name.split('_')
|
8
|
+
name = parts[-1]
|
9
|
+
raise(ProcedureNameParserError, "Procedure name is empty") if proc_name.empty?
|
10
|
+
raise(ProcedureNameParserError, "Invalid procedure name") if parts.size > 3
|
11
|
+
|
12
|
+
case parts.size
|
13
|
+
when 1
|
14
|
+
Result.new(:plain_procedure, false, false, name, nil)
|
15
|
+
when 2
|
16
|
+
case parts[0]
|
17
|
+
when 'get'
|
18
|
+
Result.new(:service_property_getter, false, false, name, nil)
|
19
|
+
when 'set'
|
20
|
+
Result.new(:service_property_setter, true, false, name, nil)
|
21
|
+
else
|
22
|
+
Result.new(:class_method, false, true, name, parts[0])
|
23
|
+
end
|
24
|
+
when 3
|
25
|
+
case parts[1]
|
26
|
+
when 'get'
|
27
|
+
Result.new(:class_property_getter, false, true, name, parts[0])
|
28
|
+
when 'set'
|
29
|
+
Result.new(:class_property_setter, true, true, name, parts[0])
|
30
|
+
when 'static'
|
31
|
+
Result.new(:class_static_method, false, true, name, parts[0])
|
32
|
+
else
|
33
|
+
raise(ProcedureNameParserError, "Invalid procedure name")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class Result < Struct.new(:type, :setter?, :class_member?, :member_name, :class_name)
|
40
|
+
def class_name
|
41
|
+
raise(ValueError, "Procedure is not a class method or property") unless super
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -1,20 +1,41 @@
|
|
1
1
|
require 'krpc/krpc.pb'
|
2
|
+
require 'krpc/procedure_name_parser'
|
2
3
|
|
3
4
|
module KRPC
|
4
5
|
module ProtobufExtensions
|
6
|
+
module SafeEquals
|
5
7
|
|
6
|
-
module MessageExtensions
|
7
8
|
def ==(other)
|
8
9
|
super
|
9
10
|
rescue TypeError
|
10
11
|
false
|
11
12
|
end
|
13
|
+
|
14
|
+
end
|
15
|
+
module MessageExtensions
|
16
|
+
include SafeEquals
|
17
|
+
|
18
|
+
def field_empty?(field)
|
19
|
+
val = self.send(field)
|
20
|
+
"" == val || [] == val || val.nil?
|
21
|
+
end
|
22
|
+
|
12
23
|
end
|
24
|
+
module ProcedureExtensions
|
25
|
+
extend Forwardable
|
13
26
|
|
27
|
+
def info
|
28
|
+
@info ||= ProcedureNameParser.parse(name)
|
29
|
+
end
|
30
|
+
def_delegators :info, *ProcedureNameParser::Result.members
|
31
|
+
|
32
|
+
end
|
14
33
|
end
|
15
34
|
end
|
16
35
|
|
36
|
+
Google::Protobuf::RepeatedField.prepend KRPC::ProtobufExtensions::SafeEquals
|
17
37
|
KRPC::PB.constants(false).map {|const_name| KRPC::PB.const_get(const_name,true)}.each do |msgclass|
|
18
38
|
msgclass.prepend KRPC::ProtobufExtensions::MessageExtensions
|
19
39
|
end
|
40
|
+
KRPC::PB::Procedure.prepend KRPC::ProtobufExtensions::ProcedureExtensions
|
20
41
|
|
data/lib/krpc/protobuf_utils.rb
CHANGED
@@ -2,28 +2,21 @@ require 'krpc/krpc.pb'
|
|
2
2
|
|
3
3
|
module KRPC
|
4
4
|
module ProtobufUtils
|
5
|
-
class << self
|
6
|
-
def create_PB_to_PB_message_class_hash(package)
|
7
|
-
protobuf_module = Kernel.const_get(package.gsub(".","::") + "::PB")
|
8
|
-
protobuf_module.constants.map do |name|
|
9
|
-
[package + "." + name.to_s, protobuf_module.const_get(name,false)]
|
10
|
-
end.to_h
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
5
|
module Decoder
|
15
6
|
class << self
|
7
|
+
|
16
8
|
def decode(bytes, type)
|
17
9
|
meth_name = "decode_" + type
|
18
10
|
raise RuntimeError.new("Unsupported type #{type}") unless respond_to?(meth_name)
|
19
11
|
send(meth_name, bytes)
|
20
12
|
end
|
21
13
|
|
22
|
-
# based on: https://developers.google.com/protocol-buffers/docs/encoding#varints & http://www.rubydoc.info/gems/ruby-protocol-buffers/1.0.1/ProtocolBuffers/Varint#decode-class_method & https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/decoder.py#L136
|
14
|
+
# based on: https://developers.google.com/protocol-buffers/docs/encoding#varints & http://www.rubydoc.info/gems/ruby-protocol-buffers/1.0.1/ProtocolBuffers/Varint#decode-class_method & https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/decoder.py#L136
|
23
15
|
def decode_varint(bytes)
|
24
16
|
decode_varint_pos(bytes)[0]
|
25
17
|
end
|
26
18
|
def decode_varint_pos(bytes)
|
19
|
+
raise(RuntimeError, "can't decode varint from empty byte buffer") if bytes.empty?
|
27
20
|
pos = 0
|
28
21
|
result = 0
|
29
22
|
shift = 0
|
@@ -36,17 +29,16 @@ module KRPC
|
|
36
29
|
raise(RuntimeError, "too many bytes when decoding varint") if shift >= 64
|
37
30
|
end
|
38
31
|
end
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
result
|
32
|
+
def decode_zigzaged_varint(bytes)
|
33
|
+
zigzaged = decode_varint(bytes)
|
34
|
+
(zigzaged >> 1) ^ -(zigzaged & 1)
|
43
35
|
end
|
44
|
-
|
45
|
-
alias_method :
|
46
|
-
alias_method :
|
36
|
+
|
37
|
+
alias_method :decode_sint32, :decode_zigzaged_varint
|
38
|
+
alias_method :decode_sint64, :decode_zigzaged_varint
|
47
39
|
alias_method :decode_uint32, :decode_varint
|
48
40
|
alias_method :decode_uint64, :decode_varint
|
49
|
-
|
41
|
+
|
50
42
|
# based on: https://github.com/ruby-protobuf/protobuf/search?q=pack
|
51
43
|
def decode_float(bytes)
|
52
44
|
bytes.unpack('e').first
|
@@ -65,18 +57,19 @@ module KRPC
|
|
65
57
|
size, pos = decode_varint_pos(bytes)
|
66
58
|
bytes[pos..(pos+size)].bytes
|
67
59
|
end
|
68
|
-
|
60
|
+
|
69
61
|
end
|
70
62
|
end
|
71
|
-
|
63
|
+
|
72
64
|
module Encoder
|
73
65
|
class << self
|
66
|
+
|
74
67
|
def encode(value, type)
|
75
68
|
meth_name = "encode_" + type
|
76
69
|
raise(RuntimeError, "Unsupported type #{type}") unless respond_to?(meth_name)
|
77
70
|
send(meth_name, value)
|
78
71
|
end
|
79
|
-
|
72
|
+
|
80
73
|
# based on: http://www.rubydoc.info/gems/ruby-protocol-buffers/1.0.1/ProtocolBuffers/Varint#decode-class_method & https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/encoder.py#L390
|
81
74
|
def encode_varint(value)
|
82
75
|
return [value].pack('C') if value < 0b1000_0000
|
@@ -91,20 +84,24 @@ module KRPC
|
|
91
84
|
end
|
92
85
|
end
|
93
86
|
end
|
94
|
-
def encode_signed_varint(value)
|
95
|
-
value += (1 << 64) if value < 0
|
96
|
-
encode_varint(value)
|
97
|
-
end
|
98
87
|
def encode_nonnegative_varint(value)
|
99
88
|
raise(RangeError, "Value must be non-negative, got #{value}") if value < 0
|
100
89
|
encode_varint(value)
|
101
90
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
91
|
+
def encode_zigzaged_varint_32(value)
|
92
|
+
zigzaged = (value << 1) ^ (value >> 31)
|
93
|
+
encode_varint(zigzaged)
|
94
|
+
end
|
95
|
+
def encode_zigzaged_varint_64(value)
|
96
|
+
zigzaged = (value << 1) ^ (value >> 63)
|
97
|
+
encode_varint(zigzaged)
|
98
|
+
end
|
99
|
+
|
100
|
+
alias_method :encode_sint32, :encode_zigzaged_varint_32
|
101
|
+
alias_method :encode_sint64, :encode_zigzaged_varint_64
|
105
102
|
alias_method :encode_uint32, :encode_nonnegative_varint
|
106
103
|
alias_method :encode_uint64, :encode_nonnegative_varint
|
107
|
-
|
104
|
+
|
108
105
|
def encode_float(value)
|
109
106
|
[value].pack('e')
|
110
107
|
end
|
@@ -122,9 +119,9 @@ module KRPC
|
|
122
119
|
size = encode_varint(value.size)
|
123
120
|
size + value.map(&:chr).join.b
|
124
121
|
end
|
125
|
-
|
122
|
+
|
126
123
|
end
|
127
124
|
end
|
128
|
-
|
125
|
+
|
129
126
|
end
|
130
127
|
end
|
data/lib/krpc/service.rb
CHANGED
@@ -1,81 +1,60 @@
|
|
1
1
|
require 'krpc/gen'
|
2
|
-
require 'krpc/attributes'
|
3
|
-
require 'krpc/encoder'
|
4
|
-
require 'krpc/types'
|
5
2
|
require 'krpc/doc'
|
6
3
|
require 'krpc/streaming'
|
7
4
|
|
8
5
|
module KRPC
|
9
6
|
module Services
|
10
7
|
class << self
|
11
|
-
|
8
|
+
|
12
9
|
# Generate classes and methods for the service - see documentation for Client#generate_services_api!
|
13
10
|
def create_service(service_msg)
|
14
11
|
service_name = service_msg.name
|
15
|
-
|
12
|
+
|
16
13
|
# Create service class
|
17
14
|
service_class = Class.new(ServiceBase)
|
18
15
|
const_set(service_name, service_class)
|
19
|
-
|
16
|
+
|
20
17
|
# Create service' classes
|
21
|
-
|
22
|
-
TypeStore[
|
18
|
+
class_types_by_name = Hash.new do |h,k|
|
19
|
+
TypeStore[PB::Type.new(code: :CLASS, service: service_name, name: k)]
|
23
20
|
end
|
24
|
-
|
21
|
+
service_msg.classes.map(&:name).each {|cn| class_types_by_name[cn] }
|
22
|
+
|
25
23
|
# Create service' enums
|
26
24
|
service_msg.enumerations.each do |enum|
|
27
|
-
enum_type = TypeStore[
|
25
|
+
enum_type = TypeStore[PB::Type.new(code: :ENUMERATION, service: service_name, name: enum.name)]
|
28
26
|
enum_type.set_values(enum.values)
|
29
27
|
end
|
30
|
-
|
28
|
+
|
31
29
|
# Create service' procedures
|
32
30
|
service_msg.procedures.each do |proc|
|
33
|
-
if
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
Gen.add_rpc_method(class_cls, method_name, service_name, proc, :prepend_self_to_args)
|
40
|
-
else
|
41
|
-
Gen.add_rpc_method(class_cls, method_name + '=', service_name, proc, :prepend_self_to_args, :no_stream)
|
42
|
-
end
|
43
|
-
elsif Attributes.is_a_class_method(proc.attributes) # service' class method
|
44
|
-
Gen.add_rpc_method(class_cls, method_name, service_name, proc, :prepend_self_to_args)
|
45
|
-
else # service' static class method
|
46
|
-
Gen.add_rpc_method(class_cls, method_name, service_name, proc, :static)
|
47
|
-
end
|
48
|
-
elsif Attributes.is_a_property_accessor(proc.attributes) # service' property
|
49
|
-
property_name = Attributes.get_property_name(proc.attributes)
|
50
|
-
if Attributes.is_a_property_getter(proc.attributes)
|
51
|
-
Gen.add_rpc_method(service_class, property_name, service_name, proc)
|
52
|
-
elsif Attributes.is_a_property_setter(proc.attributes)
|
53
|
-
Gen.add_rpc_method(service_class, property_name + '=', service_name, proc, :no_stream)
|
54
|
-
end
|
55
|
-
else # plain procedure = method available to service class and its instance
|
56
|
-
Gen.add_rpc_method(service_class, proc.name, service_name, proc, :static)
|
57
|
-
end
|
31
|
+
cls = if proc.class_member?
|
32
|
+
class_types_by_name[proc.class_name].ruby_type
|
33
|
+
else
|
34
|
+
service_class
|
35
|
+
end
|
36
|
+
Gen.add_rpc_method(cls, service_name, proc)
|
58
37
|
end
|
59
|
-
|
38
|
+
|
60
39
|
# Return service class
|
61
40
|
service_class
|
62
41
|
end
|
63
|
-
|
42
|
+
|
64
43
|
end
|
65
|
-
|
44
|
+
|
66
45
|
##
|
67
46
|
# Base class for service objects, created at runtime using information received from the server.
|
68
47
|
class ServiceBase
|
69
48
|
include Doc::SuffixMethods
|
70
49
|
include Streaming::StreamConstructors
|
71
|
-
|
50
|
+
|
72
51
|
attr_reader :client
|
73
|
-
|
52
|
+
|
74
53
|
def initialize(client)
|
75
54
|
@client = client
|
76
55
|
end
|
77
56
|
end
|
78
|
-
|
57
|
+
|
79
58
|
##
|
80
59
|
# Hardcoded version of `krpc` service - The core kRPC service, e.g. for querying for the available services.
|
81
60
|
class Core < ServiceBase
|
@@ -85,7 +64,7 @@ module KRPC
|
|
85
64
|
super(client)
|
86
65
|
unless respond_to? :get_status
|
87
66
|
# Generate enumerations
|
88
|
-
TypeStore['
|
67
|
+
TypeStore[PB::Type.new(code: :ENUMERATION, service: 'Core', name: 'GameScene')].set_values(
|
89
68
|
Encoder.hash_to_enumeration_values(
|
90
69
|
space_center: 0, flight: 1, tracking_station: 2, editor_vab: 3, editor_sph: 4
|
91
70
|
)
|
@@ -94,33 +73,31 @@ module KRPC
|
|
94
73
|
# Generate procedures
|
95
74
|
opts = {doc_service_name: 'Core'}
|
96
75
|
|
97
|
-
include_rpc_method '
|
98
|
-
return_type:
|
76
|
+
include_rpc_method 'KRPC', 'GetStatus',
|
77
|
+
return_type: PB::Type.new(code: :STATUS),
|
99
78
|
xmldoc: "<doc><summary>Gets a status message from the server containing information including the server’s version string and performance statistics.</summary></doc>",
|
100
|
-
|
101
|
-
include_rpc_method '
|
102
|
-
return_type:
|
103
|
-
xmldoc: "<doc><summary>
|
104
|
-
|
105
|
-
include_rpc_method '
|
106
|
-
params: [PB::Parameter.new(name: '
|
107
|
-
return_type:
|
108
|
-
xmldoc: "<doc><summary>Add a streaming request
|
109
|
-
|
110
|
-
include_rpc_method '
|
111
|
-
params: [PB::Parameter.new(name: 'id', type:
|
112
|
-
xmldoc: "<doc><summary>Remove a streaming request
|
113
|
-
|
114
|
-
include_rpc_method '
|
115
|
-
return_type:
|
116
|
-
attributes: ['Property.Get(Clients)', 'ReturnType.List(Tuple(bytes,string,string))'],
|
79
|
+
**opts
|
80
|
+
include_rpc_method 'KRPC', 'GetServices',
|
81
|
+
return_type: PB::Type.new(code: :SERVICES),
|
82
|
+
xmldoc: "<doc><summary>Returns information on all services, procedures, classes, properties etc. provided by the server.\nCan be used by client libraries to automatically create functionality such as stubs.</summary></doc>",
|
83
|
+
**opts
|
84
|
+
include_rpc_method 'KRPC', 'AddStream',
|
85
|
+
params: [PB::Parameter.new(name: 'call', type: PB::Type.new(code: :PROCEDURE_CALL))],
|
86
|
+
return_type: PB::Type.new(code: :STREAM),
|
87
|
+
xmldoc: "<doc><summary>Add a streaming request and return its identifier.</summary></doc>",
|
88
|
+
**opts
|
89
|
+
include_rpc_method 'KRPC', 'RemoveStream',
|
90
|
+
params: [PB::Parameter.new(name: 'id', type: PB::Type.new(code: :UINT64))],
|
91
|
+
xmldoc: "<doc><summary>Remove a streaming request.</summary></doc>",
|
92
|
+
**opts
|
93
|
+
include_rpc_method 'KRPC', 'get_Clients',
|
94
|
+
return_type: PB::Type.new(code: :LIST, types: [PB::Type.new(code: :TUPLE, types: [PB::Type.new(code: :BYTES), PB::Type.new(code: :STRING), PB::Type.new(code: :STRING)])]),
|
117
95
|
xmldoc: "<doc><summary>A list of RPC clients that are currently connected to the server.\nEach entry in the list is a clients identifier, name and address.</summary></doc>",
|
118
|
-
|
119
|
-
include_rpc_method '
|
120
|
-
return_type: '
|
121
|
-
attributes: ['Property.Get(CurrentGameScene)', 'ReturnType.Enum(Core.GameScene)'],
|
96
|
+
**opts
|
97
|
+
include_rpc_method 'KRPC', 'get_CurrentGameScene',
|
98
|
+
return_type: PB::Type.new(code: :ENUMERATION, service: 'Core', name: 'GameScene'),
|
122
99
|
xmldoc: "<doc><summary>Get the current game scene.</summary></doc>",
|
123
|
-
|
100
|
+
**opts
|
124
101
|
end
|
125
102
|
end
|
126
103
|
end
|