title: Google Protocol Buffers - Confused about encode decode base64 char * c string protocol buffer data
body: <p>I am using Google Protocol Buffers to send a message to a server.  My confusion comes in about how I send an image vs how I receive the image.  See code below for details but my question is:</p>
  
  <p>Do I need to base64_decode the returned string that has never been base64 encoded, because it was sent using char * and size?  Perhaps Google Protocol Buffers handles this but I can't find any evidence in the generated class.</p>
  
  <p>I may have found the answer <a href="https://stackoverflow.com/a/11467692/1735836">here</a> but I want to be sure.</p>
  
  <hr>
  
  <p>Here is the code to send the data.  Clearly I am sending an unsigned char * and a const long unsigned int to set the image.</p>
  
  <pre><code>std::string message::myMessaging::generateMessage(unsigned char *imageData, const long unsigned int elemSize, long unsigned int *msgSize)
  {
      ImageMessage message;
      message.set_ismaster(true);
      message.set_personname("Lucy");
      message.set_image(imageData, elemSize);
  
      string out;
      message.SerializeToString(&amp;out);
      int size = message.ByteSize();
      memcpy(msgSize, &amp;size, sizeof(int));
      return out;
  }
  </code></pre>
  
  <p>Here is the code to receive the data.  Coming back from the server I receive the messageData as a const string.  I create my Google Protocol Buffer message and parse it to get the information out of it.  Here, my image is a string.</p>
  
  <pre><code>std::string message::myMessaging::parseMessage(const string messageData, long unsigned int *msgSize)
  {
      ImageMessage message;
      message.Clear();
      message.ParseFromString(messageData);
  
      string personname = message.personname();
      string image = message.image();
  
      // do I need to decode it ?
      std::string decoded = base64_decode(image);
  
      // or can I just return the string image ?
      return decoded;
  }
  </code></pre>