Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / io / SnappyFrameUtils.h
blob923994c661399cc0f7d3bca4663997cefeff3cfd
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_SnappyFrameUtils_h__
8 #define mozilla_SnappyFrameUtils_h__
10 #include <cstddef>
12 #include "mozilla/Attributes.h"
13 #include "nsError.h"
15 namespace mozilla {
16 namespace detail {
19 // Utility class providing primitives necessary to build streams based
20 // on the snappy compressor. This essentially abstracts the framing format
21 // defined in:
23 // other-licences/snappy/src/framing_format.txt
25 // NOTE: Currently only the StreamIdentifier and CompressedData chunks are
26 // supported.
28 class SnappyFrameUtils {
29 public:
30 enum ChunkType {
31 Unknown,
32 StreamIdentifier,
33 CompressedData,
34 UncompressedData,
35 Padding,
36 Reserved,
37 ChunkTypeCount
40 static const size_t kChunkTypeLength = 1;
41 static const size_t kChunkLengthLength = 3;
42 static const size_t kHeaderLength = kChunkTypeLength + kChunkLengthLength;
43 static const size_t kStreamIdentifierDataLength = 6;
44 static const size_t kCRCLength = 4;
46 static nsresult WriteStreamIdentifier(char* aDest, size_t aDestLength,
47 size_t* aBytesWrittenOut);
49 static nsresult WriteCompressedData(char* aDest, size_t aDestLength,
50 const char* aData, size_t aDataLength,
51 size_t* aBytesWrittenOut);
53 static nsresult ParseHeader(const char* aSource, size_t aSourceLength,
54 ChunkType* aTypeOut, size_t* aDataLengthOut);
56 static nsresult ParseData(char* aDest, size_t aDestLength, ChunkType aType,
57 const char* aData, size_t aDataLength,
58 size_t* aBytesWrittenOut, size_t* aBytesReadOut);
60 static nsresult ParseStreamIdentifier(char* aDest, size_t aDestLength,
61 const char* aData, size_t aDataLength,
62 size_t* aBytesWrittenOut,
63 size_t* aBytesReadOut);
65 static nsresult ParseCompressedData(char* aDest, size_t aDestLength,
66 const char* aData, size_t aDataLength,
67 size_t* aBytesWrittenOut,
68 size_t* aBytesReadOut);
70 static size_t MaxCompressedBufferLength(size_t aSourceLength);
72 protected:
73 SnappyFrameUtils() = default;
74 virtual ~SnappyFrameUtils() = default;
77 } // namespace detail
78 } // namespace mozilla
80 #endif // mozilla_SnappyFrameUtils_h__