main.c 798 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * main.c
  3. *
  4. * Created on: 07.03.2014
  5. * Author: mrt
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <memory.h>
  10. #include "opcua.h"
  11. int main() {
  12. char* buf;
  13. int pos = 0, retval, size;
  14. // the value to encode
  15. UA_Int32 i = -42, j;
  16. // get buffer for encoding
  17. size = UA_Int32_calcSize(UA_NULL);
  18. buf = (char *) malloc(size);
  19. printf("buf=%p, size=%d\n", buf, size);
  20. if (buf == UA_NULL) return -1;
  21. // encode
  22. pos = 0;
  23. retval = UA_Int32_encode(&i, &pos, buf);
  24. printf("retval=%d, src=%d, pos=%d, buf={%d,%d,%d,%d}\n", retval, i, pos, buf[0], buf[1], buf[2], buf[3]);
  25. // decode
  26. pos = 0;
  27. retval = UA_Int32_decode(buf, &pos, &j);
  28. printf("retval=%d, dst=%d, pos=%d, {%d,%d,%d,%d}\n", retval, j, pos, buf[0], buf[1], buf[2], buf[3]);
  29. // return memory
  30. free(buf);
  31. return 0;
  32. }