Rizin
unix-like reverse engineering framework and cli tools
DotZLib.CodecBase Class Referenceabstract

Implements the common functionality needed for all Codecs More...

Inheritance diagram for DotZLib.CodecBase:
DotZLib.Codec DotZLib.Deflater DotZLib.Inflater

Public Member Functions

 CodecBase ()
 Initializes a new instance of the CodeBase class. More...
 
void Add (byte[] data)
 Adds more data to the codec to be processed. More...
 
abstract void Add (byte[] data, int offset, int count)
 Adds more data to the codec to be processed. More...
 
abstract void Finish ()
 Finishes up any pending data that needs to be processed and handled. More...
 
void Dispose ()
 Releases any unmanaged resources and calls the CleanUp() method of the derived class More...
 

Protected Member Functions

void OnDataAvailable ()
 Fires the DataAvailable event More...
 
abstract void CleanUp ()
 Performs any codec specific cleanup More...
 
void copyInput (byte[] data, int startIndex, int count)
 Copies a number of bytes to the internal codec buffer - ready for proccesing More...
 
void resetOutput ()
 Resets the internal output buffers to a known state - ready for processing More...
 
void setChecksum (uint newSum)
 Updates the running checksum property More...
 

Protected Attributes

bool _isDisposed = false
 True if the object instance has been disposed, false otherwise More...
 

Static Protected Attributes

const int kBufferSize = 16384
 The size of the internal buffers More...
 

Package Attributes

ZStream _ztream = new ZStream()
 Instance of the internal zlib buffer structure that is passed to all functions in the zlib dll More...
 

Properties

uint Checksum [get]
 Gets the checksum of the data that has been added so far More...
 
- Properties inherited from DotZLib.Codec
uint Checksum [get]
 Gets the checksum of the data that has been added so far More...
 

Events

DataAvailableHandler DataAvailable
 Occurs when more processed data are available. More...
 
- Events inherited from DotZLib.Codec
DataAvailableHandler DataAvailable
 Occurs when more processed data are available. More...
 

Private Member Functions

 ~CodecBase ()
 Destroys this instance More...
 
void CleanUp (bool isDisposing)
 

Private Attributes

byte[] _outBuffer = new byte[kBufferSize]
 
byte[] _inBuffer = new byte[kBufferSize]
 
GCHandle _hInput
 
GCHandle _hOutput
 
uint _checksum = 0
 

Detailed Description

Implements the common functionality needed for all Codecs

Definition at line 16 of file CodecBase.cs.

Constructor & Destructor Documentation

◆ CodecBase()

DotZLib.CodecBase.CodecBase ( )
inline

Initializes a new instance of the CodeBase class.

Definition at line 50 of file CodecBase.cs.

51  {
52  try
53  {
54  _hInput = GCHandle.Alloc(_inBuffer, GCHandleType.Pinned);
55  _hOutput = GCHandle.Alloc(_outBuffer, GCHandleType.Pinned);
56  }
57  catch (Exception)
58  {
59  CleanUp(false);
60  throw;
61  }
62  }
GCHandle _hOutput
Definition: CodecBase.cs:41
byte[] _inBuffer
Definition: CodecBase.cs:38
abstract void CleanUp()
Performs any codec specific cleanup
byte[] _outBuffer
Definition: CodecBase.cs:37
GCHandle _hInput
Definition: CodecBase.cs:40

References DotZLib.CodecBase._hInput, DotZLib.CodecBase._hOutput, DotZLib.CodecBase._inBuffer, DotZLib.CodecBase._outBuffer, and DotZLib.CodecBase.CleanUp().

◆ ~CodecBase()

DotZLib.CodecBase.~CodecBase ( )
inlineprivate

Destroys this instance

Definition at line 123 of file CodecBase.cs.

124  {
125  CleanUp(false);
126  }

References DotZLib.CodecBase.CleanUp().

Member Function Documentation

◆ Add() [1/2]

void DotZLib.CodecBase.Add ( byte[]  data)
inline

Adds more data to the codec to be processed.

Parameters
dataByte array containing the data to be added to the codec

Adding data may, or may not, raise the DataAvailable event

Implements DotZLib.Codec.

Definition at line 90 of file CodecBase.cs.

91  {
92  Add(data,0,data.Length);
93  }
void Add(byte[] data)
Adds more data to the codec to be processed.
Definition: CodecBase.cs:90

◆ Add() [2/2]

abstract void DotZLib.CodecBase.Add ( byte[]  data,
int  offset,
int  count 
)
pure virtual

Adds more data to the codec to be processed.

Parameters
dataByte array containing the data to be added to the codec
offsetThe index of the first byte to add from data
countThe number of bytes to add

Adding data may, or may not, raise the DataAvailable event

This must be implemented by a derived class

Implements DotZLib.Codec.

Implemented in DotZLib.Inflater, and DotZLib.Deflater.

◆ CleanUp() [1/2]

abstract void DotZLib.CodecBase.CleanUp ( )
protectedpure virtual

Performs any codec specific cleanup

This must be implemented by a derived class

Implemented in DotZLib.Inflater, and DotZLib.Deflater.

Referenced by DotZLib.CodecBase.CleanUp(), DotZLib.CodecBase.CodecBase(), DotZLib.CodecBase.Dispose(), and DotZLib.CodecBase.~CodecBase().

◆ CleanUp() [2/2]

void DotZLib.CodecBase.CleanUp ( bool  isDisposing)
inlineprivate

Definition at line 143 of file CodecBase.cs.

144  {
145  if (!_isDisposed)
146  {
147  CleanUp();
148  if (_hInput.IsAllocated)
149  _hInput.Free();
150  if (_hOutput.IsAllocated)
151  _hOutput.Free();
152 
153  _isDisposed = true;
154  }
155  }
bool _isDisposed
True if the object instance has been disposed, false otherwise
Definition: CodecBase.cs:30

References DotZLib.CodecBase._hInput, DotZLib.CodecBase._hOutput, DotZLib.CodecBase._isDisposed, and DotZLib.CodecBase.CleanUp().

◆ copyInput()

void DotZLib.CodecBase.copyInput ( byte[]  data,
int  startIndex,
int  count 
)
inlineprotected

Copies a number of bytes to the internal codec buffer - ready for proccesing

Parameters
dataThe byte array that contains the data to copy
startIndexThe index of the first byte to copy
countThe number of bytes to copy from data

Definition at line 168 of file CodecBase.cs.

169  {
170  Array.Copy(data, startIndex, _inBuffer,0, count);
171  _ztream.next_in = _hInput.AddrOfPinnedObject();
172  _ztream.total_in = 0;
174 
175  }
#define Array(T)
Definition: array.h:15
ZStream _ztream
Instance of the internal zlib buffer structure that is passed to all functions in the zlib dll
Definition: CodecBase.cs:25
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
unsigned int uint
Definition: gzlog.c:242
uint avail_in
Definition: DotZLib.cs:33
IntPtr next_in
Definition: DotZLib.cs:32
uint total_in
Definition: DotZLib.cs:34

References DotZLib.CodecBase._hInput, DotZLib.CodecBase._inBuffer, DotZLib.CodecBase._ztream, Array, DotZLib.ZStream.avail_in, count, DotZLib.ZStream.next_in, and DotZLib.ZStream.total_in.

Referenced by DotZLib.Deflater.Add(), and DotZLib.Inflater.Add().

◆ Dispose()

void DotZLib.CodecBase.Dispose ( )
inline

Releases any unmanaged resources and calls the CleanUp() method of the derived class

Definition at line 131 of file CodecBase.cs.

132  {
133  CleanUp(true);
134  }

References DotZLib.CodecBase.CleanUp().

◆ Finish()

abstract void DotZLib.CodecBase.Finish ( )
pure virtual

Finishes up any pending data that needs to be processed and handled.

This must be implemented by a derived class

Implements DotZLib.Codec.

Implemented in DotZLib.Inflater, and DotZLib.Deflater.

◆ OnDataAvailable()

void DotZLib.CodecBase.OnDataAvailable ( )
inlineprotected

Fires the DataAvailable event

Definition at line 75 of file CodecBase.cs.

76  {
77  if (_ztream.total_out > 0)
78  {
79  if (DataAvailable != null)
81  resetOutput();
82  }
83  }
void resetOutput()
Resets the internal output buffers to a known state - ready for processing
Definition: CodecBase.cs:180
DataAvailableHandler DataAvailable
Occurs when more processed data are available.
Definition: CodecBase.cs:70
uint total_out
Definition: DotZLib.cs:38

References DotZLib.CodecBase._outBuffer, DotZLib.CodecBase._ztream, DotZLib.CodecBase.DataAvailable, DotZLib.CodecBase.resetOutput(), and DotZLib.ZStream.total_out.

Referenced by DotZLib.Deflater.Add(), DotZLib.Inflater.Add(), DotZLib.Deflater.Finish(), and DotZLib.Inflater.Finish().

◆ resetOutput()

void DotZLib.CodecBase.resetOutput ( )
inlineprotected

Resets the internal output buffers to a known state - ready for processing

Definition at line 180 of file CodecBase.cs.

181  {
182  _ztream.total_out = 0;
184  _ztream.next_out = _hOutput.AddrOfPinnedObject();
185  }
const int kBufferSize
The size of the internal buffers
Definition: CodecBase.cs:35
uint avail_out
Definition: DotZLib.cs:37
IntPtr next_out
Definition: DotZLib.cs:36

References DotZLib.CodecBase._hOutput, DotZLib.CodecBase._ztream, DotZLib.ZStream.avail_out, DotZLib.CodecBase.kBufferSize, DotZLib.ZStream.next_out, and DotZLib.ZStream.total_out.

Referenced by DotZLib.Deflater.Deflater(), DotZLib.Deflater.Finish(), DotZLib.Inflater.Finish(), DotZLib.Inflater.Inflater(), and DotZLib.CodecBase.OnDataAvailable().

◆ setChecksum()

void DotZLib.CodecBase.setChecksum ( uint  newSum)
inlineprotected

Updates the running checksum property

Parameters
newSumThe new checksum value

Definition at line 191 of file CodecBase.cs.

192  {
193  _checksum = newSum;
194  }

References DotZLib.CodecBase._checksum.

Referenced by DotZLib.Deflater.Add(), DotZLib.Inflater.Add(), DotZLib.Deflater.Finish(), and DotZLib.Inflater.Finish().

Member Data Documentation

◆ _checksum

uint DotZLib.CodecBase._checksum = 0
private

Definition at line 43 of file CodecBase.cs.

Referenced by DotZLib.CodecBase.setChecksum().

◆ _hInput

GCHandle DotZLib.CodecBase._hInput
private

◆ _hOutput

GCHandle DotZLib.CodecBase._hOutput
private

◆ _inBuffer

byte [] DotZLib.CodecBase._inBuffer = new byte[kBufferSize]
private

Definition at line 38 of file CodecBase.cs.

Referenced by DotZLib.CodecBase.CodecBase(), and DotZLib.CodecBase.copyInput().

◆ _isDisposed

bool DotZLib.CodecBase._isDisposed = false
protected

True if the object instance has been disposed, false otherwise

Definition at line 30 of file CodecBase.cs.

Referenced by DotZLib.CodecBase.CleanUp().

◆ _outBuffer

byte [] DotZLib.CodecBase._outBuffer = new byte[kBufferSize]
private

Definition at line 37 of file CodecBase.cs.

Referenced by DotZLib.CodecBase.CodecBase(), and DotZLib.CodecBase.OnDataAvailable().

◆ _ztream

◆ kBufferSize

const int DotZLib.CodecBase.kBufferSize = 16384
staticprotected

The size of the internal buffers

Definition at line 35 of file CodecBase.cs.

Referenced by DotZLib.Deflater.Add(), DotZLib.Inflater.Add(), and DotZLib.CodecBase.resetOutput().

Property Documentation

◆ Checksum

uint DotZLib.CodecBase.Checksum
get

Gets the checksum of the data that has been added so far

Definition at line 114 of file CodecBase.cs.

114 { get { return _checksum; } }

Event Documentation

◆ DataAvailable

DataAvailableHandler DotZLib.CodecBase.DataAvailable

Occurs when more processed data are available.

Definition at line 70 of file CodecBase.cs.

Referenced by DotZLib.CodecBase.OnDataAvailable().


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