blob: 4d0e1e04eae128890f8ef7c3c65dbed1b0934883 [file] [log] [blame]
Tianjie Xu1f1cdb22017-11-20 11:05:55 -08001// Copyright 2017 The Chromium OS 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 _BSDIFF_BSDIFF_ARGUMENTS_H_
6#define _BSDIFF_BSDIFF_ARGUMENTS_H_
7
8#include <stdint.h>
9
10#include <string>
11
12#include "bsdiff/constants.h"
13#include "bsdiff/patch_writer_interface.h"
14
15using std::string;
16
17namespace bsdiff {
18
19// Class to store the patch writer options about format, type and quality.
20class BsdiffArguments {
21 public:
22 BsdiffArguments()
23 : format_(BsdiffFormat::kLegacy),
24 compressor_type_(CompressorType::kBZ2),
25 compression_quality_(-1) {}
26
27 BsdiffArguments(BsdiffFormat format, CompressorType type, int quality)
28 : format_(format),
29 compressor_type_(type),
30 compression_quality_(quality) {}
31
32 // Check if the compressor type is compatible with the bsdiff format.
33 bool IsValid() const;
34
35 // Getter functions.
36 BsdiffFormat format() const { return format_; }
37
38 CompressorType compressor_type() const { return compressor_type_; }
39
40 int compression_quality() const { return compression_quality_; }
41
42 // Parse the command line arguments of the main function and set all the
43 // fields accordingly.
44 bool ParseCommandLine(int argc, char** argv);
45
46 // Parse the compression type from string.
47 static bool ParseCompressorType(const string& str, CompressorType* type);
48
49 // Parse the bsdiff format from string.
50 static bool ParseBsdiffFormat(const string& str, BsdiffFormat* format);
51
52 // Parse the compression quality (for brotli) from string.
53 static bool ParseQuality(const string& str, int* quality);
54
55 private:
56 // Current format supported are the legacy "BSDIFF40" or "BSDF2".
57 BsdiffFormat format_;
58
59 // The algorithm to compress the patch, i.e. BZ2 or Brotli.
60 CompressorType compressor_type_;
61
62 // The quality of compression, only valid when using brotli as the
63 // compression algorithm.
64 int compression_quality_;
65};
66
67} // namespace bsdiff
68
69#endif //_BSDIFF_BSDIFF_ARGUMENTS_H_