leb128 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/leb128.gemspec +1 -1
  4. data/lib/leb128.rb +6 -3
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20748dc4ff2f263fdf41f1a864716734727820d2
4
- data.tar.gz: 1429a8e432ebbf3564c7f5b65ed88801ffca98e4
3
+ metadata.gz: 0ed16554ca16a052d5cfa797d55edc70a79d4c02
4
+ data.tar.gz: 46b3d05dd5714fcc60cb4015967037a09e8ba547
5
5
  SHA512:
6
- metadata.gz: 96530e760a059bab741ad7f017693d3890e09e5262644c9bffc06d120a81921125f2b56c1b400c2de11aed63f47729cd0604e923a140ad411739e96b22730cae
7
- data.tar.gz: ead3aa1418ce06b4f313c4d365c248cc381b890a8bd70e34e5e98cf40f392de5acc314b09359ebacb6c1bacb1f199d26f5dc953ca3d4f2daf4ffa7777914f3cd
6
+ metadata.gz: ae77aacabcc90c23c515a9e1150dd643c9038ce73cd1f8213234c6a448cf4dc3bcf85ee62edddf9e51431387b2fb8604403a299f0a382117e64022ab69f89ac6
7
+ data.tar.gz: 9867aae8687da55df2c60d83b73a2eaf9962a2978df78db2d27a890595d9219d2aacb2aacb24de9792973c680eec377e9f1102a165ed10c2c3cb07140f347e11
data/README.md CHANGED
@@ -1,7 +1,20 @@
1
1
  # LEB128
2
2
 
3
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/cl8n/leb128/master/LICENSE.md) [![Build Status](https://travis-ci.org/cl8n/leb128.svg?branch=master)](https://travis-ci.org/cl8n/leb128) [![Documentation](https://img.shields.io/badge/docs-rubydoc.info-orange.svg)](http://www.rubydoc.info/gems/leb128)
4
+
3
5
  This gem is a pair of utility functions for encoding and decoding LEB128-compressed integers.
4
6
 
7
+ As a visual example, this is an excerpt from the [LEB128 Wikipedia page](https://en.wikipedia.org/wiki/LEB128) describing how an integer is encoded into an unsigned LEB128:
8
+
9
+ ```
10
+ 10011000011101100101 In raw binary
11
+ 010011000011101100101 Padded to a multiple of 7 bits
12
+ 0100110 0001110 1100101 Split into 7-bit groups
13
+ 00100110 10001110 11100101 Add high 1 bits on all but last group to form bytes
14
+ 0x26 0x8E 0xE5 In hexadecimal
15
+ 0xE5 0x8E 0x26 Output stream
16
+ ```
17
+
5
18
  ## Installation
6
19
 
7
20
  Add this line to your application's Gemfile:
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "leb128"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.1.1"
4
4
  spec.authors = ["Clayton Bonigut"]
5
5
 
6
6
  spec.summary = %q{A pair of utility functions for encoding and decoding LEB128-compressed integers.}
@@ -13,19 +13,22 @@ module LEB128
13
13
 
14
14
  def self.encode(value, signed)
15
15
  if value < 0 && !signed
16
- raise(ArgumentError, 'Cannot encode a negative integer to an unsigned LEB128')
16
+ raise(ArgumentError,
17
+ 'Cannot encode a negative integer to an unsigned LEB128')
17
18
  end
18
19
  io = StringIO.new
19
20
  loop do
20
21
  byte = value & 0x7F
21
22
  value >>= 7
22
23
  if signed
23
- byte |= 0x80 unless (value == 0 && byte & 0x40 == 0) || (value == -1 && byte & 0x40 != 0)
24
+ byte |= 0x80 unless (value == 0 && byte & 0x40 == 0) ||
25
+ (value == -1 && byte & 0x40 != 0)
24
26
  elsif value != 0
25
27
  byte |= 0x80
26
28
  end
27
29
  io.putc(byte)
28
- break if (signed && byte & 0x80 == 0) || (!signed && value == 0)
30
+ break if (signed && byte & 0x80 == 0) ||
31
+ (!signed && value == 0)
29
32
  end
30
33
  io.pos = 0
31
34
  io
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leb128
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clayton Bonigut