RedBitStream:
Filter:
redSys/Classes (extension) | Red > redTools

RedBitStream
ExtensionExtension

stream bits

Description

Modeled after CollStream. Produces a bit stream out if an array of integers. The least significant bit comes first in each byte (LSB). Use class RedBitStream2 for most significant bit first (MSB).

Class Methods

.new

Arguments:

collection

An Array of integers.

byte

Number of bits per byte in this collection of integers. If byte is 8 then integers should not be greater than 255.

Instance Methods

.bytePos

Get or set the byte position.

.collection

Get the current collection.

.contents

Get the current bit stream.

.next

Step one bit forward and return the bit value at that position. Returns nil when reached the end.

.nextByte

Step forward byte number of bits. Returns an Array of bit values and can contain nil when reached the end.

.peek

Get the bit value (0/1) at the current position.

.peekByte

Get the byte at the current -bytePos position (reading from -collection).

.poke

Set the bit value (0/1) at the current position.

Arguments:

bit

Value 0 or 1.

.pos

Get or set the bit position.

.put

Write a value at current position and advance the position by one bit.

Arguments:

item

Value 0 or 1.

.putByte

Write a byte value at the current position and advance the position by one byte.

Arguments:

item

A byte value.

.reset

Empty the -collection and set -pos to 0.

Examples