YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/util/protobuf_util.h
Line
Count
Source (jump to first uncovered line)
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
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
// Portions Copyright (c) YugaByte, Inc.
34
35
#ifndef YB_UTIL_PROTOBUF_UTIL_H
36
#define YB_UTIL_PROTOBUF_UTIL_H
37
38
#include <float.h>
39
40
#include <chrono>
41
#include <sstream>
42
#include <string>
43
#include <type_traits>
44
45
#include <boost/mpl/and.hpp>
46
#include <google/protobuf/stubs/port.h>
47
#include <google/protobuf/generated_enum_reflection.h>
48
#include <google/protobuf/message_lite.h>
49
50
#include "yb/util/enums.h"
51
#include "yb/util/format.h"
52
#include "yb/util/math_util.h"
53
#include "yb/util/tostring.h"
54
#include "yb/util/type_traits.h"
55
56
#define PB_ENUM_FORMATTERS(EnumType) \
57
129
  inline std::string PBEnumToString(EnumType value) { \
58
129
    if (BOOST_PP_CAT(EnumType, _IsValid)(value)) { \
59
126
      return BOOST_PP_CAT(EnumType, _Name)(value); \
60
3
    } else { \
61
3
      return ::yb::Format("<unknown " BOOST_PP_STRINGIZE(EnumType) " : $0>", \
62
3
          ::yb::to_underlying(value)); \
63
3
    } \
64
129
  } \
Unexecuted instantiation: _Z14PBEnumToStringN2yb9consensus17LeaderLeaseStatusE
tablet-split-itest.cc:_ZN2yb12_GLOBAL__N_114PBEnumToStringENS_14IsolationLevelE
Line
Count
Source
57
123
  inline std::string PBEnumToString(EnumType value) { \
58
123
    if (BOOST_PP_CAT(EnumType, _IsValid)(value)) { \
59
123
      return BOOST_PP_CAT(EnumType, _Name)(value); \
60
0
    } else { \
61
0
      return ::yb::Format("<unknown " BOOST_PP_STRINGIZE(EnumType) " : $0>", \
62
0
          ::yb::to_underlying(value)); \
63
0
    } \
64
123
  } \
_ZN2yb7pb_util14PBEnumToStringENS_10TestPBEnumE
Line
Count
Source
57
6
  inline std::string PBEnumToString(EnumType value) { \
58
6
    if (BOOST_PP_CAT(EnumType, _IsValid)(value)) { \
59
3
      return BOOST_PP_CAT(EnumType, _Name)(value); \
60
3
    } else { \
61
3
      return ::yb::Format("<unknown " BOOST_PP_STRINGIZE(EnumType) " : $0>", \
62
3
          ::yb::to_underlying(value)); \
63
3
    } \
64
6
  } \
Unexecuted instantiation: _Z14PBEnumToStringN2yb21AppStatusPB_ErrorCodeE
Unexecuted instantiation: _Z14PBEnumToStringN2yb8PeerRoleE
Unexecuted instantiation: _Z14PBEnumToStringN2yb6tablet16RaftGroupStatePBE
Unexecuted instantiation: _ZN2yb5tools10enterprise14PBEnumToStringENS_6master24SysSnapshotEntryPB_StateE
65
125
  inline std::string ToString(EnumType value) { \
66
125
    return PBEnumToString(value); \
67
125
  } \
Unexecuted instantiation: _Z8ToStringN2yb9consensus17LeaderLeaseStatusE
tablet-split-itest.cc:_ZN2yb12_GLOBAL__N_18ToStringENS_14IsolationLevelE
Line
Count
Source
65
123
  inline std::string ToString(EnumType value) { \
66
123
    return PBEnumToString(value); \
67
123
  } \
_ZN2yb7pb_util8ToStringENS_10TestPBEnumE
Line
Count
Source
65
2
  inline std::string ToString(EnumType value) { \
66
2
    return PBEnumToString(value); \
67
2
  } \
Unexecuted instantiation: _Z8ToStringN2yb8PeerRoleE
Unexecuted instantiation: _Z8ToStringN2yb21AppStatusPB_ErrorCodeE
Unexecuted instantiation: _Z8ToStringN2yb6tablet16RaftGroupStatePBE
Unexecuted instantiation: _ZN2yb5tools10enterprise8ToStringENS_6master24SysSnapshotEntryPB_StateE
68
2
  __attribute__((unused)) inline std::ostream& operator << (std::ostream& out, EnumType value) { \
69
2
    return out << PBEnumToString(value); \
70
2
  }
Unexecuted instantiation: _ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEEN2yb9consensus17LeaderLeaseStatusE
Unexecuted instantiation: tablet-split-itest.cc:_ZN2yb12_GLOBAL__N_1lsERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEENS_14IsolationLevelE
_ZN2yb7pb_utillsERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEENS_10TestPBEnumE
Line
Count
Source
68
2
  __attribute__((unused)) inline std::ostream& operator << (std::ostream& out, EnumType value) { \
69
2
    return out << PBEnumToString(value); \
70
2
  }
Unexecuted instantiation: _ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEEN2yb8PeerRoleE
Unexecuted instantiation: _ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEEN2yb21AppStatusPB_ErrorCodeE
Unexecuted instantiation: _ZlsRNSt3__113basic_ostreamIcNS_11char_traitsIcEEEEN2yb6tablet16RaftGroupStatePBE
Unexecuted instantiation: _ZN2yb5tools10enterpriselsERNSt3__113basic_ostreamIcNS2_11char_traitsIcEEEENS_6master24SysSnapshotEntryPB_StateE
71
72
namespace yb {
73
74
template<typename T>
75
0
std::vector<T> GetAllPbEnumValues() {
76
0
  const auto* desc = google::protobuf::GetEnumDescriptor<T>();
77
0
  std::vector<T> result;
78
0
  result.reserve(desc->value_count());
79
0
  for (int i = 0; i < desc->value_count(); ++i) {
80
0
    result.push_back(T(desc->value(i)->number()));
81
0
  }
82
0
  return result;
83
0
}
84
85
template <class Source, class Dest>
86
void AppendToRepeated(const Source& source, Dest* dest) {
87
  dest->Reserve(dest->size() + source.size());
88
  for (const auto& elem : source) {
89
    dest->Add(elem);
90
  }
91
}
92
93
} // namespace yb
94
95
#endif  // YB_UTIL_PROTOBUF_UTIL_H