Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leb128

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leb128

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

LEB128

License Build Status Documentation

This gem is a set of utility functions for encoding and decoding LEB128-compressed integers.

As a visual example, this is an excerpt from the LEB128 Wikipedia page describing how an integer is encoded into an unsigned LEB128:

      10011000011101100101  In raw binary
     010011000011101100101  Padded to a multiple of 7 bits
 0100110  0001110  1100101  Split into 7-bit groups
00100110 10001110 11100101  Add high 1 bits on all but last group to form bytes
    0x26     0x8E     0xE5  In hexadecimal
0xE5 0x8E 0x26              Output stream

Installation

Add this line to your application's Gemfile:

gem 'leb128'

And then execute:

$ bundle

Or install it yourself as:

$ gem install leb128

Usage

Require the Gem:

require 'leb128'

Encoding and Decoding

Encode integers into LEB128-compressed data by using the encode_unsigned and encode_signed methods. The functions take one argument, being the integer to encode. The following encodes the given integer and returns a new StringIO containing it:

LEB128.encode_signed(-0x143f)
#=> #<StringIO:0x00000000000000>

Decode LEB128-compressed data into integers by using the decode_unsigned and decode_signed methods. The functions take two arguments: a StringIO containing the LEB128-compressed data, and an optional integer that sets the position of the StringIO (default is 0). The following decodes the given StringIO and returns a new integer containing it:

sio = StringIO.new
sio.putc(0xc1)
sio.putc(0x57)
LEB128.decode_unsigned(sio)
#=> 11201

License

This gem is available as open source under the terms of the MIT License. See LICENSE.md and https://opensource.org/licenses/MIT.

FAQs

Package last updated on 26 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc