writer

package
v0.0.0-...-90a1d6d Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: AGPL-3.0, AGPL-3.0-only Imports: 3 Imported by: 0

Documentation

Overview

Package writer contains the data writer that implements io.Writer, io.ByteWriter and allows to write single bits. The writer WriteBit method might be used in a dual way. By default it writes next bit starting from the LSB - least significant bit. By creating the Writer with NewMSB function the writer would write all bits starting from the MSB - most significant bit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryWriter

type BinaryWriter interface {
	BitWriter
	io.Writer
	io.ByteWriter
	Data() []byte
}

BinaryWriter is the interface that implements writer.BitWriter, io.Writer and io.ByteWriter.

type BitWriter

type BitWriter interface {
	// WriteBit writes the 'bit' - {0,1} value to the writer.
	WriteBit(bit int) error
	// WriteBits writes 'number' of 'bits'.
	WriteBits(bits uint64, number int) (n int, err error)
	// FinishByte sets the bitIndex to the end of given byte. This resets the bitIndex to 0
	// and the byte index to the next byte.
	FinishByte()
	// SkipBits skips the 'skip' number of bits in the writer - changes the index position of the bit and byte.
	// The value -1 sets the bitIndex to the beginning of the byte.
	SkipBits(skip int) error
}

BitWriter is the interface that allows to write single bits.

type Buffer

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

Buffer is the Writer implementation that works on expandable data slices.

func BufferedMSB

func BufferedMSB() *Buffer

BufferedMSB creates a buffered writer with MSB bit writing method.

func (*Buffer) Data

func (b *Buffer) Data() []byte

Data gets the buffer byte slice data. The buffer is the owner of the byte slice data, thus the data is available until next buffer Reset.

func (*Buffer) FinishByte

func (b *Buffer) FinishByte()

FinishByte finishes current bit written byte and sets the current byte index pointe to the next byte.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes of the unwritten portion of the buffer.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the data buffer as well as the bit and byte indexes.

func (*Buffer) ResetBitIndex

func (b *Buffer) ResetBitIndex()

ResetBitIndex resets the current bit index.

func (*Buffer) SkipBits

func (b *Buffer) SkipBits(skip int) error

SkipBits implements BitWriter interface.

func (*Buffer) Write

func (b *Buffer) Write(d []byte) (int, error)

Write implements io.Writer interface.

func (*Buffer) WriteBit

func (b *Buffer) WriteBit(bit int) error

WriteBit implements BitWriter interface.

func (*Buffer) WriteBits

func (b *Buffer) WriteBits(bits uint64, number int) (n int, err error)

WriteBits writes 'bits' values of a specific 'number' into the writer.Buffer.

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(bt byte) error

WriteByte implements io.ByteWriter.

type Writer

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

Writer is the structure used to write bits, bytes into predefined data. It allows to write the bits in two modes. The first and default writes bytes with the initial bitIndex 0 as the LSB (Least Significant Bit) The second mode writes bits in an opposite manner starting from the MSB (Most Significant Bit). The writer is being created by the methods: 'New' and 'NewMSB', where the first creates default writer and the second the 'msb' flagged writer. Implements io.Writer, io.ByteWriter interfaces.

func New

func New(data []byte) *Writer

New creates new writer for the provided data.

func NewMSB

func NewMSB(data []byte) *Writer

NewMSB creates new writer with the msb flag. While default writer writes single bits into LSB, the msbWriter writes single bits starting from the MSB. Example:

InverseWriter contains following data:
data - 10010100 01001110 00000000
					 	 ^
The default current bit index is pointed by '^'.
Writing new '1' bit to the following data would result as:
data - 10010100 01001110 10000000

func (*Writer) Data

func (w *Writer) Data() []byte

Data gets the writer data.

func (*Writer) FinishByte

func (w *Writer) FinishByte()

FinishByte implements BitWriter interface.

func (*Writer) ResetBit

func (w *Writer) ResetBit()

ResetBit resets the bit counter setting it to '0'.

func (*Writer) SkipBits

func (w *Writer) SkipBits(skip int) error

SkipBits implements BitWriter interface.

func (*Writer) UseMSB

func (w *Writer) UseMSB() bool

UseMSB gets the writer flag if it works on the MSB mode.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write implements io.Writer interface.

func (*Writer) WriteBit

func (w *Writer) WriteBit(bit int) error

WriteBit writes single bit into provided bit writer data.

func (*Writer) WriteBits

func (w *Writer) WriteBits(bits uint64, number int) (n int, err error)

WriteBits writes the 'bits' of the specific 'number' into writer.

func (*Writer) WriteByte

func (w *Writer) WriteByte(c byte) error

WriteByte implements io.ByteWriter interface.

Jump to

Keyboard shortcuts

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