在 pbtools 中编码重复条目

Encoding repeated entries in pbtools

我有一个带有一堆重复结构的 protobuf 模式。像

syntax = "proto3";
package My

message TopLevel 
{
   string swVersion = 3;
   string reportMac = 4;
   string reportSsid = 6
}

message Temperature
{
   required uint64 ts = 1;
   required uint32 source = 3;
   repeated sint32 readings = 4;
}

message MyMessage
{
   required TopLevel topLevel = 1;
   repeated Temperature temperature = 2;
}

我用 pbtools 编译并获得温度和读数的结构和函数。但是我很难弄清楚如何动态添加 "Temperature" 条目。 还是我运气不好,pbtools 需要提前告诉它我有多少条目。一个问题是数据在生成时被编码,我不知道每份报告会有多少。 我附上了生成的代码。

pbtools 在添加任何项目之前需要长度。