binary

package
v1.7.0-dev-20190926 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: Apache-2.0 Imports: 5 Imported by: 93

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumeBytes

func ConsumeBytes(r Reader, bytes uint64) uint64

ConsumeBytes reads and throws away a number of bytes from r, returning the number of bytes it consumed.

func ReadInt

func ReadInt(r Reader, bits int32) int64

ReadInt reads a signed integer of either 8, 16, 32 or 64 bits from r, returning the result as a int64.

func ReadUint

func ReadUint(r Reader, bits int32) uint64

ReadUint reads an unsigned integer of either 8, 16, 32 or 64 bits from r, returning the result as a uint64.

func Write added in v1.1.0

func Write(w Writer, v interface{})

Write writes v to the writer w. v must be an byte, integer, float, boolean, string, slice or array.

func WriteBytes

func WriteBytes(w Writer, v uint8, count int32)

WriteBytes writes the given v for count times to writer w.

func WriteInt

func WriteInt(w Writer, bits int32, v int64)

WriteInt writes the signed integer v of either 8, 16, 32 or 64 bits to w.

func WriteUint

func WriteUint(w Writer, bits int32, v uint64)

WriteUint writes the unsigned integer v of either 8, 16, 32 or 64 bits to w.

Types

type BitStream

type BitStream struct {
	Data     []byte // The byte slice containing the bits
	ReadPos  uint32 // The current read offset from the start of the Data slice (in bits)
	WritePos uint32 // The current write offset from the start of the Data slice (in bits)
}

BitStream provides methods for reading and writing bits to a slice of bytes. Bits are packed in a least-significant-bit to most-significant-bit order.

func (*BitStream) CanRead added in v0.6.2

func (s *BitStream) CanRead(count uint32) bool

CanRead returns true if there's enough data to call Read(count).

func (*BitStream) Read

func (s *BitStream) Read(count uint32) uint64

Read reads the specified number of bits from the BitStream, increamenting the ReadPos by the specified number of bits and returning the bits packed into a uint64. The bits are packed into the uint64 from LSB to MSB.

func (*BitStream) ReadBit

func (s *BitStream) ReadBit() uint64

ReadBit reads a single bit from the BitStream, incrementing ReadPos by one.

func (*BitStream) Write

func (s *BitStream) Write(bits uint64, count uint32)

Write writes the specified number of bits from the packed uint64, increamenting the WritePos by the specified number of bits. The bits are read from the uint64 from LSB to MSB.

func (*BitStream) WriteBit

func (s *BitStream) WriteBit(bit uint64)

WriteBit writes a single bit to the BitStream, incrementing WritePos by one.

type Reader

type Reader interface {
	io.Reader
	// Data reads the data bytes in their entirety.
	Data([]byte)
	// Bool decodes and returns a boolean value from the Reader.
	Bool() bool
	// Int8 decodes and returns a signed, 8 bit integer value from the Reader.
	Int8() int8
	// Uint8 decodes and returns an unsigned, 8 bit integer value from the Reader.
	Uint8() uint8
	// Int16 decodes and returns a signed, 16 bit integer value from the Reader.
	Int16() int16
	// Uint16 decodes and returns an unsigned, 16 bit integer value from the Reader.
	Uint16() uint16
	// Int32 decodes and returns a signed, 32 bit integer value from the Reader.
	Int32() int32
	// Uint32 decodes and returns an unsigned, 32 bit integer value from the Reader.
	Uint32() uint32
	// Float16 decodes and returns a 16 bit floating-point value from the Reader.
	Float16() f16.Number
	// Float32 decodes and returns a 32 bit floating-point value from the Reader.
	Float32() float32
	// Int64 decodes and returns a signed, 64 bit integer value from the Reader.
	Int64() int64
	// Uint64 decodes and returns an unsigned, 64 bit integer value from the Reader.
	Uint64() uint64
	// Float64 decodes and returns a 64 bit floating-point value from the Reader.
	Float64() float64
	// String decodes and returns a string from the Reader.
	String() string
	// Decode a collection count from the stream.
	Count() uint32
	// If there is an error reading any input, all further reading returns the
	// zero value of the type read. Error() returns the error which stopped
	// reading from the stream. If reading has not stopped it returns nil.
	Error() error
	// Set the error state and stop reading from the stream.
	SetError(error)
}

Reader provides methods for decoding values.

type Writer

type Writer interface {
	// Data writes the data bytes in their entirety.
	Data([]byte)
	// Bool encodes a boolean value to the Writer.
	Bool(bool)
	// Int8 encodes a signed, 8 bit integer value to the Writer.
	Int8(int8)
	// Uint8 encodes an unsigned, 8 bit integer value to the Writer.
	Uint8(uint8)
	// Int16 encodes a signed, 16 bit integer value to the Writer.
	Int16(int16)
	// Uint16 encodes an unsigned, 16 bit integer value to the Writer.
	Uint16(uint16)
	// Int32 encodes a signed, 32 bit integer value to the Writer.
	Int32(int32)
	// Uint32 encodes an usigned, 32 bit integer value to the Writer.
	Uint32(uint32)
	// Float16 encodes a 16 bit floating-point value to the Writer.
	Float16(f16.Number)
	// Float32 encodes a 32 bit floating-point value to the Writer.
	Float32(float32)
	// Int64 encodes a signed, 64 bit integer value to the Writer.
	Int64(int64)
	// Uint64 encodes an unsigned, 64 bit integer value to the Encoders's io.Writer.
	Uint64(uint64)
	// Float64 encodes a 64 bit floating-point value to the Writer.
	Float64(float64)
	// String encodes a string to the Writer.
	String(string)
	// If there is an error writing any output, all further writing becomes
	// a no-op. Error() returns the error which stopped writing to the stream.
	// If writing has not stopped it returns nil.
	Error() error
	// Set the error state and stop writing to the stream.
	SetError(error)
}

Writer provides methods for encoding values.

Jump to

Keyboard shortcuts

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