MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / value_from_json

Function value_from_json

src/json.cpp:103–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103migraphx::value value_from_json(const json& j)
104{
105 migraphx::value val;
106 json::value_t type = j.type();
107 switch(type)
108 {
109 case json::value_t::null: val = nullptr; break;
110
111 case json::value_t::boolean: val = j.get<bool>(); break;
112
113 case json::value_t::number_float: val = j.get<double>(); break;
114
115 case json::value_t::number_integer: val = j.get<int64_t>(); break;
116
117 case json::value_t::number_unsigned: val = j.get<uint64_t>(); break;
118
119 case json::value_t::string: val = j.get<std::string>(); break;
120
121 case json::value_t::array:
122 val = migraphx::value::array{};
123 std::transform(j.begin(), j.end(), std::back_inserter(val), [&](const json& jj) {
124 return jj.get<value>();
125 });
126 break;
127
128 case json::value_t::object:
129 if(j.contains("bytes") and j.size() == 1)
130 {
131 val = migraphx::value::binary{j["bytes"].get<std::vector<std::uint8_t>>()};
132 }
133 else
134 {
135 val = migraphx::value::object{};
136 for(const auto& item : j.items())
137 {
138 const auto& key = item.key();
139 const json& jv = item.value();
140 val[key] = jv.get<value>();
141 }
142 }
143 break;
144
145 case json::value_t::binary: MIGRAPHX_THROW("Convert JSON to Value: binary type not supported!");
146 case json::value_t::discarded:
147 MIGRAPHX_THROW("Convert JSON to Value: discarded type not supported!");
148 }
149
150 return val;
151}
152
153std::string to_json_string(const value& val)
154{

Callers 1

from_jsonMethod · 0.85

Calls 7

transformFunction · 0.50
typeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
containsMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected