Example #1
0
// static
void Serdes::DeserializeMapObjects(std::vector<int8_t> const & bytes, MapObjects & result)
{
  MemReader reader(bytes.data(), bytes.size());
  NonOwningReaderSource source(reader);

  std::string tmp(bytes.begin(), bytes.end());
  std::istringstream is(tmp);

  std::string eventString;
  MapObjectEvent event;
  MapObject poi;

  try
  {
    while (getline(is, eventString))
    {
      if (eventString.empty())
        return;

      coding::DeserializerJson des(eventString);
      des(event);
      poi.SetBestType(event.m_bestPoiType);
      poi.SetPos(event.m_poiPos);
      poi.SetDefaultName(event.m_defaultName);
      poi.SetReadableName(event.m_readableName);

      bool found = false;
      result.ForEachInRect(poi.GetLimitRect(), [&found, &poi, &event](MapObject const & item)
      {
        if (item != poi)
          return;

        if (!found)
          found = true;

        item.GetEditableEvents().push_back(event.m_event);
      });

      if (!found)
      {
        poi.GetEditableEvents().push_back(event.m_event);
        result.Add(poi);
      }
    }
  }
  catch (base::Json::Exception & ex)
  {
    LOG(LERROR, ("Cannot deserialize map objects. Exception:", ex.Msg(), ". Event string:",
                 eventString, ". Content:", std::string(bytes.begin(), bytes.end())));
  }
}