title: is native C++ code that uses serialization portable to WebAssembly?
body: <p>Recently I have decided to use web for GUI in my app's client and therefore I have faced a question of communicating between native code and JS.
  Another option I began to consider is porting C++ code to WebAssembly (which I am completely unfamiliar with). It would be rather handy to have a possibility to compile the client C++ code both to native and to Wasm without the need to modify much of it, in case I will be required to make a pure native application. I don't know the limitations for such portability, except for needing 3rdparty libraries to have a ported version.</p>
  <p>So, one of the problems:
  my native C++ client among other things communicates with different devices via various custom protocols. For example, I have a protocol for a joystick. I receive a byte array via serial port and cast it to a protocol struct via <code>reinterpret_cast</code> (using <code>std::copy</code> to avoid UB):</p>
  <pre><code>#pragma pack(push, 1)
  
      /*!
       * \brief Data structure for deserialization of a received message from Joystick
       */
      struct JoyL410FData
      {
          constexpr static uint8_t header[] = {0x68, 0x9B};
  
          uint8_t id;        
          uint8_t id2;       
          uint8_t VerLo;        
          uint8_t VerHi;        
  
          uint16_t function: 1,     
          dispSwitch: 4, 
          zero: 1,        
          diskrZoom: 4,        
          distance: 1,        
          analogZoom: 2,        
          modeSelect: 1,        
          freezeFrame: 1,        
          reserve: 1;        
          uint16_t inversBit;
          int16_t x;                           
          int16_t y;                           
          uint16_t crc16;                        
          void setVersion(uint8_t AVerLo, uint8_t AVerHi)
          {
              VerLo = AVerLo;
              VerHi = AVerHi;
          }
  
          void clear()
          {
              std::memset((uint8_t *) this + 3, 0, sizeof(JoyL410FData) - 3);
          }
      };
  
  </code></pre>
  <p>Example for receiving data.</p>
  <pre><code>    // this line is just for abstraction
      std::vector&lt;uint8_t&gt; receivedArray = receive();
      JoyL410FData data{};
      std::copy(receivedArray.cbegin(), receivedArray.cend(), reinterpret_cast&lt;uint8_t*&gt;(&amp;data));
  </code></pre>
  <ol>
  <li>Is this code portable to WebAssembly?</li>
  <li>What about endianness?</li>
  <li>Will this result in a noticeable drop of performance?</li>
  </ol>