bring subcommand abstraction in line with main command abstraction

This commit is contained in:
Martin Michelsen
2022-04-03 11:00:14 -07:00
parent 9c33c2de46
commit fe9eceed5c
13 changed files with 882 additions and 489 deletions
+16
View File
@@ -207,3 +207,19 @@ void print_received_command(
print_data(stderr, w.str());
}
void check_size_v(size_t size, size_t min_size, size_t max_size) {
if (size < min_size) {
throw std::runtime_error(string_printf(
"command too small (expected at least 0x%zX bytes, received 0x%zX bytes)",
min_size, size));
}
if (max_size < min_size) {
max_size = min_size;
}
if (size > max_size) {
throw std::runtime_error(string_printf(
"command too large (expected at most 0x%zX bytes, received 0x%zX bytes)",
max_size, size));
}
}