codetablewriter_interface.h revision c7f5f8508d98d5952d42ed7648c2a8f30a4da156
1// Copyright 2008 Google Inc. All Rights Reserved.
2// Author: ajenjo@google.com (Lincoln Smith)
3//
4// Definition of an abstract class that describes the interface between the
5// encoding engine (which finds the best string matches between the source and
6// target data) and the code table writer.  The code table writer is passed a
7// series of Add, Copy, and Run instructions and produces an output file in the
8// desired format.
9
10#ifndef OPEN_VCDIFF_CODETABLEWRITER_INTERFACE_H_
11#define OPEN_VCDIFF_CODETABLEWRITER_INTERFACE_H_
12
13#include <stddef.h>  // size_t
14
15namespace open_vcdiff {
16
17class OutputStringInterface;
18
19// The method calls after construction should follow this pattern:
20//    {{Add|Copy|Run}* Output}*
21//
22// Output() will produce an encoding using the given series of Add, Copy,
23// and/or Run instructions.  One implementation of the interface
24// (VCDiffCodeTableWriter) produces a VCDIFF delta window, but other
25// implementations may be used to produce other output formats, or as test
26// mocks, or to gather encoding statistics.
27//
28class CodeTableWriterInterface {
29 public:
30  virtual ~CodeTableWriterInterface() { }
31
32  // Encode an ADD opcode with the "size" bytes starting at data
33  virtual void Add(const char* data, size_t size) = 0;
34
35  // Encode a COPY opcode with args "offset" (into dictionary) and "size" bytes.
36  virtual void Copy(int32_t offset, size_t size) = 0;
37
38  // Encode a RUN opcode for "size" copies of the value "byte".
39  virtual void Run(size_t size, unsigned char byte) = 0;
40
41  // Finishes encoding and appends the encoded delta window to the output
42  // string.  The output string is not null-terminated and may contain embedded
43  // '\0' characters.
44  virtual void Output(OutputStringInterface* out) = 0;
45
46  // Returns the number of target bytes processed, which is the sum of all the
47  // size arguments passed to Add(), Copy(), and Run().
48  virtual size_t target_length() const = 0;
49};
50
51}  // namespace open_vcdiff
52
53#endif  // OPEN_VCDIFF_CODETABLEWRITER_INTERFACE_H_
54