我正在使用以下.proto
文件:
message Header
{
enum MessageType
{
UNKNOWN = 0;
CONNECT = 1;
DISCONNECT = 2;
UPDATE = 3;
REQUEST = 4;
SUBSCRIBE = 5;
UNSUBSCRIBE = 6;
}
required MessageType msgType = 1;
}
message DataSet
{
optional string id = 1;
optional string value = 2;
}
message StdMessage
{
required Header header = 1;
repeated DataSet dataSet = 2;
}
这是编译后的 StdMessage 类:
class StdMessage : public ::google::protobuf::Message {
public:
StdMessage();
virtual ~StdMessage();
StdMessage(const StdMessage& from);
inline StdMessage& operator=(const StdMessage& from) {
CopyFrom(from);
return *this;
}
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
return _unknown_fields_;
}
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const ::google::protobuf::Descriptor* descriptor();
static const StdMessage& default_instance();
void Swap(StdMessage* other);
// implements Message ----------------------------------------------
StdMessage* New() const;
void CopyFrom(const ::google::protobuf::Message& from);
void MergeFrom(const ::google::protobuf::Message& from);
void CopyFrom(const StdMessage& from);
void MergeFrom(const StdMessage& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::google::protobuf::Metadata GetMetadata() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required .Header header = 1;
inline bool has_header() const;
inline void clear_header();
static const int kHeaderFieldNumber = 1;
inline const ::Header& header() const;
inline ::Header* mutable_header();
inline ::Header* release_header();
// repeated .DataSet dataSet = 2;
inline int dataset_size() const;
inline void clear_dataset();
static const int kDataSetFieldNumber = 2;
inline const ::DataSet& dataset(int index) const;
inline ::DataSet* mutable_dataset(int index);
inline ::DataSet* add_dataset();
inline const ::google::protobuf::RepeatedPtrField< ::DataSet >&
dataset() const;
inline ::google::protobuf::RepeatedPtrField< ::DataSet >*
mutable_dataset();
// @@protoc_insertion_point(class_scope:StdMessage)
private:
inline void set_has_header();
inline void clear_has_header();
::google::protobuf::UnknownFieldSet _unknown_fields_;
::Header* header_;
::google::protobuf::RepeatedPtrField< ::DataSet > dataset_;
mutable int _cached_size_;
::google::protobuf::uint32 _has_bits_[(2 + 31) / 32];
friend void protobuf_AddDesc_xplane_2eproto();
friend void protobuf_AssignDesc_xplane_2eproto();
friend void protobuf_ShutdownFile_xplane_2eproto();
void InitAsDefaultInstance();
static StdMessage* default_instance_;
};
// -------------------------------------------------------------------
在编译/生成的cpp文件中,类中没有set_header
或类似的功能StdMessage
。我的问题是,如何设置标题StdMessage
?提前致谢。