varint 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +25 -0
- data/Rakefile +5 -0
- data/ext/varint/extconf.rb +3 -0
- data/ext/varint/varint.c +52 -0
- data/lib/varint/version.rb +3 -0
- data/varint.gemspec +22 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2009, Decho Corporation
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of Decho Corporation nor the names of its contributors
|
12
|
+
may be used to endorse or promote products derived from this software
|
13
|
+
without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Varint
|
2
|
+
|
3
|
+
A small C extension to speed up varint in protocol buffers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'varint'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install varint
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ext/varint/varint.c
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
static VALUE Varint;
|
4
|
+
static ID getbyte, putbyte;
|
5
|
+
|
6
|
+
static VALUE varint_encode(VALUE module, VALUE io, VALUE int_valV)
|
7
|
+
{
|
8
|
+
/* unsigned for the bit shifting ops */
|
9
|
+
unsigned long long int_val = (unsigned long long)NUM2LL(int_valV);
|
10
|
+
unsigned char byte;
|
11
|
+
while (1) {
|
12
|
+
byte = int_val & 0x7f;
|
13
|
+
int_val >>= 7;
|
14
|
+
if (int_val == 0) {
|
15
|
+
rb_funcall(io, putbyte, 1, INT2FIX(byte));
|
16
|
+
return Qnil;
|
17
|
+
} else {
|
18
|
+
rb_funcall(io, putbyte, 1, INT2FIX(byte | 0x80));
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE varint_decode(VALUE module, VALUE io)
|
24
|
+
{
|
25
|
+
unsigned long long int_val = 0;
|
26
|
+
unsigned shift = 0;
|
27
|
+
unsigned char byte;
|
28
|
+
|
29
|
+
while (1) {
|
30
|
+
if (shift >= 64) {
|
31
|
+
rb_raise(rb_eArgError, "too many bytes when decoding varint");
|
32
|
+
}
|
33
|
+
byte = (unsigned char)FIX2INT(rb_funcall(io, getbyte, 0));
|
34
|
+
int_val |= ((unsigned long long)(byte & 0x7f)) << shift;
|
35
|
+
shift += 7;
|
36
|
+
if ((byte & 0x80) == 0) {
|
37
|
+
/* return ULL2NUM(int_val); */
|
38
|
+
return LL2NUM((long long)int_val);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
void Init_varint()
|
44
|
+
{
|
45
|
+
Varint = rb_define_module("Varint");
|
46
|
+
|
47
|
+
getbyte = rb_intern("getbyte");
|
48
|
+
putbyte = rb_intern("putc");
|
49
|
+
|
50
|
+
rb_define_module_function(Varint, "encode", varint_encode, 2);
|
51
|
+
rb_define_module_function(Varint, "decode", varint_decode, 1);
|
52
|
+
}
|
data/varint.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'varint/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "varint"
|
8
|
+
gem.version = Varint::VERSION
|
9
|
+
gem.authors = ["Brian Palmer", "Beneidkt Böhm", "Rob Marable", "Paulo Luis Franchini Casaretto"]
|
10
|
+
gem.email = ["brian@codekitchen.net", "bb@xnull.de"]
|
11
|
+
gem.summary = %q{varint C extension}
|
12
|
+
gem.homepage = "https://github.com/madvertise/varint"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.extensions = ["ext/varint/extconf.rb"]
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: varint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Palmer
|
9
|
+
- Beneidkt Böhm
|
10
|
+
- Rob Marable
|
11
|
+
- Paulo Luis Franchini Casaretto
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rake
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- brian@codekitchen.net
|
36
|
+
- bb@xnull.de
|
37
|
+
executables: []
|
38
|
+
extensions:
|
39
|
+
- ext/varint/extconf.rb
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- .gitignore
|
43
|
+
- Gemfile
|
44
|
+
- LICENSE.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- ext/varint/extconf.rb
|
48
|
+
- ext/varint/varint.c
|
49
|
+
- lib/varint/version.rb
|
50
|
+
- varint.gemspec
|
51
|
+
homepage: https://github.com/madvertise/varint
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.24
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: varint C extension
|
75
|
+
test_files: []
|
76
|
+
has_rdoc:
|