Storing binary data buffer in protocol buffer message
NickName:Martin G Ask DateTime:2017-03-07T17:55:00

Storing binary data buffer in protocol buffer message

I have a binary data buffer which i want to store in a protocol buffer.

In the documentation (https://developers.google.com/protocol-buffers/docs/proto#scalar) it says that the bytes type is equivalent to string in C++. I could not believe this so i had to try it and yes, this seems to be the case..

This proto:

message BufferMsg {
  required bytes buffer = 1;
}

gives a message definition containing this:

private:
  ::std::string* buffer_;

The public setter/getter API looks like this:

  // required bytes buffer = 1;
  inline bool has_buffer() const;
  inline void clear_buffer();
  static const int kBufferFieldNumber = 1;
  inline const ::std::string& buffer() const;
  inline void set_buffer(const ::std::string& 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);

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 unsigned char array or something like that to store the data.

Copyright Notice:Content Author:「Martin G」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42645047/storing-binary-data-buffer-in-protocol-buffer-message

More about “Storing binary data buffer in protocol buffer message” related questions

Storing binary data buffer in protocol buffer message

I have a binary data buffer which i want to store in a protocol buffer. In the documentation (https://developers.google.com/protocol-buffers/docs/proto#scalar) it says that the bytes type is equiv...

Show Detail

Why the message classes generated by the protocol buffer compiler are all immutable?

The protocol buffer compiler generated message classes are immutable. The message classes contain appropriate setter methods but no getter methods on it. This constraint does not apply to other

Show Detail

Finding protocol buffer message type from serialized data

I have some binary data, which was obtained by serializing a google protocol buffer class. How do I find out, at runtime, the class for which the data was serialized. For example, suppose i have a...

Show Detail

Using Protocol buffer as general Data object?

We're introducing protocol buffers as the new transport for some back end RPC services. Because there's resistance to manually shuttling data between different forms of similar objects, I can forse...

Show Detail

Protocol-buffer with Python choose the order of data with SerializeToString

I have buffer that encoded with protocol-buffer , I want to read the buffer and change some data and encode it again. I saw that when I encode the buffer ( SerializeToString) the binary data is not...

Show Detail

JSON or protocol buffer to replace the custom TCP message

Originally, We have two applications communication with TCP/IP, and both of them are implemented by C++. The messages between them are custom message type. Now the client program will be changed t...

Show Detail

Protocol Buffer - merge binary data files with the same .proto file to the one file

I have a lot of data files (almost 150) in binary structure created according the .proto scheme of Protocol Buffer. Is there any efficient solution how to merge all the files to just one big binary...

Show Detail

Writing binary data to Buffer

Normally, I would expect that the following would be good enough to represent binary data in a Buffer: new Buffer('01001000','binary') but I am pretty certain Node.js/JS does not support this 'bi...

Show Detail

Peek into protocol buffer message files

Is there a command line tool to peek into files containing several protocol buffer messages (of the same message type)?

Show Detail

Sending a string using a protocol buffer message

How to send string as protocol buffer message? I want to do the following: Message message1 = "some string" ByteString data1 = (message1).toByteString(); System.out.println(String.format("Publishi...

Show Detail