| 6 | //! encode option |
| 7 | |
| 8 | void encode_single_options( |
| 9 | std::pair<std::string, std::shared_ptr<lar::Value>> item, |
| 10 | std::vector<std::pair<mgb::json::String, std::shared_ptr<mgb::json::Value>>>& |
| 11 | list, |
| 12 | bool encode_all) { |
| 13 | auto type = item.second->get_type(); |
| 14 | if (type == JsonValueType::Bool) { |
| 15 | auto val_ptr = std::static_pointer_cast<lar::Bool>(item.second); |
| 16 | if (!encode_all && val_ptr->get_value() == val_ptr->get_default()) { |
| 17 | return; |
| 18 | } |
| 19 | list.push_back( |
| 20 | {mgb::json::String(item.first), |
| 21 | mgb::json::Bool::make(val_ptr->get_value())}); |
| 22 | } else if (type == JsonValueType::NumberInt32) { |
| 23 | auto val_ptr = std::static_pointer_cast<lar::NumberInt32>(item.second); |
| 24 | if (!encode_all && val_ptr->get_value() == val_ptr->get_default()) { |
| 25 | return; |
| 26 | } |
| 27 | list.push_back( |
| 28 | {mgb::json::String(item.first), |
| 29 | mgb::json::NumberInt::make( |
| 30 | static_cast<int64_t>(val_ptr->get_value()))}); |
| 31 | } else if (type == JsonValueType::NumberUint64) { |
| 32 | auto val_ptr = std::static_pointer_cast<lar::NumberUint64>(item.second); |
| 33 | list.push_back( |
| 34 | {mgb::json::String(item.first), |
| 35 | mgb::json::NumberInt::make( |
| 36 | static_cast<int64_t>(val_ptr->get_value()))}); |
| 37 | } else if (type == JsonValueType::Number) { |
| 38 | auto val_ptr = std::static_pointer_cast<lar::Number>(item.second); |
| 39 | list.push_back( |
| 40 | {mgb::json::String(item.first), |
| 41 | mgb::json::Number::make(val_ptr->get_value())}); |
| 42 | } else if (type == JsonValueType::String) { |
| 43 | auto val_ptr = std::static_pointer_cast<lar::String>(item.second); |
| 44 | if (!encode_all && val_ptr->get_value() == val_ptr->get_default()) { |
| 45 | return; |
| 46 | } |
| 47 | list.push_back( |
| 48 | {mgb::json::String(item.first), |
| 49 | mgb::json::String::make(val_ptr->get_value())}); |
| 50 | } else { |
| 51 | mgb_log_error( |
| 52 | "unsupport JsonValueType:%s for lar::Value", |
| 53 | item.second->type_string().c_str()); |
| 54 | } |
| 55 | } |
| 56 | std::string JsonOptionsCoder::encode(OptionValMap& option_val_map, bool encode_all) { |
| 57 | std::vector<std::pair<mgb::json::String, std::shared_ptr<mgb::json::Value>>> |
| 58 | json_options; |
no test coverage detected