in riegeli/chunk_encoding/compressor_options.cc [45:146]
absl::Status CompressorOptions::FromString(absl::string_view text) {
// Set just `compression_type_` first because other parsers depend on
// `compression_type_`.
{
OptionsParser options_parser;
options_parser.AddOption(
"uncompressed",
ValueParser::And(ValueParser::FailIfSeen("brotli", "zstd", "snappy"),
[this](ValueParser& value_parser) {
compression_type_ = CompressionType::kNone;
return true;
}));
options_parser.AddOption(
"brotli", ValueParser::And(
ValueParser::FailIfSeen("uncompressed", "zstd", "snappy"),
[this](ValueParser& value_parser) {
compression_type_ = CompressionType::kBrotli;
return true;
}));
options_parser.AddOption(
"zstd", ValueParser::And(
ValueParser::FailIfSeen("uncompressed", "brotli", "snappy"),
[this](ValueParser& value_parser) {
compression_type_ = CompressionType::kZstd;
return true;
}));
options_parser.AddOption(
"snappy", ValueParser::And(
ValueParser::FailIfSeen("uncompressed", "brotli", "zstd"),
[this](ValueParser& value_parser) {
compression_type_ = CompressionType::kSnappy;
return true;
}));
options_parser.AddOption("window_log",
[](ValueParser& value_parser) { return true; });
if (ABSL_PREDICT_FALSE(!options_parser.FromString(text))) {
return options_parser.status();
}
}
int window_log;
OptionsParser options_parser;
options_parser.AddOption(
"uncompressed",
ValueParser::And(ValueParser::FailIfSeen("window_log"),
ValueParser::Empty(0, &compression_level_)));
options_parser.AddOption(
"brotli",
ValueParser::Or(
ValueParser::Empty(
BrotliWriterBase::Options::kDefaultCompressionLevel,
&compression_level_),
ValueParser::Int(BrotliWriterBase::Options::kMinCompressionLevel,
BrotliWriterBase::Options::kMaxCompressionLevel,
&compression_level_)));
options_parser.AddOption(
"zstd",
ValueParser::Or(
ValueParser::Empty(ZstdWriterBase::Options::kDefaultCompressionLevel,
&compression_level_),
ValueParser::Int(ZstdWriterBase::Options::kMinCompressionLevel,
ZstdWriterBase::Options::kMaxCompressionLevel,
&compression_level_)));
options_parser.AddOption(
"snappy", ValueParser::And(ValueParser::FailIfSeen("window_log"),
ValueParser::Empty(0, &compression_level_)));
options_parser.AddOption("window_log", [&] {
switch (compression_type_) {
case CompressionType::kNone:
return ValueParser::FailIfSeen("uncompressed");
case CompressionType::kBrotli:
return ValueParser::Or(
ValueParser::Enum({{"auto", absl::nullopt}}, &window_log_),
ValueParser::And(
ValueParser::Int(BrotliWriterBase::Options::kMinWindowLog,
BrotliWriterBase::Options::kMaxWindowLog,
&window_log),
[this, &window_log](ValueParser& value_parser) {
window_log_ = window_log;
return true;
}));
case CompressionType::kZstd:
return ValueParser::Or(
ValueParser::Enum({{"auto", absl::nullopt}}, &window_log_),
ValueParser::And(
ValueParser::Int(ZstdWriterBase::Options::kMinWindowLog,
ZstdWriterBase::Options::kMaxWindowLog,
&window_log),
[this, &window_log](ValueParser& value_parser) {
window_log_ = window_log;
return true;
}));
case CompressionType::kSnappy:
return ValueParser::FailIfSeen("snappy");
}
RIEGELI_ASSERT_UNREACHABLE() << "Unknown compression type: "
<< static_cast<unsigned>(compression_type_);
}());
if (ABSL_PREDICT_FALSE(!options_parser.FromString(text))) {
return options_parser.status();
}
return absl::OkStatus();
}