mirror of
https://github.com/samba-team/samba.git
synced 2025-01-24 02:04:21 +03:00
lib:util: Add (PULL|PUSH)_(BE|LE)_I(8|16|32|64) byterarray macros
The only difference is that the pull macros do the correct casting of the integer in the end. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri Feb 21 03:35:58 UTC 2020 on sn-devel-184
This commit is contained in:
parent
a84c24e71d
commit
a2692b6494
@ -34,28 +34,44 @@
|
||||
*/
|
||||
#define PULL_LE_U8(data, pos) \
|
||||
(_DATA_BYTE_CONST(data, pos))
|
||||
#define PULL_LE_I8(data, pos) \
|
||||
(int8_t)PULL_LE_U8(data, pos)
|
||||
|
||||
#define PULL_LE_U16(data, pos) \
|
||||
((uint16_t)PULL_LE_U8(data, pos) | ((uint16_t)(PULL_LE_U8(data, (pos) + 1))) << 8)
|
||||
#define PULL_LE_I16(data, pos) \
|
||||
(int16_t)PULL_LE_U16(data, pos)
|
||||
|
||||
#define PULL_LE_U32(data, pos) \
|
||||
((uint32_t)(PULL_LE_U16(data, pos) | ((uint32_t)PULL_LE_U16(data, (pos) + 2)) << 16))
|
||||
#define PULL_LE_I32(data, pos) \
|
||||
(int32_t)PULL_LE_U32(data, pos)
|
||||
|
||||
#define PULL_LE_U64(data, pos) \
|
||||
((uint64_t)(PULL_LE_U32(data, pos) | ((uint64_t)PULL_LE_U32(data, (pos) + 4)) << 32))
|
||||
#define PULL_LE_I64(data, pos) \
|
||||
(int64_t)PULL_LE_U64(data, pos)
|
||||
|
||||
|
||||
#define PUSH_LE_U8(data, pos, val) \
|
||||
(_DATA_BYTE(data, pos) = ((uint8_t)(val)))
|
||||
#define PUSH_LE_I8(data, pos, val) \
|
||||
PUSH_LE_U8(data, pos, val)
|
||||
|
||||
#define PUSH_LE_U16(data, pos, val) \
|
||||
(PUSH_LE_U8((data), (pos), (uint8_t)((uint16_t)(val) & 0xff)), PUSH_LE_U8((data), (pos) + 1, (uint8_t)((uint16_t)(val) >> 8)))
|
||||
#define PUSH_LE_I16(data, pos, val) \
|
||||
PUSH_LE_U16(data, pos, val)
|
||||
|
||||
#define PUSH_LE_U32(data, pos, val) \
|
||||
(PUSH_LE_U16((data), (pos), (uint16_t)((uint32_t)(val) & 0xffff)), PUSH_LE_U16((data), (pos) + 2, (uint16_t)((uint32_t)(val) >> 16)))
|
||||
#define PUSH_LE_I32(data, pos, val) \
|
||||
PUSH_LE_U32(data, pos, val)
|
||||
|
||||
#define PUSH_LE_U64(data, pos, val) \
|
||||
(PUSH_LE_U32((data), (pos), (uint32_t)((uint64_t)(val) & 0xffffffff)), PUSH_LE_U32((data), (pos) + 4, (uint32_t)((uint64_t)(val) >> 32)))
|
||||
#define PUSH_LE_I64(data, pos, val) \
|
||||
PUSH_LE_U64(data, pos, val)
|
||||
|
||||
|
||||
|
||||
@ -65,28 +81,44 @@
|
||||
*/
|
||||
#define PULL_BE_U8(data, pos) \
|
||||
(_DATA_BYTE_CONST(data, pos))
|
||||
#define PULL_BE_I8(data, pos) \
|
||||
(int8_t)PULL_BE_U8(data, pos)
|
||||
|
||||
#define PULL_BE_U16(data, pos) \
|
||||
((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
|
||||
#define PULL_BE_I16(data, pos) \
|
||||
(int16_t)PULL_BE_U16(data, pos)
|
||||
|
||||
#define PULL_BE_U32(data, pos) \
|
||||
((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
|
||||
#define PULL_BE_I32(data, pos) \
|
||||
(int32_t)PULL_BE_U32(data, pos)
|
||||
|
||||
#define PULL_BE_U64(data, pos) \
|
||||
((((uint64_t)PULL_BE_U32(data, pos)) << 32) | (uint64_t)(PULL_BE_U32(data, (pos) + 4)))
|
||||
#define PULL_BE_I64(data, pos) \
|
||||
(int64_t)PULL_BE_U64(data, pos)
|
||||
|
||||
|
||||
|
||||
#define PUSH_BE_U8(data, pos, val) \
|
||||
(_DATA_BYTE(data, pos) = ((uint8_t)(val)))
|
||||
#define PUSH_BE_I8(data, pos, val) \
|
||||
PUSH_BE_U8(data, pos, val)
|
||||
|
||||
#define PUSH_BE_U16(data, pos, val) \
|
||||
(PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
|
||||
#define PUSH_BE_I16(data, pos, val) \
|
||||
PUSH_BE_U16(data, pos, val)
|
||||
|
||||
#define PUSH_BE_U32(data, pos, val) \
|
||||
(PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
|
||||
#define PUSH_BE_I32(data, pos, val) \
|
||||
PUSH_BE_U32(data, pos, val)
|
||||
|
||||
#define PUSH_BE_U64(data, pos, val) \
|
||||
(PUSH_BE_U32((data), (pos), (uint32_t)(((uint64_t)(val)) >> 32)), PUSH_BE_U32((data), (pos) + 4, (uint32_t)((val) & 0xffffffff)))
|
||||
#define PUSH_BE_I64(data, pos, val) \
|
||||
PUSH_BE_U64(data, pos, val)
|
||||
|
||||
#endif /* _BYTEARRAY_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user