#pragma once

#include "types.h"

#define DECODE_U16(buff) \
	(U16(buff[1]) << 8 | buff[0])

#define DECODE_U24(buff) \
	(U32(buff[2]) << 16 | DECODE_U16(buff))

#define DECODE_U32(buff) \
	(U32(buff[3]) << 24 | DECODE_U24(buff))

u16 shark_crc16_update_byte(u16 crc, u8 value);
u16 shark_crc16_update(u16 crc, const u8 *data, u16 size);
u16 shark_crc16_check(const u8 *data, u16 size);
u16 shark_decode_u16(const u8 *buff);
u32 shark_decode_u24(const u8 *buff);
u32 shark_decode_u32(const u8 *buff);
void shark_encode_u16(u8 *buff, u16 value);
void shark_encode_u24(u8 *buff, u32 value);
void shark_encode_u32(u8 *buff, u32 value);
u32 shark_iap_checksum_put(u32 crc, const u8 *buff, u32 length);
u32 shark_iap_checksum_finish(u32 crc);
u32 shark_iap_checksum_init(void);

