1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*C
(c) 2005 bl0rg.net
**/
#ifndef PACK_H__
#define PACK_H__
/*M
\emph{8 bits value packing macro.}
This macro advances the buffer pointer it is given as first
argument, and fills the buffer with the 8 bits value
given as second argument.
**/
#define UINT8_PACK(ptr, i) { *(ptr++) = i; }
/*M
\emph{8 bits value unpacking macro.}
This macro advances the buffer pointer it is given as first
argument, and returns the unpacked 8 bits value in the buffer.
**/
#define UINT8_UNPACK(ptr) (*(ptr++))
/*M
\emph{16 bits value packing macro.}
This macro advances the buffer pointer it is given as first
argument, and fills the buffer with the big endian packed value
given as second argument.
**/
#define UINT16_PACK(ptr, i) \
{ *(ptr++) = (unsigned char)(((i) >> 8) & 0xFF); \
*(ptr++) = (unsigned char)((i) & 0xFF); }
/*M
\emph{32 bits value packing macro.}
This macro advances the buffer pointer it is given as first
argument, and fills the buffer with the big endian packed value
given as second argument.
**/
#define UINT32_PACK(ptr, i) \
{ *(ptr++) = (unsigned char)(((i) >> 24) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 16) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 8) & 0xFF); \
*(ptr++) = (unsigned char)((i) & 0xFF); }
/*M
\emph{24 bits value packing macro.}
**/
#define UINT24_PACK(ptr, i) \
{ *(ptr++) = (unsigned char)(((i) >> 16) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 8) & 0xFF); \
*(ptr++) = (unsigned char)((i) & 0xFF); }
/*M
\emph{16 bits value unpacking macro.}
This macro advances the buffer pointer it is given as first
argument, and returns the unpacked big endian value in the buffer.
**/
#define UINT16_UNPACK(ptr) uint16_unpack__(&ptr)
unsigned int uint16_unpack__(/*@out@*/ unsigned char **ptr);
/*M
\emph{32 bits value unpacking macro.}
This macro advances the buffer pointer it is given as first
argument, and returns the unpacked big endian value in the
buffer.
**/
#define UINT32_UNPACK(ptr) uint32_unpack__(&ptr)
unsigned int uint32_unpack__(/*@out@*/ unsigned char **ptr);
/*M
\emph{16 bits value packing macro.}
This macro advances the buffer pointer it is given as first
argument, and fills the buffer with the little endian packed value
given as second argument.
**/
#define LE_UINT16_PACK(ptr, i) \
{ *(ptr++) = (unsigned char)((i) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 8) & 0xFF); }
/*M
\emph{32 bits value packing macro.}
This macro advances the buffer pointer it is given as first
argument, and fills the buffer with the little endian packed value
given as second argument.
**/
#define LE_UINT32_PACK(ptr, i) \
{ *(ptr++) = (unsigned char)((i) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 8) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 16) & 0xFF); \
*(ptr++) = (unsigned char)(((i) >> 24) & 0xFF); }
/*M
\emph{16 bits value unpacking macro.}
This macro advances the buffer pointer it is given as first
argument, and returns the unpacked little endian value in the buffer.
**/
#define LE_UINT16_UNPACK(ptr) le_uint16_unpack__(&ptr)
unsigned int le_uint16_unpack__(/*@out@*/ unsigned char **ptr);
/*M
\emph{32 bits value unpacking macro.}
This macro advances the buffer pointer it is given as first
argument, and returns the unpacked little endian value in the
buffer.
**/
#define LE_UINT32_UNPACK(ptr) le_uint32_unpack__(&ptr)
unsigned int le_uint32_unpack__(/*@out@*/ unsigned char **ptr);
#endif /* PACK_H__ */
/*C
**/
|