SHARE
TWEET

Untitled

a guest Oct 18th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. INPUT:
  2.  
  3. struct test1
  4. b testbyte
  5. f testfloat
  6. ---
  7. struct test2
  8. s  testshort
  9. n testint
  10. ---
  11. struct test3
  12. us testushort
  13. un testuint
  14. ---
  15. struct uni
  16. b t1
  17. s t4
  18. us t5
  19. n t2
  20. un t3
  21. f t6
  22.  
  23. OUTPUT:
  24.  
  25. printf("sizeof(test1)=%i", sizeof(struct test1));
  26. printf("sizeof(test2)=%i", sizeof(struct test2));
  27. printf("sizeof(test3)=%i", sizeof(struct test3));
  28. printf("sizeof(uni)=%i", sizeof(struct uni));
  29.  
  30.  
  31. int pack_struct_test1(void* buffer, struct test1* s) {
  32.         int n=0;
  33.         PACK_uint8_t(s->testbyte, buffer, &n);
  34.         PACK_float(s->testfloat, buffer, &n);
  35.         return n;
  36. }
  37.  
  38. void unpack_struct_test1(void* buffer, struct test1* s) {
  39.         int n=0;
  40.         UNPACK_float(s->testfloat, buffer, &n);
  41.         UNPACK_uint8_t(s->testbyte, buffer, &n);
  42.         return n;
  43. }
  44.  
  45. int pack_struct_test2(void* buffer, struct test2* s) {
  46.         int n=0;
  47.         PACK_int16_t(s->testshort, buffer, &n);
  48.         PACK_int32_t(s->testint, buffer, &n);
  49.         return n;
  50. }
  51.  
  52. void unpack_struct_test2(void* buffer, struct test2* s) {
  53.         int n=0;
  54.         UNPACK_int32_t(s->testint, buffer, &n);
  55.         UNPACK_int16_t(s->testshort, buffer, &n);
  56.         return n;
  57. }
  58.  
  59. int pack_struct_test3(void* buffer, struct test3* s) {
  60.         int n=0;
  61.         PACK_uint16_t(s->testushort, buffer, &n);
  62.         PACK_uint32_t(s->testuint, buffer, &n);
  63.         return n;
  64. }
  65.  
  66. void unpack_struct_test3(void* buffer, struct test3* s) {
  67.         int n=0;
  68.         UNPACK_uint32_t(s->testuint, buffer, &n);
  69.         UNPACK_uint16_t(s->testushort, buffer, &n);
  70.         return n;
  71. }
  72.  
  73. int pack_struct_uni(void* buffer, struct uni* s) {
  74.         int n=0;
  75.         PACK_uint8_t(s->t1, buffer, &n);
  76.         PACK_int16_t(s->t4, buffer, &n);
  77.         PACK_uint16_t(s->t5, buffer, &n);
  78.         PACK_int32_t(s->t2, buffer, &n);
  79.         PACK_uint32_t(s->t3, buffer, &n);
  80.         PACK_float(s->t6, buffer, &n);
  81.         return n;
  82. }
  83.  
  84. void unpack_struct_uni(void* buffer, struct uni* s) {
  85.         int n=0;
  86.         UNPACK_float(s->t6, buffer, &n);
  87.         UNPACK_uint32_t(s->t3, buffer, &n);
  88.         UNPACK_int32_t(s->t2, buffer, &n);
  89.         UNPACK_uint16_t(s->t5, buffer, &n);
  90.         UNPACK_int16_t(s->t4, buffer, &n);
  91.         UNPACK_uint8_t(s->t1, buffer, &n);
  92.         return n;
  93. }
RAW Paste Data
Top