summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3.h
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-02-01 09:17:19 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-02-01 09:17:19 +0000
commit8748d16e6e5bf741ede89af1940f8291fb1b8046 (patch)
tree2c9d393e21eb669ae6bdecf931331e1202bffec6 /xdelta3/xdelta3.h
parent9f465a9db201b97c43d69778eabd222d4fc09fd5 (diff)
Implmeent xd3_encode_memory() and xd3_decode_memory(), add comments.
Diffstat (limited to 'xdelta3/xdelta3.h')
-rwxr-xr-xxdelta3/xdelta3.h125
1 files changed, 87 insertions, 38 deletions
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index fd91ac8..ca4c79a 100755
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -597,6 +597,11 @@ struct _xd3_source
597 const char *name; /* its name, for debug/print purposes */ 597 const char *name; /* its name, for debug/print purposes */
598 void *ioh; /* opaque handle */ 598 void *ioh; /* opaque handle */
599 599
600 /* getblk sets */
601 xoff_t curblkno; /* current block number: client sets after getblk request */
602 usize_t onblk; /* number of bytes on current block: client sets, xd3 verifies */
603 const uint8_t *curblk; /* current block array: client sets after getblk request */
604
600 /* xd3 sets */ 605 /* xd3 sets */
601 usize_t srclen; /* length of this source window */ 606 usize_t srclen; /* length of this source window */
602 xoff_t srcbase; /* offset of this source window in the source itself */ 607 xoff_t srcbase; /* offset of this source window in the source itself */
@@ -604,11 +609,6 @@ struct _xd3_source
604 usize_t cpyoff_blocks; /* offset of copy window in blocks */ 609 usize_t cpyoff_blocks; /* offset of copy window in blocks */
605 usize_t cpyoff_blkoff; /* offset of copy window in blocks, remainder */ 610 usize_t cpyoff_blkoff; /* offset of copy window in blocks, remainder */
606 xoff_t getblkno; /* request block number: xd3 sets current getblk request */ 611 xoff_t getblkno; /* request block number: xd3 sets current getblk request */
607
608 /* getblk sets */
609 xoff_t curblkno; /* current block number: client sets after getblk request */
610 usize_t onblk; /* number of bytes on current block: client sets, xd3 verifies */
611 const uint8_t *curblk; /* current block array: client sets after getblk request */
612}; 612};
613 613
614/* The primary xd3_stream object, used for encoding and decoding. You may access only two 614/* The primary xd3_stream object, used for encoding and decoding. You may access only two
@@ -812,11 +812,86 @@ struct _xd3_stream
812 PUBLIC FUNCTIONS 812 PUBLIC FUNCTIONS
813 ******************************************************************************************/ 813 ******************************************************************************************/
814 814
815/* The two I/O disciplines, encode and decode, have similar stream semantics. It is 815/* This function configures an xd3_stream using the provided in-memory input buffer,
816 * recommended that applications use the same code for compression and decompression - 816 * source buffer, output buffer, and flags. The output array must be large enough or else
817 * because there are only a few differences in handling encoding/decoding. 817 * ENOSPC will be returned. This is the simplest in-memory encoding interface. */
818int xd3_encode_memory (const uint8_t *input,
819 usize_t input_size,
820 const uint8_t *source,
821 usize_t source_size,
822 uint8_t *output,
823 usize_t *output_size,
824 usize_t avail_output,
825 int flags);
826
827/* The reverse of xd3_encode_memory. */
828int xd3_decode_memory (const uint8_t *input,
829 usize_t input_size,
830 const uint8_t *source,
831 usize_t source_size,
832 uint8_t *output,
833 usize_t *output_size,
834 usize_t avail_output,
835 int flags);
836
837/* This function encodes an in-memory input. Everything else about the xd3_stream is
838 * configurable. The output array must be large enough to hold the output or else ENOSPC
839 * is returned. The source (if any) should be set using xd3_set_source() with a
840 * single-block xd3_source. This calls the underlying non-blocking interface,
841 * xd3_encode_input(), handling the necessary input/output states. This method be
842 * considered a reference for any application using xd3_encode_input() directly.
843 *
844 * xd3_stream stream;
845 * xd3_config config;
846 * xd3_source src;
847 *
848 * memset (& src, 0, sizeof (src));
849 * memset (& stream, 0, sizeof (stream));
850 * memset (& config, 0, sizeof (config));
818 * 851 *
819 * See also the xd3_avail_input() and xd3_consume_output() routines, inlined below. 852 * if (source != NULL)
853 * {
854 * src.size = source_size;
855 * src.blksize = source_size;
856 * src.curblkno = 0;
857 * src.onblk = source_size;
858 * src.curblk = source;
859 * xd3_set_source(&stream, &src);
860 * }
861 *
862 * config.flags = flags;
863 * config.srcwin_maxsz = source_size;
864 * config.winsize = input_size;
865 *
866 * ... set smatcher, appheader, encoding-table, compression-level, etc.
867 *
868 * xd3_config_stream(&stream, &config);
869 * xd3_encode_stream(&stream, ...);
870 * xd3_free_stream(&stream);
871 *
872 * DO NOT USE except for testing. These methods are allocate bad buffer sizes.
873 */
874int xd3_encode_stream (xd3_stream *stream,
875 const uint8_t *input,
876 usize_t input_size,
877 uint8_t *output,
878 usize_t *output_size,
879 usize_t avail_output);
880
881/* The reverse of xd3_encode_stream. */
882int xd3_decode_stream (xd3_stream *stream,
883 const uint8_t *input,
884 usize_t input_size,
885 uint8_t *output,
886 usize_t *output_size,
887 usize_t avail_size);
888
889/* This is the non-blocking interface.
890 *
891 * Handling input and output states is the same for encoding or decoding using the
892 * xd3_avail_input() and xd3_consume_output() routines, inlined below.
893 *
894 * Return values:
820 * 895 *
821 * XD3_INPUT: the process requires more input: call xd3_avail_input() then repeat 896 * XD3_INPUT: the process requires more input: call xd3_avail_input() then repeat
822 * XD3_OUTPUT: the process has more output: read stream->next_out, stream->avail_out, 897 * XD3_OUTPUT: the process has more output: read stream->next_out, stream->avail_out,
@@ -844,14 +919,6 @@ struct _xd3_stream
844 * consistent for either encoding or decoding. 919 * consistent for either encoding or decoding.
845 * XD3_GETSRCBLK: If the xd3_getblk() callback is NULL, this value is returned to 920 * XD3_GETSRCBLK: If the xd3_getblk() callback is NULL, this value is returned to
846 * initiate a non-blocking source read. 921 * initiate a non-blocking source read.
847 *
848 * For simple usage, see the xd3_process_completely_stream() function, which underlies
849 * xd3_encode_completely_stream() and xd3_decode_completely_stream() [xdelta3.c]. For
850 * real application usage, including the application header, the see command-line utility
851 * [xdelta3-main.h].
852 *
853 * main_input() implements the command-line encode and decode as well as the optional
854 * VCDIFF_TOOLS printhdr, printhdrs, and printdelta with a single loop [xdelta3-main.h].
855 */ 922 */
856int xd3_decode_input (xd3_stream *stream); 923int xd3_decode_input (xd3_stream *stream);
857int xd3_encode_input (xd3_stream *stream); 924int xd3_encode_input (xd3_stream *stream);
@@ -868,7 +935,7 @@ int xd3_config_stream (xd3_stream *stream,
868 * resources it supplied. */ 935 * resources it supplied. */
869int xd3_close_stream (xd3_stream *stream); 936int xd3_close_stream (xd3_stream *stream);
870 937
871/* This unconditionally closes/frees the stream, future close() will succeed.*/ 938/* This unconditionally closes/frees the stream, future close() will succeed. */
872void xd3_abort_stream (xd3_stream *stream); 939void xd3_abort_stream (xd3_stream *stream);
873 940
874/* xd3_free_stream frees all memory allocated for the stream. The application is 941/* xd3_free_stream frees all memory allocated for the stream. The application is
@@ -884,36 +951,18 @@ void xd3_free_stream (xd3_stream *stream);
884int xd3_set_source (xd3_stream *stream, 951int xd3_set_source (xd3_stream *stream,
885 xd3_source *source); 952 xd3_source *source);
886 953
887/* This function invokes xd3_encode_input using whole-file, in-memory inputs. The output
888 * array must be large enough to hold the output or else ENOSPC is returned. */
889int xd3_encode_completely_stream (xd3_stream *stream,
890 const uint8_t *input,
891 usize_t input_size,
892 uint8_t *output,
893 usize_t *output_size,
894 usize_t avail_output);
895
896/* This function invokes xd3_decode_input using whole-file, in-memory inputs. The output
897 * array must be large enough to hold the output or else ENOSPC is returned. */
898int xd3_decode_completely_stream (xd3_stream *stream,
899 const uint8_t *input,
900 usize_t input_size,
901 uint8_t *output,
902 usize_t *output_size,
903 usize_t avail_size);
904
905/* This should be called before the first call to xd3_encode_input() to include 954/* This should be called before the first call to xd3_encode_input() to include
906 * application-specific data in the VCDIFF header. */ 955 * application-specific data in the VCDIFF header. */
907void xd3_set_appheader (xd3_stream *stream, 956void xd3_set_appheader (xd3_stream *stream,
908 const uint8_t *data, 957 const uint8_t *data,
909 usize_t size); 958 usize_t size);
910 959
911/* xd3_get_appheader may be called in the decoder after XD3_GOTHEADER. For convenience, 960/* xd3_get_appheader may be called in the decoder after XD3_GOTHEADER. For convenience,
912 * the decoder always adds a single byte padding to the end of the application header, 961 * the decoder always adds a single byte padding to the end of the application header,
913 * which is set to zero in case the application header is a string. */ 962 * which is set to zero in case the application header is a string. */
914int xd3_get_appheader (xd3_stream *stream, 963int xd3_get_appheader (xd3_stream *stream,
915 uint8_t **data, 964 uint8_t **data,
916 usize_t *size); 965 usize_t *size);
917 966
918/* After receiving XD3_GOTHEADER, the decoder should check this function which returns 1 967/* After receiving XD3_GOTHEADER, the decoder should check this function which returns 1
919 * if the decoder will require source data. */ 968 * if the decoder will require source data. */