Moep Library  2.0-nc
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Frame

The Frame API contains the functioality used to manage frames. More...

Files

file  frame.h
 

Typedefs

typedef struct moep_frame * moep_frame_t
 a moep frame More...
 

Functions

u8 * moep_frame_get_payload (moep_frame_t frame, size_t *len)
 return payload of a frame More...
 
u8 * moep_frame_set_payload (moep_frame_t frame, u8 *payload, size_t len)
 set payload of a frame More...
 
u8 * moep_frame_adjust_payload_len (moep_frame_t frame, size_t len)
 adjust the len of the payload of a frame More...
 
int moep_frame_decode (moep_frame_t frame, u8 *buf, size_t buflen)
 decode a frame More...
 
int moep_frame_encode (moep_frame_t frame, u8 **buf, size_t buflen)
 encode a frame More...
 
void moep_frame_destroy (moep_frame_t frame)
 destroy a frame More...
 

Detailed Description

The Frame API contains the functioality used to manage frames.

This is the generic API available for all frames. Specialized functions are provided by the respective module.

Typedef Documentation

typedef struct moep_frame* moep_frame_t

a moep frame

This is the opaque representation of a frame.

Function Documentation

u8* moep_frame_get_payload ( moep_frame_t  frame,
size_t *  len 
)

return payload of a frame

The function moep_frame_get_payload() returns the payload associated with the frame.

Parameters
framethe frame
lenreturns the length of the payload.
Returns
This function returns a pointer to the payload or NULL if no payload is associated with the frame.
u8* moep_frame_set_payload ( moep_frame_t  frame,
u8 *  payload,
size_t  len 
)

set payload of a frame

The function moep_frame_set_payload() adds a payload to the frame. Any payload previously set is freed. If payload is NULL only the previous payload is removed. The content of payload is copied to an internal buffer so that payload does not need to be preserved.

Parameters
framethe frame
payloada pointer to the payload
lenthe length of the payload
Returns
This function returns a pointer to the internally saved payload.
Return values
NULLon error (errno is set appropriately) or if payload is NULL
Errors
ENOMEMNot enough memory available.
u8* moep_frame_adjust_payload_len ( moep_frame_t  frame,
size_t  len 
)

adjust the len of the payload of a frame

The function moep_frame_adjust_payload_len() changes the size of the payload associated with the frame. If necessary the internal buffer is changed.

Parameters
framethe frame
lenthe new length of the payload
Returns
This function returns a pointer to the new internal payload buffer.
Return values
NULLon error (errno is set appropriately) or if len is 0
Errors
ENOMEMNot enough memory available.
int moep_frame_decode ( moep_frame_t  frame,
u8 *  buf,
size_t  buflen 
)

decode a frame

The function moep_frame_decode() decodes a frame from the buffer buf and saves the parsed content inside frame. This function needs a frame to be already created, so normally one would use moep_dev_frame_decode().

Parameters
framethe frame to store data in
bufthe buffer with the frame
buflenthe length of the buffer
Return values
0on success
-1on error, errno is set appropriately.
int moep_frame_encode ( moep_frame_t  frame,
u8 **  buf,
size_t  buflen 
)

encode a frame

The function moep_frame_encode() encodes a frame to a buffer. This function can be used in multiple ways:

  • if buf is NULL, only the length the frame would need is returned.
  • if *buf is NULL and buflen is 0, an appropriate buffer is allocated to hold the frame and returned in buf.
  • if *buf is NULL and buflen is not 0, a buffer of at most buflen is allocated.
  • if *buf is not NULL, it will be used as buffer if it is big enough to hold the frame.
Parameters
framethe frame to be encoded
bufa pointer to the buffer
buflenthe length of the buffer
Returns
This function returns the length of the encoded frame.
Return values
-1on error, errno is set appropriately.
Errors
These are some standard errors generated by this function. Additional errors may be generated and returned from the underlying device specific functions.
EMSGSIZEThe buffer is too small to hold the encoded frame.
ENOMEMNot enough memory available.
void moep_frame_destroy ( moep_frame_t  frame)

destroy a frame

The function moep_frame_destroy() destroys a frame and releases its associated ressources.

Parameters
framethe frame