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