std::unique_ptr Decoder::decode()

in hessian2/basic_codec/type_ref_codec.cc [6:36]


std::unique_ptr<Object::TypeRef> Decoder::decode() {
  auto ret = reader_->peek<uint8_t>();
  if (!ret.first) {
    return nullptr;
  }
  auto code = ret.second;
  if (code <= 31 || (code >= 48 && code <= 51) || code == 82 || code == 83) {
    // String type
    auto type_str = decode<std::string>();
    if (!type_str) {
      return nullptr;
    }
    types_ref_.push_back(*type_str);
    return std::make_unique<Object::TypeRef>(*type_str);
  }

  // int32_t
  auto ret_int = decode<int32_t>();
  if (!ret_int) {
    return nullptr;
  }

  auto ref = static_cast<uint32_t>(*ret_int);
  if (types_ref_.size() <= ref) {
    return nullptr;
  } else {
    return std::make_unique<Object::TypeRef>(types_ref_[ref]);
  }

  return nullptr;
}