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