MCPcopy Create free account
hub / github.com/apache/brpc / IsProtobufMap

Function IsProtobufMap

src/json2pb/protobuf_map.cpp:26–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24using google::protobuf::FieldDescriptor;
25
26bool IsProtobufMap(const FieldDescriptor* field) {
27 if (field->type() != FieldDescriptor::TYPE_MESSAGE || !field->is_repeated()) {
28 return false;
29 }
30 const Descriptor* entry_desc = field->message_type();
31 if (entry_desc == NULL) {
32 return false;
33 }
34 if (entry_desc->field_count() != 2) {
35 return false;
36 }
37 const FieldDescriptor* key_desc = entry_desc->field(KEY_INDEX);
38 if (NULL == key_desc
39 || key_desc->is_repeated()
40 || key_desc->cpp_type() != FieldDescriptor::CPPTYPE_STRING
41 || key_desc->name() != KEY_NAME) {
42 return false;
43 }
44 const FieldDescriptor* value_desc = entry_desc->field(VALUE_INDEX);
45 if (NULL == value_desc
46 || value_desc->name() != VALUE_NAME) {
47 return false;
48 }
49 return true;
50}
51
52} // namespace json2pb

Callers 2

JsonValueToProtoMessageFunction · 0.85
ConvertMethod · 0.85

Calls 4

field_countMethod · 0.80
fieldMethod · 0.80
typeMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected