Coverage Report

Created: 2025-12-17 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/brpc/src/json2pb/protobuf_map.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "protobuf_map.h"
19
#include <stdio.h>
20
21
namespace json2pb {
22
23
using google::protobuf::Descriptor;
24
using google::protobuf::FieldDescriptor;
25
26
9.47k
bool IsProtobufMap(const FieldDescriptor* field) {
27
9.47k
    if (field->type() != FieldDescriptor::TYPE_MESSAGE || !field->is_repeated()) {
28
8.95k
        return false;
29
8.95k
    }
30
524
    const Descriptor* entry_desc = field->message_type();
31
524
    if (entry_desc == NULL) {
32
0
        return false;
33
0
    }
34
524
    if (entry_desc->field_count() != 2) {
35
524
        return false;
36
524
    }
37
0
    const FieldDescriptor* key_desc = entry_desc->field(KEY_INDEX);
38
0
    if (NULL == key_desc
39
0
        || key_desc->is_repeated()
40
0
        || key_desc->cpp_type() != FieldDescriptor::CPPTYPE_STRING
41
0
        || strcmp(KEY_NAME, key_desc->name().c_str()) != 0) {
42
0
        return false;
43
0
    }
44
0
    const FieldDescriptor* value_desc = entry_desc->field(VALUE_INDEX);
45
0
    if (NULL == value_desc
46
0
        || strcmp(VALUE_NAME, value_desc->name().c_str()) != 0) {
47
0
        return false;
48
0
    }
49
0
    return true;
50
0
}
51
52
} // namespace json2pb