• Stars
    star
    1,317
  • Rank 35,709 (Top 0.8 %)
  • Language
    C
  • License
    ISC License
  • Created almost 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

data compression library for embedded/real-time systems

heatshrink

A data compression/decompression library for embedded/real-time systems.

Key Features:

  • Low memory usage (as low as 50 bytes) It is useful for some cases with less than 50 bytes, and useful for many general cases with < 300 bytes.
  • Incremental, bounded CPU use You can chew on input data in arbitrarily tiny bites. This is a useful property in hard real-time environments.
  • Can use either static or dynamic memory allocation The library doesn't impose any constraints on memory management.
  • ISC license You can use it freely, even for commercial purposes.

Getting Started:

There is a standalone command-line program, heatshrink, but the encoder and decoder can also be used as libraries, independent of each other. To do so, copy heatshrink_common.h, heatshrink_config.h, and either heatshrink_encoder.c or heatshrink_decoder.c (and their respective header) into your project. For projects that use both, static libraries are built that use static and dynamic allocation.

Dynamic allocation is used by default, but in an embedded context, you probably want to statically allocate the encoder/decoder. Set HEATSHRINK_DYNAMIC_ALLOC to 0 in heatshrink_config.h.

Basic Usage

  1. Allocate a heatshrink_encoder or heatshrink_decoder state machine using their alloc function, or statically allocate one and call their reset function to initialize them. (See below for configuration options.)

  2. Use sink to sink an input buffer into the state machine. The input_size pointer argument will be set to indicate how many bytes of the input buffer were actually consumed. (If 0 bytes were conusmed, the buffer is full.)

  3. Use poll to move output from the state machine into an output buffer. The output_size pointer argument will be set to indicate how many bytes were output, and the function return value will indicate whether further output is available. (The state machine may not output any data until it has received enough input.)

Repeat steps 2 and 3 to stream data through the state machine. Since it's doing data compression, the input and output sizes can vary significantly. Looping will be necessary to buffer the input and output as the data is processed.

  1. When the end of the input stream is reached, call finish to notify the state machine that no more input is available. The return value from finish will indicate whether any output remains. if so, call poll to get more.

Continue calling finish and polling to flush remaining output until finish indicates that the output has been exhausted.

Sinking more data after finish has been called will not work without calling reset on the state machine.

Configuration

heatshrink has a couple configuration options, which impact its resource usage and how effectively it can compress data. These are set when dynamically allocating an encoder or decoder, or in heatshrink_config.h if they are statically allocated.

  • window_sz2, -w in the CLI: Set the window size to 2^W bytes.

The window size determines how far back in the input can be searched for repeated patterns. A window_sz2 of 8 will only use 256 bytes (2^8), while a window_sz2 of 10 will use 1024 bytes (2^10). The latter uses more memory, but may also compress more effectively by detecting more repetition.

The window_sz2 setting currently must be between 4 and 15.

  • lookahead_sz2, -l in the CLI: Set the lookahead size to 2^L bytes.

The lookahead size determines the max length for repeated patterns that are found. If the lookahead_sz2 is 4, a 50-byte run of 'a' characters will be represented as several repeated 16-byte patterns (2^4 is 16), whereas a larger lookahead_sz2 may be able to represent it all at once. The number of bits used for the lookahead size is fixed, so an overly large lookahead size can reduce compression by adding unused size bits to small patterns.

The lookahead_sz2 setting currently must be between 3 and the window_sz2 - 1.

  • input_buffer_size - How large an input buffer to use for the decoder. This impacts how much work the decoder can do in a single step, and a larger buffer will use more memory. An extremely small buffer (say, 1 byte) will add overhead due to lots of suspend/resume function calls, but should not change how well data compresses.

Recommended Defaults

For embedded/low memory contexts, a window_sz2 in the 8 to 10 range is probably a good default, depending on how tight memory is. Smaller or larger window sizes may make better trade-offs in specific circumstances, but should be checked with representative data.

The lookahead_sz2 should probably start near the window_sz2/2, e.g. -w 8 -l 4 or -w 10 -l 5. The command-line program can be used to measure how well test data works with different settings.

More Information and Benchmarks:

heatshrink is based on LZSS, since it's particularly suitable for compression in small amounts of memory. It can use an optional, small index to make compression significantly faster, but otherwise can run in under 100 bytes of memory. The index currently adds 2^(window size+1) bytes to memory usage for compression, and temporarily allocates 512 bytes on the stack during index construction (if the index is enabled).

For more information, see the blog post for an overview, and the heatshrink_encoder.h / heatshrink_decoder.h header files for API documentation.

Build Status

Build Status

More Repositories

1

objection

A lightweight dependency injection framework for Objective-C
Objective-C
1,847
star
2

ts-react-graphql-starter-kit

A starter kit repository for building single page webapps in TypeScript with react, redux, graphql/express, jest
TypeScript
114
star
3

odo

an atomic odometer for the command line
C
71
star
4

elegant-form-validation-react

Elegant Form Validation in React
JavaScript
62
star
5

lenses

TypeScript
57
star
6

piece_pipe

PiecePipe helps you break your code into small interesting pieces and provides the glue for pipelining them together to provide elegant, readable code.
Ruby
53
star
7

VMWareFB_OpenStep

VMWareFB OpenStep display driver -- run OpenStep and NeXTStep in VMWare in high color and high res
Objective-C
42
star
8

hamsterdam

Immutable Struct-like record structures based on Hamster.
Ruby
36
star
9

hex_string

String extensions to convert binary data to / from human readable hex tuples.
Ruby
35
star
10

ecs-deployment

Shell
32
star
11

monadt

Monads & ADTs in Ruby
Ruby
27
star
12

motion-objection

Wrapping Objection in RubyMotion.
Ruby
25
star
13

publisher

Simple event firing/subscribing mechanism in Ruby.
Ruby
23
star
14

space-battle-2

RTS game engine for Atomic Games
Ruby
23
star
15

ddc

Data Driven Controllers for your Rails app
Ruby
22
star
16

ansible-laptop-playbook-example

example Ansible playbook for a laptop
Shell
21
star
17

ts-workshop

Guided TypeScript workshop
TypeScript
18
star
18

typescript-permissions-demo

TypeScript
18
star
19

jquery.expand

Structural template engine for jQuery.
CoffeeScript
17
star
20

to_api

Instead of to_xml and as_json, simply implement to_api. Return an unformatted hash. Let the model understand the data. Let the controller understand the format. In Rails, the controller can simply call render :xml => model.to_api or render :json => model.to_api.
Ruby
16
star
21

docker-cli-distribution

Example code to accompany the blog post
Ruby
14
star
22

constructor

Declarative named-argument object initialization
Ruby
13
star
23

atomic_vim

Shared Atomic Object vim configuration
Vim Script
12
star
24

autopsy

Emit helpful artifacts on Capybara Webkit test failures
Ruby
11
star
25

fire_poll

Simple method for knowing when something is ready, running correctly, and dealing with asynchronous effects in tests and specs.
Ruby
11
star
26

multiple_return_in_c_benchmarks

benchmarks for post "Comparing the Cost of Different Multiple-return Techniques in C"
C
7
star
27

utf8_to_gsm

`Utf8ToGsm` provides functionality to convert UTF-8 characters to their GSM equivalents.
Ruby
6
star
28

CSharpMemoizer

C# Memoization Example
C#
6
star
29

ts-stack

TypeScript
6
star
30

Ensemble-Test-Framework

Ensemble Test Framework
6
star
31

birdbath

A rails gem for verifying migrations with rspec or Test::Unit
Ruby
6
star
32

strange-loop-ts-workshop

Strange Loop 2019 TypeScript Workshop!
TypeScript
5
star
33

rubymotion-nimbus-table-example

Example of using a Nimbus table view in RubyMotion.
Ruby
5
star
34

ssl_certificate_expiration_checker

Simple application to check the expiration dates on SSL certificates, and send notifications to a service.
Ruby
4
star
35

mvccontrib

Atomic MVC Contrib 'Fork'
JavaScript
3
star
36

injection

Injection is a simple dependency injection plugin for Rails. It allows you to inject objects into your controllers and observers which have been described in a yaml file (config/objects.yml).
Ruby
3
star
37

csharp_mvp_generator

Ruby code that generates model / view / presenter C# code stubs
Ruby
3
star
38

diy

Constructor-based dependency injection container using YAML input.
Ruby
2
star
39

environment_configurable

A library that makes environment dependent configuration easy in Rails.
Ruby
2
star
40

roommate-lambda

AO Conference Room IoT Project - Backend
F#
2
star
41

survival-pack

Surviving a Zombie Apocolypse
2
star
42

psinfo

psinfo example application used for embedded TDD workshops
Ruby
2
star
43

roommate

AO Conference Room IoT Project - embedded device
C
2
star
44

mongoid_class_for_collection

Flexible migrations for mongoid_rails_migrations
Ruby
2
star
45

jquery.persistedtoggle

Toggle the visibility of elements on a page using keyboard shortcuts, persisting the visibility state across requests.
JavaScript
2
star
46

terraform-aws-tailscale-router

deploys a Tailscale subnet router container into an AWS VPC
HCL
2
star
47

hardmock

A strict, ordered, expectation-oriented mock object library for testing Ruby code.
Ruby
2
star
48

kinetic-c

Seagate Kinetic Cloud Storage C Client Library and Examples
C
1
star
49

june_2012_embedded_tdd_workshop

Examples and documentation from the June 2012 Embedded TDD workshop
Ruby
1
star
50

ubuntu-1604-ruby-233-nodejs-6-passenger

Docker build configuration for Ubuntu 16.04 with Ruby 2.3.3 and NodeJS 6.10.2 LTS and Passenger (specific version tags)
Dockerfile
1
star
51

require_options

Enforces key requirements in a hash
Ruby
1
star
52

angular-pdf-library-test

TypeScript
1
star
53

alexa-atomic-spin

Alexa Skill for reading Atomic Spin posts
Ruby
1
star
54

kinetic-ruby

Seagate Kinetic Protocol Client Library
Ruby
1
star
55

LTIB-Ruby-Source

Ruby package for cross-compiling with LTIB
Ruby
1
star
56

systir

Write and run automated system tests in a domain specific language (DSL) you design, as you need it.
Ruby
1
star
57

cdcicd

Test CI/CD github actions
HTML
1
star