lzmada_1.1.0_13442894/src/lzma-vli.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
pragma Style_Checks (Off);

with Interfaces.C; use Interfaces.C;
with Ada.Streams;
with Lzma.Base;

package Lzma.Vli is

   --  unsupported macro: LZMA_VLI_MAX (UINT64_MAX / 2)
   --  unsupported macro: LZMA_VLI_UNKNOWN UINT64_MAX

   LZMA_VLI_BYTES_MAX : constant := 9;  --  /usr/include/lzma/vli.h:44
   --  arg-macro: procedure LZMA_VLI_C UINT64_C(n)
   --    UINT64_C(n)
   --  arg-macro: function lzma_vli_is_valid ((vli) <= LZMA_VLI_MAX  or else  (vli) = LZMA_VLI_UNKNOWN
   --    return (vli) <= LZMA_VLI_MAX  or else  (vli) = LZMA_VLI_UNKNOWN;

  --*
  -- * \file        lzma/vli.h
  -- * \brief       Variable-length integer handling
  -- *
  -- * In the .xz format, most integers are encoded in a variable-length
  -- * representation, which is sometimes called little endian base-128 encoding.
  -- * This saves space when smaller values are more likely than bigger values.
  -- *
  -- * The encoding scheme encodes seven bits to every byte, using minimum
  -- * number of bytes required to represent the given value. Encodings that use
  -- * non-minimum number of bytes are invalid, thus every integer has exactly
  -- * one encoded representation. The maximum number of bits in a VLI is 63,
  -- * thus the vli argument must be less than or equal to UINT64_MAX / 2. You
  -- * should use LZMA_VLI_MAX for clarity.
  --

  -- * Author: Lasse Collin
  -- *
  -- * This file has been put into the public domain.
  -- * You can do whatever you want with this file.
  -- *
  -- * See ../lzma.h for information about liblzma as a whole.
  --

  --*
  -- * \brief       Maximum supported value of a variable-length integer
  --

  --*
  -- * \brief       VLI value to denote that the value is unknown
  --

  --*
  -- * \brief       Maximum supported encoded length of variable length integers
  --

  --*
  -- * \brief       VLI constant suffix
  --

  --*
  -- * \brief       Variable-length integer type
  -- *
  -- * Valid VLI values are in the range [0, LZMA_VLI_MAX]. Unknown value is
  -- * indicated with LZMA_VLI_UNKNOWN, which is the maximum value of the
  -- * underlaying integer type.
  -- *
  -- * lzma_vli will be uint64_t for the foreseeable future. If a bigger size
  -- * is needed in the future, it is guaranteed that 2 * LZMA_VLI_MAX will
  -- * not overflow lzma_vli. This simplifies integer overflow detection.
  --

   subtype lzma_vli is Long_Long_Integer;  -- /usr/include/lzma/vli.h:63

  --*
  -- * \brief       Validate a variable-length integer
  -- *
  -- * This is useful to test that application has given acceptable values
  -- * for example in the uncompressed_size and compressed_size variables.
  -- *
  -- * \return      True if the integer is representable as VLI or if it
  -- *              indicates unknown value.
  --

  --*
  -- * \brief       Encode a variable-length integer
  -- *
  -- * This function has two modes: single-call and multi-call. Single-call mode
  -- * encodes the whole integer at once; it is an error if the output buffer is
  -- * too small. Multi-call mode saves the position in *vli_pos, and thus it is
  -- * possible to continue encoding if the buffer becomes full before the whole
  -- * integer has been encoded.
  -- *
  -- * \param       vli       Integer to be encoded
  -- * \param       vli_pos   How many VLI-encoded bytes have already been written
  -- *                        out. When starting to encode a new integer in
  -- *                        multi-call mode, *vli_pos must be set to zero.
  -- *                        To use single-call encoding, set vli_pos to NULL.
  -- * \param       out       Beginning of the output buffer
  -- * \param       out_pos   The next byte will be written to out[*out_pos].
  -- * \param       out_size  Size of the out buffer; the first byte into
  -- *                        which no data is written to is out[out_size].
  -- *
  -- * \return      Slightly different return values are used in multi-call and
  -- *              single-call modes.
  -- *
  -- *              Single-call (vli_pos == NULL):
  -- *              - LZMA_OK: Integer successfully encoded.
  -- *              - LZMA_PROG_ERROR: Arguments are not sane. This can be due
  -- *                to too little output space; single-call mode doesn't use
  -- *                LZMA_BUF_ERROR, since the application should have checked
  -- *                the encoded size with lzma_vli_size().
  -- *
  -- *              Multi-call (vli_pos != NULL):
  -- *              - LZMA_OK: So far all OK, but the integer is not
  -- *                completely written out yet.
  -- *              - LZMA_STREAM_END: Integer successfully encoded.
  -- *              - LZMA_BUF_ERROR: No output space was provided.
  -- *              - LZMA_PROG_ERROR: Arguments are not sane.
  --

   function lzma_vli_encode
     (vli : lzma_vli;
      vli_pos : access Interfaces.C.size_t;
      c_out : access Ada.Streams.Stream_Element;
      out_pos : access Interfaces.C.size_t;
      out_size : Interfaces.C.size_t) return Lzma.Base.lzma_ret;  -- /usr/include/lzma/vli.h:115
   pragma Import (C, lzma_vli_encode, "lzma_vli_encode");

  --*
  -- * \brief       Decode a variable-length integer
  -- *
  -- * Like lzma_vli_encode(), this function has single-call and multi-call modes.
  -- *
  -- * \param       vli       Pointer to decoded integer. The decoder will
  -- *                        initialize it to zero when *vli_pos == 0, so
  -- *                        application isn't required to initialize *vli.
  -- * \param       vli_pos   How many bytes have already been decoded. When
  -- *                        starting to decode a new integer in multi-call
  -- *                        mode, *vli_pos must be initialized to zero. To
  -- *                        use single-call decoding, set vli_pos to NULL.
  -- * \param       in        Beginning of the input buffer
  -- * \param       in_pos    The next byte will be read from in[*in_pos].
  -- * \param       in_size   Size of the input buffer; the first byte that
  -- *                        won't be read is in[in_size].
  -- *
  -- * \return      Slightly different return values are used in multi-call and
  -- *              single-call modes.
  -- *
  -- *              Single-call (vli_pos == NULL):
  -- *              - LZMA_OK: Integer successfully decoded.
  -- *              - LZMA_DATA_ERROR: Integer is corrupt. This includes hitting
  -- *                the end of the input buffer before the whole integer was
  -- *                decoded; providing no input at all will use LZMA_DATA_ERROR.
  -- *              - LZMA_PROG_ERROR: Arguments are not sane.
  -- *
  -- *              Multi-call (vli_pos != NULL):
  -- *              - LZMA_OK: So far all OK, but the integer is not
  -- *                completely decoded yet.
  -- *              - LZMA_STREAM_END: Integer successfully decoded.
  -- *              - LZMA_DATA_ERROR: Integer is corrupt.
  -- *              - LZMA_BUF_ERROR: No input was provided.
  -- *              - LZMA_PROG_ERROR: Arguments are not sane.
  --

   function lzma_vli_decode
     (vli : access lzma_vli;
      vli_pos : access Interfaces.C.size_t;
      c_in : access Ada.Streams.Stream_Element;
      in_pos : access Interfaces.C.size_t;
      in_size : Interfaces.C.size_t) return Lzma.Base.lzma_ret;  -- /usr/include/lzma/vli.h:154
   pragma Import (C, lzma_vli_decode, "lzma_vli_decode");

  --*
  -- * \brief       Get the number of bytes required to encode a VLI
  -- *
  -- * \return      Number of bytes on success (1-9). If vli isn't valid,
  -- *              zero is returned.
  --

   function lzma_vli_size (vli : lzma_vli) return Interfaces.C.unsigned;  -- /usr/include/lzma/vli.h:165
   pragma Import (C, lzma_vli_size, "lzma_vli_size");

end Lzma.Vli;