| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "shark_utils.h"
- void shark_encode_u16(shark_u8 *buff, shark_u16 value)
- {
- shark_encode_u8(buff, value);
- shark_encode_u8(buff + 1, value >> 8);
- }
- void shark_encode_u24(shark_u8 *buff, shark_u32 value)
- {
- shark_encode_u16(buff, value);
- shark_encode_u8(buff + 2, value >> 16);
- }
- void shark_encode_u32(shark_u8 *buff, shark_u32 value)
- {
- shark_encode_u24(buff, value);
- shark_encode_u8(buff + 3, value >> 24);
- }
- void shark_encode_u64(shark_u8 *buff, shark_u64 value)
- {
- memcpy(buff, &value, sizeof(value));
- }
- shark_u16 shark_decode_u16(const shark_u8 *buff)
- {
- return SHARK_U16(buff[1]) << 8 | shark_decode_u8(buff);
- }
- shark_u32 shark_decode_u24(const shark_u8 *buff)
- {
- return SHARK_U24(buff[2]) << 16 | shark_decode_u16(buff);
- }
- shark_u32 shark_decode_u32(const shark_u8 *buff)
- {
- return SHARK_U32(buff[3]) << 24 | shark_decode_u24(buff);
- }
- shark_u64 shark_decode_u64(const shark_u8 *buff)
- {
- shark_u64 value;
- memcpy(&value, buff, sizeof(buff));
- return value;
- }
|