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

Function StringToProtocolType

src/brpc/protocol.cpp:161–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161ProtocolType StringToProtocolType(const butil::StringPiece& name,
162 bool print_log_on_unknown) {
163 // Force init of s_protocol_name.
164 GlobalInitializeOrDie();
165
166 ProtocolEntry* const protocol_map = get_protocol_map();
167 for (size_t i = 0; i < MAX_PROTOCOL_SIZE; ++i) {
168 if (protocol_map[i].valid.load(butil::memory_order_acquire) &&
169 CompareStringPieceWithoutCase(name, protocol_map[i].protocol.name)) {
170 return static_cast<ProtocolType>(i);
171 }
172 }
173 // We need to print a log here otherwise the return value cannot reflect
174 // the original input, which makes later initializations of other classes
175 // fail with vague logs which is not informational to user, like this:
176 // "channel doesn't support protocol=unknown"
177 // Some callsite may not need this log, so we keep a flag.
178 if (print_log_on_unknown) {
179 std::ostringstream err;
180 err << "Unknown protocol `" << name << "', supported protocols:";
181 for (size_t i = 0; i < MAX_PROTOCOL_SIZE; ++i) {
182 if (protocol_map[i].valid.load(butil::memory_order_acquire)) {
183 err << ' ' << protocol_map[i].protocol.name;
184 }
185 }
186 LOG(ERROR) << err.str();
187 }
188 return PROTOCOL_UNKNOWN;
189}
190
191const char* ProtocolTypeToString(ProtocolType type) {
192 // Force init of s_protocol_name.

Callers

nothing calls this directly

Calls 4

GlobalInitializeOrDieFunction · 0.85
get_protocol_mapFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected