Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_ZUCCHINI_ZUCCHINI_H_ |
| 6 | #define COMPONENTS_ZUCCHINI_ZUCCHINI_H_ |
| 7 | |
Samuel Huang | 6951a28 | 2018-04-30 22:47:52 +0000 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 10 | #include "components/zucchini/buffer_view.h" |
| 11 | #include "components/zucchini/patch_reader.h" |
| 12 | #include "components/zucchini/patch_writer.h" |
| 13 | |
Samuel Huang | f35146e | 2018-06-21 15:50:22 +0000 | [diff] [blame] | 14 | // Core Zucchini library, consisting of: |
| 15 | // - Global constants. |
| 16 | // - Patch gen and apply functions, where "old" and "new" data are represented |
| 17 | // as buffers, and patch data represented as EnsemblePatchWriter or |
| 18 | // EnsemblePatchReader. |
Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 19 | |
| 20 | namespace zucchini { |
| 21 | |
| 22 | namespace status { |
| 23 | |
| 24 | // Zucchini status code, which can also be used as process exit code. Therefore |
| 25 | // success is explicitly 0. |
| 26 | enum Code { |
| 27 | kStatusSuccess = 0, |
| 28 | kStatusInvalidParam = 1, |
| 29 | kStatusFileReadError = 2, |
| 30 | kStatusFileWriteError = 3, |
| 31 | kStatusPatchReadError = 4, |
| 32 | kStatusPatchWriteError = 5, |
| 33 | kStatusInvalidOldImage = 6, |
| 34 | kStatusInvalidNewImage = 7, |
| 35 | kStatusFatal = 8, |
| 36 | }; |
| 37 | |
| 38 | } // namespace status |
| 39 | |
Samuel Huang | 6951a28 | 2018-04-30 22:47:52 +0000 | [diff] [blame] | 40 | // Generates ensemble patch from |old_image| to |new_image| using the default |
| 41 | // element detection and matching heuristics, writes the results to |
| 42 | // |patch_writer|, and returns a status::Code. |
Samuel Huang | f35146e | 2018-06-21 15:50:22 +0000 | [diff] [blame] | 43 | status::Code GenerateBuffer(ConstBufferView old_image, |
| 44 | ConstBufferView new_image, |
| 45 | EnsemblePatchWriter* patch_writer); |
Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 46 | |
Samuel Huang | 6951a28 | 2018-04-30 22:47:52 +0000 | [diff] [blame] | 47 | // Same as GenerateEnsemble(), but if |imposed_matches| is non-empty, then |
| 48 | // overrides default element detection and matching heuristics with custom |
| 49 | // element matching encoded in |imposed_matches|, which should be formatted as: |
| 50 | // "#+#=#+#,#+#=#+#,..." (e.g., "1+2=3+4", "1+2=3+4,5+6=7+8"), |
| 51 | // where "#+#=#+#" encodes a match as 4 unsigned integers: |
| 52 | // [offset in "old", size in "old", offset in "new", size in "new"]. |
Samuel Huang | f35146e | 2018-06-21 15:50:22 +0000 | [diff] [blame] | 53 | status::Code GenerateBufferImposed(ConstBufferView old_image, |
| 54 | ConstBufferView new_image, |
| 55 | std::string imposed_matches, |
| 56 | EnsemblePatchWriter* patch_writer); |
Samuel Huang | 6951a28 | 2018-04-30 22:47:52 +0000 | [diff] [blame] | 57 | |
Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 58 | // Generates raw patch from |old_image| to |new_image|, and writes it to |
| 59 | // |patch_writer|. |
Samuel Huang | f35146e | 2018-06-21 15:50:22 +0000 | [diff] [blame] | 60 | status::Code GenerateBufferRaw(ConstBufferView old_image, |
| 61 | ConstBufferView new_image, |
| 62 | EnsemblePatchWriter* patch_writer); |
Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 63 | |
| 64 | // Applies |patch_reader| to |old_image| to build |new_image|, which refers to |
| 65 | // preallocated memory of sufficient size. |
Samuel Huang | f35146e | 2018-06-21 15:50:22 +0000 | [diff] [blame] | 66 | status::Code ApplyBuffer(ConstBufferView old_image, |
| 67 | const EnsemblePatchReader& patch_reader, |
| 68 | MutableBufferView new_image); |
Samuel Huang | 06f1ae9 | 2018-03-13 18:19:34 +0000 | [diff] [blame] | 69 | |
| 70 | } // namespace zucchini |
| 71 | |
| 72 | #endif // COMPONENTS_ZUCCHINI_ZUCCHINI_H_ |