file.h
-
using ouster::osf::ChunkBuffer = std::vector<uint8_t>
Chunk buffer type to store raw byte buffers of data.
-
enum class ouster::osf::OpenMode : uint8_t
Enum representing the available file opening modes.
Values:
-
enumerator READ
Open the file in read-only mode.
-
enumerator WRITE
Open the file in write-only mode. (CURRENTLY NOT SUPPORTED)
-
enumerator READ
-
enum class ouster::osf::FileState : uint8_t
Enum representing the state of the OSF file.
Values:
-
enumerator GOOD
The file is good.
-
enumerator BAD
There is something wrong with the file.
-
enumerator GOOD
-
class OsfFile
Interface to abstract the way of how we handle file system read/write operations.
Public Functions
-
explicit OsfFile()
Default constructor, sets most data to nullptr and 0.
-
explicit OsfFile(const std::string &filename, OpenMode mode = OpenMode::READ)
Opens the OSF file.
Note
Only OpenMode::READ is supported
- Parameters:
filename – [in] The OSF file to open
mode – [in] The mode to open the file in, this argument is optional.
-
~OsfFile()
Cleans up any filebuffers/memory mapping.
-
uint64_t size() const
Returns the size of the OSF file.
- Returns:
The size of the OSF file in bytes.
-
std::string filename() const
Returns the filename of the open OSF file.
- Returns:
The filename of the open OSF file.
-
OSF_VERSION version()
Returns the version of the OSF file.
- Returns:
The version of the OSF file.
-
uint64_t metadata_offset()
Returns the offset in the OSF file where the metadata section is located.
- Throws:
std::logic_error – Exception on bad osf file.
- Returns:
Offset to the metadata in bytes
-
uint64_t chunks_offset()
Returns the offset in the OSF file where the chunk section is located.
- Throws:
std::logic_error – Exception on bad osf file.
- Returns:
Offset to the chunks in bytes
-
bool valid()
Checks the validity of header and session/file_info blocks.
- Returns:
If the header, session, and file_info blocks are valid.
-
bool good() const
Return the status of the OSF file.
- Todo:
Need to have more states here (eod, valid, error, etc)
- Returns:
If the OSF file is good or not.
-
uint64_t offset() const
Get the current offset in the OSF file.
- Returns:
The current offset in the OSF file.
-
OsfFile &seek(uint64_t pos)
File seek (in mmap mode it’s just moving the offset_ pointer without any file system opeations.)
- Throws:
std::logic_error – Exception on bad osf file.
std::out_of_range – Exception on out of range seek.
- Parameters:
pos – [in] position in the file
- Returns:
A reference to
this
object.
-
OsfFile &read(uint8_t *buf, const uint64_t count)
Read from file (in current mmap mode it’s copying data from mmap address to the ‘buf’ address).
- Todo:
Handle errors in future and get the way to read them back with FileState etc.
- Throws:
std::logic_error – Exception on bad osf file.
std::out_of_range – Exception on out of range read.
- Parameters:
buf – [out] The buffer to write to.
count – [in] The number of bytes to write to buf.
- Returns:
A reference to
this
object.
-
bool is_memory_mapped() const
Returns whether the OSF file is memory mapped or not.
- Returns:
Is the OSF file memory mapped or not.
-
const uint8_t *buf(const uint64_t offset = 0) const
Mmap access to the file content with the specified offset from the beginning of the file.
- Throws:
std::logic_error – Exception on bad osf file.
std::logic_error – Exception not being memory mapped.
std::out_of_range – Exception on out of range read.
- Parameters:
offset – [in] The specified offset to access into the OSF file, this argument is optional.
- Returns:
The pointer to the OSF file.
-
void close()
Clears file handle and allocated resources. In current mmap implementation it’s unmapping memory and essentially invalidates the memory addresses that might be captured within MessageRefs and Reader.
See also
-
std::string to_string()
Debug helper method to dump OsfFile state to a string.
- Returns:
The string representation of OsfFile
-
OsfFile &operator=(const OsfFile&) = delete
Copy policy: Don’t allow the copying of the file handler
-
OsfFile(OsfFile &&other)
Move policy: Allow transferring ownership of the underlying file handler (mmap).
-
OsfFile &operator=(OsfFile &&other)
Move policy: Allow transferring ownership of the underlying file handler (mmap).
-
std::shared_ptr<ChunkBuffer> read_chunk(uint64_t offset)
Read chunk specified at offset.
- Throws:
std::out_of_range – Exception on out of range read.
- Parameters:
offset – [in] The offset to read the chunk from.
- Returns:
Shared pointer to the chunk. nullptr if osf file is bad
-
uint8_t *get_header_chunk_ptr()
Get a pointer to the start of the header chunk.
- Returns:
Pointer to the header chunk. nullptr if filestream is bad.
-
uint8_t *get_metadata_chunk_ptr()
Get a pointer to the start of the header chunk.
- Returns:
Pointer to the metadata chunk. nullptr if filestream is bad.
-
explicit OsfFile()