meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
courses:ct30a5002:packingdata [2013/09/20 13:52]
julaakko
courses:ct30a5002:packingdata [2013/09/23 18:51] (current)
julaakko
Line 1: Line 1:
 +===== Packing data to character buffer =====
  
 +In previous years some people had problems with packing integers to character buffers so here is an example about how to do it. Just remember to keep track of the amount of bytes each integer reserves from the buffer used for storing data. <code c>
 +//PACK
 +*(uint16_t*)&​buffer_holding_data[position_to_store] = htons(value_to_store);​
 +
 +//UNPACK
 +uint16_t retrieved_value = ntohs(*(uint16_t*)&​buffer_holding_data[position_from_to_retrieve]);​
 +</​code>​
 +
 +
 +----
 +[[courses:​ct30a5002:​start#​code_snippets|CT30A5002 - Games and Networking]]