Skip to content

Commit

Permalink
Import gipfeli. Change the constructor for PullSerializer to support …
Browse files Browse the repository at this point in the history
…compression.
  • Loading branch information
pleroy committed Apr 5, 2018
1 parent 4d70d8a commit a4170e0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions Principia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project Property Sheets", "
ProjectSection(SolutionItems) = preProject
generate_version_translation_unit.props = generate_version_translation_unit.props
google_benchmark.props = google_benchmark.props
google_gipfeli.props = google_gipfeli.props
google_glog.props = google_glog.props
google_googlemock_main.props = google_googlemock_main.props
google_googletest.props = google_googletest.props
Expand Down
9 changes: 8 additions & 1 deletion base/pull_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
#include "base/array.hpp"
#include "base/macros.hpp"
#include "base/not_null.hpp"
#include "gipfeli/compression.h"
#include "google/protobuf/message.h"
#include "google/protobuf/io/zero_copy_stream.h"

namespace principia {
namespace base {
namespace internal_pull_serializer {

using google::compression::Compressor;

// An output stream based on an array that delegates to a function the handling
// of the case where one array is full. It calls the |on_full| function passed
// at construction and proceeds with filling the array returned by that
Expand Down Expand Up @@ -59,7 +62,8 @@ class PullSerializer final {
// |chunk_size|. At most |number_of_chunks| chunks are held in the internal
// queue. This class uses at most
// |number_of_chunks * (chunk_size + O(1)) + O(1)| bytes.
PullSerializer(int chunk_size, int number_of_chunks);
//TODO(phl):comment
PullSerializer(int chunk_size, int number_of_chunks, Compressor* compressor);
~PullSerializer();

// Starts the serializer, which will proceed to serialize |message|. This
Expand All @@ -81,8 +85,11 @@ class PullSerializer final {

std::unique_ptr<google::protobuf::Message const> message_;

Compressor* const compressor_;
int const chunk_size_;
int const compressed_chunk_size_;
int const number_of_chunks_;
int const number_of_compression_chunks_;

// The array supporting the stream and the stream itself.
std::unique_ptr<std::uint8_t[]> data_;
Expand Down
24 changes: 18 additions & 6 deletions base/pull_serializer_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,31 @@ inline std::int64_t DelegatingArrayOutputStream::ByteCount() const {
}

inline PullSerializer::PullSerializer(int const chunk_size,
int const number_of_chunks)
: chunk_size_(chunk_size),
int const number_of_chunks,
Compressor* const compressor)
: compressor_(compressor),
chunk_size_(chunk_size),
compressed_chunk_size_(
compressor == nullptr ? chunk_size_
: compressor->MaxCompressedLength(chunk_size_)),
number_of_chunks_(number_of_chunks),
data_(std::make_unique<std::uint8_t[]>(chunk_size_ * number_of_chunks_)),
number_of_compression_chunks_(compressor == nullptr ? 0 : 1),
data_(std::make_unique<std::uint8_t[]>(
compressed_chunk_size_ *
(number_of_chunks_ + number_of_compression_chunks_))),
stream_(Bytes(data_.get(), chunk_size_),
std::bind(&PullSerializer::Push, this, _1)) {
// Mark all the chunks as free except the last one which is a sentinel for the
// |queue_|. The 0th chunk has been passed to the stream, but it's still free
// until the first call to |on_full|.
// until the first call to |on_full|. Note that the last
// |compressed_chunk_size_ - chunk_size_| bytes of each chunk are not
// considered as free.
for (int i = 0; i < number_of_chunks_ - 1; ++i) {
free_.push(data_.get() + i * chunk_size_);
free_.push(data_.get() + i * compressed_chunk_size_);
}
queue_.push(Bytes(data_.get() + (number_of_chunks_ - 1) * chunk_size_, 0));
queue_.push(Bytes(data_.get() +
(number_of_chunks_ - 1) * compressed_chunk_size_,
0));
}

inline PullSerializer::~PullSerializer() {
Expand Down
1 change: 1 addition & 0 deletions base/push_deserializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/array.hpp"
#include "base/macros.hpp"
#include "base/not_null.hpp"
#include "gipfeli/gipfeli.h"
#include "google/protobuf/message.h"
#include "google/protobuf/io/zero_copy_stream.h"

Expand Down
16 changes: 16 additions & 0 deletions google_gipfeli.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)..\Google\gipfeli\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(SolutionDir)..\Google\gipfeli\msvc\$(PrincipiaDependencyConfiguration)\$(Platform);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>libgipfeli.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
2 changes: 2 additions & 0 deletions principia.props
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
<Import Project="$(SolutionDir)google_protobuf.props" />
<Import Project="$(SolutionDir)..\Google\glog\vsprojects\portability_macros.props" />
<Import Project="$(SolutionDir)google_glog.props" />
<Import Project="$(SolutionDir)..\Google\gipfeli\msvc\portability_macros.props" />
<Import Project="$(SolutionDir)google_gipfeli.props" />
<Import Project="$(SolutionDir)generate_version_translation_unit.props" />

<ImportGroup Condition="$(ProjectName) == benchmarks or
Expand Down

0 comments on commit a4170e0

Please sign in to comment.