protobuf 2.4.8 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Let's say you have a `defs.proto` file that defines a User message.
22
22
  package foo;
23
23
  message User {
24
24
  required string first_name = 1;
25
- required string last_name = 1;
25
+ required string last_name = 2;
26
26
  }
27
27
 
28
28
  Now let's compile that definition to ruby:
@@ -147,7 +147,7 @@ module Foo
147
147
  end
148
148
  ```
149
149
 
150
- Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new service instance based on the request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods the aid in code quality and simpilicity.
150
+ Simply implement the instance method for the defined rpc. You can provide any other methods in this class as helpers, but only those defined in the proto file will be callable by remote clients. Every request made by a client will provide a non-empty request of the defined type. The server creates a new service instance based on the request, so you should not be constrained to just the endpoint method. This is similar to rails controllers where only methods defined by the routes file are hooked up to HTTP requests, but it's very common to implement private methods to aid in code quality and simpilicity.
151
151
 
152
152
  Every instance has a `request` and `response` object used for fulfilling the call, again, similar to a rails controller action. You should never attempt to modify the `request` object. The `response` object however should be modified or replaced entirely. If you need to create your own response object (a valid case), simply use `respond_with(new_response)`. The returned object should conform to one of three properties:
153
153
 
@@ -176,7 +176,9 @@ This means that the client's `on_failure` callback will be invoked instead of th
176
176
  Service Filters provides ActionController-style filter support to service instances, specifically adding `before_filter`, `after_filter`, and `around_filter`.
177
177
 
178
178
  ```ruby
179
- class Foo::UserService < ::Protobuf::Rpc::Service
179
+ require 'lib/foo/user.pb'
180
+
181
+ class Foo::UserService
180
182
  before_filter :start_request_timer
181
183
  after_filter :end_request_timer
182
184
  around_filter :benchmark_request
@@ -236,13 +238,13 @@ __:except__ – The opposite of the `:only` option. A string/symbol or Array of
236
238
 
237
239
  ### Servers
238
240
 
239
- A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook the phone lines!
241
+ A service is nothing without being hooked up to a socket. It's the nerdy kid waiting by the telephone for someone to call without knowing that the phone company disconnected their house. Sad and pathetic. So hook up the phone lines!
240
242
 
241
243
  ```
242
244
  $ rpc_server -o myserver.com -p 9939 -l ./log/protobuf.log ./config/environment.rb
243
245
  ```
244
246
 
245
- The previous call will start an Socket server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it.
247
+ The previous call will start a Socket server running on the given host and port which will load your application into memory. You certainly don't have to run rails or any other framework, just make sure you have some kind of file that will load your services all into memory. The server doesn't know where you put your code, so tell it.
246
248
 
247
249
  Be aware that the server needs to be able to translate the socket stream of bytes into an actual protobuf request object. If the definition for that request object aren't known to the server, you're going to have a long day getting this going. It's necessary to store all your definitions and their generated classes in a shared repository (read: gem) so that both client and server have access to the ruby classes in their respective load paths.
248
250
 
@@ -287,7 +289,7 @@ Foo::UserService.client.find(req) do |c|
287
289
 
288
290
  # Register a block for execution when the response
289
291
  # is deemed a failure. This can be either a client-side
290
- # or server-side failure. The object passed the to the
292
+ # or server-side failure. The object passed to the
291
293
  # block has a `message` and a `code` attribute
292
294
  # to aid in logging/diagnosing the failure.
293
295
  c.on_failure do |err|
@@ -5,8 +5,16 @@ module Protobuf
5
5
  class StringField < BytesField
6
6
  ENCODING = 'UTF-8'.freeze
7
7
 
8
+ def decode(bytes)
9
+ bytes.force_encoding(::Protobuf::Field::StringField::ENCODING)
10
+ bytes
11
+ end
12
+
8
13
  def encode(value)
9
- value.force_encoding(::Protobuf::Field::StringField::ENCODING)
14
+ # TODO: make replace character configurable?
15
+ value.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "")
16
+ value.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING)
17
+
10
18
  string_size = ::Protobuf::Field::VarintField.encode(value.size)
11
19
  string_size << value
12
20
  end
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.4.8'
2
+ VERSION = '2.5.0'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -21,6 +21,21 @@ describe Protobuf::Message do
21
21
  end
22
22
 
23
23
  describe '#encode' do
24
+ context "encoding" do
25
+ it "accepts UTF-8 strings into string fields" do
26
+ message = ::Test::Resource.new(:name => "Kyle Redfearn\u0060s iPad")
27
+
28
+ expect { message.serialize_to_string }.to_not raise_error
29
+ end
30
+
31
+ it "trims unicode characters from string fields" do
32
+ message = ::Test::Resource.new(:name => "my name\xc3")
33
+ new_message = ::Test::Resource.new
34
+ new_message.parse_from_string(message.serialize_to_string)
35
+ new_message.name.should eq("my name")
36
+ end
37
+ end
38
+
24
39
  context "when there's no value for a required field" do
25
40
  let(:message) { ::Test::Resource.new }
26
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.8
4
+ version: 2.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-19 00:00:00.000000000 Z
13
+ date: 2012-11-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -498,7 +498,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
498
498
  version: '0'
499
499
  segments:
500
500
  - 0
501
- hash: -3822315942507757741
501
+ hash: 2566852558843863563
502
502
  required_rubygems_version: !ruby/object:Gem::Requirement
503
503
  none: false
504
504
  requirements:
@@ -507,7 +507,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
507
507
  version: '0'
508
508
  segments:
509
509
  - 0
510
- hash: -3822315942507757741
510
+ hash: 2566852558843863563
511
511
  requirements: []
512
512
  rubyforge_project:
513
513
  rubygems_version: 1.8.24