ua_debug_dump_pkgs.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include "ua_util.h"
  4. #include <ctype.h>
  5. #include <stdio.h>
  6. void UA_dump_hex_pkg(UA_Byte* buffer, size_t bufferLen) {
  7. printf("--------------- HEX Package Start ---------------\n");
  8. char ascii[17];
  9. memset(ascii,0,17);
  10. for (size_t i = 0; i < bufferLen; i++)
  11. {
  12. if (i == 0)
  13. printf("%08zx ", i);
  14. else if (i%16 == 0)
  15. printf(" |%s|\n%08zx ", ascii, i);
  16. if (isprint((int)(buffer[i])))
  17. ascii[i%16] = (char)buffer[i];
  18. else
  19. ascii[i%16] = '.';
  20. if (i%8==0)
  21. printf(" ");
  22. printf("%02X ", (unsigned char)buffer[i]);
  23. }
  24. size_t fillPos = bufferLen %16;
  25. ascii[fillPos] = 0;
  26. for (size_t i=fillPos; i<16; i++) {
  27. if (i%8==0)
  28. printf(" ");
  29. printf(" ");
  30. }
  31. printf(" |%s|\n%08zx\n", ascii, bufferLen);
  32. printf("--------------- HEX Package END ---------------\n");
  33. }