Define the logic here because multiple inheritance makes it difficult for this base class, the InputStream and the RandomAccessFile interfaces to co-exist.
| 264 | // for this base class, the InputStream and the RandomAccessFile |
| 265 | // interfaces to co-exist. |
| 266 | arrow::Result<int64_t> ReadBase(int64_t nbytes, void* out) { |
| 267 | if (closed()) { |
| 268 | return arrow::Status::IOError("R connection is closed"); |
| 269 | } |
| 270 | |
| 271 | if (nbytes > std::numeric_limits<int>::max()) { |
| 272 | return arrow::Status::Invalid( |
| 273 | "Can't read more than INT_MAX bytes from an R connection"); |
| 274 | } |
| 275 | |
| 276 | return SafeCallIntoR<int64_t>( |
| 277 | [&] { |
| 278 | cpp11::function read_bin = cpp11::package("base")["readBin"]; |
| 279 | cpp11::writable::raws ptype(static_cast<R_xlen_t>(0)); |
| 280 | cpp11::integers n = cpp11::as_sexp<int>(static_cast<int>(nbytes)); |
| 281 | |
| 282 | cpp11::sexp result = read_bin(connection_sexp_, ptype, n); |
| 283 | |
| 284 | int64_t result_size = cpp11::safe[Rf_xlength](result); |
| 285 | memcpy(out, cpp11::safe[RAW](result), result_size); |
| 286 | bytes_read_++; |
| 287 | return result_size; |
| 288 | }, |
| 289 | "readBin() on R connection"); |
| 290 | } |
| 291 | |
| 292 | arrow::Result<std::shared_ptr<arrow::Buffer>> ReadBase(int64_t nbytes) { |
| 293 | arrow::BufferBuilder builder; |