blob: fe523ac07c5e55251175b5945402f7774eb8900f [file] [log] [blame]
void Config::record_to_inspect(inspect::Inspector* inspector) {
inspect::Node inspect_config = inspector->GetRoot().CreateChild("config");
{{#each fields}}
{{#if (is_string_vector type_)}}
auto {{ident}} = inspect_config.CreateStringArray("{{ident}}", this->{{ident}}().size());
for (size_t i = 0; i < this->{{ident}}().size(); i++) {
auto ref = std::string_view(this->{{ident}}()[i].data());
{{ident}}.Set(i, ref);
}
inspector->emplace(std::move({{ident}}));
{{else}}
{{#if (is_vector type_)}}
auto {{ident}} =
inspect_config.Create{{(inspect_type type_)}}Array("{{ident}}", this->{{ident}}().size());
for (size_t i = 0; i < this->{{ident}}().size(); i++) {
{{ident}}.Set(i, this->{{ident}}()[i]);
}
inspector->emplace(std::move({{ident}}));
{{else}}
inspect_config.Create{{(inspect_type type_)}}("{{ident}}", this->{{ident}}(), inspector);
{{/if}}
{{/if}}
{{/each}}
inspector->emplace(std::move(inspect_config));
}
std::ostream& operator<<(std::ostream& os, const Config& c) {
{{#each fields}}
{{#if (is_vector type_)}}
os << " {{ident}}: [" << std::endl;
for (auto value : c.{{ident}}()) {
os << " " << value << "," << std::endl;
}
os << "]" << std::endl;
{{else}}
os << " {{ident}}: " << c.{{ident}}() << std::endl;
{{/if}}
{{~/each~}}
return os;
}
template <class T>
std::vector<T> from_vector_view(fidl::VectorView<T> v) {
size_t count = v.count();
std::vector<T> data(count);
for (size_t i = 0; i < count; i++) {
data[i] = v[i];
}
return data;
}
std::vector<std::string> from_vector_string_view(fidl::VectorView<fidl::StringView> v) {
size_t count = v.count();
std::vector<std::string> data(count);
for (size_t i = 0; i < count; i++) {
data[i] = std::string(v[i].get());
}
return data;
}