writer

package
v0.0.0-...-fb73569 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 2 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

View Source
var (
	// ErrInvalidBitValue defines the error when invalid 'bit' value is provided.
	ErrInvalidBitValue = errors.New("invalid bit value")
)

Functions

This section is empty.

Types

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) 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) 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