pbio 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +53 -0
- data/LICENSE +20 -0
- data/README.md +27 -0
- data/Rakefile +9 -0
- data/lib/pbio.rb +3 -0
- data/lib/pbio/delimited.rb +60 -0
- data/pbio.gemspec +23 -0
- data/spec/lib/pbio/delimited_spec.rb +32 -0
- data/spec/spec_helper.rb +15 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b7b794873adade256aa3a133018ca891d5b160aff747233db4cf0ea534da3fc
|
4
|
+
data.tar.gz: 909c3ed71f37ab6dcb1140c7bc999ea295604b28c3ffcc5269373890529c79df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10b80972ce679a9a1243dab4eb5740b4a5a828249c0863c95f6920eae1e5084c0b93c71e58ee19f0d6c1e9df40876a205cafeb2281cdfceeab5bc019c0bdceaa
|
7
|
+
data.tar.gz: e3fbb13072427cde21c717db1282e27ab0fe9b40295ba71b88d096f291466321a7c32361e0cc579ccc640ee21d79bd355439b4efee4acd5b59bdb39ac9c78b67
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
|
4
|
+
Naming/MemoizedInstanceVariableName:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/CyclomaticComplexity:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/PerceivedComplexity:
|
12
|
+
Enabled: false
|
13
|
+
Metrics/BlockLength:
|
14
|
+
Exclude: [spec/**]
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
Style/NumericLiterals:
|
21
|
+
Exclude: [spec/**]
|
22
|
+
Style/TrailingCommaInArguments:
|
23
|
+
EnforcedStyleForMultiline: consistent_comma
|
24
|
+
Style/TrailingCommaInArrayLiteral:
|
25
|
+
EnforcedStyleForMultiline: consistent_comma
|
26
|
+
Style/TrailingCommaInHashLiteral:
|
27
|
+
EnforcedStyleForMultiline: consistent_comma
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pbio (0.1.0)
|
5
|
+
google-protobuf
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
google-protobuf (3.5.1.2)
|
13
|
+
parallel (1.12.1)
|
14
|
+
parser (2.5.1.0)
|
15
|
+
ast (~> 2.4.0)
|
16
|
+
powerpack (0.1.1)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (12.3.1)
|
19
|
+
rspec (3.7.0)
|
20
|
+
rspec-core (~> 3.7.0)
|
21
|
+
rspec-expectations (~> 3.7.0)
|
22
|
+
rspec-mocks (~> 3.7.0)
|
23
|
+
rspec-core (3.7.1)
|
24
|
+
rspec-support (~> 3.7.0)
|
25
|
+
rspec-expectations (3.7.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.7.0)
|
28
|
+
rspec-mocks (3.7.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.7.0)
|
31
|
+
rspec-support (3.7.1)
|
32
|
+
rubocop (0.55.0)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.5)
|
35
|
+
powerpack (~> 0.1)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
ruby-progressbar (~> 1.7)
|
38
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
39
|
+
ruby-progressbar (1.9.0)
|
40
|
+
unicode-display_width (1.3.2)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler
|
47
|
+
pbio!
|
48
|
+
rake
|
49
|
+
rspec
|
50
|
+
rubocop
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
1.16.1
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 Black Square Media
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# PB IO
|
2
|
+
|
3
|
+
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
4
|
+
|
5
|
+
Protobuf IO is a Ruby equivalent of https://godoc.org/github.com/gogo/protobuf/io.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add `gem 'pbio'` to your Gemfile.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
File.open("file.txt", "w") do |f|
|
15
|
+
pbio = PBIO::Delimited.new(f)
|
16
|
+
pbio.write MyProtoMsg.new(title: "Foo")
|
17
|
+
pbio.write MyProtoMsg.new(title: "Bar")
|
18
|
+
end
|
19
|
+
|
20
|
+
File.open("file.txt", "r") do |f|
|
21
|
+
pbio = PBIO::Delimited.new(f)
|
22
|
+
pbio.read MyProtoMsg # => #<MyProtoMsg: title: "Foo">
|
23
|
+
pbio.read MyProtoMsg # => #<MyProtoMsg: title: "Bar">
|
24
|
+
pbio.read MyProtoMsg # => nil
|
25
|
+
f.eof? # => true
|
26
|
+
end
|
27
|
+
```
|
data/Rakefile
ADDED
data/lib/pbio.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module PBIO
|
2
|
+
# Delimited contains write and read methods to consume and generate
|
3
|
+
# delimited protobuf IO streams.
|
4
|
+
class Delimited
|
5
|
+
# @param [Integer] num number
|
6
|
+
# @return [Array<Byte>] uvarint byte array
|
7
|
+
def self.encode_uvarint(num)
|
8
|
+
bytes = []
|
9
|
+
while num >= 0x80
|
10
|
+
b = num & 0xFF | 0x80
|
11
|
+
bytes << b
|
12
|
+
num >>= 7
|
13
|
+
end
|
14
|
+
bytes << num
|
15
|
+
bytes.pack('c*')
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [IO] io stream
|
19
|
+
# @return [Integer] decoded number
|
20
|
+
def self.read_uvarint(io)
|
21
|
+
num = shift = 0
|
22
|
+
io.each_byte do |b|
|
23
|
+
if b < 0x80
|
24
|
+
num |= b << shift
|
25
|
+
break
|
26
|
+
end
|
27
|
+
|
28
|
+
num |= (b & 0x7f) << shift
|
29
|
+
shift += 7
|
30
|
+
end
|
31
|
+
num
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :io
|
35
|
+
|
36
|
+
# @param [IO] io object
|
37
|
+
def initialize(io)
|
38
|
+
@io = io
|
39
|
+
end
|
40
|
+
|
41
|
+
# Writes a message to the IO stream.
|
42
|
+
# @param [Protobuf::Message] msg the message
|
43
|
+
def write(msg)
|
44
|
+
payload = msg.to_proto
|
45
|
+
size = Delimited.encode_uvarint(payload.bytesize)
|
46
|
+
io.write(size) + io.write(payload)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Reads the next message
|
50
|
+
def read(klass)
|
51
|
+
size = Delimited.read_uvarint(io)
|
52
|
+
klass.decode io.read(size) unless size.zero?
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Boolean] EOF status
|
56
|
+
def eof?
|
57
|
+
io.respond_to?(:eof?) && io.eof?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/pbio.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'pbio'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.authors = ['Dimitrij Denissenko']
|
6
|
+
s.email = ['dimitrij@blacksquaremedia.com']
|
7
|
+
s.summary = 'Protobuf Streaming'
|
8
|
+
s.description = ''
|
9
|
+
s.homepage = 'https://github.com/bsm/pbio'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
13
|
+
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
s.required_ruby_version = '>= 2.2.0'
|
16
|
+
|
17
|
+
s.add_dependency 'google-protobuf'
|
18
|
+
|
19
|
+
s.add_development_dependency 'bundler'
|
20
|
+
s.add_development_dependency 'rake'
|
21
|
+
s.add_development_dependency 'rspec'
|
22
|
+
s.add_development_dependency 'rubocop'
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PBIO::Delimited do
|
4
|
+
let(:io) { StringIO.new }
|
5
|
+
let(:msg1) { PBIO::Spec::Message.new(name: 'Test A') }
|
6
|
+
let(:msg2) { PBIO::Spec::Message.new(name: 'Test B') }
|
7
|
+
let(:msg3) { PBIO::Spec::Message.new(name: 'x' * 32_000) }
|
8
|
+
|
9
|
+
subject { described_class.new io }
|
10
|
+
|
11
|
+
it 'should write' do
|
12
|
+
expect(subject.write(msg1)).to eq(9)
|
13
|
+
expect(subject.write(msg2)).to eq(9)
|
14
|
+
expect(io.size).to eq(18)
|
15
|
+
|
16
|
+
expect(subject.write(msg3)).to eq(32_007)
|
17
|
+
expect(io.size).to eq(32_025)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should read' do
|
21
|
+
expect(subject.write(msg1)).to eq(9)
|
22
|
+
expect(subject.write(msg2)).to eq(9)
|
23
|
+
io.rewind
|
24
|
+
|
25
|
+
expect(subject.read(PBIO::Spec::Message)).to eq(msg1)
|
26
|
+
expect(subject).to_not be_eof
|
27
|
+
expect(subject.read(PBIO::Spec::Message)).to eq(msg2)
|
28
|
+
expect(subject).to be_eof
|
29
|
+
expect(subject.read(PBIO::Spec::Message)).to be_nil
|
30
|
+
expect(subject).to be_eof
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pbio'
|
2
|
+
require 'rspec'
|
3
|
+
require 'google/protobuf'
|
4
|
+
|
5
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
6
|
+
add_message 'pbio.spec.Message' do
|
7
|
+
optional :name, :string, 1
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module PBIO
|
12
|
+
module Spec
|
13
|
+
Message = Google::Protobuf::DescriptorPool.generated_pool.lookup('pbio.spec.Message').msgclass
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pbio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dimitrij Denissenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-protobuf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- dimitrij@blacksquaremedia.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/pbio.rb
|
99
|
+
- lib/pbio/delimited.rb
|
100
|
+
- pbio.gemspec
|
101
|
+
- spec/lib/pbio/delimited_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/bsm/pbio
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 2.2.0
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Protobuf Streaming
|
127
|
+
test_files:
|
128
|
+
- spec/lib/pbio/delimited_spec.rb
|
129
|
+
- spec/spec_helper.rb
|