Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
content_install_limits.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <algorithm>
10#include <cstdint>
11#include <string>
12#include <string_view>
13
14namespace pulp::state {
15
20 std::uint64_t max_total_bytes = std::uint64_t{4} << 30;
21 std::uint64_t max_entry_bytes = std::uint64_t{1} << 30;
25 std::uint64_t max_entries = 65536;
26};
27
32 std::uint64_t max_bytes) {
33 limits.max_total_bytes = std::min(limits.max_total_bytes, max_bytes);
34 limits.max_entry_bytes = std::min(limits.max_entry_bytes, max_bytes);
35 return limits;
36}
37
42 public:
44
48 std::string admit(std::string_view entry_name, std::uint64_t bytes) {
49 if (entries_ >= limits_.max_entries) {
50 return "archive-size: entry `" + std::string(entry_name) + "` is entry " +
51 std::to_string(entries_ + 1) + ", above the entry-count cap of " +
52 std::to_string(limits_.max_entries) + " entries";
53 }
54 if (bytes > limits_.max_entry_bytes) {
55 return "archive-size: entry `" + std::string(entry_name) + "` declares " +
56 std::to_string(bytes) + " bytes, above the per-entry cap of " +
57 std::to_string(limits_.max_entry_bytes) + " bytes";
58 }
59 if (bytes > limits_.max_total_bytes - total_) {
60 return "archive-size: entry `" + std::string(entry_name) +
61 "` would bring the pack to " + std::to_string(total_ + bytes) +
62 " bytes, above the total cap of " + std::to_string(limits_.max_total_bytes) +
63 " bytes";
64 }
65 total_ += bytes;
66 ++entries_;
67 return {};
68 }
69
70 std::uint64_t admitted_bytes() const {
71 return total_;
72 }
73 std::uint64_t admitted_entries() const {
74 return entries_;
75 }
77 return limits_;
78 }
79
80 private:
82 std::uint64_t total_ = 0;
83 std::uint64_t entries_ = 0;
84};
85
86} // namespace pulp::state
std::uint64_t admitted_bytes() const
Definition content_install_limits.hpp:70
std::string admit(std::string_view entry_name, std::uint64_t bytes)
Admit bytes for entry_name.
Definition content_install_limits.hpp:48
ContentSizeBudget(ContentInstallLimits limits={})
Definition content_install_limits.hpp:43
std::uint64_t admitted_entries() const
Definition content_install_limits.hpp:73
const ContentInstallLimits & limits() const
Definition content_install_limits.hpp:76
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
ContentInstallLimits clamp_content_install_bytes(ContentInstallLimits limits, std::uint64_t max_bytes)
Lower both byte caps to at most max_bytes (a user-facing --max-pack-bytes value).
Definition content_install_limits.hpp:31
Caps on what an archive may inflate to.
Definition content_install_limits.hpp:19
std::uint64_t max_entries
Number of file entries.
Definition content_install_limits.hpp:25
std::uint64_t max_entry_bytes
Any single entry's declared size.
Definition content_install_limits.hpp:21
std::uint64_t max_total_bytes
Sum of every entry's declared size.
Definition content_install_limits.hpp:20