Crypto++
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Deflator Class Reference

DEFLATE (RFC 1951) compressor. More...

#include <zdeflate.h>

Inheritance diagram for Deflator:
LowFirstBitWriter Filter BufferedTransformation NotCopyable Algorithm Waitable Clonable Gzip ZlibCompressor

Classes

struct  EncodedMatch
 

Public Types

enum  { MIN_DEFLATE_LEVEL = 0, DEFAULT_DEFLATE_LEVEL = 6, MAX_DEFLATE_LEVEL = 9 }
 
enum  { MIN_LOG2_WINDOW_SIZE = 9, DEFAULT_LOG2_WINDOW_SIZE = 15, MAX_LOG2_WINDOW_SIZE = 15 }
 

Public Member Functions

 Deflator (BufferedTransformation *attachment=NULL, int deflateLevel=DEFAULT_DEFLATE_LEVEL, int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
 
 Deflator (const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
 possible parameter names: Log2WindowSize, DeflateLevel, DetectUncompressible
 
void SetDeflateLevel (int deflateLevel)
 this function can be used to set the deflate level in the middle of compression
 
int GetDeflateLevel () const
 
int GetLog2WindowSize () const
 
void IsolatedInitialize (const NameValuePairs &parameters)
 
size_t Put2 (const byte *inString, size_t length, int messageEnd, bool blocking)
 input multiple bytes for blocking or non-blocking processing More...
 
bool IsolatedFlush (bool hardFlush, bool blocking)
 
void PutBits (unsigned long value, unsigned int length)
 
void FlushBitBuffer ()
 
void ClearBitBuffer ()
 
void StartCounting ()
 
unsigned long FinishCounting ()
 
bool Attachable ()
 returns whether this object allows attachment More...
 
BufferedTransformationAttachedTransformation ()
 returns the object immediately attached to this object or NULL for no attachment
 
const BufferedTransformationAttachedTransformation () const
 
void Detach (BufferedTransformation *newAttachment=NULL)
 delete the current attachment chain and replace it with newAttachment
 
size_t TransferTo2 (BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
 upon return, byteCount contains number of bytes that have finished being transfered, and returns the number of bytes left in the current transfer block
 
size_t CopyRangeTo2 (BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
 upon return, begin contains the start position of data yet to be finished copying, and returns the number of bytes left in the current transfer block
 
void Initialize (const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
 initialize or reinitialize this object
 
bool Flush (bool hardFlush, int propagation=-1, bool blocking=true)
 flush buffered input and/or output More...
 
bool MessageSeriesEnd (int propagation=-1, bool blocking=true)
 mark end of a series of messages More...
 
BufferedTransformationRef ()
 return a reference to this object, useful for passing a temporary object to a function that takes a non-const reference
 
virtual std::string AlgorithmName () const
 returns name of this algorithm, not universally implemented yet
 
virtual ClonableClone () const
 this is not implemented by most classes yet
 
bool Wait (unsigned long milliseconds, CallStack const &callStack)
 wait on this object More...
 
INPUT
size_t Put (byte inByte, bool blocking=true)
 input a byte for processing
 
size_t Put (const byte *inString, size_t length, bool blocking=true)
 input multiple bytes
 
size_t PutWord16 (word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
 input a 16-bit word
 
size_t PutWord32 (word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
 input a 32-bit word
 
virtual byte * CreatePutSpace (size_t &size)
 request space which can be written into by the caller, and then used as input to Put() More...
 
virtual bool CanModifyInput () const
 
size_t PutModifiable (byte *inString, size_t length, bool blocking=true)
 input multiple bytes that may be modified by callee
 
bool MessageEnd (int propagation=-1, bool blocking=true)
 
size_t PutMessageEnd (const byte *inString, size_t length, int propagation=-1, bool blocking=true)
 
virtual size_t PutModifiable2 (byte *inString, size_t length, int messageEnd, bool blocking)
 input multiple bytes that may be modified by callee for blocking or non-blocking processing More...
 
WAITING
unsigned int GetMaxWaitObjectCount () const
 maximum number of wait objects that this object can return
 
void GetWaitObjects (WaitObjectContainer &container, CallStack const &callStack)
 put wait objects into container More...
 
SIGNALS
virtual bool IsolatedMessageSeriesEnd (bool blocking)
 
virtual void SetAutoSignalPropagation (int propagation)
 set propagation of automatically generated and transferred signals More...
 
virtual int GetAutoSignalPropagation () const
 
RETRIEVAL OF ONE MESSAGE
virtual lword MaxRetrievable () const
 returns number of bytes that is currently ready for retrieval More...
 
virtual bool AnyRetrievable () const
 returns whether any bytes are currently ready for retrieval
 
virtual size_t Get (byte &outByte)
 try to retrieve a single byte
 
virtual size_t Get (byte *outString, size_t getMax)
 try to retrieve multiple bytes
 
virtual size_t Peek (byte &outByte) const
 peek at the next byte without removing it from the output buffer
 
virtual size_t Peek (byte *outString, size_t peekMax) const
 peek at multiple bytes without removing them from the output buffer
 
size_t GetWord16 (word16 &value, ByteOrder order=BIG_ENDIAN_ORDER)
 try to retrieve a 16-bit word
 
size_t GetWord32 (word32 &value, ByteOrder order=BIG_ENDIAN_ORDER)
 try to retrieve a 32-bit word
 
size_t PeekWord16 (word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
 try to peek at a 16-bit word
 
size_t PeekWord32 (word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
 try to peek at a 32-bit word
 
lword TransferTo (BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL)
 move transferMax bytes of the buffered output to target as input
 
virtual lword Skip (lword skipMax=LWORD_MAX)
 discard skipMax bytes from the output buffer
 
lword CopyTo (BufferedTransformation &target, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const
 copy copyMax bytes of the buffered output to target as input
 
lword CopyRangeTo (BufferedTransformation &target, lword position, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const
 copy copyMax bytes of the buffered output, starting at position (relative to current position), to target as input
 
RETRIEVAL OF MULTIPLE MESSAGES
virtual lword TotalBytesRetrievable () const
 
virtual unsigned int NumberOfMessages () const
 number of times MessageEnd() has been received minus messages retrieved or skipped
 
virtual bool AnyMessages () const
 returns true if NumberOfMessages() > 0
 
virtual bool GetNextMessage ()
 start retrieving the next message More...
 
virtual unsigned int SkipMessages (unsigned int count=UINT_MAX)
 skip count number of messages
 
unsigned int TransferMessagesTo (BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL)
 
unsigned int CopyMessagesTo (BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const
 
virtual void SkipAll ()
 
void TransferAllTo (BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL)
 
void CopyAllTo (BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) const
 
virtual bool GetNextMessageSeries ()
 
virtual unsigned int NumberOfMessagesInThisSeries () const
 
virtual unsigned int NumberOfMessageSeries () const
 
NON-BLOCKING TRANSFER OF OUTPUT
size_t TransferMessagesTo2 (BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
 upon return, messageCount contains number of messages that have finished being transfered, and returns the number of bytes left in the current transfer block
 
size_t TransferAllTo2 (BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
 returns the number of bytes left in the current transfer block
 
CHANNELS
size_t ChannelPut (const std::string &channel, byte inByte, bool blocking=true)
 
size_t ChannelPut (const std::string &channel, const byte *inString, size_t length, bool blocking=true)
 
size_t ChannelPutModifiable (const std::string &channel, byte *inString, size_t length, bool blocking=true)
 
size_t ChannelPutWord16 (const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
 
size_t ChannelPutWord32 (const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
 
bool ChannelMessageEnd (const std::string &channel, int propagation=-1, bool blocking=true)
 
size_t ChannelPutMessageEnd (const std::string &channel, const byte *inString, size_t length, int propagation=-1, bool blocking=true)
 
virtual byte * ChannelCreatePutSpace (const std::string &channel, size_t &size)
 
virtual size_t ChannelPut2 (const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking)
 
virtual size_t ChannelPutModifiable2 (const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking)
 
virtual bool ChannelFlush (const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
 
virtual bool ChannelMessageSeriesEnd (const std::string &channel, int propagation=-1, bool blocking=true)
 
virtual void SetRetrievalChannel (const std::string &channel)
 
ATTACHMENT
virtual void Attach (BufferedTransformation *newAttachment)
 add newAttachment to the end of attachment chain
 

Static Public Attributes

static const std::string & NULL_CHANNEL
 

Protected Types

enum  { STORED = 0, STATIC = 1, DYNAMIC = 2 }
 
enum  { MIN_MATCH = 3, MAX_MATCH = 258 }
 

Protected Member Functions

virtual void WritePrestreamHeader ()
 
virtual void ProcessUncompressedData (const byte *string, size_t length)
 
virtual void WritePoststreamTail ()
 
void InitializeStaticEncoders ()
 
void Reset (bool forceReset=false)
 
unsigned int FillWindow (const byte *str, size_t length)
 
unsigned int ComputeHash (const byte *str) const
 
unsigned int LongestMatch (unsigned int &bestMatch) const
 
void InsertString (unsigned int start)
 
void ProcessBuffer ()
 
void LiteralByte (byte b)
 
void MatchFound (unsigned int distance, unsigned int length)
 
void EncodeBlock (bool eof, unsigned int blockType)
 
void EndBlock (bool eof)
 
virtual BufferedTransformationNewDefaultAttachment () const
 
void Insert (Filter *nextFilter)
 
virtual bool ShouldPropagateMessageEnd () const
 
virtual bool ShouldPropagateMessageSeriesEnd () const
 
void PropagateInitialize (const NameValuePairs &parameters, int propagation)
 
size_t Output (int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
 
size_t OutputModifiable (int outputSite, byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
 
bool OutputMessageEnd (int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
 
bool OutputFlush (int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
 
bool OutputMessageSeriesEnd (int outputSite, int propagation, bool blocking, const std::string &channel=DEFAULT_CHANNEL)
 

Static Protected Member Functions

static int DecrementPropagation (int propagation)
 

Protected Attributes

int m_deflateLevel
 
int m_log2WindowSize
 
int m_compressibleDeflateLevel
 
unsigned int m_detectSkip
 
unsigned int m_detectCount
 
unsigned int DSIZE
 
unsigned int DMASK
 
unsigned int HSIZE
 
unsigned int HMASK
 
unsigned int GOOD_MATCH
 
unsigned int MAX_LAZYLENGTH
 
unsigned int MAX_CHAIN_LENGTH
 
bool m_headerWritten
 
bool m_matchAvailable
 
unsigned int m_dictionaryEnd
 
unsigned int m_stringStart
 
unsigned int m_lookahead
 
unsigned int m_minLookahead
 
unsigned int m_previousMatch
 
unsigned int m_previousLength
 
HuffmanEncoder m_staticLiteralEncoder
 
HuffmanEncoder m_staticDistanceEncoder
 
HuffmanEncoder m_dynamicLiteralEncoder
 
HuffmanEncoder m_dynamicDistanceEncoder
 
SecByteBlock m_byteBuffer
 
SecBlock< word16 > m_head
 
SecBlock< word16 > m_prev
 
FixedSizeSecBlock< unsigned
int, 286 > 
m_literalCounts
 
FixedSizeSecBlock< unsigned
int, 30 > 
m_distanceCounts
 
SecBlock< EncodedMatchm_matchBuffer
 
unsigned int m_matchBufferEnd
 
unsigned int m_blockStart
 
unsigned int m_blockLength
 
bool m_counting
 
unsigned long m_bitCount
 
unsigned long m_buffer
 
unsigned int m_bitsBuffered
 
unsigned int m_bytesBuffered
 
FixedSizeSecBlock< byte, 256 > m_outputBuffer
 
size_t m_inputPosition
 
int m_continueAt
 

Detailed Description

DEFLATE (RFC 1951) compressor.

Definition at line 55 of file zdeflate.h.

Constructor & Destructor Documentation

Deflator::Deflator ( BufferedTransformation attachment = NULL,
int  deflateLevel = DEFAULT_DEFLATE_LEVEL,
int  log2WindowSize = DEFAULT_LOG2_WINDOW_SIZE,
bool  detectUncompressible = true 
)
Note
detectUncompressible makes it faster to process uncompressible files, but if a file has both compressible and uncompressible parts, it may fail to compress some of the compressible parts.

Member Function Documentation

size_t Deflator::Put2 ( const byte *  inString,
size_t  length,
int  messageEnd,
bool  blocking 
)
virtual

input multiple bytes for blocking or non-blocking processing

Parameters
messageEndmeans how many filters to signal MessageEnd to, including this one

Implements BufferedTransformation.

bool Filter::Attachable ( )
inlinevirtualinherited

returns whether this object allows attachment

Some BufferedTransformation objects (e.g. Filter objects) allow other BufferedTransformation objects to be attached. When this is done, the first object instead of buffering its output, sents that output to the attached object as input. The entire attachment chain is deleted when the anchor object is destructed.

Reimplemented from BufferedTransformation.

Definition at line 22 of file filters.h.

bool Filter::Flush ( bool  hardFlush,
int  propagation = -1,
bool  blocking = true 
)
virtualinherited

flush buffered input and/or output

Parameters
hardFlushis used to indicate whether all data should be flushed
Note
Hard flushes must be used with care. It means try to process and output everything, even if there may not be enough data to complete the action. For example, hard flushing a HexDecoder would cause an error if you do it after inputing an odd number of hex encoded characters. For some types of filters, for example ZlibDecompressor, hard flushes can only be done at "synchronization points". These synchronization points are positions in the data stream that are created by hard flushes on the corresponding reverse filters, in this example ZlibCompressor. This is useful when zlib compressed data is moved across a network in packets and compression state is preserved across packets, as in the ssh2 protocol.

Reimplemented from BufferedTransformation.

Reimplemented in InformationDispersal, and SecretSharing.

bool Filter::MessageSeriesEnd ( int  propagation = -1,
bool  blocking = true 
)
virtualinherited

mark end of a series of messages

There should be a MessageEnd immediately before MessageSeriesEnd.

Reimplemented from BufferedTransformation.

virtual byte* BufferedTransformation::CreatePutSpace ( size_t &  size)
inlinevirtualinherited

request space which can be written into by the caller, and then used as input to Put()

Parameters
sizeis requested size (as a hint) for input, and size of the returned space for output
Note
The purpose of this method is to help avoid doing extra memory allocations.

Reimplemented in ArrayXorSink, ArraySink, OutputProxy, Redirector, HashFilter, MeterFilter, and ByteQueue.

Definition at line 798 of file cryptlib.h.

Referenced by ArrayXorSink::CreatePutSpace().

virtual size_t BufferedTransformation::PutModifiable2 ( byte *  inString,
size_t  length,
int  messageEnd,
bool  blocking 
)
inlinevirtualinherited

input multiple bytes that may be modified by callee for blocking or non-blocking processing

Parameters
messageEndmeans how many filters to signal MessageEnd to, including this one

Reimplemented in OutputProxy, FilterWithBufferedInput, and MeterFilter.

Definition at line 816 of file cryptlib.h.

void BufferedTransformation::GetWaitObjects ( WaitObjectContainer container,
CallStack const &  callStack 
)
virtualinherited

put wait objects into container

Parameters
callStackis used for tracing no wait loops, example: something.GetWaitObjects(c, CallStack("my func after X", 0));
  • or in an outer GetWaitObjects() method that itself takes a callStack parameter: innerThing.GetWaitObjects(c, CallStack("MyClass::GetWaitObjects at X", &callStack));

Implements Waitable.

Reimplemented in Redirector, NetworkSink, and NetworkSource.

virtual void BufferedTransformation::SetAutoSignalPropagation ( int  propagation)
inlinevirtualinherited

set propagation of automatically generated and transferred signals

propagation == 0 means do not automaticly generate signals

Reimplemented in SourceTemplate< T >, SourceTemplate< FileStore >, SourceTemplate< RandomNumberStore >, and SourceTemplate< StringStore >.

Definition at line 856 of file cryptlib.h.

virtual lword BufferedTransformation::MaxRetrievable ( ) const
virtualinherited

returns number of bytes that is currently ready for retrieval

All retrieval functions return the actual number of bytes retrieved, which is the lesser of the request number and MaxRetrievable().

Reimplemented in NullStore, RandomNumberStore, ByteQueue::Walker, FileStore, MessageQueue, and ByteQueue.

Referenced by RandomNumberStore::AnyRetrievable().

virtual bool BufferedTransformation::GetNextMessage ( )
virtualinherited

start retrieving the next message

Returns false if no more messages exist or this message is not completely retrieved.

Reimplemented in Store, and MessageQueue.

bool Waitable::Wait ( unsigned long  milliseconds,
CallStack const &  callStack 
)
inherited

wait on this object

same as creating an empty container, calling GetWaitObjects(), and calling Wait() on the container


The documentation for this class was generated from the following file: