-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a mechanism to let Riegeli/records use the Rust implementation of…
… the Brotli encoder instead of the C implementation. Rust Brotli is currently not available in open sourced Riegeli. PiperOrigin-RevId: 665264284
- Loading branch information
Showing
10 changed files
with
182 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "riegeli/chunk_encoding/brotli_encoder_selection.h" | ||
|
||
#include <memory> | ||
|
||
#include "absl/base/attributes.h" | ||
#include "absl/status/status.h" | ||
#include "riegeli/base/assert.h" | ||
#include "riegeli/base/chain.h" | ||
#include "riegeli/base/maker.h" | ||
#include "riegeli/base/recycling_pool.h" | ||
#include "riegeli/brotli/brotli_writer.h" | ||
#include "riegeli/bytes/chain_writer.h" | ||
#include "riegeli/bytes/null_writer.h" | ||
#include "riegeli/bytes/writer.h" | ||
#include "riegeli/chunk_encoding/compressor_options.h" | ||
|
||
namespace riegeli { | ||
namespace chunk_encoding_internal { | ||
|
||
ABSL_ATTRIBUTE_WEAK std::unique_ptr<Writer> NewBrotliWriter( | ||
Chain* compressed, const CompressorOptions& compressor_options, | ||
ABSL_ATTRIBUTE_UNUSED const RecyclingPoolOptions& recycling_pool_options) { | ||
switch (compressor_options.brotli_encoder()) { | ||
case BrotliEncoder::kRBrotliOrCBrotli: | ||
case BrotliEncoder::kCBrotli: | ||
return NewCBrotliWriter(compressed, compressor_options); | ||
case BrotliEncoder::kRBrotli: { | ||
std::unique_ptr<Writer> writer = std::make_unique<riegeli::NullWriter>(); | ||
writer->Fail(absl::UnimplementedError("Rust Brotli not available")); | ||
return writer; | ||
} | ||
} | ||
RIEGELI_ASSERT_UNREACHABLE() | ||
<< "Unknown Brotli encoder: " | ||
<< static_cast<int>(compressor_options.brotli_encoder()); | ||
} | ||
|
||
std::unique_ptr<Writer> NewCBrotliWriter( | ||
Chain* compressed, const CompressorOptions& compressor_options) { | ||
return std::make_unique<BrotliWriter<ChainWriter<>>>( | ||
riegeli::Maker(compressed), | ||
BrotliWriterBase::Options() | ||
.set_compression_level(compressor_options.compression_level()) | ||
.set_window_log(compressor_options.brotli_window_log())); | ||
} | ||
|
||
} // namespace chunk_encoding_internal | ||
} // namespace riegeli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RIEGELI_CHUNK_ENCODING_BROTLI_ENCODER_SELECTION_H_ | ||
#define RIEGELI_CHUNK_ENCODING_BROTLI_ENCODER_SELECTION_H_ | ||
|
||
#include <memory> | ||
|
||
#include "riegeli/base/chain.h" | ||
#include "riegeli/base/recycling_pool.h" | ||
#include "riegeli/bytes/writer.h" | ||
#include "riegeli/chunk_encoding/compressor_options.h" | ||
|
||
namespace riegeli { | ||
namespace chunk_encoding_internal { | ||
|
||
// Creates a `Writer` which compresses data with Brotli and writes them to | ||
// `compressed`. | ||
// | ||
// The encoder implementation is determined by | ||
// `compressor_options.brotli_encoder()`. | ||
// | ||
// This is a weak function. Its default definition supports only C Brotli. | ||
// It can be overridden to support also Rust Brotli. | ||
std::unique_ptr<Writer> NewBrotliWriter( | ||
Chain* compressed, const CompressorOptions& compressor_options, | ||
const RecyclingPoolOptions& recycling_pool_options); | ||
|
||
// Support for `NewBrotliWriter()`: uses C Brotli, ignores | ||
// `compressor_options.brotli_encoder()`. | ||
std::unique_ptr<Writer> NewCBrotliWriter( | ||
Chain* compressed, const CompressorOptions& compressor_options); | ||
|
||
} // namespace chunk_encoding_internal | ||
} // namespace riegeli | ||
|
||
#endif // RIEGELI_CHUNK_ENCODING_BROTLI_ENCODER_SELECTION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters