ruby_protobuf 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -1
- data/VERSION +1 -1
- data/bin/rprotoc +2 -0
- data/lib/protobuf/common/util.rb +6 -0
- data/lib/protobuf/message/enum.rb +1 -1
- data/lib/protobuf/message/field.rb +1 -4
- data/test/proto/address_book_service.rb +31 -0
- data/test/proto/client_add.rb +18 -0
- data/test/proto/client_search.rb +18 -0
- data/test/proto/float_default.pb.rb +28 -0
- data/test/proto/rpc.pb.rb +16 -0
- data/test/test_serialize.rb +7 -0
- metadata +29 -24
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.5
|
data/bin/rprotoc
CHANGED
@@ -21,6 +21,8 @@ opts.on('-o', '--out <OUT_DIR>', 'Specify the directory in which Ruby source fil
|
|
21
21
|
opts.on_tail('-v', '--version', 'Show version.'){ puts(opts.ver); exit }
|
22
22
|
opts.on_tail('-h', '--help', 'Show this message.'){ puts(opts.help); exit }
|
23
23
|
|
24
|
+
Version = Protobuf::Version
|
25
|
+
|
24
26
|
begin
|
25
27
|
opts.order!
|
26
28
|
rescue OptionParser::ParseError
|
data/lib/protobuf/common/util.rb
CHANGED
@@ -345,11 +345,8 @@ module Protobuf
|
|
345
345
|
def encode(value)
|
346
346
|
if value.respond_to?(:force_encoding)
|
347
347
|
# Ruby 1.9
|
348
|
-
old_encoding = value.encoding
|
349
348
|
result = VarintField.encode(value.bytesize)
|
350
|
-
result << value.force_encoding(Encoding::ASCII_8BIT)
|
351
|
-
value.force_encoding(old_encoding)
|
352
|
-
result
|
349
|
+
result << value.dup.force_encoding(Encoding::ASCII_8BIT)
|
353
350
|
else
|
354
351
|
# Ruby 1.8
|
355
352
|
result = VarintField.encode(value.size)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'protobuf/rpc/server'
|
2
|
+
require 'protobuf/rpc/handler'
|
3
|
+
require 'test/proto/rpc.pb'
|
4
|
+
|
5
|
+
class Tutorial::SearchHandler < Protobuf::Rpc::Handler
|
6
|
+
request Tutorial::Person
|
7
|
+
response Tutorial::AddressBook
|
8
|
+
|
9
|
+
def self.process_request(request, response)
|
10
|
+
# TODO: edit this method
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Tutorial::AddHandler < Protobuf::Rpc::Handler
|
15
|
+
request Tutorial::Person
|
16
|
+
response Tutorial::Person
|
17
|
+
|
18
|
+
def self.process_request(request, response)
|
19
|
+
# TODO: edit this method
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Tutorial::AddressBookService < Protobuf::Rpc::Server
|
24
|
+
def setup_handlers
|
25
|
+
@handlers = {
|
26
|
+
:search => Tutorial::SearchHandler,
|
27
|
+
:add => Tutorial::AddHandler,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'protobuf/rpc/client'
|
3
|
+
require 'test/proto/rpc.pb'
|
4
|
+
|
5
|
+
# build request
|
6
|
+
request = Tutorial::Person.new
|
7
|
+
# TODO: setup a request
|
8
|
+
raise StandardError, 'setup a request'
|
9
|
+
|
10
|
+
# create blunk response
|
11
|
+
response = Tutorial::Person.new
|
12
|
+
|
13
|
+
# execute rpc
|
14
|
+
Protobuf::Rpc::Client.new('localhost', 9999).call :add, request, response
|
15
|
+
|
16
|
+
# show response
|
17
|
+
puts response
|
18
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'protobuf/rpc/client'
|
3
|
+
require 'test/proto/rpc.pb'
|
4
|
+
|
5
|
+
# build request
|
6
|
+
request = Tutorial::Person.new
|
7
|
+
# TODO: setup a request
|
8
|
+
raise StandardError, 'setup a request'
|
9
|
+
|
10
|
+
# create blunk response
|
11
|
+
response = Tutorial::AddressBook.new
|
12
|
+
|
13
|
+
# execute rpc
|
14
|
+
Protobuf::Rpc::Client.new('localhost', 9999).call :search, request, response
|
15
|
+
|
16
|
+
# show response
|
17
|
+
puts response
|
18
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
### Generated by rprotoc. DO NOT EDIT!
|
2
|
+
### <proto file: test/proto/float_default.proto>
|
3
|
+
# message M {
|
4
|
+
# optional float f = 1 [default = 4.2];
|
5
|
+
# optional float g = 2 [default = -4.2];
|
6
|
+
# optional float h = 3 [default = 4352];
|
7
|
+
# optional float i = 4 [default = 23145.2 ];
|
8
|
+
# optional float j = 5 [default = -5 ];
|
9
|
+
# optional float k = 6 [default = +23 ];
|
10
|
+
# optional float l = 7 [default = +23.42 ];
|
11
|
+
# }
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'protobuf/message/message'
|
15
|
+
require 'protobuf/message/enum'
|
16
|
+
require 'protobuf/message/service'
|
17
|
+
require 'protobuf/message/extend'
|
18
|
+
|
19
|
+
class M < ::Protobuf::Message
|
20
|
+
defined_in __FILE__
|
21
|
+
optional :float, :f, 1, :default => 4.2
|
22
|
+
optional :float, :g, 2, :default => -4.2
|
23
|
+
optional :float, :h, 3, :default => 4352
|
24
|
+
optional :float, :i, 4, :default => 23145.2
|
25
|
+
optional :float, :j, 5, :default => -5
|
26
|
+
optional :float, :k, 6, :default => 23
|
27
|
+
optional :float, :l, 7, :default => 23.42
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
### Generated by rprotoc. DO NOT EDIT!
|
2
|
+
### <proto file: test/proto/rpc.proto>
|
3
|
+
# package tutorial;
|
4
|
+
#
|
5
|
+
# service AddressBookService {
|
6
|
+
# rpc Search (Person) returns (AddressBook);
|
7
|
+
# rpc Add (Person) returns (Person);
|
8
|
+
# }
|
9
|
+
|
10
|
+
require 'protobuf/message/message'
|
11
|
+
require 'protobuf/message/enum'
|
12
|
+
require 'protobuf/message/service'
|
13
|
+
require 'protobuf/message/extend'
|
14
|
+
|
15
|
+
module Tutorial
|
16
|
+
end
|
data/test/test_serialize.rb
CHANGED
@@ -40,6 +40,13 @@ class SerializeTest < Test::Unit::TestCase
|
|
40
40
|
assert_equal('山田 太郎', person2.name)
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_frozen_string
|
44
|
+
person = Tutorial::Person.new
|
45
|
+
person.id = 1234
|
46
|
+
person.name = 'a b c'.freeze
|
47
|
+
assert_nothing_raised { serialized_string = person.serialize_to_string }
|
48
|
+
end
|
49
|
+
|
43
50
|
def test_unknown_field
|
44
51
|
person = Tutorial::Person.new
|
45
52
|
person.id = 1234
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 5
|
9
|
+
version: 0.4.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- MATSUYAMA Kengo
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-17 00:00:00 +09:00
|
18
18
|
default_executable: rprotoc
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -147,33 +147,38 @@ signing_key:
|
|
147
147
|
specification_version: 3
|
148
148
|
summary: Protocol Buffers for Ruby
|
149
149
|
test_files:
|
150
|
-
- test/check_unbuild.rb
|
151
|
-
- test/test_descriptor.rb
|
152
|
-
- test/test_optional_field.rb
|
153
|
-
- test/proto/merge.pb.rb
|
154
|
-
- test/proto/ext_collision.pb.rb
|
155
|
-
- test/proto/lowercase.pb.rb
|
156
|
-
- test/proto/addressbook_base.pb.rb
|
157
150
|
- test/proto/packed.pb.rb
|
158
|
-
- test/proto/
|
151
|
+
- test/proto/types.pb.rb
|
159
152
|
- test/proto/addressbook.pb.rb
|
160
|
-
- test/proto/addressbook_ext.pb.rb
|
161
|
-
- test/proto/nested.pb.rb
|
162
153
|
- test/proto/ext_range.pb.rb
|
163
|
-
- test/proto/
|
154
|
+
- test/proto/nested.pb.rb
|
155
|
+
- test/proto/client_search.rb
|
156
|
+
- test/proto/addressbook_base.pb.rb
|
157
|
+
- test/proto/rpc.pb.rb
|
158
|
+
- test/proto/address_book_service.rb
|
164
159
|
- test/proto/collision.pb.rb
|
165
|
-
- test/
|
166
|
-
- test/
|
167
|
-
- test/
|
168
|
-
- test/
|
169
|
-
- test/
|
170
|
-
- test/
|
171
|
-
- test/
|
172
|
-
- test/test_lowercase.rb
|
160
|
+
- test/proto/optional_field.pb.rb
|
161
|
+
- test/proto/merge.pb.rb
|
162
|
+
- test/proto/addressbook_ext.pb.rb
|
163
|
+
- test/proto/client_add.rb
|
164
|
+
- test/proto/float_default.pb.rb
|
165
|
+
- test/proto/lowercase.pb.rb
|
166
|
+
- test/proto/ext_collision.pb.rb
|
173
167
|
- test/test_compiler.rb
|
174
|
-
- test/test_message.rb
|
175
168
|
- test/test_parse.rb
|
176
169
|
- test/test_addressbook.rb
|
170
|
+
- test/test_extension.rb
|
171
|
+
- test/test_lowercase.rb
|
172
|
+
- test/test_standard_message.rb
|
173
|
+
- test/test_enum_value.rb
|
174
|
+
- test/test_message.rb
|
175
|
+
- test/test_types.rb
|
176
|
+
- test/test_repeated_types.rb
|
177
|
+
- test/test_descriptor.rb
|
178
|
+
- test/test_optional_field.rb
|
179
|
+
- test/test_packed_field.rb
|
180
|
+
- test/test_serialize.rb
|
181
|
+
- test/check_unbuild.rb
|
182
|
+
- examples/addressbook.pb.rb
|
177
183
|
- examples/writing_a_message.rb
|
178
184
|
- examples/reading_a_message.rb
|
179
|
-
- examples/addressbook.pb.rb
|