Advertisement
tomkiewicz

unpack

Feb 15th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. struct gg_login110_ok
  2. {
  3.     uint64_t unknown1;
  4.     char *somehash;
  5.     gg_uin_t uin;
  6.     uint32_t server_time;
  7. };
  8.  
  9. int gg_packet_login110_ok_unpack(char *packet, size_t length, struct gg_login110_ok &dst)
  10. {
  11.     gg_pbuff *pb = gg_pbuff_new(packet, length);
  12.     if (!pb)
  13.         return 0;
  14.  
  15.     gg_pbuff_get_uint64(pb, &dst->unknown1);
  16.     gg_pbuff_get_str(pb, &dst->somehash);
  17.     gg_pbuff_get_uin(pb, &dst->uin);
  18.     gg_pbuff_get_uint32(pb, &dst->server_time);
  19.  
  20.     return gg_pbuff_cleanup(pb); // zwraca 1, jeżeli pb jest "valid", a jest valid, jeżeli typy się zgadzały
  21. }
  22.  
  23. void gg_packet_login110_ok_cleanup(struct gg_login110_ok &pkt)
  24. {
  25.     free(pkt->somehash);
  26.     pkt->somehash = NULL;
  27. }
  28.  
  29. // inne metody do pobierania danych:
  30. {
  31.     (...)
  32.     gg_pbuff_get_str_optional(pb, &dst->str, NULL);
  33.     gg_pbuff_get_uint64_optional(pb, &dst->val, (uint64_t)-1);
  34.     gg_pbuff_get_submessage(pb, &dst->sub, &gg_packet_submsg_unpack);
  35.     gg_pbuff_get_array(pb, &dst->arr1, &dst->arr1_count, &gg_pbuff_get_uint32, sizeof(uint32_t));
  36.     gg_pbuff_get_array(pb, &dst->arr2, &dst->arr2_count, &gg_packet_submsg_unpack, sizeof(gg_submsg_t));
  37.     (...)
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement