// 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. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/40285824): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #ifndef COMPONENTS_ZUCCHINI_PATCH_UTILS_H_ #define COMPONENTS_ZUCCHINI_PATCH_UTILS_H_ #include <stdint.h> #include <iterator> #include <type_traits> #include "components/zucchini/image_utils.h" #include "components/zucchini/version_info.h" namespace zucchini { // A Zucchini 'ensemble' patch is the concatenation of a patch header with a // list of patch 'elements', each containing data for patching individual // elements. // Supported by MSVC, g++, and clang++. Ensures no gaps in packing. #pragma pack(push, 1) // Header for a Zucchini patch, found at the beginning of an ensemble patch. struct PatchHeader { … }; // Sanity check. static_assert …; // Header for a patch element, found at the beginning of every patch element. struct PatchElementHeader { … }; // Sanity check. static_assert …; #pragma pack(pop) // Descibes a raw FIX operation. struct RawDeltaUnit { … }; // A Zucchini patch contains data streams encoded using varint format to reduce // uncompressed size. // Writes |value| as a varint in |dst| and returns an iterator pointing beyond // the written region. |dst| is assumed to hold enough space. Typically, this // will write to a vector using back insertion, e.g.: // EncodeVarUInt(value, std::back_inserter(vector)); template <class T, class It> It EncodeVarUInt(T value, It dst) { … } // Same as EncodeVarUInt(), but for signed values. template <class T, class It> It EncodeVarInt(T value, It dst) { … } // Tries to read a varint unsigned integer from |[first, last)|. If // succesful, writes result into |value| and returns the number of bytes // read from |[first, last)|. Otherwise returns 0. template <class T, class It> typename std::iterator_traits<It>::difference_type DecodeVarUInt(It first, It last, T* value) { … } // Same as DecodeVarUInt(), but for signed values. template <class T, class It> typename std::iterator_traits<It>::difference_type DecodeVarInt(It first, It last, T* value) { … } } // namespace zucchini #endif // COMPONENTS_ZUCCHINI_PATCH_UTILS_H_