blob: 984744079b8ed3e651019a8bb0f68d1864b274b2 [file] [log] [blame]
Samuel Huang06f1ae92018-03-13 18:19:34 +00001// 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 Huang6951a282018-04-30 22:47:52 +00008#include <string>
9
Samuel Huang06f1ae92018-03-13 18:19:34 +000010#include "components/zucchini/buffer_view.h"
11#include "components/zucchini/patch_reader.h"
12#include "components/zucchini/patch_writer.h"
13
Samuel Huangf35146e2018-06-21 15:50:22 +000014// 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 Huang06f1ae92018-03-13 18:19:34 +000019
20namespace zucchini {
21
22namespace status {
23
24// Zucchini status code, which can also be used as process exit code. Therefore
25// success is explicitly 0.
26enum 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 Huang6951a282018-04-30 22:47:52 +000040// 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 Huangf35146e2018-06-21 15:50:22 +000043status::Code GenerateBuffer(ConstBufferView old_image,
44 ConstBufferView new_image,
45 EnsemblePatchWriter* patch_writer);
Samuel Huang06f1ae92018-03-13 18:19:34 +000046
Samuel Huang6951a282018-04-30 22:47:52 +000047// 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 Huangf35146e2018-06-21 15:50:22 +000053status::Code GenerateBufferImposed(ConstBufferView old_image,
54 ConstBufferView new_image,
55 std::string imposed_matches,
56 EnsemblePatchWriter* patch_writer);
Samuel Huang6951a282018-04-30 22:47:52 +000057
Samuel Huang06f1ae92018-03-13 18:19:34 +000058// Generates raw patch from |old_image| to |new_image|, and writes it to
59// |patch_writer|.
Samuel Huangf35146e2018-06-21 15:50:22 +000060status::Code GenerateBufferRaw(ConstBufferView old_image,
61 ConstBufferView new_image,
62 EnsemblePatchWriter* patch_writer);
Samuel Huang06f1ae92018-03-13 18:19:34 +000063
64// Applies |patch_reader| to |old_image| to build |new_image|, which refers to
65// preallocated memory of sufficient size.
Samuel Huangf35146e2018-06-21 15:50:22 +000066status::Code ApplyBuffer(ConstBufferView old_image,
67 const EnsemblePatchReader& patch_reader,
68 MutableBufferView new_image);
Samuel Huang06f1ae92018-03-13 18:19:34 +000069
70} // namespace zucchini
71
72#endif // COMPONENTS_ZUCCHINI_ZUCCHINI_H_