Example #1
0
inline void serialize(json_config_iarchive_cast& js, std::vector<T>& vs) {
  // check errors
  if (!detail::check_json_type(js, pfi::text::json::json::Array)) {
    return;
  }

  size_t size = js.get_config().size();
  std::vector<T> v(size);
  for (size_t i = 0; i < size; ++i) {
    json_from_config(js.get_config()[i], v[i], js.errors());
  }
  vs.swap(v);
}
Example #2
0
inline void serialize(
    json_config_iarchive_cast& js,
    pfi::data::serialization::named_value<pfi::data::optional<T> >& v) {
  using pfi::text::json::json;
  if (js.get_config().contain(v.name)
      && (js.get_config()[v.name].get().type() != json::Null)) {
    T value = T();
    json_from_config(js.get_config()[v.name], value, js.errors());
    v.v = value;
  } else {
    // optional can be null
    v.v = pfi::data::optional<T>();
  }
}
Example #3
0
inline bool check_json_type(
    json_config_iarchive_cast& js,
    jubatus::util::text::json::json::json_type_t t) {
  if (js.get().type() != t) {
    type_error e(js.get_config().path(), t, js.get().type());
    if (js.trace_error()) {
      js.push_error(e);
    } else {
      throw JUBATUS_EXCEPTION(e);
    }
    return false;
  }
  return true;
}
Example #4
0
inline void serialize(json_config_iarchive_cast& js, std::map<K, V>& m) {
  if (!detail::check_json_type(js, pfi::text::json::json::Object)) {
    return;
  }

  std::map<K, V> tmp;
  typedef config::iterator iter_t;
  for (iter_t it = js.get_config().begin(), end = js.get_config().end();
       it != end; ++it) {
    V value = V();
    json_from_config(it.value(), value, js.errors());
    tmp[it.key()] = value;
  }
  tmp.swap(m);
}
Example #5
0
inline void serialize(json_config_iarchive_cast& js,
                      jubatus::util::data::serialization::named_value<T>& v) {
  if (js.get_config().contain(v.name)) {
    json_from_config(js.get_config()[v.name], v.v, js.errors());
  } else {
    not_found e(js.get_config().path(), v.name);
    if (js.trace_error()) {
      js.push_error(e);
    } else {
      throw JUBATUS_EXCEPTION(e);
    }
  }
}
Example #6
0
inline bool check_json_float(json_config_iarchive_cast& js) {
  if (js.get().type() != pfi::text::json::json::Float
      && js.get().type() != pfi::text::json::json::Integer) {
    type_error e(
        js.get_config().path(),
        pfi::text::json::json::Float,
        js.get().type());
    if (js.trace_error()) {
      js.push_error(e);
    } else {
      throw JUBATUS_EXCEPTION(e);
    }
    return false;
  }
  return true;
}
Example #7
0
inline bool check_json_type(
    json_config_iarchive_cast& js,
    pfi::text::json::json::json_type_t t) {
  if (js.get().type() != t) {
    // int -> float is valid
    if (js.get().type() == pfi::text::json::json::Integer &&
        t == pfi::text::json::json::Float) {
      return true;
    }
    type_error e(js.get_config().path(), t, js.get().type());
    if (js.trace_error()) {
      js.push_error(e);
    } else {
      throw e;
    }
    return false;
  }
  return true;
}
Example #8
0
inline void serialize(json_config_iarchive_cast& js, T& v) {
  if (js.get().type() == jubatus::util::text::json::json::Object) {
    member_collector collector;
    jubatus::util::data::serialization::access::serialize(collector, v);
    std::set<std::string> members(collector.get_members().begin(),
        collector.get_members().end());
    for (jubatus::util::text::json::json::const_iterator it = js.get().begin();
         it != js.get().end(); ++it) {
      const std::string& key = it->first;
      if (members.count(key) == 0) {
        redundant_key e(js.get_config().path(), key);
        if (js.trace_error()) {
          js.push_error(e);
        } else {
          throw JUBATUS_EXCEPTION(e);
        }
      }
    }
  }

  jubatus::util::data::serialization::access::serialize(js, v);
}
Example #9
0
inline void serialize(json_config_iarchive_cast& js, config& v) {
  v = config(js.get(), js.get_config().path());
}
Example #10
0
inline void serialize(
    json_config_iarchive_cast& js,
    jubatus::util::text::json::json& v) {
  v = js.get();
}
Example #11
0
inline void serialize(json_config_iarchive_cast& js, pfi::text::json::json& v) {
  v = js.get();
}