我刚刚遇到了 Google 的协议缓冲区。这似乎是我正在编写的 C++ 后端应用程序的解决方案。问题是我似乎找不到任何有关矢量类型的信息。文档提到了repeat_types,但我似乎找不到任何东西。
假设我有这些类:
class UnifiedBinaryHeader
{
public:
UnifiedBinaryHeader();
void Serialize(std::ostream& output) const;
void Deserialize(std::istream& input);
private:
wxString m_name;
wxDateTime m_time;
};
struct UnifiedBinaryRow
{
wxDateTime date;
float value;
UnifiedBinaryRow()
{
value= 0;
}
void Serialize(std::ostream& output) const;
void Deserialize(std::istream& input);
};
class UnifiedBinaryRowCollection
{
private:
typedef std::vector<UnifiedBinaryRow> UnifiedBinaryRowVector;
public:
typedef UnifiedBinaryRowVector::iterator iterator;
typedef UnifiedBinaryRowVector::const_iterator const_iterator;
UnifiedBinaryRowCollection();
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
UnifiedBinaryRowCollection& AddRow(const UnifiedBinaryRow& row);
size_t NumRows() const;
private:
UnifiedBinaryRowVector m_rows;
};
class UnifiedBinaryFormat
{
public:
UnifiedBinaryFormat();
UnifiedBinaryHeader& Header();
const UnifiedBinaryHeader& Header() const;
UnifiedBinaryFormat& Header(UnifiedBinaryHeader& header);
UnifiedBinaryRowCollection& Rows();
const UnifiedBinaryRowCollection& Rows() const;
UnifiedBinaryFormat& Rows(const UnifiedBinaryRowCollection& rows);
void Serialize(std::ostream& output) const;
void Deserialize(std::istream& input);
private:
UnifiedBinaryHeader m_header;
UnifiedBinaryRowCollection m_rows;
};
我如何为这些类编写 .proto 文件,因为我使用了很多向量成员。在将这些类“移植”到我可以使用的 .proto 文件中的任何帮助将不胜感激。