std::unique_ptr Decoder::decode()

in hessian2/basic_codec/map_codec.cc [8:53]


std::unique_ptr<TypedMapObject> Decoder::decode() {
  std::string type;
  Object::TypedMap obj_map;

  auto result = std::make_unique<TypedMapObject>();
  values_ref_.push_back(result.get());
  auto ret = reader_->read<uint8_t>();
  ABSL_ASSERT(ret.first);
  auto code = ret.second;
  ABSL_ASSERT(code == 'M');
  // Read Type
  auto type_str = decode<Object::TypeRef>();
  if (!type_str) {
    return nullptr;
  }

  obj_map.type_name_ = std::move(type_str->type_);

  ret = reader_->peek<uint8_t>();
  if (!ret.first) {
    return nullptr;
  }

  while (ret.second != 'Z') {
    auto key = decode<Object>();
    if (!key) {
      return nullptr;
    }

    auto value = decode<Object>();
    if (!value) {
      return nullptr;
    }

    obj_map.field_name_and_value_.emplace(std::move(key), std::move(value));
    ret = reader_->peek<uint8_t>();
    if (!ret.first) {
      return nullptr;
    }
  }

  // Skip last 'Z'
  reader_->read<uint8_t>();
  result->setTypedMap(std::move(obj_map));
  return result;
}