libassetmap  1.0.0
Hash-table based archive format containing compressed data
Classes | Typedefs | Functions | Variables
AssetMap Namespace Reference

Classes

class  CityHash
 
class  DirectoryMetadata
 
class  ICompress
 
class  IDecompress
 
class  IHasher
 
class  IMemMapper
 
class  MemMappedArchive
 
class  MemMappedBucket
 
class  MemMappedBucketEntry
 
class  MemMapper
 
class  ZSTD
 

Typedefs

using lam_size_t = LIBARCHIVEMAP_SIZE_TYPE
 

Functions

template<typename T >
constexpr void PutValue (uint8_t *buf, T value) noexcept
 Writes any integral value, byte-by-byte to a memory location. More...
 
template<typename T >
constexpr T GetValue (const uint8_t *buf) noexcept
 Reads any integral value byte-by-byte and return it. More...
 

Variables

constexpr auto PutLamSizeT = PutValue<lam_size_t>
 
constexpr auto GetLamSizeT = GetValue<lam_size_t>
 

Detailed Description

An archive is laid out according to the compile-time integer size.
By default this is a uint32_t though it can be changed via CMake.

Target number of buckets is defined by IHasher.
All offsets are specified relative to the beginning of the file. This makes
it easier to inspect values in a hex editor and was chosen since the bucket
table is at the start which would buy very little additional space if it
were made relative to the current pointer. If you need more space, use
64-bit values.

Each file entry is padded to the sizeof() the chosen integer width. This
is not actually required but is designed to avoid the overhead on unaligned
accesses in cases where the compiler knows the CPU would happily read
unaligned data.

All integer values are stored little-endian.

If a dictionary has been used, it is concatenated to the end and a value
indicating its size is appended after it.

A single byte is placed at the end of the file indicating whether a
dictionary is present or not. If the value is anything other than 0 or 1, an
exception will be thrown as this is assumed to indicate a future version.

Assuming a 32-bit size with 2 buckets across 3 files, which all happened to
be compressed to a few bytes each, this would be the layout:

B = bucket
I = Item
+------+----------------------------------+---+---+---+---+---+---+---------------------------+-------------------------+---+---+---+------------------+-----+---------+---------+
|      |                 0                | 1 | 2 | 3 | 4 | 5 | 6 |             7             |            8            | 9 | A | B |         C        |  D  |    E    |    F    |
+------+----------------------------------+---+---+---+---+---+---+---------------------------+-------------------------+---+---+---+------------------+-----+---------+---------+
| 0x00 |              [bucket_count] = 2              |          [B0][offset] = 0xC           |         [B1][offset] = 0x24         |             [B0][I0][size] = 5             |
+------+----------------------------------------------+-----------+---------------------------+-------------------------------------+--------------------------------------------+
| 0x10 |                [B0][I0][name] = "f1.txt\0"               |                       [I0][data] = {bytes}                      |            [B0][Iend][size] = 0            |
+------+----------------------------------+-----------+-----------+---------------------------+-------------------------------------+--------------------------------------------+
| 0x20 |      [B0][Iend][name] = "\0"     | [padding] |           [B1][I0][size] = 5          |                           [B1][I0][name] = "file2.S\0"                           |
+------+----------------------------------+-----------+---+-----------------------------------+-------------------------------------+--------------------------------------------+
| 0x30 |             [B1][I0][data] = {bytes}             |             [padding]             |          [B1][I1][size] = 7         |          [B1][I1][name] = "abc\0"          |
+------+--------------------------------------------------+-------+---------------------------+-------------------------------------+------------------------+-------------------+
| 0x40 |               [B1][I1][data] = {bytes}                   | [B1][I1][padding] = {any} |          [B1][I2][size] = 3         | [B1][I2][name] = "x\0" | [B1][I2][data]... |
+------+----------------------------------+-----------+-----------+---------------------------+-------------------------+-----------+------------------+-----+-------------------+
| 0x50 | ...[B1][I2][data] = {bytes}      | [padding] |          [B1][Iend][size] = 0         | [B1][Iend][name] = "\0" | [padding] |   [hasDict] = 0  |   {EOF} unaddressable.  |
+------+----------------------------------+-----------+---------------------------------------+-------------------------+-----------+------------------+-------------------------+

Function Documentation

◆ GetValue()

template<typename T >
constexpr T AssetMap::GetValue ( const uint8_t *  buf)
inlineconstexprnoexcept

Reads any integral value byte-by-byte and return it.

Precondition
buf must contain at least sizeof(T) bytes.
Template Parameters
TAny integral type
Parameters
bufThe buffer to read the value from.
Returns
The integral value read from the buffer.

◆ PutValue()

template<typename T >
constexpr void AssetMap::PutValue ( uint8_t *  buf,
T  value 
)
inlineconstexprnoexcept

Writes any integral value, byte-by-byte to a memory location.

         It is left to the compiler to determine whether the value can
         be written with an unaligned access or not.
Todo:
When the project is upgraded to C++ 20, alignment hinting be supported to allow using std::assume_aligned.
Precondition
buf must be able to hold at least sizeof(T) bytes.
Template Parameters
TThe integral type to write (deduced)
Parameters
bufThe buffer to write the value into.
valueThe integral value to write