KCodecs::IdentityCodec

Search for usage in LXR

KCodecs::IdentityCodec Class Reference

#include <kcodecsidentity.h>

Inheritance diagram for KCodecs::IdentityCodec:

Public Member Functions

 IdentityCodec ()
 
 ~IdentityCodec () override
 
virtual bool decode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, NewlineType newline=NewlineLF) const
 
QByteArray decode (const QByteArray &src, Codec::NewlineType newline=Codec::NewlineLF) const override
 
virtual QByteArray decode (const QByteArray &src, NewlineType newline=NewlineLF) const
 
virtual bool encode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, NewlineType newline=NewlineLF) const
 
QByteArray encode (const QByteArray &src, Codec::NewlineType newline=Codec::NewlineLF) const override
 
virtual QByteArray encode (const QByteArray &src, NewlineType newline=NewlineLF) const
 
DecodermakeDecoder (Codec::NewlineType newline=Codec::NewlineCRLF) const override
 
EncodermakeEncoder (Codec::NewlineType newline=Codec::NewlineCRLF) const override
 
int maxDecodedSizeFor (int insize, Codec::NewlineType newline) const override
 
int maxEncodedSizeFor (int insize, Codec::NewlineType newline=Codec::NewlineLF) const override
 
- Public Member Functions inherited from KCodecs::Codec
virtual ~Codec ()
 
virtual bool decode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, NewlineType newline=NewlineLF) const
 
virtual bool encode (const char *&scursor, const char *const send, char *&dcursor, const char *const dend, NewlineType newline=NewlineLF) const
 
virtual const char * name () const =0
 

Additional Inherited Members

- Public Types inherited from KCodecs::Codec
enum  NewlineType { NewlineLF, NewlineCRLF }
 
- Static Public Member Functions inherited from KCodecs::Codec
static CodeccodecForName (const char *name)
 
static CodeccodecForName (const QByteArray &name)
 
- Protected Member Functions inherited from KCodecs::Codec
 Codec ()
 

Detailed Description

A class representing the Identify codec.

Definition at line 32 of file kcodecsidentity.h.

Constructor & Destructor Documentation

◆ IdentityCodec()

KCodecs::IdentityCodec::IdentityCodec ( )
inline

Constructs the Identity codec.

Definition at line 38 of file kcodecsidentity.h.

◆ ~IdentityCodec()

KCodecs::IdentityCodec::~IdentityCodec ( )
inlineoverride

Destroys the codec.

Definition at line 46 of file kcodecsidentity.h.

Member Function Documentation

◆ decode() [1/3]

bool KCodecs::Codec::decode

Convenience wrapper that can be used for small chunks of data when you can provide a large enough buffer.

The default implementation creates a Decoder and uses it.

Decodes a chunk of bytes starting at scursor and extending to send into the buffer described by dcursor and dend.

This function doesn't support chaining of blocks. The returned block cannot be added to, but you don't need to finalize it, too.

Example usage (in contains the input data):

KCodecs::Codec *codec = KCodecs::Codec::codecForName("base64");
if (!codec) {
    qFatal() << "no base64 codec found!?";
}
QByteArray out(in.size()); // good guess for any encoding...
QByteArray::Iterator iit = in.begin();
QByteArray::Iterator oit = out.begin();
if (!codec->decode(iit, in.end(), oit, out.end())) {
    qDebug() << "output buffer too small";
    return;
}
qDebug() << "Size of decoded data:" << oit - out.begin();
Parameters
scursoris a pointer to the start of the input buffer.
sendis a pointer to the end of the input buffer.
dcursoris a pointer to the start of the output buffer.
dendis a pointer to the end of the output buffer.
newlinewhether make new lines using CRLF, or LF (default is LF).
Returns
false if the decoded data didn't fit into the output buffer; true otherwise.

Definition at line 682 of file kcodecs.cpp.

◆ decode() [2/3]

QByteArray IdentityCodec::decode ( const QByteArray src,
Codec::NewlineType  newline = Codec::NewlineLF 
) const
overridevirtual

QByteArray Codec::decode()

Reimplemented from KCodecs::Codec.

Definition at line 94 of file kcodecsidentity.cpp.

◆ decode() [3/3]

QByteArray KCodecs::Codec::decode

Even more convenient, but also a bit slower and more memory intensive, since it allocates storage for the worst case and then shrinks the result QByteArray to the actual size again.

For use with small src.

Parameters
srcis a QByteArray containing the data to decode.
newlinewhether make new lines using CRLF, or LF (default is LF).

Definition at line 659 of file kcodecs.cpp.

◆ encode() [1/3]

bool KCodecs::Codec::encode

Convenience wrapper that can be used for small chunks of data when you can provide a large enough buffer.

The default implementation creates an Encoder and uses it.

Encodes a chunk of bytes starting at scursor and extending to send into the buffer described by dcursor and dend.

This function doesn't support chaining of blocks. The returned block cannot be added to, but you don't need to finalize it, too.

Example usage (in contains the input data):

KCodecs::Codec *codec = KCodecs::Codec::codecForName("base64");
if (!codec) {
    qFatal() << "no base64 codec found!?";
}
QByteArray out(in.size() * 1.4); // crude maximal size of b64 encoding
QByteArray::Iterator iit = in.begin();
QByteArray::Iterator oit = out.begin();
if (!codec->encode(iit, in.end(), oit, out.end())) {
    qDebug() << "output buffer too small";
    return;
}
qDebug() << "Size of encoded data:" << oit - out.begin();
Parameters
scursoris a pointer to the start of the input buffer.
sendis a pointer to the end of the input buffer.
dcursoris a pointer to the start of the output buffer.
dendis a pointer to the end of the output buffer.
newlinewhether make new lines using CRLF, or LF (default is LF).
Returns
false if the encoded data didn't fit into the output buffer; true otherwise.

Definition at line 610 of file kcodecs.cpp.

◆ encode() [2/3]

QByteArray IdentityCodec::encode ( const QByteArray src,
Codec::NewlineType  newline = Codec::NewlineLF 
) const
overridevirtual

QByteArray Codec::encode()

Reimplemented from KCodecs::Codec.

Definition at line 86 of file kcodecsidentity.cpp.

◆ encode() [3/3]

QByteArray KCodecs::Codec::encode

Even more convenient, but also a bit slower and more memory intensive, since it allocates storage for the worst case and then shrinks the result QByteArray to the actual size again.

For use with small src.

Parameters
srcis a QByteArray containing the data to encode.
newlinewhether make new lines using CRLF, or LF (default is LF).

Definition at line 636 of file kcodecs.cpp.

◆ makeDecoder()

Decoder * IdentityCodec::makeDecoder ( Codec::NewlineType  newline = Codec::NewlineCRLF) const
overridevirtual

Codec::makeDecoder()

Implements KCodecs::Codec.

Definition at line 66 of file kcodecsidentity.cpp.

◆ makeEncoder()

Encoder * IdentityCodec::makeEncoder ( Codec::NewlineType  newline = Codec::NewlineCRLF) const
overridevirtual

Codec::makeEncoder()

Implements KCodecs::Codec.

Definition at line 61 of file kcodecsidentity.cpp.

◆ maxDecodedSizeFor()

int KCodecs::IdentityCodec::maxDecodedSizeFor ( int  insize,
Codec::NewlineType  newline 
) const
inlineoverridevirtual

Codec::maxDecodedSizeFor()

Implements KCodecs::Codec.

Reimplemented in KCodecs::BinaryCodec.

Definition at line 82 of file kcodecsidentity.h.

◆ maxEncodedSizeFor()

int KCodecs::IdentityCodec::maxEncodedSizeFor ( int  insize,
Codec::NewlineType  newline = Codec::NewlineLF 
) const
inlineoverridevirtual

Codec::maxEncodedSizeFor()

Implements KCodecs::Codec.

Reimplemented in KCodecs::BinaryCodec.

Definition at line 69 of file kcodecsidentity.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 04:10:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.