ruby_protobuf 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,14 @@
1
- === 0.4.7 / 2010-09-28
1
+ === 0.4.9 / 2011-01-17
2
2
 
3
+ * 0.4.9
4
+ * Bug fixes.
5
+ * EnumValue object in Message#to_hash.
6
+ * Optimized for speed.
7
+ * 0.4.8
8
+ * Bug fixes.
9
+ * Compilation was failed when rpc service name was on top-level.
10
+ * Options for rpc service methods are silently ignored.
11
+ * Frozen message object causes an exception on inspect method.
3
12
  * 0.4.7
4
13
  * Bug fixes.
5
14
  * Compilation error for importing message.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.9
@@ -43,6 +43,7 @@ module Protobuf
43
43
  raise TagCollisionError, "Field tag #{tag} has already been used in #{self.name}."
44
44
  end
45
45
  fields[tag] = Field.build(self, rule, type, fname, tag, options)
46
+ clear_field_cache
46
47
  end
47
48
 
48
49
  def extension_tag?(tag)
@@ -58,27 +59,40 @@ module Protobuf
58
59
  def sorted_fields
59
60
  @sorted_fields ||= fields.sort_by {|tag, _| tag}
60
61
  end
61
-
62
- # Find a field object by +name+.
63
- def get_field_by_name(name)
64
- name = name.to_sym
65
- fields.values.find {|field| field.name == name}
62
+ private :sorted_fields
63
+
64
+ #:nodoc:
65
+ def field_dictionary
66
+ return @field_dictionary if @field_dictionary
67
+ @field_dictionary = fields.dup
68
+ fields.each do |_, field|
69
+ @field_dictionary[field.name] = field
70
+ @field_dictionary[field.name.to_s] = field
71
+ end
72
+ @field_dictionary
66
73
  end
74
+ private :field_dictionary
67
75
 
68
- # Find a field object by +tag+ number.
69
- def get_field_by_tag(tag)
70
- fields[tag]
76
+ #:nodoc:
77
+ def clear_field_cache
78
+ @field_dictionary = nil
79
+ @sorted_fields = nil
71
80
  end
81
+ private :clear_field_cache
72
82
 
73
83
  # Find a field object by +tag_or_name+.
74
84
  def get_field(tag_or_name)
75
85
  case tag_or_name
76
- when Integer then get_field_by_tag(tag_or_name)
77
- when String, Symbol then get_field_by_name(tag_or_name)
78
- else raise TypeError, tag_or_name.class
86
+ when Integer, String, Symbol
87
+ field_dictionary[tag_or_name]
88
+ else
89
+ raise TypeError, tag_or_name.class
79
90
  end
80
91
  end
81
92
 
93
+ alias get_field_by_tag get_field # for compatibility
94
+ alias get_field_by_name get_field # for compatibility
95
+
82
96
  def descriptor
83
97
  @descriptor ||= Descriptor::Descriptor.new(self)
84
98
  end
@@ -91,6 +105,7 @@ module Protobuf
91
105
  unless field.ready?
92
106
  field = field.setup
93
107
  self.class.fields[tag] = field
108
+ self.class.__send__(:clear_field_cache)
94
109
  end
95
110
  if field.repeated?
96
111
  @values[field.name] = Field::FieldArray.new(field)
@@ -163,7 +178,7 @@ module Protobuf
163
178
  i = ' ' * indent
164
179
  field_value_to_string = lambda {|field, value|
165
180
  result << \
166
- if field.optional? && ! has_field?(field.name)
181
+ if field.optional? && ! @values.has_key?(field.name)
167
182
  ''
168
183
  else
169
184
  case field
@@ -282,7 +297,7 @@ module Protobuf
282
297
  # # do something
283
298
  # end
284
299
  def each_field
285
- self.class.sorted_fields.each do |_, field|
300
+ self.class.__send__(:sorted_fields).each do |_, field|
286
301
  value = __send__(field.name)
287
302
  yield(field, value)
288
303
  end
@@ -291,13 +306,15 @@ module Protobuf
291
306
  def to_hash
292
307
  hash = {}
293
308
  each_field do |field, value|
294
- next unless has_field?(field.tag)
309
+ next unless @values.has_key?(field.name)
295
310
  case value
296
311
  when Array
297
312
  next if value.empty?
298
313
  hash[field.name] = value.map {|val| val.is_a?(Message) ? val.to_hash : val}
299
314
  when Message
300
315
  hash[field.name] = value.to_hash
316
+ when EnumValue
317
+ hash[field.name] = value.name
301
318
  else
302
319
  hash[field.name] = value
303
320
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_protobuf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 8
10
- version: 0.4.8
9
+ - 9
10
+ version: 0.4.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - MATSUYAMA Kengo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-23 00:00:00 +09:00
18
+ date: 2011-01-14 00:00:00 +09:00
19
19
  default_executable: rprotoc
20
20
  dependencies: []
21
21