protobuffy 3.6.0 → 4.0.0

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.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +67 -0
  4. data/.rubocop_todo.yml +145 -0
  5. data/.travis.yml +25 -5
  6. data/CHANGES.md +55 -0
  7. data/CONTRIBUTING.md +1 -1
  8. data/LICENSE.txt +17 -9
  9. data/README.md +13 -12
  10. data/Rakefile +15 -11
  11. data/bin/protoc-gen-ruby +8 -3
  12. data/bin/rpc_server +1 -0
  13. data/examples/lib/example/reverse-client.rb +2 -2
  14. data/install-protobuf.sh +28 -0
  15. data/lib/protobuf.rb +57 -53
  16. data/lib/protobuf/cli.rb +94 -74
  17. data/lib/protobuf/code_generator.rb +60 -9
  18. data/lib/protobuf/decoder.rb +19 -65
  19. data/lib/protobuf/deprecation.rb +117 -0
  20. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +11 -1
  21. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +55 -3
  22. data/lib/protobuf/encoder.rb +13 -53
  23. data/lib/protobuf/enum.rb +58 -63
  24. data/lib/protobuf/field.rb +4 -4
  25. data/lib/protobuf/field/base_field.rb +101 -173
  26. data/lib/protobuf/field/bool_field.rb +17 -11
  27. data/lib/protobuf/field/bytes_field.rb +21 -35
  28. data/lib/protobuf/field/double_field.rb +0 -1
  29. data/lib/protobuf/field/enum_field.rb +23 -22
  30. data/lib/protobuf/field/field_array.rb +5 -4
  31. data/lib/protobuf/field/fixed32_field.rb +1 -1
  32. data/lib/protobuf/field/fixed64_field.rb +0 -1
  33. data/lib/protobuf/field/float_field.rb +4 -1
  34. data/lib/protobuf/field/int32_field.rb +0 -1
  35. data/lib/protobuf/field/int64_field.rb +0 -1
  36. data/lib/protobuf/field/integer_field.rb +0 -1
  37. data/lib/protobuf/field/message_field.rb +13 -28
  38. data/lib/protobuf/field/sfixed32_field.rb +0 -1
  39. data/lib/protobuf/field/sfixed64_field.rb +0 -1
  40. data/lib/protobuf/field/signed_integer_field.rb +0 -1
  41. data/lib/protobuf/field/sint32_field.rb +0 -1
  42. data/lib/protobuf/field/sint64_field.rb +0 -1
  43. data/lib/protobuf/field/string_field.rb +2 -4
  44. data/lib/protobuf/field/uint32_field.rb +0 -1
  45. data/lib/protobuf/field/uint64_field.rb +0 -1
  46. data/lib/protobuf/field/varint_field.rb +30 -13
  47. data/lib/protobuf/generators/base.rb +30 -16
  48. data/lib/protobuf/generators/enum_generator.rb +6 -9
  49. data/lib/protobuf/generators/extension_generator.rb +1 -2
  50. data/lib/protobuf/generators/field_generator.rb +25 -13
  51. data/lib/protobuf/generators/file_generator.rb +157 -35
  52. data/lib/protobuf/generators/group_generator.rb +22 -17
  53. data/lib/protobuf/generators/message_generator.rb +13 -14
  54. data/lib/protobuf/generators/option_generator.rb +17 -0
  55. data/lib/protobuf/generators/printable.rb +12 -13
  56. data/lib/protobuf/generators/service_generator.rb +2 -3
  57. data/lib/protobuf/http.rb +2 -2
  58. data/lib/protobuf/lifecycle.rb +20 -33
  59. data/lib/protobuf/logging.rb +39 -0
  60. data/lib/protobuf/message.rb +114 -47
  61. data/lib/protobuf/message/fields.rb +170 -88
  62. data/lib/protobuf/message/serialization.rb +19 -18
  63. data/lib/protobuf/optionable.rb +53 -6
  64. data/lib/protobuf/rpc/buffer.rb +18 -19
  65. data/lib/protobuf/rpc/client.rb +22 -50
  66. data/lib/protobuf/rpc/connectors/base.rb +177 -12
  67. data/lib/protobuf/rpc/connectors/http.rb +14 -9
  68. data/lib/protobuf/rpc/connectors/ping.rb +89 -0
  69. data/lib/protobuf/rpc/connectors/socket.rb +13 -8
  70. data/lib/protobuf/rpc/connectors/zmq.rb +178 -73
  71. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +4 -1
  72. data/lib/protobuf/rpc/env.rb +12 -12
  73. data/lib/protobuf/rpc/error.rb +3 -3
  74. data/lib/protobuf/rpc/error/client_error.rb +4 -4
  75. data/lib/protobuf/rpc/error/server_error.rb +9 -9
  76. data/lib/protobuf/rpc/middleware/exception_handler.rb +6 -2
  77. data/lib/protobuf/rpc/middleware/logger.rb +8 -4
  78. data/lib/protobuf/rpc/middleware/request_decoder.rb +17 -21
  79. data/lib/protobuf/rpc/middleware/response_encoder.rb +22 -27
  80. data/lib/protobuf/rpc/middleware/statsd.rb +3 -3
  81. data/lib/protobuf/rpc/rpc.pb.rb +4 -1
  82. data/lib/protobuf/rpc/server.rb +1 -1
  83. data/lib/protobuf/rpc/servers/http/server.rb +19 -17
  84. data/lib/protobuf/rpc/servers/socket/server.rb +78 -70
  85. data/lib/protobuf/rpc/servers/socket/worker.rb +4 -4
  86. data/lib/protobuf/rpc/servers/socket_runner.rb +27 -15
  87. data/lib/protobuf/rpc/servers/zmq/broker.rb +70 -31
  88. data/lib/protobuf/rpc/servers/zmq/server.rb +55 -47
  89. data/lib/protobuf/rpc/servers/zmq/util.rb +14 -13
  90. data/lib/protobuf/rpc/servers/zmq/worker.rb +16 -16
  91. data/lib/protobuf/rpc/servers/zmq_runner.rb +26 -7
  92. data/lib/protobuf/rpc/service.rb +21 -27
  93. data/lib/protobuf/rpc/service_directory.rb +43 -27
  94. data/lib/protobuf/rpc/service_dispatcher.rb +9 -10
  95. data/lib/protobuf/rpc/service_filters.rb +32 -55
  96. data/lib/protobuf/rpc/stat.rb +4 -8
  97. data/lib/protobuf/socket.rb +1 -2
  98. data/lib/protobuf/tasks/compile.rake +3 -4
  99. data/lib/protobuf/varint.rb +9 -0
  100. data/lib/protobuf/varint_pure.rb +13 -0
  101. data/lib/protobuf/version.rb +1 -1
  102. data/lib/protobuf/zmq.rb +2 -2
  103. data/proto/google/protobuf/descriptor.proto +190 -31
  104. data/protobuffy.gemspec +30 -17
  105. data/spec/benchmark/tasks.rb +27 -19
  106. data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
  107. data/spec/encoding/all_types_spec.rb +96 -84
  108. data/spec/encoding/extreme_values_spec.rb +0 -0
  109. data/spec/functional/class_inheritance_spec.rb +52 -0
  110. data/spec/functional/code_generator_spec.rb +38 -0
  111. data/spec/functional/socket_server_spec.rb +15 -15
  112. data/spec/functional/zmq_server_spec.rb +29 -27
  113. data/spec/lib/protobuf/cli_spec.rb +82 -67
  114. data/spec/lib/protobuf/code_generator_spec.rb +37 -10
  115. data/spec/lib/protobuf/enum_spec.rb +77 -46
  116. data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
  117. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  118. data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
  119. data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
  120. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  121. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  122. data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
  123. data/spec/lib/protobuf/field/int32_field_spec.rb +114 -1
  124. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  125. data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
  126. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  127. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  128. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  129. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  130. data/spec/lib/protobuf/field/string_field_spec.rb +44 -11
  131. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  132. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  133. data/spec/lib/protobuf/field_spec.rb +4 -6
  134. data/spec/lib/protobuf/generators/base_spec.rb +80 -13
  135. data/spec/lib/protobuf/generators/enum_generator_spec.rb +35 -21
  136. data/spec/lib/protobuf/generators/extension_generator_spec.rb +12 -13
  137. data/spec/lib/protobuf/generators/field_generator_spec.rb +73 -21
  138. data/spec/lib/protobuf/generators/file_generator_spec.rb +89 -6
  139. data/spec/lib/protobuf/generators/service_generator_spec.rb +25 -13
  140. data/spec/lib/protobuf/lifecycle_spec.rb +25 -20
  141. data/spec/lib/protobuf/message_spec.rb +578 -79
  142. data/spec/lib/protobuf/optionable_spec.rb +202 -26
  143. data/spec/lib/protobuf/rpc/client_spec.rb +16 -16
  144. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +167 -13
  145. data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +4 -5
  146. data/spec/lib/protobuf/rpc/connectors/http_spec.rb +13 -11
  147. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
  148. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +6 -7
  149. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +35 -52
  150. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +10 -10
  151. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +11 -11
  152. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +23 -23
  153. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +11 -11
  154. data/spec/lib/protobuf/rpc/middleware/statsd_spec.rb +6 -6
  155. data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +47 -44
  156. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +6 -6
  157. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +12 -10
  158. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +11 -11
  159. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -7
  160. data/spec/lib/protobuf/rpc/service_directory_spec.rb +47 -49
  161. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +8 -25
  162. data/spec/lib/protobuf/rpc/service_filters_spec.rb +102 -69
  163. data/spec/lib/protobuf/rpc/service_spec.rb +37 -36
  164. data/spec/lib/protobuf/rpc/stat_spec.rb +7 -9
  165. data/spec/lib/protobuf/varint_spec.rb +29 -0
  166. data/spec/lib/protobuf_spec.rb +55 -28
  167. data/spec/spec_helper.rb +12 -27
  168. data/spec/support/all.rb +0 -1
  169. data/spec/support/packed_field.rb +4 -3
  170. data/spec/support/{test → protos}/all_types.data.bin +0 -0
  171. data/spec/support/{test → protos}/all_types.data.txt +0 -0
  172. data/spec/support/{test → protos}/enum.pb.rb +8 -4
  173. data/spec/support/{test → protos}/enum.proto +4 -1
  174. data/spec/support/{test → protos}/extreme_values.data.bin +0 -0
  175. data/spec/support/protos/google_unittest.bin +0 -0
  176. data/spec/support/protos/google_unittest.pb.rb +798 -0
  177. data/spec/support/{test → protos}/google_unittest.proto +237 -66
  178. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  179. data/spec/support/protos/google_unittest_custom_options.pb.rb +268 -0
  180. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  181. data/spec/support/protos/google_unittest_import.pb.rb +55 -0
  182. data/spec/support/{test → protos}/google_unittest_import.proto +19 -10
  183. data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
  184. data/spec/support/{test → protos}/google_unittest_import_public.proto +8 -5
  185. data/spec/support/{test → protos}/multi_field_extensions.pb.rb +5 -2
  186. data/spec/support/{test → protos}/multi_field_extensions.proto +2 -0
  187. data/spec/support/{test → protos}/resource.pb.rb +47 -11
  188. data/spec/support/{test → protos}/resource.proto +24 -1
  189. data/spec/support/resource_service.rb +23 -0
  190. data/spec/support/server.rb +32 -61
  191. metadata +119 -59
  192. data/lib/protobuf/deprecator.rb +0 -42
  193. data/lib/protobuf/logger.rb +0 -93
  194. data/lib/protobuf/rpc/connector.rb +0 -21
  195. data/lib/protobuf/rpc/connectors/common.rb +0 -172
  196. data/spec/data/data.bin +0 -3
  197. data/spec/data/types.bin +0 -0
  198. data/spec/lib/protobuf/logger_spec.rb +0 -145
  199. data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
  200. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
  201. data/spec/support/test/defaults.pb.rb +0 -25
  202. data/spec/support/test/defaults.proto +0 -9
  203. data/spec/support/test/extended.pb.rb +0 -22
  204. data/spec/support/test/extended.proto +0 -10
  205. data/spec/support/test/google_unittest.pb.rb +0 -543
  206. data/spec/support/test/google_unittest_import.pb.rb +0 -37
  207. data/spec/support/test/google_unittest_import_public.pb.rb +0 -8
  208. data/spec/support/test/resource_service.rb +0 -26
  209. data/spec/support/tolerance_matcher.rb +0 -40
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # This file is auto-generated. DO NOT EDIT!
5
+ #
6
+ require 'protobuf'
7
+
8
+
9
+ ##
10
+ # Imports
11
+ #
12
+ require 'protos/google_unittest_import_public.pb'
13
+
14
+ module Protobuf_unittest_import
15
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
16
+
17
+ ##
18
+ # Enum Classes
19
+ #
20
+ class ImportEnum < ::Protobuf::Enum
21
+ define :IMPORT_FOO, 7
22
+ define :IMPORT_BAR, 8
23
+ define :IMPORT_BAZ, 9
24
+ end
25
+
26
+ class ImportEnumForMap < ::Protobuf::Enum
27
+ define :UNKNOWN, 0
28
+ define :FOO, 1
29
+ define :BAR, 2
30
+ end
31
+
32
+
33
+ ##
34
+ # Message Classes
35
+ #
36
+ class ImportMessage < ::Protobuf::Message; end
37
+
38
+
39
+ ##
40
+ # File Options
41
+ #
42
+ set_option :java_package, "com.google.protobuf.test"
43
+ set_option :optimize_for, ::Google::Protobuf::FileOptions::OptimizeMode::SPEED
44
+ set_option :cc_enable_arenas, true
45
+
46
+
47
+ ##
48
+ # Message Fields
49
+ #
50
+ class ImportMessage
51
+ optional :int32, :d, 1
52
+ end
53
+
54
+ end
55
+
@@ -1,6 +1,6 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
3
+ // https://developers.google.com/protocol-buffers/
4
4
  //
5
5
  // Redistribution and use in source and binary forms, with or without
6
6
  // modification, are permitted provided that the following conditions are
@@ -34,23 +34,25 @@
34
34
  //
35
35
  // A proto file which is imported by unittest.proto to test importing.
36
36
 
37
+ syntax = "proto2";
37
38
 
38
39
  // We don't put this in a package within proto2 because we need to make sure
39
40
  // that the generated code doesn't depend on being in the proto2 namespace.
40
41
  // In test_util.h we do
41
42
  // "using namespace unittest_import = protobuf_unittest_import".
42
- package googleUnittestImport;
43
+ package protobuf_unittest_import;
43
44
 
44
- //############################## Test public import
45
- // TODO: This will be supported in the next release of the
46
- // compiler
47
- // import public "test/google_unittest_import_public.proto";
45
+ option optimize_for = SPEED;
46
+ option cc_enable_arenas = true;
48
47
 
49
- message PublicImportMessage {
50
- optional int32 e = 1;
51
- }
48
+ // Exercise the java_package option.
49
+ option java_package = "com.google.protobuf.test";
50
+
51
+ // Do not set a java_outer_classname here to verify that Proto2 works without
52
+ // one.
52
53
 
53
- //###############################
54
+ // Test public import
55
+ import public "protos/google_unittest_import_public.proto";
54
56
 
55
57
  message ImportMessage {
56
58
  optional int32 d = 1;
@@ -62,3 +64,10 @@ enum ImportEnum {
62
64
  IMPORT_BAZ = 9;
63
65
  }
64
66
 
67
+
68
+ // To use an enum in a map, it must has the first value as 0.
69
+ enum ImportEnumForMap {
70
+ UNKNOWN = 0;
71
+ FOO = 1;
72
+ BAR = 2;
73
+ }
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # This file is auto-generated. DO NOT EDIT!
5
+ #
6
+ require 'protobuf'
7
+
8
+ module Protobuf_unittest_import
9
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
10
+
11
+ ##
12
+ # Message Classes
13
+ #
14
+ class PublicImportMessage < ::Protobuf::Message; end
15
+
16
+
17
+ ##
18
+ # File Options
19
+ #
20
+ set_option :java_package, "com.google.protobuf.test"
21
+
22
+
23
+ ##
24
+ # Message Fields
25
+ #
26
+ class PublicImportMessage
27
+ optional :int32, :e, 1
28
+ end
29
+
30
+ end
31
+
@@ -1,6 +1,6 @@
1
1
  // Protocol Buffers - Google's data interchange format
2
2
  // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
3
+ // https://developers.google.com/protocol-buffers/
4
4
  //
5
5
  // Redistribution and use in source and binary forms, with or without
6
6
  // modification, are permitted provided that the following conditions are
@@ -30,9 +30,12 @@
30
30
 
31
31
  // Author: liujisi@google.com (Pherl Liu)
32
32
 
33
+ syntax = "proto2";
33
34
 
34
- package googleUnittestImport;
35
+ package protobuf_unittest_import;
35
36
 
36
- //message PublicImportMessage {
37
- // optional int32 e = 1;
38
- //}
37
+ option java_package = "com.google.protobuf.test";
38
+
39
+ message PublicImportMessage {
40
+ optional int32 e = 1;
41
+ }
@@ -1,9 +1,12 @@
1
+ # encoding: utf-8
2
+
1
3
  ##
2
4
  # This file is auto-generated. DO NOT EDIT!
3
5
  #
4
- require 'protobuf/message'
6
+ require 'protobuf'
5
7
 
6
8
  module Test
9
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
7
10
 
8
11
  ##
9
12
  # Message Classes
@@ -35,7 +38,7 @@ module Test
35
38
  required ::Test::Header::Type, :type, 1
36
39
  # Extension Fields
37
40
  extensions 100...536870912
38
- optional ::Test::PayloadA, :payload, 100, :extension => true
41
+ optional ::Test::PayloadA, :".test.PayloadA.payload", 100, :extension => true
39
42
  end
40
43
 
41
44
  class PayloadA
@@ -1,3 +1,5 @@
1
+ syntax = "proto2";
2
+
1
3
  package test;
2
4
 
3
5
  message Header {
@@ -1,19 +1,32 @@
1
+ # encoding: utf-8
2
+
1
3
  ##
2
4
  # This file is auto-generated. DO NOT EDIT!
3
5
  #
4
- require 'protobuf/message'
6
+ require 'protobuf'
5
7
  require 'protobuf/rpc/service'
6
8
 
9
+
10
+ ##
11
+ # Imports
12
+ #
13
+ require 'google/protobuf/descriptor.pb'
14
+
7
15
  module Test
16
+ ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
8
17
 
9
18
  ##
10
19
  # Enum Classes
11
20
  #
12
21
  class StatusType < ::Protobuf::Enum
22
+ set_option :allow_alias, true
23
+ set_option :".test.enum_option", -789
24
+
13
25
  define :PENDING, 0
14
26
  define :ENABLED, 1
15
27
  define :DISABLED, 2
16
28
  define :DELETED, 3
29
+ define :ALIASED, 3
17
30
  end
18
31
 
19
32
 
@@ -44,6 +57,13 @@ module Test
44
57
 
45
58
 
46
59
 
60
+ ##
61
+ # File Options
62
+ #
63
+ set_option :cc_generic_services, true
64
+ set_option :".test.file_option", 9876543210
65
+
66
+
47
67
  ##
48
68
  # Message Fields
49
69
  #
@@ -59,17 +79,17 @@ module Test
59
79
  end
60
80
 
61
81
  class Resource
62
- required :string, :name, 1
82
+ required :string, :name, 1, :ctype => ::Google::Protobuf::FieldOptions::CType::CORD, :".test.field_option" => 8765432109
63
83
  optional :int64, :date_created, 2
64
84
  optional ::Test::StatusType, :status, 3
65
85
  repeated ::Test::StatusType, :repeated_enum, 4
66
86
  # Extension Fields
67
87
  extensions 100...536870912
68
- optional :bool, :ext_is_searchable, 100, :extension => true
69
- optional :bool, :ext_is_hidden, 101, :extension => true
70
- optional ::Test::Searchable::SearchType, :ext_search_type, 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true
71
- optional :bool, :ext_nested_in_level_one, 105, :extension => true
72
- optional :bool, :ext_dup_field, 106, :extension => true
88
+ optional :bool, :".test.Searchable.ext_is_searchable", 100, :extension => true
89
+ optional :bool, :".test.Searchable.ext_is_hidden", 101, :extension => true
90
+ optional ::Test::Searchable::SearchType, :".test.Searchable.ext_search_type", 102, :default => ::Test::Searchable::SearchType::FLAT, :extension => true
91
+ optional :bool, :".test.Nested.NestedLevelOne.ext_nested_in_level_one", 105, :extension => true
92
+ optional :bool, :".test.Nested.NestedLevelOne.ext_dup_field", 106, :extension => true
73
93
  end
74
94
 
75
95
  class ResourceWithRequiredField
@@ -88,8 +108,8 @@ module Test
88
108
  optional :bool, :level_one, 1, :default => true
89
109
  # Extension Fields
90
110
  extensions 100...102
91
- optional :bool, :ext_nested_level_one_outer, 101, :extension => true
92
- optional :bool, :ext_nested_level_one, 100, :extension => true
111
+ optional :bool, :".test.ext_nested_level_one_outer", 101, :extension => true
112
+ optional :bool, :".test.Nested.ext_nested_level_one", 100, :extension => true
93
113
  end
94
114
 
95
115
  optional :string, :name, 1
@@ -98,8 +118,24 @@ module Test
98
118
  optional ::Test::StatusType, :status, 4
99
119
  # Extension Fields
100
120
  extensions 100...111
101
- optional :string, :foo, 100, :extension => true
102
- optional :int64, :bar, 101, :extension => true
121
+ optional :string, :".test.foo", 100, :extension => true
122
+ optional :int64, :".test.bar", 101, :extension => true
123
+ end
124
+
125
+
126
+ ##
127
+ # Extended Message Fields
128
+ #
129
+ class ::Google::Protobuf::FileOptions < ::Protobuf::Message
130
+ optional :uint64, :".test.file_option", 9585869, :extension => true
131
+ end
132
+
133
+ class ::Google::Protobuf::FieldOptions < ::Protobuf::Message
134
+ optional :uint64, :".test.field_option", 858769, :extension => true
135
+ end
136
+
137
+ class ::Google::Protobuf::EnumOptions < ::Protobuf::Message
138
+ optional :int64, :".test.enum_option", 590284, :extension => true
103
139
  end
104
140
 
105
141
 
@@ -1,10 +1,33 @@
1
+ syntax = "proto2";
2
+
3
+ import "google/protobuf/descriptor.proto";
4
+
1
5
  package test;
2
6
 
7
+ option cc_generic_services = true;
8
+ option (file_option) = 9876543210;
9
+
10
+ extend google.protobuf.FileOptions {
11
+ optional uint64 file_option = 9585869;
12
+ }
13
+
14
+ extend google.protobuf.FieldOptions {
15
+ optional uint64 field_option = 858769;
16
+ }
17
+
18
+ extend google.protobuf.EnumOptions {
19
+ optional int64 enum_option = 590284;
20
+ }
21
+
3
22
  enum StatusType {
23
+ option allow_alias = true;
24
+ option (enum_option) = -789;
25
+
4
26
  PENDING = 0;
5
27
  ENABLED = 1;
6
28
  DISABLED = 2;
7
29
  DELETED = 3;
30
+ ALIASED = 3;
8
31
  }
9
32
 
10
33
  message ResourceFindRequest {
@@ -21,7 +44,7 @@ message ResourceSleepRequest {
21
44
  message Resource {
22
45
  extensions 100 to max;
23
46
 
24
- required string name = 1;
47
+ required string name = 1 [(field_option) = 8765432109, ctype = CORD];
25
48
  optional int64 date_created = 2;
26
49
  optional StatusType status = 3;
27
50
  repeated StatusType repeated_enum = 4;
@@ -0,0 +1,23 @@
1
+ require PROTOS_PATH.join('resource.pb')
2
+
3
+ Test::ResourceService.class_eval do
4
+ # request -> Test::ResourceFindRequest
5
+ # response -> Test::Resource
6
+ def find
7
+ response.name = request.name
8
+ response.status = request.active ? 1 : 0
9
+ end
10
+
11
+ # request -> Test::ResourceSleepRequest
12
+ # response -> Test::Resource
13
+ def find_with_sleep
14
+ sleep(request.sleep || 1)
15
+ response.name = 'Request should have timed out'
16
+ end
17
+
18
+ # request -> Test::ResourceFindRequest
19
+ # response -> Test::Resource
20
+ def find_with_rpc_failed
21
+ rpc_failed('Find failed')
22
+ end
23
+ end
@@ -1,91 +1,62 @@
1
1
  require 'ostruct'
2
- require 'protobuf/logger'
2
+
3
+ require 'active_support/core_ext/hash/reverse_merge'
4
+
5
+ require 'spec_helper'
6
+ require 'protobuf/logging'
3
7
  require 'protobuf/rpc/server'
4
8
  require 'protobuf/rpc/servers/socket/server'
5
9
  require 'protobuf/rpc/servers/socket_runner'
6
10
  require 'protobuf/rpc/servers/zmq/server'
7
11
  require 'protobuf/rpc/servers/zmq_runner'
8
- require 'spec/support/test/resource_service'
12
+ require SUPPORT_PATH.join('resource_service')
9
13
 
10
14
  # Want to abort if server dies?
11
15
  Thread.abort_on_exception = true
12
16
 
13
- module StubProtobufServerFactory
14
- def self.build(delay)
15
- new_server = Class.new(Protobuf::Rpc::Socket::Server) do
16
- def self.sleep_interval
17
- @sleep_interval
18
- end
17
+ class StubServer
18
+ include Protobuf::Logging
19
19
 
20
- def self.sleep_interval=(si)
21
- @sleep_interval = si
22
- end
20
+ private
23
21
 
24
- def post_init
25
- sleep self.class.sleep_interval
26
- super
27
- end
28
- end
22
+ attr_accessor :options, :runner, :runner_thread
29
23
 
30
- new_server.sleep_interval = delay
31
- return new_server
32
- end
33
- end
34
-
35
- class StubServer
36
- include Protobuf::Logger::LogMethods
37
-
38
- attr_accessor :options
24
+ public
39
25
 
40
26
  def initialize(options = {})
41
- @running = true
42
- @options = OpenStruct.new({ :host => "127.0.0.1",
43
- :port => 9399,
44
- :worker_port => 9400,
45
- :delay => 0,
46
- :server => Protobuf::Rpc::Socket::Server }.merge(options))
27
+ self.options = OpenStruct.new(
28
+ options.reverse_merge(
29
+ :host => '127.0.0.1',
30
+ :port => 9399,
31
+ :worker_port => 9400,
32
+ :delay => 0,
33
+ :server => Protobuf::Rpc::Socket::Server
34
+ )
35
+ )
47
36
 
48
37
  start
49
38
  yield self
50
39
  ensure
51
- stop if @running
40
+ stop
52
41
  end
53
42
 
54
43
  def start
55
- case
56
- when @options.server == Protobuf::Rpc::Zmq::Server
57
- start_zmq_server
58
- else
59
- start_socket_server
60
- end
61
- log_debug { sign_message("Server started #{@options.host}:#{@options.port}") }
62
- end
44
+ runner_class = {
45
+ ::Protobuf::Rpc::Zmq::Server => ::Protobuf::Rpc::ZmqRunner,
46
+ ::Protobuf::Rpc::Socket::Server => ::Protobuf::Rpc::SocketRunner,
47
+ }.fetch(options.server)
63
48
 
64
- def start_socket_server
65
- @sock_runner = ::Protobuf::Rpc::SocketRunner.new(options)
66
- @sock_thread = Thread.new(@sock_runner) { |runner| runner.run }
67
- @sock_thread.abort_on_exception = true # Set for testing purposes
68
- Thread.pass until @sock_runner.running?
69
- end
49
+ self.runner = runner_class.new(options)
50
+ self.runner_thread = Thread.new(runner, &:run)
51
+ runner_thread.abort_on_exception = true # Set for testing purposes
52
+ Thread.pass until runner.running?
70
53
 
71
- def start_zmq_server
72
- @zmq_runner = ::Protobuf::Rpc::ZmqRunner.new(options)
73
- @zmq_thread = Thread.new(@zmq_runner) { |runner| runner.run }
74
- @zmq_thread.abort_on_exception = true # Set for testing purposes
75
- Thread.pass until @zmq_runner.running?
54
+ logger.debug { sign_message("Server started #{options.host}:#{options.port}") }
76
55
  end
77
56
 
78
57
  def stop
79
- case
80
- when @options.server == Protobuf::Rpc::Zmq::Server then
81
- @zmq_runner.try :stop
82
- @zmq_thread.join if @zmq_thread
83
- else
84
- @sock_runner.stop
85
- @sock_thread.join if @sock_thread
86
- end
87
-
88
- @running = false
58
+ runner.stop
59
+ runner_thread.join
89
60
  end
90
61
 
91
62
  def log_signature