GithubHelp home page GithubHelp logo

small_ints's Introduction

small_ints

small_ints is an Erlang module that can help you deal with encoding and decoding of integers using the varint and ZigZag algorithms described in the "Encoding" section of Google Protocol Buffer's docs.

Building

$ rebar3 compile

Varint

Basically, you use a variable number of bytes to represent a positive integer. You can encode varints to binaries and decode them from binaries like this:

small_ints:encode_varint(5).    %=> <<5>>
small_ints:encode_varint(1034). %=> <<138,8>>

small_ints:decode_varint(<<5,"foo">>). %=> {5, <<"foo">>}
small_ints:decode_varint(<<138,8>>). %=> {1034, <<>>}

ZigZag

The ZigZag algorithm is used to encode small positive and negative numbers with a small number of bytes.

small_ints:encode_zigzag(1).  %=> 2
small_ints:encode_zigzag(-5). %=> 9

small_ints:decode_zigzag(6).  %=> 3

Other stuff

small_ints also provides two utility functions which just combine the varint and ZigZag algorithms:

  • small_ints:decode_zigzag_varint/1: decodes the next varint from the given binary and then decodes it with ZigZag
  • small_ints:encode_zigzag_varint/1: encodes the given integer with ZigZag, then encodes the result with varint

License

MIT License © 2015, Andrea Leopardi

small_ints's People

Contributors

mpriestman avatar whatyouhide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

small_ints's Issues

Request for tag

Hi.

Would you consider tagging your code with 1.0.0 (or something like it)?

Thanks much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.