Wire Buffer
[Common Code]


Files

file  xdas_wire.c
 OpenXDAS wire buffer insertion and extraction routines.
file  xdas_wire.h
 OpenXDAS wire buffer insertion and extraction routines.

Buffer extraction and insertion macros.

These macros safely extract 16, 24, and 32-bit values from and insert them into raw wire buffers, regardless of machine endian-ness, or hardware alignment strictness.

The do so by reading and writing a byte at a time which defeats alignment issues, and building the value by bit-shifting, which doesn't care about endian-ness. Buffer values are assumed to be in network byte order (big-endian) format.

#define AS_UINT16(p)
 Extract an unsigned 16-bit quantity from a wire buffer.
#define AS_UINT24(p)
 Extract an unsigned 24-bit quantity from a wire buffer.
#define AS_UINT32(p)
 Extract an unsigned 32-bit quantity from a wire buffer.
#define TO_UINT16(p, v)
 Insert an unsigned 16-bit quantity into a wire buffer.
#define TO_UINT24(p, v)
 Insert an unsigned 24-bit quantity into a wire buffer.
#define TO_UINT32(p, v)
 Insert an unsigned 32-bit quantity into a wire buffer.

Functions

uint16_t xdas_get_uint16 (char **cpp)
 Extract a 16-bit big-endian buffer value into a native 16-bit word.
uint32_t xdas_get_uint24 (char **cpp)
 Extract a 24-bit big-endian buffer value into a native 32-bit word.
uint32_t xdas_get_uint32 (char **cpp)
 Extract a 32-bit big-endian buffer value into a native 32-bit word.
void xdas_put_uint16 (char **cpp, size_t val)
 Insert a 16-bit native word into a buffer in big-endian format.
void xdas_put_uint24 (char **cpp, size_t val)
 Insert a 24-bit native word into a buffer in big-endian format.
void xdas_put_uint32 (char **cpp, size_t val)
 Insert a 32-bit native word into a buffer in big-endian format.

Define Documentation

#define AS_UINT16 (  ) 

Value:

(uint16_t)((((uint8_t *)(p))[0] <<  8) |\
              (((uint8_t *)(p))[1]      ))
Extract an unsigned 16-bit quantity from a wire buffer.

Definition at line 68 of file xdas_wire.h.

Referenced by xdas_get_uint16().

#define AS_UINT24 (  ) 

Value:

(uint32_t)((((uint8_t *)(p))[0] << 16) |\
              (((uint8_t *)(p))[1] <<  8) |\
              (((uint8_t *)(p))[2]      ))
Extract an unsigned 24-bit quantity from a wire buffer.

Definition at line 74 of file xdas_wire.h.

Referenced by xdas_get_uint24().

#define AS_UINT32 (  ) 

Value:

(uint32_t)((((uint8_t *)(p))[0] << 24) |\
              (((uint8_t *)(p))[1] << 16) |\
              (((uint8_t *)(p))[2] <<  8) |\
              (((uint8_t *)(p))[3]      ))
Extract an unsigned 32-bit quantity from a wire buffer.

Definition at line 81 of file xdas_wire.h.

Referenced by mcache_read_record(), mcache_update_bof(), xdas_get_uint32(), xdas_req_rsp(), and xdasd_read_stream().

#define TO_UINT16 ( p,
 ) 

Value:

((((uint8_t *)(p))[0]=(uint8_t)(((v) >>  8) & 0xff)),\
    (((uint8_t *)(p))[1]=(uint8_t)(((v)      ) & 0xff)))
Insert an unsigned 16-bit quantity into a wire buffer.

Definition at line 89 of file xdas_wire.h.

Referenced by xdas_put_uint16().

#define TO_UINT24 ( p,
 ) 

Value:

((((uint8_t *)(p))[0]=(uint8_t)(((v) >> 16) & 0xff)),\
    (((uint8_t *)(p))[1]=(uint8_t)(((v) >>  8) & 0xff)),\
    (((uint8_t *)(p))[2]=(uint8_t)(((v)      ) & 0xff)))
Insert an unsigned 24-bit quantity into a wire buffer.

Definition at line 95 of file xdas_wire.h.

Referenced by xdas_put_uint24().

#define TO_UINT32 ( p,
 ) 

Value:

((((uint8_t *)(p))[0]=(uint8_t)(((v) >> 24) & 0xff)),\
    (((uint8_t *)(p))[1]=(uint8_t)(((v) >> 16) & 0xff)),\
    (((uint8_t *)(p))[2]=(uint8_t)(((v) >>  8) & 0xff)),\
    (((uint8_t *)(p))[3]=(uint8_t)(((v)      ) & 0xff)))
Insert an unsigned 32-bit quantity into a wire buffer.

Definition at line 102 of file xdas_wire.h.

Referenced by xdas_put_uint32().


Function Documentation

uint16_t xdas_get_uint16 ( char **  cpp  ) 

Extract a 16-bit big-endian buffer value into a native 16-bit word.

Parameters:
[in,out] cpp - The address of a pointer from which to extract.
Returns:
A 16-bit unsigned value in native format; the buffer pointer is moved ahead by 2 bytes on return.

For internal use only.

Definition at line 50 of file xdas_wire.c.

References AS_UINT16.

Referenced by mcache_read_record().

uint32_t xdas_get_uint24 ( char **  cpp  ) 

Extract a 24-bit big-endian buffer value into a native 32-bit word.

Parameters:
[in,out] cpp - The address of a pointer from which to extract.
Returns:
A 32-bit unsigned value in native format; the buffer pointer is moved ahead by 3 bytes on return.

For internal use only.

Definition at line 66 of file xdas_wire.c.

References AS_UINT24.

uint32_t xdas_get_uint32 ( char **  cpp  ) 

Extract a 32-bit big-endian buffer value into a native 32-bit word.

Parameters:
[in,out] cpp - The address of a pointer from which to extract.
Returns:
A 32-bit unsigned value in native format; the buffer pointer is moved ahead by 4 bytes on return.

For internal use only.

Definition at line 82 of file xdas_wire.c.

References AS_UINT32.

Referenced by mcache_read_file_header(), and mcache_read_record().

void xdas_put_uint16 ( char **  cpp,
size_t  val 
)

Insert a 16-bit native word into a buffer in big-endian format.

Parameters:
[in,out] cpp - the address of a pointer where val is written.
[in] val - a 16-bit native value to be inserted into cpp.
Note:
The buffer address is moved ahead by 2 bytes on return.

For internal use only.

Definition at line 98 of file xdas_wire.c.

References TO_UINT16.

Referenced by mcache_write_record().

void xdas_put_uint24 ( char **  cpp,
size_t  val 
)

Insert a 24-bit native word into a buffer in big-endian format.

Parameters:
[in,out] cpp - the address of a pointer where val is written.
[in] val - a 24-bit native value to be inserted into cpp.
Note:
The buffer address is moved ahead by 3 bytes on return.

For internal use only.

Definition at line 113 of file xdas_wire.c.

References TO_UINT24.

void xdas_put_uint32 ( char **  cpp,
size_t  val 
)

Insert a 32-bit native word into a buffer in big-endian format.

Parameters:
[in,out] cpp - the address of a pointer where val is written.
[in] val - a 32-bit native value to be inserted into cpp.
Note:
The buffer address is moved ahead by 4 bytes on return.

For internal use only.

Definition at line 128 of file xdas_wire.c.

References TO_UINT32.

Referenced by mcache_write_file_header(), and mcache_write_record().


Generated on Thu Aug 20 22:33:07 2009 for OpenXDAS by  doxygen 1.5.6