ruby-protocol-buffers 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,9 @@
1
1
  /*.pb.rb
2
2
  /*.d
3
3
  /*.proto
4
+ .yardoc/
5
+ Gemfile.lock
6
+ doc/*
4
7
  coverage
5
8
  rdoc
6
9
  pkg
@@ -1,3 +1,7 @@
1
+ # ruby-protocol-buffers 1.0.1
2
+
3
+ * Treat unknown enum values as unknown fields
4
+
1
5
  # ruby-protocol-buffers 1.0.0
2
6
 
3
7
  * The library has reached to 1.0 status, hurrah
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-protocol-buffers.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,56 +1,20 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'spec'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
4
3
 
5
- begin
6
- require 'metric_fu'
7
- rescue LoadError
8
- end
9
-
10
- begin
11
- require 'jeweler'
12
- Jeweler::Tasks.new do |gem|
13
- gem.name = "ruby-protocol-buffers"
14
- gem.summary = %Q{Ruby compiler and runtime for the google protocol buffers library.}
15
- gem.homepage = "http://github.com/mozy/ruby-protocol-buffers"
16
- gem.authors = ["Brian Palmer"]
17
- gem.version = File.read('VERSION')
18
- gem.add_development_dependency "rspec", ">= 1.2.9"
19
- gem.required_ruby_version = ">=1.8.6"
20
- gem.require_path = 'lib'
21
- gem.extra_rdoc_files << "Changelog.md"
22
- gem.files << "Changelog.md"
23
- # disabled to avoid needing to compile a C extension just to boost
24
- # performance. TODO: is there a way to tell gems to make the extension
25
- # optional?
26
- # s.extensions << 'ext/extconf.rb'
27
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
28
- end
29
- Jeweler::GemcutterTasks.new
30
- rescue LoadError
31
- # You'll need to install Jeweler to build packages
32
- end
4
+ task :default => 'spec'
33
5
 
34
- require 'spec/rake/spectask'
35
- Spec::Rake::SpecTask.new(:spec) do |spec|
36
- spec.libs << 'lib' << 'spec'
37
- spec.pattern = 'spec/**/*_spec.rb'
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = "-c -f d"
38
9
  end
39
-
40
- Spec::Rake::SpecTask.new(:rcov) do |spec|
41
- spec.libs << 'lib' << 'spec'
42
- spec.pattern = 'spec/**/*_spec.rb'
43
- spec.rcov = true
10
+ RSpec::Core::RakeTask.new(:rcov) do |t|
11
+ t.rspec_opts = "-c -f d"
12
+ t.rcov = true
13
+ t.rcov_opts = ["--exclude", "spec,gems/,rubygems/"]
44
14
  end
45
15
 
46
- task :default => :spec
47
-
48
- require 'rake/rdoctask'
49
- Rake::RDocTask.new do |rdoc|
50
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
-
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "ruby-protocol-buffers #{version}"
54
- rdoc.rdoc_files.include('README*', 'LICENSE')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
16
+ require 'yard'
17
+ YARD::Rake::YardocTask.new(:doc) do |t|
18
+ version = ProtocolBuffers::VERSION
19
+ t.options = ["--title", "ruby protocol buffers #{version}", "--files", "LICENSE,Changelog.md"]
56
20
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -11,11 +11,15 @@ require 'tempfile'
11
11
  ruby_out = "."
12
12
  include_dirs = []
13
13
 
14
+ require 'protocol_buffers'
15
+ require 'protocol_buffers/compiler'
16
+
14
17
  opts = OptionParser.new
15
18
  opts.banner = <<BANNER
16
19
  Usage: #{opts.program_name} [OPTION] PROTO_FILES
17
20
  Parse PROTO_FILES and generate output based on the options given:
18
21
  BANNER
22
+ opts.version = ProtocolBuffers::VERSION
19
23
 
20
24
  opts.on("-o", "--ruby_out", "=OUT_DIR",
21
25
  "generates ruby code in OUT_DIR", "[defaults to pwd]",
@@ -29,9 +33,6 @@ filenames = rest
29
33
 
30
34
  (puts "Missing input file.\n\n"; puts opts; exit) if filenames.empty?
31
35
 
32
- require 'protocol_buffers'
33
- require 'protocol_buffers/compiler'
34
-
35
36
  protocfile = Tempfile.new("ruby-protoc")
36
37
  protocfile.binmode
37
38
  ProtocolBuffers::Compiler.compile(protocfile.path, filenames, :include_dirs => include_dirs)
@@ -38,10 +38,21 @@ module ProtocolBuffers
38
38
  end
39
39
 
40
40
  if field
41
- deserialized = field.deserialize(value)
42
- # merge_field handles repeated field logic
43
- message.merge_field(tag, deserialized, field)
44
- else
41
+ begin
42
+ deserialized = field.deserialize(value)
43
+ # merge_field handles repeated field logic
44
+ message.merge_field(tag, deserialized, field)
45
+ rescue ArgumentError
46
+ # for enum fields, treat bad values as unknown fields
47
+ if field.is_a?(Field::EnumField)
48
+ field = nil
49
+ else
50
+ raise
51
+ end
52
+ end
53
+ end
54
+
55
+ unless field
45
56
  # ignore unknown fields, pass them on when re-serializing this message
46
57
 
47
58
  # special handling -- if it's a LENGTH_DELIMITED field, we need to
@@ -480,6 +480,10 @@ module ProtocolBuffers
480
480
  @unknown_fields.each { |tag_int, value| yield tag_int, value }
481
481
  end
482
482
 
483
+ def unknown_field_count
484
+ (@unknown_fields || []).size
485
+ end
486
+
483
487
  # Generate the initialize method using reflection, to improve speed. This is
484
488
  # called by the generated .pb.rb code, it's not necessary to call this
485
489
  # method directly.
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "protocol_buffers"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby-protocol-buffers"
7
+ s.version = ProtocolBuffers::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brian Palmer"]
10
+ s.email = ["brian@codekitchen.net"]
11
+ s.homepage = "https://github.com/mozy/ruby-protocol-buffers"
12
+ s.summary = %{Ruby compiler and runtime for the google protocol buffers library.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.extra_rdoc_files << "Changelog.md"
20
+
21
+ s.add_development_dependency "rspec", "~> 2.5"
22
+ s.add_development_dependency "autotest-standalone"
23
+ s.add_development_dependency "autotest-growl"
24
+ s.add_development_dependency "rcov"
25
+ s.add_development_dependency "yard"
26
+ end
@@ -1,5 +1,7 @@
1
1
  package featureful;
2
2
 
3
+ option optimize_for = LITE_RUNTIME;
4
+
3
5
  message A {
4
6
  message Sub {
5
7
  enum Payloads {
@@ -6,12 +6,13 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
6
  require 'protocol_buffers'
7
7
  require 'protocol_buffers/compiler'
8
8
 
9
- ProtocolBuffers::Compiler.compile_and_load(
10
- File.join(File.dirname(__FILE__), "proto_files", "simple.proto"))
11
- ProtocolBuffers::Compiler.compile_and_load(
12
- File.join(File.dirname(__FILE__), "proto_files", "featureful.proto"))
13
-
14
9
  describe ProtocolBuffers, "runtime" do
10
+ before(:each) do
11
+ ProtocolBuffers::Compiler.compile_and_load(
12
+ File.join(File.dirname(__FILE__), "proto_files", "simple.proto"))
13
+ ProtocolBuffers::Compiler.compile_and_load(
14
+ File.join(File.dirname(__FILE__), "proto_files", "featureful.proto"))
15
+ end
15
16
 
16
17
  it "can handle basic operations" do
17
18
 
@@ -354,18 +355,17 @@ describe ProtocolBuffers, "runtime" do
354
355
  ProtocolBuffers::Compiler.compile_and_load_string <<-EOS
355
356
  package tehUnknown;
356
357
  message MyResult {
357
- optional int32 field_1 = 1;
358
+ optional int64 field_1 = 1;
358
359
  }
359
360
  EOS
360
361
 
361
- res1 = TehUnknown::MyResult.new(:field_1 => 5)
362
+ res1 = TehUnknown::MyResult.new(:field_1 => (2**33))
362
363
  buf = res1.to_s
363
364
 
364
365
  ProtocolBuffers::Compiler.compile_and_load_string <<-EOS
365
366
  package tehUnknown;
366
367
  message MyResult {
367
- enum E { A = 1; }
368
- optional E field_1 = 1;
368
+ optional int32 field_1 = 1;
369
369
  }
370
370
  EOS
371
371
 
@@ -427,4 +427,56 @@ describe ProtocolBuffers, "runtime" do
427
427
  res3.field_4.should == 0xfffc
428
428
  end
429
429
 
430
+ it "ignores and passes on unknown enum values" do
431
+ ProtocolBuffers::Compiler.compile_and_load_string <<-EOS
432
+ package tehUnknown;
433
+ message MyResult {
434
+ enum E {
435
+ V1 = 1;
436
+ V2 = 2;
437
+ }
438
+ optional E field_1 = 1;
439
+ }
440
+ EOS
441
+
442
+ res1 = TehUnknown::MyResult.new(:field_1 => TehUnknown::MyResult::E::V2)
443
+ serialized = res1.to_s
444
+
445
+ # remove field_2 to pretend we never knew about it
446
+ ProtocolBuffers::Compiler.compile_and_load_string <<-EOS
447
+ package tehUnknown;
448
+ message MyResult {
449
+ enum E {
450
+ V1 = 1;
451
+ }
452
+ optional E field_1 = 1;
453
+ }
454
+ EOS
455
+
456
+ res2 = nil
457
+ proc do
458
+ res2 = TehUnknown::MyResult.parse(serialized)
459
+ end.should_not raise_error()
460
+
461
+ res2.value_for_tag?(1).should be_false
462
+ res2.unknown_field_count.should == 1
463
+
464
+ serialized2 = res2.to_s
465
+
466
+ # now we know about field_2 again
467
+ ProtocolBuffers::Compiler.compile_and_load_string <<-EOS
468
+ package tehUnknown;
469
+ message MyResult {
470
+ enum E {
471
+ V1 = 1;
472
+ V2 = 2;
473
+ }
474
+ optional E field_1 = 1;
475
+ }
476
+ EOS
477
+
478
+ res3 = TehUnknown::MyResult.parse(serialized2)
479
+ res3.field_1.should == 2
480
+ end
481
+
430
482
  end
@@ -1,8 +1,6 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
1
  require 'protocol_buffers'
4
- require 'spec'
5
- require 'spec/autorun'
6
2
 
7
- Spec::Runner.configure do |config|
3
+ require 'rspec'
4
+
5
+ RSpec.configure do |config|
8
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-protocol-buffers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Palmer
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-07 00:00:00 -07:00
19
- default_executable: ruby-protoc
18
+ date: 2011-03-20 00:00:00 -06:00
19
+ default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
@@ -24,30 +24,85 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 13
29
+ hash: 9
30
30
  segments:
31
- - 1
32
31
  - 2
33
- - 9
34
- version: 1.2.9
32
+ - 5
33
+ version: "2.5"
35
34
  type: :development
36
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: autotest-standalone
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: autotest-growl
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rcov
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: yard
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
37
92
  description:
38
93
  email:
94
+ - brian@codekitchen.net
39
95
  executables:
40
96
  - ruby-protoc
41
97
  extensions: []
42
98
 
43
99
  extra_rdoc_files:
44
100
  - Changelog.md
45
- - LICENSE
46
- - README.md
47
101
  files:
48
102
  - .document
49
103
  - .gitignore
50
104
  - Changelog.md
105
+ - Gemfile
51
106
  - LICENSE
52
107
  - README.md
53
108
  - Rakefile
@@ -77,6 +132,7 @@ files:
77
132
  - lib/protocol_buffers/runtime/message.rb
78
133
  - lib/protocol_buffers/runtime/service.rb
79
134
  - lib/protocol_buffers/runtime/varint.rb
135
+ - ruby-protocol-buffers.gemspec
80
136
  - spec/compiler_spec.rb
81
137
  - spec/fields_spec.rb
82
138
  - spec/proto_files/depends.proto
@@ -88,12 +144,12 @@ files:
88
144
  - spec/spec.opts
89
145
  - spec/spec_helper.rb
90
146
  has_rdoc: true
91
- homepage: http://github.com/mozy/ruby-protocol-buffers
147
+ homepage: https://github.com/mozy/ruby-protocol-buffers
92
148
  licenses: []
93
149
 
94
150
  post_install_message:
95
- rdoc_options:
96
- - --charset=UTF-8
151
+ rdoc_options: []
152
+
97
153
  require_paths:
98
154
  - lib
99
155
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -101,12 +157,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
157
  requirements:
102
158
  - - ">="
103
159
  - !ruby/object:Gem::Version
104
- hash: 59
160
+ hash: 3
105
161
  segments:
106
- - 1
107
- - 8
108
- - 6
109
- version: 1.8.6
162
+ - 0
163
+ version: "0"
110
164
  required_rubygems_version: !ruby/object:Gem::Requirement
111
165
  none: false
112
166
  requirements:
@@ -126,6 +180,11 @@ summary: Ruby compiler and runtime for the google protocol buffers library.
126
180
  test_files:
127
181
  - spec/compiler_spec.rb
128
182
  - spec/fields_spec.rb
183
+ - spec/proto_files/depends.proto
184
+ - spec/proto_files/featureful.proto
185
+ - spec/proto_files/no_package.proto
186
+ - spec/proto_files/simple.proto
187
+ - spec/proto_files/top_level_enum.proto
129
188
  - spec/runtime_spec.rb
189
+ - spec/spec.opts
130
190
  - spec/spec_helper.rb
131
- - examples/json_protobuf.rb