Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
metapack_format.h
1#ifndef SOURCEMETA_CORE_METAPACK_FORMAT_H_
2#define SOURCEMETA_CORE_METAPACK_FORMAT_H_
3
4#ifndef SOURCEMETA_CORE_METAPACK_EXPORT
5#include <sourcemeta/core/metapack_export.h>
6#endif
7
8#include <array> // std::array
9#include <bit> // std::endian
10#include <cstddef> // std::size_t
11#include <cstdint> // std::int64_t, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t
12#include <limits> // std::numeric_limits
13
14namespace sourcemeta::core {
15
16// Every multi-byte field is read where it lies rather than byte-swapped, so
17// the byte order the format is written in is the only one it can be read in
18static_assert(std::endian::native == std::endian::little,
19 "The metapack format is little-endian and this host is not");
20
23enum class MetapackEncoding : std::uint8_t {
27 GZIP = 1
28};
29
30#pragma pack(push, 1)
35 std::uint32_t magic{0};
37 std::uint16_t format_version{0};
41 std::uint8_t reserved{0};
43 std::int64_t last_modified{0};
45 std::uint64_t content_bytes{0};
48 std::array<std::uint8_t, 32> checksum{};
50 std::uint16_t media_type_length{0};
51};
52#pragma pack(pop)
53
54static_assert(alignof(MetapackHeader) == 1,
55 "The header is read where it lies, so its layout must be packed");
56static_assert(sizeof(MetapackHeader) == 58,
57 "The header layout is part of the format, so moving, resizing or "
58 "adding a field means bumping the format revision");
59
62inline constexpr std::size_t METAPACK_CHECKSUM_HEX_LENGTH{64};
63
64static_assert(METAPACK_CHECKSUM_HEX_LENGTH ==
65 2 * sizeof(MetapackHeader::checksum),
66 "Rendering a checksum takes two characters per byte");
67
70inline constexpr std::uint16_t METAPACK_MAXIMUM_MEDIA_TYPE_BYTES{
71 std::numeric_limits<std::uint16_t>::max()};
72
75inline constexpr std::uint32_t METAPACK_MAXIMUM_EXTENSION_BYTES{
76 std::numeric_limits<std::uint32_t>::max()};
77
78} // namespace sourcemeta::core
79
80#endif
std::uint32_t magic
The magic number that identifies the format.
Definition metapack_format.h:35
std::int64_t last_modified
Nanoseconds since the Unix epoch at which the file was written.
Definition metapack_format.h:43
std::uint16_t format_version
The revision of the format the file was written to.
Definition metapack_format.h:37
std::array< std::uint8_t, 32 > checksum
Definition metapack_format.h:48
std::uint8_t reserved
Reserved for a future revision of the format.
Definition metapack_format.h:41
MetapackEncoding encoding
The encoding the contents are stored under.
Definition metapack_format.h:39
std::uint64_t content_bytes
How many bytes the contents take once decoded.
Definition metapack_format.h:45
std::uint16_t media_type_length
How many bytes the media type that follows the header takes.
Definition metapack_format.h:50
constexpr std::uint32_t METAPACK_MAXIMUM_EXTENSION_BYTES
Definition metapack_format.h:75
MetapackEncoding
Definition metapack_format.h:23
constexpr std::uint16_t METAPACK_MAXIMUM_MEDIA_TYPE_BYTES
Definition metapack_format.h:70
constexpr std::size_t METAPACK_CHECKSUM_HEX_LENGTH
Definition metapack_format.h:62
@ Identity
The contents are stored as they are.
Definition metapack_format.h:25
@ GZIP
The contents are stored compressed as per RFC 1952.
Definition metapack_format.h:27
Definition metapack_format.h:33