I'm having a hard time in realizing how to use the repeated field rule. for example, this is my .proto:
message Test
{
repeated float value = 1;
}
Run Code Online (Sandbox Code Playgroud)
now, I'm initialize a new Test object:
Test test = test_init_zero()
Run Code Online (Sandbox Code Playgroud)
Finally, I want to assign some values. For example:
float values[] = { 1.0, 2.2, 5.5, 7.13 }
Run Code Online (Sandbox Code Playgroud)
My question is how can I assign them? is it like
test.value = values
//or
test.value[0] = values[0] //... etc.
Run Code Online (Sandbox Code Playgroud)
and then, …
我有一个 proto 消息定义为:
message SimpleMessage {
repeated int32 number = 1;}
Run Code Online (Sandbox Code Playgroud)
现在,编译后,该字段为 of pb_callback_t,我想编写该函数。(没有 .options 文件)
现在,该函数应该包含在哪里以及包含哪些内容?数据本身存储在哪里以及如何访问它/为其分配新数据?
* 编辑 *
根据@Groo 的回答,这是我试过的代码:
typedef struct {
int numbers_decoded;
} DecodingState;
bool read_single_number(pb_istream_t *istream, const pb_field_t *field, void **arg)
{
// get the pointer to the custom state
DecodingState *state = (DecodingState*)(*arg);
int32_t value;
if (!pb_decode_varint32(istream, &value))
{
const char * error = PB_GET_ERROR(istream);
printf("Protobuf error: %s", error);
return false;
}
printf("Decoded successfully: %d", value);
state->numbers_decoded++;
return true;
}
int main(void) …Run Code Online (Sandbox Code Playgroud)