ua_debug_dump_pkgs.c 994 B

1234567891011121314151617181920212223242526272829303132
  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. printf("%02X ", (unsigned char)buffer[i]);
  21. }
  22. size_t fillPos = bufferLen %16;
  23. ascii[fillPos] = 0;
  24. for (size_t i=fillPos; i<16; i++) {
  25. printf(" ");
  26. }
  27. printf("|%s|\n%08zx\n", ascii, bufferLen);
  28. printf("--------------- HEX Package END ---------------\n");
  29. }