bool get_payload_timestamp_json(void* payload, size_t size, uint64_t* tx_nsec)
{
  boost::property_tree::ptree pt;
  std::string json(reinterpret_cast<char*>(payload), size);
  std::istringstream input(json);

  try {
    boost::property_tree::read_json(input, pt);
  }
  catch (boost::property_tree::json_parser_error& e) {
    return false;
  }
  
  try {
    std::string time_string = pt.get<std::string>("time");
    return string_to_nsec(time_string, tx_nsec);
  }
  catch (boost::property_tree::ptree_bad_path& e) {
    return false;
  }
  catch (boost::property_tree::ptree_bad_data& e) {
    return false;
  }
  return false;
}
示例#2
0
static uint64_t
string2nsec(char *value)
{
	uint64_t val = string_to_nsec(value);
	if (val == 0) {
		char err[1024];
		snprintf(err, 1024, "Cannot convert %s to nsecs\n", value);
		add_error(err);
	}
	return (val);
}