blob: e53de99f3527c932dcfd277f0d99be924b0e00d6 [file] [log] [blame]
openvcdiff@gmail.com64fe2322011-09-27 21:51:41 +00001// Copyright 2008 Google Inc.
2// Author: Lincoln Smith
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
openvcdiffd1845782009-03-20 21:56:15 +000015//
16// Definition of an abstract class that describes the interface between the
17// encoding engine (which finds the best string matches between the source and
18// target data) and the code table writer. The code table writer is passed a
19// series of Add, Copy, and Run instructions and produces an output file in the
20// desired format.
21
openvcdiff@gmail.comf1dd9332009-10-09 22:40:32 +000022#ifndef OPEN_VCDIFF_CODETABLEWRITER_INTERFACE_H_
23#define OPEN_VCDIFF_CODETABLEWRITER_INTERFACE_H_
openvcdiffd1845782009-03-20 21:56:15 +000024
25#include <stddef.h> // size_t
openvcdiff@gmail.com732fff22010-08-04 18:00:00 +000026#include "checksum.h" // VCDChecksum
27#include "google/format_extension_flags.h" // VCDiffFormatExtensionFlags
openvcdiffd1845782009-03-20 21:56:15 +000028
29namespace open_vcdiff {
30
31class OutputStringInterface;
32
33// The method calls after construction should follow this pattern:
34// {{Add|Copy|Run}* Output}*
35//
36// Output() will produce an encoding using the given series of Add, Copy,
37// and/or Run instructions. One implementation of the interface
38// (VCDiffCodeTableWriter) produces a VCDIFF delta window, but other
39// implementations may be used to produce other output formats, or as test
40// mocks, or to gather encoding statistics.
41//
42class CodeTableWriterInterface {
43 public:
44 virtual ~CodeTableWriterInterface() { }
45
openvcdiff@gmail.com732fff22010-08-04 18:00:00 +000046 // Initializes the constructed object for use. It will return
47 // false if there was an error initializing the object, or true if it
48 // was successful. After the object has been initialized and used,
49 // Init() can be called again to restore the initial state of the object.
50 virtual bool Init(size_t dictionary_size) = 0;
51
52 // Writes the header to the output string.
53 virtual void WriteHeader(OutputStringInterface* out,
54 VCDiffFormatExtensionFlags format_extensions) = 0;
55
openvcdiffd1845782009-03-20 21:56:15 +000056 // Encode an ADD opcode with the "size" bytes starting at data
57 virtual void Add(const char* data, size_t size) = 0;
58
59 // Encode a COPY opcode with args "offset" (into dictionary) and "size" bytes.
60 virtual void Copy(int32_t offset, size_t size) = 0;
61
62 // Encode a RUN opcode for "size" copies of the value "byte".
63 virtual void Run(size_t size, unsigned char byte) = 0;
64
openvcdiff@gmail.com732fff22010-08-04 18:00:00 +000065 // Adds a checksum to the output.
66 virtual void AddChecksum(VCDChecksum checksum) = 0;
67
68 // Appends the encoded delta window to the output
openvcdiffd1845782009-03-20 21:56:15 +000069 // string. The output string is not null-terminated and may contain embedded
70 // '\0' characters.
71 virtual void Output(OutputStringInterface* out) = 0;
72
openvcdiff@gmail.com732fff22010-08-04 18:00:00 +000073 // Finishes encoding.
74 virtual void FinishEncoding(OutputStringInterface* out) = 0;
75
openvcdiffd1845782009-03-20 21:56:15 +000076 // Returns the number of target bytes processed, which is the sum of all the
77 // size arguments passed to Add(), Copy(), and Run().
78 virtual size_t target_length() const = 0;
79};
80
81} // namespace open_vcdiff
82
openvcdiff@gmail.comf1dd9332009-10-09 22:40:32 +000083#endif // OPEN_VCDIFF_CODETABLEWRITER_INTERFACE_H_