// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_ZUCCHINI_PATCH_WRITER_H_ #define COMPONENTS_ZUCCHINI_PATCH_WRITER_H_ #include <stddef.h> #include <stdint.h> #include <map> #include <optional> #include <utility> #include <vector> #include "base/check.h" #include "components/zucchini/buffer_sink.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/patch_utils.h" namespace zucchini { namespace patch { // If sufficient space is available, serializes |element_match| into |sink| and // returns true. Otherwise returns false, and |sink| will be in an undefined // state. bool SerializeElementMatch(const ElementMatch& element_match, BufferSink* sink); // Returns the size in bytes required to serialize |element_match|. size_t SerializedElementMatchSize(const ElementMatch& element_match); // If sufficient space is available, serializes |buffer| into |sink| and returns // true. Otherwise returns false, and |sink| will be in an undefined state. bool SerializeBuffer(const std::vector<uint8_t>& buffer, BufferSink* sink); // Returns the size in bytes required to serialize |buffer|. size_t SerializedBufferSize(const std::vector<uint8_t>& buffer); } // namespace patch // Each of *Sink classes below has an associated "main type", and performs the // following: // - Receives multiple "main type" elements (hence "Sink" in the name). // - Encodes list of received data, and writes them to internal storage (e.g., // applying delta encoding). // - Writes encoded data to BufferSink. // // Common "core functions" implemented for *Sink classes are: // - void PutNext(const MAIN_TYPE& inst): Encodes and writes an instance of // MAIN_TYPE to internal storage. Assumptions may be applied to successive // |inst| provided. // - size_t SerializedSize() const: Returns the serialized size in bytes of // internal storage. // - bool SerializeInto(BufferSink* sink) const: If |sink| has enough space, // serializes internal storage into |sink|, and returns true. Otherwise // returns false. // // Usage of *Sink instances don't mix, and PuttNext() have dissimilar // interfaces. Therefore we do not use inheritance to relate *Sink classes, // simply implement "core functions" with matching names. // Sink for equivalences. class EquivalenceSink { … }; // Sink for extra data. class ExtraDataSink { … }; // Sink for raw delta. class RawDeltaSink { … }; // Sink for reference delta. class ReferenceDeltaSink { … }; // Sink for additional targets. class TargetSink { … }; // Following are utility classes to write structured data forming a patch. // Utility to write a patch element. A patch element contains all the // information necessary to patch a single element. This class // provides an interface to individually set different building blocks of data // in the patch element. class PatchElementWriter { … }; // Utility to write a Zucchini ensemble patch. An ensemble patch is the // concatenation of a patch header with a vector of patch elements. class EnsemblePatchWriter { … }; } // namespace zucchini #endif // COMPONENTS_ZUCCHINI_PATCH_WRITER_H_