mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Refactor Input/Output file to use const char* instead of standard string, and to use parent_folder and file_name for input and output files. This also incorporates the move from nearby_connections to nearby.
PiperOrigin-RevId: 415587802
This commit is contained in:
committed by
Copybara-Service
parent
5ba6623eac
commit
f12bb6c405
@@ -29,7 +29,6 @@ cc_library(
|
||||
"cancelable_alarm.h",
|
||||
"cancellable_task.h",
|
||||
"condition_variable.h",
|
||||
"core_config.h",
|
||||
"count_down_latch.h",
|
||||
"crypto.h",
|
||||
"file.h",
|
||||
|
||||
+12
-15
@@ -17,16 +17,19 @@
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
InputFile::InputFile(PayloadId payload_id, std::int64_t size)
|
||||
: impl_(Platform::CreateInputFile(payload_id, size)), id_(payload_id) {}
|
||||
InputFile::InputFile(const char* file_path)
|
||||
: impl_(Platform::CreateInputFile(file_path)) {}
|
||||
|
||||
InputFile::~InputFile() = default;
|
||||
InputFile::InputFile(InputFile&&) noexcept = default;
|
||||
InputFile::InputFile(InputFile&& other) noexcept {
|
||||
impl_ = std::move(other.impl_);
|
||||
}
|
||||
InputFile& InputFile::operator=(InputFile&&) noexcept = default;
|
||||
|
||||
// Reads up to size bytes and returns as a ByteArray object wrapped by
|
||||
// ExceptionOr.
|
||||
// Returns Exception::kIo on error, or end of file.
|
||||
ExceptionOr<ByteArray> InputFile::Read(std::int64_t size) {
|
||||
ExceptionOr<ByteArray> InputFile::Read(std::int64_t size) const {
|
||||
return impl_->Read(size);
|
||||
}
|
||||
|
||||
@@ -36,13 +39,13 @@ std::string InputFile::GetFilePath() const { return impl_->GetFilePath(); }
|
||||
// Returns total size of this file in bytes.
|
||||
std::int64_t InputFile::GetTotalSize() const { return impl_->GetTotalSize(); }
|
||||
|
||||
ExceptionOr<size_t> InputFile::Skip(size_t offset) {
|
||||
ExceptionOr<size_t> InputFile::Skip(size_t offset) const {
|
||||
return impl_->Skip(offset);
|
||||
}
|
||||
|
||||
// Disallows further reads from the file and frees system resources,
|
||||
// associated with it.
|
||||
Exception InputFile::Close() { return impl_->Close(); }
|
||||
Exception InputFile::Close() const { return impl_->Close(); }
|
||||
|
||||
// Returns a handle to the underlying input stream.
|
||||
//
|
||||
@@ -51,13 +54,10 @@ Exception InputFile::Close() { return impl_->Close(); }
|
||||
// Side effects of any non-const operation invoked for InputFile (such as
|
||||
// Read, or Close will be observable through InputStream& handle, and vice
|
||||
// versa.
|
||||
InputStream& InputFile::GetInputStream() { return *impl_; }
|
||||
const InputStream& InputFile::GetInputStream() const { return *impl_; }
|
||||
|
||||
// Returns payload id of this file. The closest "file" equivalent is inode.
|
||||
PayloadId InputFile::GetPayloadId() const { return id_; }
|
||||
|
||||
OutputFile::OutputFile(PayloadId payload_id)
|
||||
: impl_(Platform::CreateOutputFile(payload_id)), id_(payload_id) {}
|
||||
OutputFile::OutputFile(const char* file_path)
|
||||
: impl_(Platform::CreateOutputFile(file_path)) {}
|
||||
OutputFile::~OutputFile() = default;
|
||||
OutputFile::OutputFile(OutputFile&&) noexcept = default;
|
||||
OutputFile& OutputFile::operator=(OutputFile&&) noexcept = default;
|
||||
@@ -85,8 +85,5 @@ Exception OutputFile::Close() { return impl_->Close(); }
|
||||
// versa.
|
||||
OutputStream& OutputFile::GetOutputStream() { return *impl_; }
|
||||
|
||||
// Returns payload id of this file. The closest "file" equivalent is inode.
|
||||
PayloadId OutputFile::GetPayloadId() const { return id_; }
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
#include "platform/api/output_file.h"
|
||||
#include "platform/api/platform.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "platform/base/core_config.h"
|
||||
#include "platform/base/exception.h"
|
||||
#include "platform/base/input_stream.h"
|
||||
#include "platform/base/output_stream.h"
|
||||
#include "platform/public/core_config.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -34,7 +34,7 @@ namespace nearby {
|
||||
class DLL_API InputFile final {
|
||||
public:
|
||||
using Platform = api::ImplementationPlatform;
|
||||
InputFile(PayloadId payload_id, std::int64_t size);
|
||||
InputFile(const char* file_path);
|
||||
~InputFile();
|
||||
InputFile(InputFile&&) noexcept;
|
||||
InputFile& operator=(InputFile&&) noexcept;
|
||||
@@ -42,7 +42,7 @@ class DLL_API InputFile final {
|
||||
// Reads up to size bytes and returns as a ByteArray object wrapped by
|
||||
// ExceptionOr.
|
||||
// Returns Exception::kIo on error, or end of file.
|
||||
ExceptionOr<ByteArray> Read(std::int64_t size);
|
||||
ExceptionOr<ByteArray> Read(std::int64_t size) const;
|
||||
|
||||
// Returns a string that uniqely identifies this file.
|
||||
std::string GetFilePath() const;
|
||||
@@ -50,11 +50,11 @@ class DLL_API InputFile final {
|
||||
// Returns total size of this file in bytes.
|
||||
std::int64_t GetTotalSize() const;
|
||||
|
||||
ExceptionOr<size_t> Skip(size_t offset);
|
||||
ExceptionOr<size_t> Skip(size_t offset) const;
|
||||
|
||||
// Disallows further reads from the file and frees system resources,
|
||||
// associated with it.
|
||||
Exception Close();
|
||||
Exception Close() const;
|
||||
|
||||
// Returns a handle to the underlying input stream.
|
||||
//
|
||||
@@ -63,20 +63,16 @@ class DLL_API InputFile final {
|
||||
// Side effects of any non-const operation invoked for InputFile (such as
|
||||
// Read, or Close will be observable through InputStream& handle, and vice
|
||||
// versa.
|
||||
InputStream& GetInputStream();
|
||||
|
||||
// Returns payload id of this file. The closest "file" equivalent is inode.
|
||||
PayloadId GetPayloadId() const;
|
||||
const InputStream& GetInputStream() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<api::InputFile> impl_;
|
||||
PayloadId id_;
|
||||
};
|
||||
|
||||
class DLL_API OutputFile final {
|
||||
public:
|
||||
using Platform = api::ImplementationPlatform;
|
||||
explicit OutputFile(PayloadId payload_id);
|
||||
explicit OutputFile(const char* file_path);
|
||||
~OutputFile();
|
||||
OutputFile(OutputFile&&) noexcept;
|
||||
OutputFile& operator=(OutputFile&&) noexcept;
|
||||
@@ -102,12 +98,8 @@ class DLL_API OutputFile final {
|
||||
// versa.
|
||||
OutputStream& GetOutputStream();
|
||||
|
||||
// Returns payload id of this file. The closest "file" equivalent is inode.
|
||||
PayloadId GetPayloadId() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<api::OutputFile> impl_;
|
||||
PayloadId id_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user