ruby-protocol-buffers 1.2.3.beta1 → 1.2.3.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/protocol_buffers/runtime/field.rb +9 -13
- data/lib/protocol_buffers/runtime/message.rb +7 -2
- data/spec/fields_spec.rb +16 -4
- data/spec/proto_files/simple.proto +5 -0
- data/spec/runtime_spec.rb +9 -0
- metadata +39 -13
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.3.
|
1
|
+
1.2.3.beta2
|
@@ -290,22 +290,18 @@ module ProtocolBuffers
|
|
290
290
|
end
|
291
291
|
|
292
292
|
class StringField < BytesField
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
293
|
+
HAS_ENCODING = (''.respond_to?(:valid_encoding?) && ''.respond_to?(:force_encoding))
|
294
|
+
|
295
|
+
def check_value(value)
|
296
|
+
if HAS_ENCODING
|
297
|
+
value.valid_encoding? || raise(ArgumentError, "string value is not valid utf-8")
|
298
|
+
end
|
299
|
+
end
|
300
300
|
|
301
301
|
def deserialize(value)
|
302
|
-
# To get bytes, the value was being read as ASCII. Ruby 1.9 stores an encoding
|
303
|
-
# with its strings, and they were getting returned with Encoding ASCII-8BIT.
|
304
|
-
# Protobuffers are supposed to only return UTF-8 strings. This attempts to
|
305
|
-
# force the encoding to UTF-8 if on Ruby 1.9 (force_encoding is defined on String).
|
306
302
|
read_value = value.read.to_s
|
307
|
-
if
|
308
|
-
read_value.force_encoding("
|
303
|
+
if HAS_ENCODING
|
304
|
+
read_value.force_encoding("utf-8")
|
309
305
|
end
|
310
306
|
read_value
|
311
307
|
end
|
@@ -209,7 +209,7 @@ module ProtocolBuffers
|
|
209
209
|
# module Foo
|
210
210
|
# VALUE_A = 1
|
211
211
|
# VALUE_B = 5
|
212
|
-
# VALUE_C 1234
|
212
|
+
# VALUE_C = 1234
|
213
213
|
# end
|
214
214
|
#
|
215
215
|
# An exception will be thrown if an enum field is assigned a value not in the
|
@@ -387,7 +387,12 @@ module ProtocolBuffers
|
|
387
387
|
ret = ProtocolBuffers.bin_sio
|
388
388
|
ret << "#<#{self.class.name}"
|
389
389
|
fields.each do |tag, field|
|
390
|
-
|
390
|
+
if value_for_tag?(tag)
|
391
|
+
value = field.inspect_value(self.__send__(field.name))
|
392
|
+
else
|
393
|
+
value = "<unset>"
|
394
|
+
end
|
395
|
+
ret << " #{field.name}=#{value}"
|
391
396
|
end
|
392
397
|
ret << ">"
|
393
398
|
return ret.string
|
data/spec/fields_spec.rb
CHANGED
@@ -37,12 +37,24 @@ describe ProtocolBuffers, "fields" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "verifies UTF-8 for string fields" do
|
40
|
-
|
40
|
+
if RUBY_VERSION < "1.9"
|
41
|
+
pending "UTF-8 validation only happens in ruby 1.9+"
|
42
|
+
else
|
43
|
+
good = proc { StringIO.new("hello") }
|
44
|
+
bad = proc { StringIO.new("\xff\xff") }
|
45
|
+
|
41
46
|
s1 = mkfield(:StringField)
|
42
|
-
|
43
|
-
|
47
|
+
s1.deserialize(good[]).should == "hello"
|
48
|
+
s1.deserialize(good[]).encoding.should == Encoding.find('utf-8')
|
49
|
+
proc { s1.check_valid(s1.deserialize(good[])) }.should_not raise_error()
|
50
|
+
s1.deserialize(bad[]).encoding.should == Encoding.find('utf-8')
|
51
|
+
proc { s1.check_valid(s1.deserialize(bad[])) }.should raise_error(ArgumentError)
|
52
|
+
|
44
53
|
b1 = mkfield(:BytesField)
|
45
|
-
|
54
|
+
b1.deserialize(good[]).should == "hello"
|
55
|
+
b1.deserialize(good[]).encoding.should == Encoding.find("us-ascii")
|
56
|
+
b1.deserialize(bad[]).encoding.should == Encoding.find("binary")
|
57
|
+
proc { b1.check_valid(b1.deserialize(bad[])) }.should_not raise_error()
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
data/spec/runtime_spec.rb
CHANGED
@@ -65,6 +65,15 @@ describe ProtocolBuffers, "runtime" do
|
|
65
65
|
a1.has_sub2?.should == true
|
66
66
|
end
|
67
67
|
|
68
|
+
describe "#inspect" do
|
69
|
+
it "should leave out un-set fields" do
|
70
|
+
b1 = Simple::Bar.new
|
71
|
+
b1.inspect.should == "#<Simple::Bar foo=<unset>>"
|
72
|
+
b1.foo = Simple::Foo.new
|
73
|
+
b1.inspect.should == "#<Simple::Bar foo=#<Simple::Foo>>"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
68
77
|
it "detects changes to a sub-message and flags it as set if it wasn't" do
|
69
78
|
a1 = Featureful::A.new
|
70
79
|
a1.has_sub2?.should == false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-protocol-buffers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.3.
|
4
|
+
version: 1.2.3.beta2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,15 @@ dependencies:
|
|
23
23
|
version: '2.5'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '2.5'
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
33
|
name: autotest-standalone
|
29
|
-
requirement:
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
30
35
|
none: false
|
31
36
|
requirements:
|
32
37
|
- - ! '>='
|
@@ -34,10 +39,15 @@ dependencies:
|
|
34
39
|
version: '0'
|
35
40
|
type: :development
|
36
41
|
prerelease: false
|
37
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
38
48
|
- !ruby/object:Gem::Dependency
|
39
49
|
name: autotest-growl
|
40
|
-
requirement:
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
41
51
|
none: false
|
42
52
|
requirements:
|
43
53
|
- - ! '>='
|
@@ -45,10 +55,15 @@ dependencies:
|
|
45
55
|
version: '0'
|
46
56
|
type: :development
|
47
57
|
prerelease: false
|
48
|
-
version_requirements:
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
49
64
|
- !ruby/object:Gem::Dependency
|
50
65
|
name: rcov
|
51
|
-
requirement:
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
52
67
|
none: false
|
53
68
|
requirements:
|
54
69
|
- - ! '>='
|
@@ -56,10 +71,15 @@ dependencies:
|
|
56
71
|
version: '0'
|
57
72
|
type: :development
|
58
73
|
prerelease: false
|
59
|
-
version_requirements:
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
60
80
|
- !ruby/object:Gem::Dependency
|
61
81
|
name: yard
|
62
|
-
requirement:
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
63
83
|
none: false
|
64
84
|
requirements:
|
65
85
|
- - ! '>='
|
@@ -67,7 +87,12 @@ dependencies:
|
|
67
87
|
version: '0'
|
68
88
|
type: :development
|
69
89
|
prerelease: false
|
70
|
-
version_requirements:
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
71
96
|
description:
|
72
97
|
email:
|
73
98
|
- brian@codekitchen.net
|
@@ -146,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
171
|
version: 1.3.1
|
147
172
|
requirements: []
|
148
173
|
rubyforge_project:
|
149
|
-
rubygems_version: 1.8.
|
174
|
+
rubygems_version: 1.8.23
|
150
175
|
signing_key:
|
151
176
|
specification_version: 3
|
152
177
|
summary: Ruby compiler and runtime for the google protocol buffers library.
|
@@ -166,3 +191,4 @@ test_files:
|
|
166
191
|
- spec/spec.opts
|
167
192
|
- spec/spec_helper.rb
|
168
193
|
- spec/unicode_string_spec.rb
|
194
|
+
has_rdoc:
|