title: Python buffer decode
body: <p>I have a UDP package that is sent from a C++ program and I have to read it in Python. I managed to receive the UDP package but unfortunately it is encoded. 
  The C++ data has the form</p>
  
  <pre><code>struct packet{
      double arg1
      double arg2
      double arg3
      double arg4
      int16_t arg5
  };
  </code></pre>
  
  <p>The data I receive is in total 42 bytes long (which is the same length that is also sent). Maybe the the data is also slightly changed before it is sent, but I'm still trying to figure that out.
  So my question is: Let's assume the structure of the sent data would be exactly as described above. How could I read it out from the buffer? (Btw. I'm using Python 2.7.9)</p>
  
  <p>Thx already</p>
  
  <p>Edit: I found something about the structure</p>
  
  <pre><code>void Send(const CrazyFliePacket&amp; packet)
      {
          FMA::ByteBuffer p = 
              FMA::Encode((PACKET_TYPE)FMA_PACKET_TYPES::CRAZYFLIE) + 
              FMA::Encode((PACKET_VERSION)0) +
              FMA::Encode(_seq++) + 
              packet.Encode();
  
          _server-&gt;SendPacket(p.data(),p.size());
          printf("Packet sent with %i bytes size\n",p.size());
      }
  </code></pre>
  
  <p>Types are: </p>
  
  <pre><code>typedef unsigned short PACKET_TYPE;
  typedef unsigned short PACKET_VERSION;
  uint16_t _seq;
  </code></pre>
  
  <p>the sent and received data is now 40 bytes long.</p>
  
  <p>Edit2: The correct solution is</p>
  
  <pre><code>print struct.unpack('&lt;HHhddddh', data)
  </code></pre>