MCPcopy Create free account
hub / github.com/Tencent/phxqueue / ParseField

Method ParseField

phxqueue_phxrpc/comm/ini2pb.cpp:47–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46
47bool INI2Pb::ParseField(google::protobuf::Message *message, const string &section_name,
48 const google::protobuf::FieldDescriptor *field_descriptor) {
49 const google::protobuf::Reflection *reflection(message->GetReflection());
50
51 string val;
52 vector<string> val_list;
53
54 func_(section_name, field_descriptor->name(), val);
55
56 if (!val.empty()) {
57
58 StrSplitList(val, " ", val_list);
59
60 if (field_descriptor->label() == google::protobuf::FieldDescriptor::LABEL_REPEATED) {
61 switch (field_descriptor->type()) {
62 case google::protobuf::FieldDescriptor::TYPE_FIXED64:
63 case google::protobuf::FieldDescriptor::TYPE_INT64:
64 {
65 for (size_t i{0}; val_list.size() > i; ++i) {
66 int64_t real_val = stoll(val_list[i]);
67 reflection->AddInt64(message, field_descriptor, real_val);
68 }
69 break;
70 }
71 case google::protobuf::FieldDescriptor::TYPE_UINT64:
72 {
73 for (size_t i{0}; val_list.size() > i; ++i) {
74 uint64_t real_val = stoull(val_list[i]);
75 reflection->AddUInt64(message, field_descriptor, real_val);
76 }
77 break;
78 }
79 case google::protobuf::FieldDescriptor::TYPE_FIXED32:
80 case google::protobuf::FieldDescriptor::TYPE_INT32:
81 {
82 for (size_t i(0); val_list.size() > i; ++i) {
83 int real_val = stoi(val_list[i]);
84 reflection->AddInt32(message, field_descriptor, real_val);
85 }
86 break;
87 }
88 case google::protobuf::FieldDescriptor::TYPE_UINT32:
89 {
90 for (size_t i(0); val_list.size() > i; ++i) {
91 uint32_t real_val = stoul(val_list[i]);
92 reflection->AddUInt32(message, field_descriptor, real_val);
93 }
94 break;
95 }
96 case google::protobuf::FieldDescriptor::TYPE_STRING:
97 {
98 for (size_t i(0); val_list.size() > i; ++i) {
99 std::string &real_val(val_list[i]);
100 reflection->AddString(message, field_descriptor, real_val);
101 }
102 break;
103 }
104 case google::protobuf::FieldDescriptor::TYPE_BOOL:

Callers

nothing calls this directly

Calls 1

StrSplitListFunction · 0.70

Tested by

no test coverage detected