24 #include "field_codec_manager.h"
26 dccl::FieldCodecManagerLocal::FieldCodecManagerLocal()
27 : deprecated_names_{{
"_static",
"dccl.static"}, {
"_time",
"dccl.time"}}
31 dccl::FieldCodecManagerLocal::~FieldCodecManagerLocal() =
default;
33 std::shared_ptr<dccl::FieldCodecBase>
34 dccl::FieldCodecManagerLocal::__find(google::protobuf::FieldDescriptor::Type type,
35 int codec_version,
const std::string& codec_name,
36 const std::string& type_name)
const
38 check_deprecated(codec_name);
40 auto it = codecs_.find(type);
42 std::vector<std::string> codec_names_to_try;
43 if (it != codecs_.end())
45 auto inside_it = it->second.end();
48 if (!std::isdigit(codec_name.back()))
49 codec_names_to_try.push_back(codec_name + std::to_string(codec_version));
51 codec_names_to_try.push_back(codec_name);
53 for (
const std::string& c_name : codec_names_to_try)
56 inside_it = it->second.find(__mangle_name(c_name, type_name));
57 if (inside_it != it->second.end())
58 return inside_it->second;
61 inside_it = it->second.find(c_name);
62 if (inside_it != it->second.end())
63 return inside_it->second;
67 std::stringstream err_ss;
68 err_ss <<
"No codec by the name `" << codec_name
69 <<
"` found for type: " << type_helper().find(type)->as_str() <<
" (tried names:";
70 for (
const std::string& c_name : codec_names_to_try) err_ss <<
" `" << c_name <<
"`";
72 throw(Exception(err_ss.str()));
75 void dccl::FieldCodecManagerLocal::check_deprecated(
const std::string& codec_name)
const
77 auto it = deprecated_names_.find(codec_name);
78 if (it != deprecated_names_.end())
80 dlog.
is(dccl::logger::DEBUG1) && dlog <<
"Codec name \"" << it->first
81 <<
"\" is deprecated: use \"" << it->second
82 <<
"\" instead " << std::endl;