MediaProcessors
Classes | Macros | Typedefs | Functions
bitparser.h File Reference

Bit parsing module utility. More...

#include <sys/types.h>
#include <inttypes.h>
#include "mem_utils.h"
Include dependency graph for bitparser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  bitparser_ctx_s
 

Macros

#define LITTLEENDIAN
 

Typedefs

typedef struct bitparser_ctx_s bitparser_ctx_t
 

Functions

bitparser_ctx_tbitparser_open (void *buf, size_t buf_size)
 
void bitparser_close (bitparser_ctx_t **ref_bitparser_ctx)
 
void bitparser_flush (bitparser_ctx_t *bitparser_ctx, size_t n)
 
WORD_T bitparser_get (bitparser_ctx_t *bitparser_ctx, size_t n)
 
WORD_T bitparser_show (bitparser_ctx_t *bitparser_ctx, size_t n)
 
void * bitparser_copy_bytes (bitparser_ctx_t *bitparser_ctx, size_t cnt)
 
void bitparser_align_2byte (bitparser_ctx_t *bitparser_ctx)
 

Detailed Description

Bit parsing module utility.

Author
Rafael Antoniello

Definition in file bitparser.h.

Macro Definition Documentation

#define LITTLEENDIAN

Endianess: define either little (un-comment definition below) or big endian (comment definition).

Definition at line 49 of file bitparser.h.

Function Documentation

void bitparser_align_2byte ( bitparser_ctx_t bitparser_ctx)

Align bit parser to the next byte boundary

Parameters
bitparser_ctxPointer to bit-parser context structure.

Definition at line 217 of file bitparser.c.

void bitparser_close ( bitparser_ctx_t **  ref_bitparser_ctx)

// FIXME!!

Definition at line 115 of file bitparser.c.

void* bitparser_copy_bytes ( bitparser_ctx_t bitparser_ctx,
size_t  cnt 
)

Copy 'cnt' bytes from bit-parser internal buffer to a dynamically (heap) allocated memory. Important: note that this function requires copy operation to be byte aligned; thus, this function copies the byte block corresponding to the current value of the internal bit-counter.

Parameters
bitparser_ctxPointer to bit-parser context structure
cntNumber of bytes to copy
Returns
Pointer to the copy allocation. The allocation should be freed later by the caller.

Definition at line 186 of file bitparser.c.

void bitparser_flush ( bitparser_ctx_t bitparser_ctx,
size_t  n 
)

Flush next n bits out of buffer (Advance internal bit-counter by 'n' bits).

Parameters
bitparser_ctxPointer to bit-parser context structure
nnumber of bits to flush.

Definition at line 129 of file bitparser.c.

WORD_T bitparser_get ( bitparser_ctx_t bitparser_ctx,
size_t  n 
)

Get next n bits right aligned in an unsigned 32/64-bit word. Bits are "flushed" from internal buffer, incrementing internal bit counter.

Parameters
bitparser_ctxPointer to bit-parser context structure
nNumber of bits to get (internal bit counter is incremented by 'n')
Returns
Unsigned 32/64-bit word showing next n bits right aligned (stream bits are ordered from left to right).

Definition at line 163 of file bitparser.c.

bitparser_ctx_t* bitparser_open ( void *  buf,
size_t  buf_size 
)

//FIXME!! Initializes the bit-parser context attributes, getting ready for parsing.

Parameters
bitparser_ctxPointer to bit-parser context structure
bufPointer to buffer to be parsed.
buf_sizeParsing buffer size in bytes. Value MUST be a multiple of 8.
Returns
Status code (refer to 'stat_codes_ctx_t' type).
See also
stat_codes_ctx_t

Definition at line 82 of file bitparser.c.

WORD_T bitparser_show ( bitparser_ctx_t bitparser_ctx,
size_t  n 
)

Show next n bits right aligned in an unsigned 32/64-bit word. Internal buffer bit counter is not modified (namely, consecutive identical calls to this function will return the same value).

Parameters
bitparser_ctxPointer to bit-parser context structure
nNumber of bits to show
Returns
Unsigned 32/64-bit word showing next n bits right aligned (stream bits are ordered from left to right).

Definition at line 175 of file bitparser.c.