protobuf 2.4.2 → 2.4.3.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -129,7 +129,7 @@ module Protobuf
129
129
 
130
130
  def clear!
131
131
  @values.delete_if do |_, value|
132
- if value.is_a?(Field::FieldArray)
132
+ if value.is_a?(::Protobuf::Field::FieldArray)
133
133
  value.clear
134
134
  false
135
135
  else
@@ -225,15 +225,17 @@ module Protobuf
225
225
  (self.__send__(key).present? || [true, false].include?(self.__send__(key)))
226
226
  end
227
227
 
228
- def serialize_to(stream)
228
+ def serialize_to_string
229
+ stream = ""
230
+
229
231
  each_field_for_serialization do |field, value|
230
232
  if field.repeated?
231
233
  if field.packed?
232
234
  key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED
233
235
  packed_value = value.map { |val| field.encode(val) }.join
234
- stream.write(::Protobuf::Field::VarintField.encode(key))
235
- stream.write(::Protobuf::Field::VarintField.encode(packed_value.size))
236
- stream.write(packed_value)
236
+ stream << ::Protobuf::Field::VarintField.encode(key)
237
+ stream << ::Protobuf::Field::VarintField.encode(packed_value.size)
238
+ stream << packed_value
237
239
  else
238
240
  value.each { |val| write_pair(stream, field, val) }
239
241
  end
@@ -241,14 +243,8 @@ module Protobuf
241
243
  write_pair(stream, field, value)
242
244
  end
243
245
  end
244
- end
245
246
 
246
- def serialize_to_string(string = '')
247
- io = StringIO.new(string)
248
- serialize_to(io)
249
- result = io.string
250
- result.force_encoding(::Protobuf::Message::STRING_ENCODING) if result.respond_to?(:force_encoding)
251
- result
247
+ return stream
252
248
  end
253
249
 
254
250
  def set_field(tag, bytes)
@@ -329,7 +325,7 @@ module Protobuf
329
325
 
330
326
  object.__send__(:initialize)
331
327
  @values.each do |name, value|
332
- if value.is_a?(Field::FieldArray)
328
+ if value.is_a?(::Protobuf::Field::FieldArray)
333
329
  object.__send__(name).replace(value.map {|v| duplicate.call(v)})
334
330
  else
335
331
  object.__send__("#{name}=", duplicate.call(value))
@@ -352,10 +348,8 @@ module Protobuf
352
348
  # Encode key and value, and write to +stream+.
353
349
  def write_pair(stream, field, value)
354
350
  key = (field.tag << 3) | field.wire_type
355
- key_bytes = ::Protobuf::Field::VarintField.encode(key)
356
- stream.write(key_bytes)
357
- bytes = field.encode(value)
358
- stream.write(bytes)
351
+ stream << ::Protobuf::Field::VarintField.encode(key)
352
+ stream << field.encode(value)
359
353
  end
360
354
 
361
355
  end
@@ -43,10 +43,9 @@ module Protobuf
43
43
 
44
44
  # Read varint integer value from +stream+.
45
45
  def read_varint(stream)
46
- read_method = stream.respond_to?(:readbyte) ? :readbyte : :readchar
47
46
  value = index = 0
48
47
  begin
49
- byte = stream.__send__(read_method)
48
+ byte = stream.readbyte
50
49
  value |= (byte & 0x7f) << (7 * index)
51
50
  index += 1
52
51
  end while (byte & 0x80).nonzero?
@@ -44,7 +44,7 @@ module Protobuf
44
44
  end
45
45
 
46
46
  def set_data(data)
47
- @data = data.is_a?(::Protobuf::Message) ? data.serialize_to_string : data.to_s
47
+ @data = data.to_s
48
48
  @size = @data.size
49
49
  end
50
50
 
@@ -104,10 +104,10 @@ module Protobuf
104
104
  def rpc_request_data
105
105
  validate_request_type
106
106
 
107
- return Protobuf::Socketrpc::Request.new(
107
+ return ::Protobuf::Socketrpc::Request.new(
108
108
  :service_name => @options[:service].name,
109
109
  :method_name => @options[:method].to_s,
110
- :request_proto => @options[:request].serialize_to_string
110
+ :request_proto => @options[:request]
111
111
  ).serialize_to_string
112
112
  rescue => e
113
113
  fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}")
@@ -86,4 +86,3 @@ module Protobuf
86
86
  end
87
87
  end
88
88
  end
89
-
@@ -49,7 +49,7 @@ module Protobuf
49
49
  end
50
50
 
51
51
  def send_data
52
- response_data = @response.is_a?(::Protobuf::Message) ? @response.serialize_to_string : @response.to_s
52
+ response_data = @response.to_s # to_s is aliases as serialize_to_string in Message
53
53
  @stats.response_size = response_data.size
54
54
  zmq_error_check(@socket.send_string(response_data))
55
55
  end
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.4.2'
2
+ VERSION = '2.4.3.rc1'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -140,6 +140,17 @@ namespace :benchmark do
140
140
  puts args[:profile_output]
141
141
  end
142
142
 
143
+ desc "benchmark Protobuf Message #serialize"
144
+ task :profile_protobuf_serialize, [:number, :profile_output] do |t, args|
145
+ args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
146
+ create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
147
+ ::PerfTools::CpuProfiler.start(args[:profile_output]) do
148
+ args[:number].to_i.times { Test::Resource.new(create_params).serialize }
149
+ end
150
+
151
+ puts args[:profile_output]
152
+ end
153
+
143
154
  desc "benchmark EventMachine client with EventMachine server"
144
155
  task :em_client_em_server, [:number, :length] do |t, args|
145
156
  args.with_defaults(:number => 1000, :length => 100)
@@ -23,23 +23,21 @@ describe Protobuf::Message do
23
23
  describe '#encode' do
24
24
  context "when there's no value for a required field" do
25
25
  let(:message) { ::Test::Resource.new }
26
- let(:stream) { StringIO.new }
27
26
 
28
27
  it "raises a 'message not initialized' error" do
29
28
  expect {
30
- message.serialize_to(stream)
29
+ message.serialize_to_string
31
30
  }.to raise_error(Protobuf::SerializationError, /required/i)
32
31
  end
33
32
  end
34
33
 
35
34
  context "repeated fields" do
36
35
  let(:message) { ::Test::Resource.new(:name => "something") }
37
- let(:stream) { StringIO.new }
38
36
 
39
37
  it "does not raise an error when repeated fields are []" do
40
38
  expect {
41
39
  message.repeated_enum = []
42
- message.serialize_to(stream)
40
+ message.serialize_to_string
43
41
  }.to_not raise_error
44
42
  end
45
43
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
5
- prerelease:
4
+ version: 2.4.3.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - BJ Neilsen
@@ -369,7 +369,6 @@ files:
369
369
  - lib/protobuf/logger.rb
370
370
  - lib/protobuf/message.rb
371
371
  - lib/protobuf/message/decoder.rb
372
- - lib/protobuf/message/extend.rb
373
372
  - lib/protobuf/message/message.rb
374
373
  - lib/protobuf/rpc/buffer.rb
375
374
  - lib/protobuf/rpc/client.rb
@@ -499,16 +498,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
499
498
  version: '0'
500
499
  segments:
501
500
  - 0
502
- hash: -3586960575258099872
501
+ hash: 952004748095048200
503
502
  required_rubygems_version: !ruby/object:Gem::Requirement
504
503
  none: false
505
504
  requirements:
506
- - - ! '>='
505
+ - - ! '>'
507
506
  - !ruby/object:Gem::Version
508
- version: '0'
509
- segments:
510
- - 0
511
- hash: -3586960575258099872
507
+ version: 1.3.1
512
508
  requirements: []
513
509
  rubyforge_project:
514
510
  rubygems_version: 1.8.24
@@ -1,8 +0,0 @@
1
- require 'protobuf/message/message'
2
-
3
- module Protobuf
4
- class Extend < Message
5
- MIN = -1.0/0
6
- MAX = 1.0/0
7
- end
8
- end