beefcake 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,12 @@ module Beefcake
14
14
 
15
15
  def self.wire_for(type)
16
16
  case type
17
+ when Class
18
+ if encodable?(type)
19
+ 2
20
+ else
21
+ raise UnknownType, type
22
+ end
17
23
  when :int32, :uint32, :sint32, :int64, :uint64, :sint64, :bool, Module
18
24
  0
19
25
  when :fixed64, :sfixed64, :double
@@ -23,11 +29,7 @@ module Beefcake
23
29
  when :fixed32, :sfixed32, :float
24
30
  5
25
31
  else
26
- if encodable?(type)
27
- 2
28
- else
29
- raise UnknownType, type
30
- end
32
+ raise UnknownType, type
31
33
  end
32
34
  end
33
35
 
@@ -80,6 +82,8 @@ module Beefcake
80
82
 
81
83
  def read(n)
82
84
  case n
85
+ when Class
86
+ n.decode(read_string)
83
87
  when Symbol
84
88
  __send__("read_#{n}")
85
89
  when Module
data/test/message_test.rb CHANGED
@@ -76,6 +76,11 @@ class PackedRepeatedMessage
76
76
  repeated :a, :int32, 1, :packed => true
77
77
  end
78
78
 
79
+ class RepeatedNestedMessage
80
+ include Beefcake::Message
81
+
82
+ repeated :simple, SimpleMessage, 1
83
+ end
79
84
 
80
85
  class MessageTest < Test::Unit::TestCase
81
86
  B = Beefcake::Buffer
@@ -284,6 +289,18 @@ class MessageTest < Test::Unit::TestCase
284
289
  assert_equal 1, got.a
285
290
  end
286
291
 
292
+ def test_decode_repeated_nested
293
+ simple = [
294
+ SimpleMessage.new(:a => 1),
295
+ SimpleMessage.new(:b => "hello")
296
+ ]
297
+ msg = RepeatedNestedMessage.new(:simple => simple).encode
298
+ got = RepeatedNestedMessage.decode(msg)
299
+ assert_equal 2, got.simple.size
300
+ assert_equal 1, got.simple[0].a
301
+ assert_equal "hello", got.simple[1].b
302
+ end
303
+
287
304
  def test_equality
288
305
  a = SimpleMessage.new :a => 1
289
306
  b = SimpleMessage.new :a => 1
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beefcake
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 23
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 5
9
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - Blake Mizerany
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-28 00:00:00 -08:00
18
+ date: 2011-02-15 00:00:00 -08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: turn
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -65,23 +68,27 @@ rdoc_options:
65
68
  require_paths:
66
69
  - lib
67
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
68
72
  requirements:
69
73
  - - ">="
70
74
  - !ruby/object:Gem::Version
75
+ hash: 3
71
76
  segments:
72
77
  - 0
73
78
  version: "0"
74
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
75
81
  requirements:
76
82
  - - ">="
77
83
  - !ruby/object:Gem::Version
84
+ hash: 3
78
85
  segments:
79
86
  - 0
80
87
  version: "0"
81
88
  requirements: []
82
89
 
83
90
  rubyforge_project: beefcake
84
- rubygems_version: 1.3.6
91
+ rubygems_version: 1.5.2
85
92
  signing_key:
86
93
  specification_version: 2
87
94
  summary: A sane protobuf library for Ruby