isobmff-builder-0.11.2.0: A (bytestring-) builder for the ISO-14496-12 base media file format

Safe HaskellNone
LanguageHaskell2010

Data.Type.BitRecords.Builder.BitBuffer

Synopsis

Documentation

type BitStringMaxLength = 64 Source #

The maximum number of bits a BitBuffer can hold.

type family ModuloBitStringMaxLength (len :: Nat) :: Nat where ... Source #

Calculate the modulus of a number and the BitStringMaxLength.

Equations

ModuloBitStringMaxLength len = len `RemPow2` 6 

bitStringMaxLength :: Num a => a Source #

The maximum number of bits a BitBuffer can hold.

bitStringMaxLengthBytes :: Word64 Source #

The maximum number of bytes a BitBuffer can hold.

data BitString Source #

A string of bits with a given length (but always <= bitStringMaxLength. The number of bits must be smaller that bitStringMaxLength.

bitString :: Int -> Word64 -> BitString Source #

Create a BitString containing len bits from LSB to MSB, properly masked, such that only len least significant bits are kept..

bitStringProxyLength :: KnownChunkSize n => Proxy n -> Word64 -> BitString Source #

Create a BitStringBuilderChunk with a length given by a Proxy to a type level Nat.

data BitStringBuilderChunk Source #

A buffer for 64 bits, such that the bits are written MSB to LSB.

type TwoFields = "f0" @: Field m .+. "f1" @: Field n

Writes: MSB LSB Bit: |k .. k-(m+1)|k-m .. k-(m+n+1)|k-(m+n) .. 0| Value: |------f0------|--------f1--------|XXXXXXXXXXXXXX|

Where k is the current bit offset. The input values are expected to be in the order of the fields, i.e.:

runHoley $ bitStringBuilderHoley (Proxy :: Proxy TwoFields) 1 2

Will result in: MSB LSB Bit: |k .. k-(m+1)|k-m .. k-(m+n+1)| k-(m+n) .. 0| Value: |0 .. 1|0 .. 10| X .. X|

bitStringBuilderChunk :: Word64 -> Int -> BitStringBuilderChunk Source #

Create a BitStringBuilderChunk containing len bits from LSB to MSB, properly masked, such that only len least significant bits are kept..

bufferBits Source #

Arguments

:: BitString

The value to write (in the lower length bits).

-> BitStringBuilderChunk

The input to write to

-> (BitString, BitStringBuilderChunk)

The remaining bits that did not fit in the buffer and the output buffer.

Copy bits starting at a specific offset from one a the the other. Set bits starting from the most significant bit to the least. For example writeBits m 1 <> writeBits n 2 would result in:

        MSB                                             LSB
   Bit: |k  ..  k-(m+1)|k-m  ..  k-(m+n+1)| k-(m+n)  ..  0|
 Value: |0     ..     1|0        ..     10|  ...          |
         ->             ->                 ->     (direction of writing)

type family KnownChunkSize (s :: Nat) :: Constraint where ... Source #

Equations

KnownChunkSize size = (KnownNat size, size <= BitStringMaxLength)