buffer.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef __BUFFER_H__
  2. #define __BUFFER_H__
  3. typedef struct {
  4. char* data;
  5. unsigned long int size;
  6. } BYTE_BUFFER;
  7. /**
  8. * Create a new byte buffer
  9. *
  10. * @return the created buffer
  11. */
  12. BYTE_BUFFER createByteBuffer();
  13. /**
  14. * Release the memory
  15. *
  16. * @param buffer the buffer to destroy
  17. */
  18. void destroyByteBuffer(BYTE_BUFFER buffer);
  19. /**
  20. * Print a byte in binary
  21. *
  22. * @param byte the byte to print
  23. */
  24. void printfBit(unsigned char byte);
  25. /**
  26. * Print all the bytes from a buffer
  27. *
  28. * @param buffer the buffer holding the data
  29. */
  30. void printfByteBuffer(BYTE_BUFFER buffer);
  31. /**
  32. * Push a byte in a buffer
  33. *
  34. * @param buffer the buffer holding the data
  35. * @param byt the byte to push
  36. */
  37. void pushByte(BYTE_BUFFER* buffer, unsigned char byte);
  38. /**
  39. * Push a word in a buffer
  40. *
  41. * @param buffer the buffer holding the data
  42. * @param word the word to push
  43. */
  44. void pushWord(BYTE_BUFFER* buffer, unsigned short int word);
  45. /**
  46. * Push some bytes in a buffer
  47. *
  48. * @param buffer the buffer holding the data
  49. * @param bytes the bytes to push
  50. * @param len the number of bytes to push
  51. */
  52. void pushBytes(BYTE_BUFFER* buffer, unsigned char *byte, unsigned int len);
  53. /**
  54. * Gives the bit at a specific position
  55. *
  56. * @param buffer the buffer to evaluate
  57. * @param n the bit position
  58. *
  59. * @return the bit value
  60. */
  61. unsigned int bitAt(BYTE_BUFFER buffer, unsigned long int n);
  62. /**
  63. * Print all the bits from a buffer
  64. *
  65. * @param buffer the buffer holding the data
  66. */
  67. //void printfBitBuffer(BIT_BUFFER buffer);
  68. void printfBitBuffer(BYTE_BUFFER buffer);
  69. #endif