nlib
Lz4OutputStream.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_OSS_LZ4INPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_OSS_LZ4INPUTSTREAM_H_
5 
6 #include "lz4frame.h"
7 #include "nn/nlib/Config.h"
8 #include "nn/nlib/OutputStream.h"
10 
11 #if defined(_MSC_VER) && defined(nx_oss_lz4_EXPORTS)
12 #undef NLIB_VIS_PUBLIC
13 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
14 #endif
15 
16 NLIB_NAMESPACE_BEGIN
17 namespace oss {
18 
19 class Lz4OutputTransform;
21  public:
23  nlib_memset(&pref_, 0, sizeof(pref_));
24  pref_.autoFlush = 1;
25  pref_.frameInfo.blockMode = LZ4F_blockLinked;
26  pref_.compressionLevel = 9; // hc
27  }
28  void SetContentSize(uint64_t size) NLIB_NOEXCEPT {
29  pref_.frameInfo.contentSize = size;
30  }
31  uint64_t GetContentSize() const NLIB_NOEXCEPT {
32  return pref_.frameInfo.contentSize;
33  }
35  if (level < 0)
36  level = 0;
37  else if (level > 16)
38  level = 16;
39  pref_.compressionLevel = level;
40  }
42  return pref_.compressionLevel;
43  }
44  void SetMaxBlockSize(LZ4F_blockSizeID_t max_block_size) NLIB_NOEXCEPT {
45  pref_.frameInfo.blockSizeID = max_block_size;
46  }
47  LZ4F_blockSizeID_t GetMaxBlockSize() const NLIB_NOEXCEPT {
48  return pref_.frameInfo.blockSizeID;
49  }
50  void SetBlockIndependence(bool independence) NLIB_NOEXCEPT {
51  pref_.frameInfo.blockMode = independence ? LZ4F_blockIndependent : LZ4F_blockLinked;
52  }
54  return (pref_.frameInfo.blockMode != LZ4F_blockLinked);
55  }
56 
57  private:
58  LZ4F_preferences_t pref_;
59  friend class Lz4OutputTransform;
60 };
61 
63  public:
67  Lz4OutputStreamSettings settings;
68  return this->Init(settings);
69  }
70  errno_t Init(const Lz4OutputStreamSettings& settings) NLIB_NOEXCEPT;
71 
72  private:
73  struct Lz4OutputStreamPrivate;
74  Lz4OutputStreamPrivate* prv_;
76 };
77 
78 } // namespace oss
79 NLIB_NAMESPACE_END
80 
81 #if defined(_MSC_VER) && defined(nx_oss_lz4_EXPORTS)
82 #undef NLIB_VIS_PUBLIC
83 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
84 #endif
85 
86 #endif // INCLUDE_NN_NLIB_OSS_LZ4INPUTSTREAM_H_
Lz4OutputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor).
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:244
uint64_t GetContentSize() const noexcept
Gets the value specified with SetContentSize(). The default is 0.
static errno_t nlib_memset(void *buf, int ch, size_t n)
Makes a function call corresponding to memset(buf, ch, n).
Definition: Platform.h:2469
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:179
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
void SetMaxBlockSize(LZ4F_blockSizeID_t max_block_size) noexcept
Sets the maximum data block size. The larger the size, the higher the speed, though more memory is re...
void SetContentSize(uint64_t size) noexcept
Data with the size before compression can be included in data compressed with LZ4.
The class to obtain and configure the Lz4OutputStream settings.
The base class for classes that act internally like OutputStream to convert data. ...
errno_t Init() noexcept
Initializes the stream with the default settings.
bool GetBlockIndependence() const noexcept
Gets the value specified with SetBlockIndependence(). The default is false.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
A file that contains the configuration information for each development environment.
void SetBlockIndependence(bool independence) noexcept
Sets whether a compressed data block can be uncompressed independently.
LZ4F_blockSizeID_t GetMaxBlockSize() const noexcept
Gets the value specified with SetMaxBlockSize(). The default is LZ4F_default.
The stream class to write data according to the LZ4 frame format.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
Defines the base class for output streams.
constexpr Lz4OutputStream() noexcept
Instantiates the object with default parameters (default constructor). Must be initialized with Init(...
int GetCompressionLevel() noexcept
Gets the value specified with SetCompressionLevel(). The default is 9.
void SetCompressionLevel(int level) noexcept
Sets a compression level. The compression rate is an integer in a range from 0 to 16...
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37