Component index
Section index

Component STREAMP


Search

Type

Object

Summary

Extract records out of a byte stream

Description

The object matches small or big reads with large or small records. The object uses fill() to grab bytes and then let process() extract records out of them. fill() may be used repeatedly to grab enough bytes to please process(). process() may be called repeatedly to exhaust the bytes in the buffer.

STREAMP has meny functags and they are all optional. In general a combination of functags and methods are used to solved a problem.

void eof ()int fill (void *buf, int size, bool &end)
void fill (const void *buf, int len)int process (const void *buf, int len, bool &end, bool nomore)
int getrecord (void *buf, int size)int validrecord (const void *buf, int len, bool &end, bool nomore)
void loop ()

Examples

sample / streamp component
sample / STREAMP object

Prototypes

STREAMP ()

Setup the object but do nothing until loop() or getrecord() is called.

Methods

void eof ()

Indicate end of file condition

Process will be called until there is no more records.

void fill (const void *buf, int len)

Inject some bytes in the engine

process() will be called until there is no more records. fill() may be used several time until one record is found.

int getrecord (void *buf, int size)

Operate the object until one record is available

The record is placed in the buffer and its length is returned.

void loop ()

Iterate between fill() and process() (or validate)

If both fill() and process() are used, loop will iterate normally until end of file. If fill() and validrecord are used, loop with iterate until one full record is available. If only process() is used, loop will iterate until there is no more record to process.

Functags

int fill (void *buf, int size, bool &end) Optional

Reads some bytes in the buffer

The functag must read some byte in buf. It returns the number of byte placed in buf, or <= 0 if end of file.

int process (const void *buf, int len, bool &end, bool nomore) Optional

Extract one record from buf and process it

The function tries to extract a complete record out of the buffer. It returns 0 if none were found (incomplete record). It return the bytes processed from the buffer (the record size generally)

int validrecord (const void *buf, int len, bool &end, bool nomore) Optional

Find out if there is a valid record in the buffer

Return the number of bytes in the record. This function kind of overlap with the process functag. It is used with the getrecord() method. When validrecord is used, process() is not.