Cogs.Core
FileContents.h
1#pragma once
2
3#include "../StringView.h"
4#include "../Memory/MemoryBuffer.h"
5
6#include <functional>
7#include <memory>
8
9namespace Cogs {
10
11 enum struct FileContentsHints : uint32_t {
12 None = 0,
14 ZStdDecompress = 1 << 0,
16 BrotliDecompress = 1 << 1
17 };
18
20 struct COGSFOUNDATION_API FileContents {
21
22
23 using Ptr = std::unique_ptr<FileContents>;
24 using Callback = std::function<void(Ptr&&)>;
25
27 const uint8_t* ptr;
29 size_t size;
30 size_t mimeTypeHash = 0;
31 FileContentsHints hints = FileContentsHints::None;
32
33 public:
34 FileContents() = delete;
35 FileContents(const uint8_t* ptr, size_t size, FileContentsHints hints) : ptr(ptr), size(size), hints(hints) {}
36 FileContents(const FileContents&) = delete;
37
38 virtual ~FileContents() = default;
39
40 FileContents& operator=(const FileContents&) = delete;
41
42 [[nodiscard]] Memory::MemoryBuffer takeCopy();
43
45 [[nodiscard]] constexpr const void* data() const { return ptr; }
46
48 [[nodiscard]] virtual Memory::MemoryBuffer take() = 0;
49
50 [[nodiscard]] virtual StringView origin() = 0;
51 };
52}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
@ None
Default flags.
FileContentsHints
Definition: FileContents.h:11
@ BrotliDecompress
A hint that the contents are Brotli (Google) compressed and is allowed to be decompressed during tran...
@ ZStdDecompress
A hint that the contents are Zstandard (Facebook) compressed and is allowed to be decompressed during...
Abstract base class storing data read from a file.
Definition: FileContents.h:20
size_t size
Number of data bytes.
Definition: FileContents.h:29
constexpr const void * data() const
Access to buffer data. Cast to actual type using static_cast<const MyType*>(..)
Definition: FileContents.h:45
virtual Memory::MemoryBuffer take()=0
Take ownership of underlying memorybuffer if exists.
const uint8_t * ptr
Start of buffer storing file data. Use.
Definition: FileContents.h:27