gcoding

package module
v0.0.0-...-c0c4c77 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2017 License: MIT Imports: 4 Imported by: 0

README

gcoding

gcoding is an encoding library for golang. Currently implements unary, gamma and golomb-rice coding.

Example

package main

import (
	"bytes"
	"fmt"

	"github.com/bluele/gcoding"
)

func main() {
	buf := new(bytes.Buffer)
	w := gcoding.NewBitsWriter(buf)
	enc := gcoding.NewGolombEncoder(w, 4)
	for _, v := range []uint{1, 2, 3, 4, 5, 10} {
		enc.Write(v)
	}
	enc.Flush()

	// 10011010 10110100 00100100 10100000
	fmt.Println(gcoding.BitsToString(buf.Bytes()))

	dec := gcoding.NewGolombDeocder(4)

	// [1 2 3 4 5 10] <nil>
	fmt.Println(dec.Decode(buf))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitsToString

func BitsToString(bs []byte) string

BitsToString returns pretty format for bits

Types

type AlphaDecoder

type AlphaDecoder struct{}

func NewAlphaDecoder

func NewAlphaDecoder() *AlphaDecoder

func (*AlphaDecoder) Decode

func (dec *AlphaDecoder) Decode(r io.Reader) ([]uint, error)

func (*AlphaDecoder) DecodeN

func (dec *AlphaDecoder) DecodeN(r io.Reader, n int) ([]uint, error)

type AlphaEncoder

type AlphaEncoder struct {
	// contains filtered or unexported fields
}

func NewAlphaEncoder

func NewAlphaEncoder(w *BitsWriter) *AlphaEncoder

func (*AlphaEncoder) Flush

func (enc *AlphaEncoder) Flush() error

func (*AlphaEncoder) Write

func (enc *AlphaEncoder) Write(v uint)

type BitsReader

type BitsReader struct {
	// contains filtered or unexported fields
}

BitsReader reads bits from the given io.Reader.

func NewBitsReader

func NewBitsReader(rd io.Reader) *BitsReader

NewBitsReader returns new a new Reader.

func (*BitsReader) Read

func (r *BitsReader) Read(n uint) (uint, error)

type BitsWriter

type BitsWriter struct {
	// contains filtered or unexported fields
}

BitsWriter writes bits into underlying io.Writer

func NewBitsWriter

func NewBitsWriter(w io.Writer) *BitsWriter

NewBitsWriter returns a new Writer.

func (*BitsWriter) Flush

func (w *BitsWriter) Flush() error

Flush writes any remaining bits to the underlying io.Writer. bits will be left-shifted.

func (*BitsWriter) Write

func (w *BitsWriter) Write(bits uint, n uint) error

BitsWrite writes bits with give size n.

type GammaDecoder

type GammaDecoder struct{}

func NewGammaDecoder

func NewGammaDecoder() *GammaDecoder

func (*GammaDecoder) Decode

func (dec *GammaDecoder) Decode(r io.Reader) ([]uint, error)

type GammaEncoder

type GammaEncoder struct {
	// contains filtered or unexported fields
}

func NewGammaEncoder

func NewGammaEncoder(w *BitsWriter) *GammaEncoder

func (*GammaEncoder) Flush

func (enc *GammaEncoder) Flush() error

func (*GammaEncoder) Write

func (enc *GammaEncoder) Write(v uint)

type GolombDecoder

type GolombDecoder struct {
	// contains filtered or unexported fields
}

func NewGolombDeocder

func NewGolombDeocder(b uint) *GolombDecoder

func (*GolombDecoder) Decode

func (dec *GolombDecoder) Decode(r io.Reader) ([]uint, error)

type GolombEncoder

type GolombEncoder struct {
	// contains filtered or unexported fields
}

func NewGolombEncoder

func NewGolombEncoder(w *BitsWriter, b uint) *GolombEncoder

func (*GolombEncoder) Flush

func (enc *GolombEncoder) Flush() error

func (*GolombEncoder) Write

func (enc *GolombEncoder) Write(n uint) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL