Adding Duplicate Buffer Fields to the Log

I am working in C ++ with the Buffer Protocol pattern including the following post:

message StringTable {
   repeated bytes s = 1;
}

      

I am trying to add a new value to existing data, for example:

pb.stringtable().s().Add(replace_key);

      

However, this generates a compile-time error (using clang for OS X):

test.cpp:51:4: error: member function 'Add' not viable: 'this' argument 
  has type 'const ::google::protobuf::RepeatedPtrField< ::std::string>', 
  but function is not marked const
                    pb.stringtable().s().Add(replace_key);
                    ^~~~~~~~~~~~~~~~~~~~

      

Any hints? I am very new to C ++, so a dumb mistake could be made.


Edit:

Using accessories creates a similar error:

pb.stringtable().add_s(replace_key);

      

leads to:

test.cpp:51:21: error: no matching member function for call to 'add_s'
                        pb.stringtable().add_s(replace_key);
                        ~~~~~~~~~~~~~~~~~^~~~~
./osmformat.pb.h:3046:26: note: candidate function not viable: 'this' argument has type 'const ::StringTable', but method is not marked const
inline void StringTable::add_s(const ::std::string& value) {
                     ^
./osmformat.pb.h:3050:26: note: candidate function not viable: 'this' argument has type 'const ::StringTable', but method is not marked const
inline void StringTable::add_s(const char* value) {
                     ^
./osmformat.pb.h:3043:36: note: candidate function not viable: requires 0 arguments, but 1 was provided
inline ::std::string* StringTable::add_s() {
                               ^
./osmformat.pb.h:3054:26: note: candidate function not viable: requires 2 arguments, but 1 was provided
inline void StringTable::add_s(const void* value, size_t size) {

      

+3


source to share


1 answer


The problem has been resolved.

The existing StringTable is unmodified by default. However, using mutable_ accessors does it like this:



pb.mutable_stringtable().add_s(replace_key);

      

+2


source







All Articles