BYTE_ARR.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef BYTE_ARRAY_HEADER
  2. #define BYTE_ARRAY_HEADER
  3. // this header needs
  4. #include "../BASIC_TYPES.h"
  5. #include "../MEM_SPACE.h"
  6. #include "../ENDIAN.h"
  7. // functions to handle raw byte arrays
  8. // enum with byte shifting modes
  9. typedef enum
  10. {
  11. BYTESHIFT_RIGHT,
  12. BYTESHIFT_LEFT,
  13. } byteshift_type;
  14. bool check_byte_array(byte * arr, umax size);
  15. umax print_byte_array(byte * arr, umax size);
  16. bool check_byteshift_type(byteshift_type shift);
  17. byte * cp_mem_bytes(byte * src, umax length, byte * dest);
  18. umax comp_bytes_until_mismatch(byte * arr1, byte * arr2, umax size);
  19. bool comp_bytes(byte * arr1, byte * arr2, umax size);
  20. byte * ignore_bytes(byte * src, umax src_size, byte * skip, umax skip_size);
  21. byte * search_byte_pattern(byte * src, umax ssize, byte * pattern, umax psize);
  22. bool byte_shift(byte * arr, umax size, byteshift_type shift);
  23. bool byte_n_shift(byte * arr, umax size, byteshift_type shift, umax n);
  24. bool byte_circ_shift(byte * arr, umax size, byteshift_type shift);
  25. bool byte_n_circ_shift(byte * arr, umax size, byteshift_type shift, umax n);
  26. // the second big type, bytarr
  27. // it is basically a re-typedef of mem_space
  28. // but with the intention to write and manage data on it
  29. typedef mem_space bytarr;
  30. #define BYTARR_SIZE sizeof(bytarr)
  31. // var_basic_types enum
  32. // the first variable types enum
  33. typedef enum
  34. {
  35. VAR_BYTESHIFT_TYPE = VAR_ENDIAN_TYPE + 1,
  36. VAR_BYTARR,
  37. } var_byte_arr;
  38. // bytarr functions
  39. bytarr * create_bytarr(byte * arr, umax size);
  40. bool check_bytarr(bytarr * arr);
  41. umax free_bytarr(bytarr * arr);
  42. umax print_bytarr(byte * src, umax size);
  43. // copy of the above functions but to be used with the new structure
  44. bytarr cp_bytarr(bytarr * src, bytarr * dest);
  45. umax comp_bytarrs_until_mismatch(bytarr * arr1, bytarr * arr2);
  46. bool comp_bytarrs(bytarr * arr1, bytarr * arr2);
  47. bytarr ignore_bytarr_bytes(bytarr * arr, bytarr * skip);
  48. bytarr search_bytarr(bytarr * src, bytarr * search);
  49. bool bytarr_shift(bytarr * arr, byteshift_type shift);
  50. bool bytarr_n_shift(bytarr * arr, byteshift_type shift, umax n);
  51. bool bytarr_circ_shift(bytarr * arr, byteshift_type shift);
  52. bool bytarr_n_circ_shift(bytarr * arr, byteshift_type shift, umax n);
  53. bytarr * ins_bytarr(bytarr * arr, umax arr_ins_pos, bytarr * bytes);
  54. umax rm_bytarr(bytarr * arr, umax rm_pos, umax rm_size);
  55. #include "BYTE_ARR.c"
  56. #endif // BYTE_ARRAY_HEADER