title: Storing binary data buffer in protocol buffer message
body: <p>I have a binary data buffer which i want to store in a protocol buffer.</p>
  
  <p>In the documentation (<a href="https://developers.google.com/protocol-buffers/docs/proto#scalar" rel="nofollow noreferrer">https://developers.google.com/protocol-buffers/docs/proto#scalar</a>) it says that the <code>bytes</code> type is equivalent to <code>string</code> in C++. I could not believe this so i had to try it and yes, this seems to be the case..</p>
  
  <p>This proto:</p>
  
  <pre><code>message BufferMsg {
    required bytes buffer = 1;
  }
  </code></pre>
  
  <p>gives a message definition containing this:</p>
  
  <pre><code>private:
    ::std::string* buffer_;
  </code></pre>
  
  <p>The public setter/getter API looks like this:</p>
  
  <pre><code>  // required bytes buffer = 1;
    inline bool has_buffer() const;
    inline void clear_buffer();
    static const int kBufferFieldNumber = 1;
    inline const ::std::string&amp; buffer() const;
    inline void set_buffer(const ::std::string&amp; value);
    inline void set_buffer(const char* value);
    inline void set_buffer(const void* value, size_t size);
    inline ::std::string* mutable_buffer();
    inline ::std::string* release_buffer();
    inline void set_allocated_buffer(::std::string* buffer);
  </code></pre>
  
  <p>Surely, this cannot be the way to store binary data in a message. How should it be done? In C++ i would typically use an <code>unsigned char</code> array or something like that to store the data.</p>