zucchini.h 2.7 KB

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