Base module

hex::Decoder

Hex decoder.

Decoder

#include <icy/hex.h>

struct Decoder

Defined in src/base/include/icy/hex.h:111

Inherits
Decoder

List of all members

NameKindOwner
lastbytevariableDeclared here
DecoderfunctionDeclared here
~DecoderfunctionDeclared here
decodefunctionDeclared here
finalizefunctionDeclared here
readnextfunctionDeclared here
nybblefunctionDeclared here
iswspacefunctionDeclared here
DecoderfunctionInherited from Decoder
~DecoderfunctionInherited from Decoder
decodefunctionInherited from Decoder
finalizefunctionInherited from Decoder

Inherited from Decoder

KindNameDescription
functionDecoderDefaulted constructor.
function~Decoder virtualDefaulted destructor.
functiondecode virtualDecodes nread bytes from inbuf and writes decoded output to outbuf.
functionfinalize virtual inlineFlushes any buffered state and writes final output to outbuf.

Public Attributes

ReturnNameDescription
charlastbyte

lastbyte

char lastbyte

Defined in src/base/include/icy/hex.h:201

Public Methods

ReturnNameDescription
Decoder inline
~Decoder virtual inline
ssize_tdecode virtual inline overrideDecodes hex-encoded input to binary. Whitespace in the input is ignored. A trailing unpaired nibble is buffered and prepended on the next call.
ssize_tfinalize virtual inline overrideNo-op finalizer; hex decoding has no pending output state.
boolreadnext inlineReads the next non-whitespace character from inbuf, prepending any buffered lastbyte before consuming from the stream.
intnybble inlineConverts an ASCII hex character to its 4-bit integer value.
booliswspace inlineReturns true if c is an ASCII whitespace character (space, CR, tab, LF).

Decoder

inline

inline Decoder()

Defined in src/base/include/icy/hex.h:113


~Decoder

virtual inline

virtual inline ~Decoder()

Defined in src/base/include/icy/hex.h:117

Reimplements


decode

virtual inline override

virtual inline ssize_t decode(const char * inbuf, size_t nread, char * outbuf) override

Defined in src/base/include/icy/hex.h:125

Decodes hex-encoded input to binary. Whitespace in the input is ignored. A trailing unpaired nibble is buffered and prepended on the next call.

Returns

Number of decoded bytes written to outbuf.

Reimplements

Parameters

ParameterTypeDescription
inbufconst char *Hex-encoded input buffer.
nreadsize_tNumber of bytes to read from inbuf.
outbufchar *Destination buffer; must have capacity >= nread / 2.

finalize

virtual inline override

virtual inline ssize_t finalize(char *) override

Defined in src/base/include/icy/hex.h:152

No-op finalizer; hex decoding has no pending output state.

Returns

Always 0.

Reimplements


readnext

inline

inline bool readnext(const char * inbuf, size_t nread, size_t & rpos, char & c)

Defined in src/base/include/icy/hex.h:161

Reads the next non-whitespace character from inbuf, prepending any buffered lastbyte before consuming from the stream.

Returns

true if more input remains after c was read, false otherwise.

Parameters

ParameterTypeDescription
inbufconst char *Input buffer.
nreadsize_tTotal bytes in inbuf.
rpossize_t &Current read position; advanced on each consumed byte.
cchar &Output: the next non-whitespace character.

nybble

inline

inline int nybble(const int n)

Defined in src/base/include/icy/hex.h:181

Converts an ASCII hex character to its 4-bit integer value.

Returns

Integer value in the range [0, 15].

Parameters

ParameterTypeDescription
nconst intASCII character ('0'-'9', 'a'-'f', 'A'-'F').

Exceptions

ExceptionDescription
std::runtime_errorif n is not a valid hex character.

iswspace

inline

inline bool iswspace(const char c)

Defined in src/base/include/icy/hex.h:196

Returns true if c is an ASCII whitespace character (space, CR, tab, LF).

Returns

true if c is whitespace.

Parameters

ParameterTypeDescription
cconst charCharacter to test.