title: Equivalent of C++ reinterpret_cast a void* to a struct in Golang
body: <p>In C++ you can read in data from a FILE descriptor and simply reinterpret_cast it into a structure to interpret the data.</p>
  
  <p>Is there an equivalent way to do this in Go?</p>
  
  <p>As a very contrived example, consider the following where "<code>ProcessBytes</code>" is simply a callback in which you are given an array of bytes that are continuously appended to when reading from a file.</p>
  
  <pre><code>struct PayloadHeader {
    uint32_t TotalPayloadLength; 
    uint8_t  PayloadType;
  };
  
  struct TextMessage {
    PayloadHeader Header;
    uint32_t      SenderId;
    uint32_t      RecieverId;
    char          Text[64]; // null padded
  };
  
  void ProcessBytes(const uint8_t* data, size_t dataLength) {
    if(dataLength &lt; sizeof(PayloadHeader))
      return;
  
    const PayloadHeader* header = reinterpret_cast&lt;const PayloadHeader*&gt;(data);
    if(header.PayloadType == TEXT_MESSAGE) {
      if(header.TotalLength != sizeof(TextMessage))
        return;
      const TextMessage* text = reinterpret_cast&lt;const TextMessage*&gt;(data);
      // Do something with the text message~
  
      // Adjust the *data* to 'erase' the bytes after we are done processing it
      // as a TextMessage
    }
  }
  </code></pre>