Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

cobs.h File Reference


Detailed Description

Consistant Overhead Byte Stuffing (COBS).

Author:
Raphael Manfredi
Date:
2002-2003

#include <glib.h>

Go to the source code of this file.

Data Structures

struct  cobs_stream
 A COBS stream is used to fill a buffer space with COBS-ed data where the input data is not known beforehand but gathered a piece at a time. More...


Typedefs

typedef cobs_stream cobs_stream_t
 A COBS stream is used to fill a buffer space with COBS-ed data where the input data is not known beforehand but gathered a piece at a time.


Enumerations

enum  cobs_magic { COBS_MAGIC = 0xc0befU }

Functions

gchar * cobs_encode (gchar *buf, size_t len, size_t *retlen)
 Encode `len' bytes starting at `buf' into new allocated buffer.

gchar * cobs_encodev (struct iovec *iov, gint iovcnt, size_t *retlen)
 Encode vector `iov' of `iovcnt' elements, whose size is held in `retlen'.

gchar * cobs_decode (gchar *buf, size_t len, size_t *retlen, gboolean inplace)
 Decode `len' bytes starting at `buf' into new allocated buffer, unless `inplace' is true in which case decoding is done inplace.

gboolean cobs_decode_into (const gchar *buf, size_t len, gchar *out, size_t outlen, size_t *retlen)
 Decode `len' bytes starting at `buf' into decoding buffer `out', which is `outlen' bytes long.

gboolean cobs_is_valid (const gchar *buf, size_t len)
 Check whether supplied buffer forms a valid COBS encoding.

void cobs_stream_init (cobs_stream_t *cs, gpointer data, size_t len)
 Initialize an incremental COBS context, where data will be written in the supplied buffer.

size_t cobs_stream_close (cobs_stream_t *cs, gboolean *saw_nul)
 Close COBS stream: we have no more data to write.

gboolean cobs_stream_write (cobs_stream_t *cs, gpointer data, size_t len)
 Add data to the COBS stream.

void cobs_stream_invalidate (cobs_stream_t *cs)
 Empty the descriptor, making it invalid.

gboolean cobs_stream_is_valid (cobs_stream_t *cs)
 Check whether the stream descriptor is valid, for assertions.


Typedef Documentation

typedef struct cobs_stream cobs_stream_t
 

A COBS stream is used to fill a buffer space with COBS-ed data where the input data is not known beforehand but gathered a piece at a time.


Enumeration Type Documentation

enum cobs_magic
 

Enumeration values:
COBS_MAGIC 


Function Documentation

gchar* cobs_decode gchar *  buf,
size_t  len,
size_t *  retlen,
gboolean  inplace
 

Decode `len' bytes starting at `buf' into new allocated buffer, unless `inplace' is true in which case decoding is done inplace.

Returns:
the new decoded buffer, or NULL if the input was not valid COBS encoding. The length of the decoded buffer is in `retlen'.

gboolean cobs_decode_into const gchar *  buf,
size_t  len,
gchar *  out,
size_t  outlen,
size_t *  retlen
 

Decode `len' bytes starting at `buf' into decoding buffer `out', which is `outlen' bytes long.

Returns:
whether the input was valid COBS encoding. The length of the decoded buffer is returned in `retlen'.

gchar* cobs_encode gchar *  buf,
size_t  len,
size_t *  retlen
 

Encode `len' bytes starting at `buf' into new allocated buffer.

Returns:
the new encoded buffer, and its length in `retlen'.

gchar* cobs_encodev struct iovec *  iov,
gint  iovcnt,
size_t *  retlen
 

Encode vector `iov' of `iovcnt' elements, whose size is held in `retlen'.

Returns:
the new encoded buffer, and its length in `retlen'.
Attention:
NB: the output is a linear buffer, not a vector.

gboolean cobs_is_valid const gchar *  buf,
size_t  len
 

Check whether supplied buffer forms a valid COBS encoding.

size_t cobs_stream_close cobs_stream_t cs,
gboolean *  saw_nul
 

Close COBS stream: we have no more data to write.

Parameters:
cs the stream to close
saw_nul if non-NULL, writes whether we saw a NUL in the input
Returns:
the final length of the stream on success, 0 on error.

void cobs_stream_init cobs_stream_t cs,
gpointer  data,
size_t  len
 

Initialize an incremental COBS context, where data will be written in the supplied buffer.

Parameters:
cs the COBS stream to initialize.
data start of buffer where data will be written
len length of supplied buffer

void cobs_stream_invalidate cobs_stream_t cs  ) 
 

Empty the descriptor, making it invalid.

gboolean cobs_stream_is_valid cobs_stream_t cs  ) 
 

Check whether the stream descriptor is valid, for assertions.

gboolean cobs_stream_write cobs_stream_t cs,
gpointer  data,
size_t  len
 

Add data to the COBS stream.

Returns:
TRUE if OK, FALSE if we cannot put the data any more.


Generated on Sun Feb 12 10:49:59 2006 for Gtk-Gnutella by doxygen 1.3.6