1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef RICE_DELTA_DECODER_H
6 #define RICE_DELTA_DECODER_H
7 
8 namespace mozilla {
9 namespace safebrowsing {
10 
11 class RiceDeltaDecoder {
12 public:
13   // This decoder is tailored for safebrowsing v4, including the
14   // bit reading order and how the remainder part is interpreted.
15   // The caller just needs to feed the byte stream received from
16   // network directly. Note that the input buffer must be mutable
17   // since the decoder will do some pre-processing before decoding.
18   RiceDeltaDecoder(uint8_t* aEncodedData, size_t aEncodedDataSize);
19 
20   // @param aNumEntries The number of values to be decoded, not including
21   //                    the first value.
22   // @param aDecodedData A pre-allocated output buffer. Note that
23   //                     aDecodedData[0] will be filled with |aFirstValue|
24   //                     and the buffer length (in byte) should be
25   //                     ((aNumEntries + 1) * sizeof(uint32_t)).
26   bool Decode(uint32_t aRiceParameter,
27               uint32_t aFirstValue,
28               uint32_t aNumEntries,
29               uint32_t* aDecodedData);
30 
31 private:
32   uint8_t* mEncodedData;
33   size_t mEncodedDataSize;
34 };
35 
36 } // namespace safebrowsing
37 } // namespace mozilla
38 
39 #endif  // UPDATE_V4_DECODER_H
40