All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kzc_input_stream.h File Reference

Input stream. More...

Macros

#define KZC_INPUT_STREAM_BUFFER_DEFAULT_SIZE
 Default size for input stream buffer. More...
 

Typedefs

typedef kzsError(* KzcCustomInputStreamDeleteFunction )(void *customData)
 Function type for deleting custom input stream. More...
 
typedef kzsError(* KzcCustomInputStreamReadFunction )(void *customData, kzUint byteCount, kzUint *out_bytesReadCount, kzByte *out_bytes)
 Function type for reading bytes from custom input stream. More...
 
typedef kzsException(* KzcCustomInputStreamSkipFunction )(void *customData, kzUint skipAmount)
 Function type for skipping in a custom input stream. More...
 

Functions

KANZI_API kzsException kzcInputStreamCreateFromFile (const struct KzcMemoryManager *memoryManager, kzString filePath, enum KzcIOStreamEndianness endianness, struct KzcInputStream **out_inputStream)
 Creates an input stream pointing to a file, whose path is given as a parameter. More...
 
KANZI_API kzsException kzcInputStreamCreateFromResource (const struct KzcMemoryManager *memoryManager, kzString resourcePath, enum KzcIOStreamEndianness endianness, struct KzcInputStream **out_inputStream)
 Creates an input stream pointing to a resource file, whose path is given as a parameter. More...
 
KANZI_API kzsException kzcInputStreamCreateFromMemory (const struct KzcMemoryManager *memoryManager, const kzByte *buffer, kzUint size, enum KzcIOStreamEndianness endianness, struct KzcInputStream **out_inputStream)
 Creates an input stream pointing to a given memory buffer of given size. More...
 
KANZI_API kzsException kzcInputStreamCreateFromMemoryTemporary (const struct KzcMemoryManager *memoryManager, const kzByte *buffer, kzUint size, enum KzcIOStreamEndianness endianness, struct KzcInputStream **out_inputStream)
 Creates an input stream pointing to a given memory buffer of given size. More...
 
KANZI_API kzsException kzcInputStreamCreateFromStream (const struct KzcMemoryManager *memoryManager, struct KzcInputStream *targetInputStream, kzInt targetLength, enum KzcIOStreamEndianness endianness, struct KzcInputStream **out_inputStream)
 Creates an input stream pointing to another input stream. More...
 
KANZI_API kzsException kzcInputStreamCreateCustom (const struct KzcMemoryManager *memoryManager, void *customData, KzcCustomInputStreamDeleteFunction deleteFunction, KzcCustomInputStreamReadFunction readFunction, KzcCustomInputStreamSkipFunction skipFunction, enum KzcIOStreamEndianness endianness, struct KzcInputStream **out_inputStream)
 Creates an input stream using custom read functions. More...
 
KANZI_API kzsError kzcInputStreamDelete (struct KzcInputStream *inputStream)
 Deletes an input stream. More...
 
KANZI_API kzsError kzcInputStreamInitBuffer (struct KzcInputStream *inputStream, kzUint bufferSize)
 Initializes the size of input stream buffer. More...
 
KANZI_API kzsException kzcInputStreamRead (struct KzcInputStream *inputStream, kzUint byteCount, kzUint *out_bytesReadCount, kzByte *out_bytes)
 Reads some amount of bytes from the given input stream. More...
 
KANZI_API kzsException kzcInputStreamTryMap (struct KzcInputStream *inputStream, kzUint byteCount, const kzByte **out_data)
 If the input stream is memory based, this will get a pointer to the current position and will advance the stream by byteCount. More...
 
KANZI_API kzsException kzcInputStreamSkip (struct KzcInputStream *inputStream, kzUint skipByteCount)
 Skips the given amount of bytes in an input stream. More...
 
KANZI_API kzUint kzcInputStreamGetPosition (const struct KzcInputStream *inputStream)
 Gets the current position in an input stream. More...
 
KANZI_API enum
KzcIOStreamEndianness 
kzcInputStreamGetEndianness (const struct KzcInputStream *inputStream)
 Gets endianness of input stream. More...
 
KANZI_API void kzcInputStreamSetEndianness (struct KzcInputStream *inputStream, enum KzcIOStreamEndianness endianness)
 Sets endianness for input stream. More...
 
KANZI_API kzsException kzcInputStreamReadBytes (struct KzcInputStream *inputStream, kzUint byteCount, kzByte *out_bytes)
 Reads given amount of bytes from the input stream. More...
 
KANZI_API kzsException kzcInputStreamReadBoolean (struct KzcInputStream *inputStream, kzBool *out_value)
 Reads a boolean from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadBoolean (struct KzcInputStream *inputStream, bool *out_value)
 
KANZI_API kzsException kzcInputStreamReadU8 (struct KzcInputStream *inputStream, kzU8 *out_value)
 Reads an unsigned 8-bit value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU8Int (struct KzcInputStream *inputStream, kzUint *out_value)
 Reads an unsigned 8-bit value casted to an unsigned integer from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS8 (struct KzcInputStream *inputStream, kzS8 *out_value)
 Reads a signed 8-bit value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS8Int (struct KzcInputStream *inputStream, kzInt *out_value)
 Reads a signed 8-bit value casted to a signed integer from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU16 (struct KzcInputStream *inputStream, kzU16 *out_value)
 Reads an unsigned 16-bit value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU16Array (struct KzcInputStream *inputStream, kzUint valueCount, kzU16 *values)
 Reads an array of 16-bit values form an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU16Int (struct KzcInputStream *inputStream, kzUint *out_value)
 Reads an unsigned 16-bit value casted to an unsigned integer from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS16 (struct KzcInputStream *inputStream, kzS16 *out_value)
 Reads a signed 16-bit value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS16Array (struct KzcInputStream *inputStream, kzUint valueCount, kzS16 *values)
 Reads an array of signed 16-bit values form an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS16Int (struct KzcInputStream *inputStream, kzInt *out_value)
 Reads a signed 16-bit value casted to a signed integer from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU32 (struct KzcInputStream *inputStream, kzU32 *out_value)
 Reads an unsigned 32-bit value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU32Array (struct KzcInputStream *inputStream, kzUint valueCount, kzU32 *values)
 Reads an array of unsigned 32-bit values from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadU32Int (struct KzcInputStream *inputStream, kzUint *out_value)
 Reads an unsigned 32-bit value casted to an unsigned integer from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS32 (struct KzcInputStream *inputStream, kzS32 *out_value)
 Reads a signed 32-bit value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS32Array (struct KzcInputStream *inputStream, kzUint valueCount, kzS32 *values)
 Reads an array of signed 32-bit values from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadS32Int (struct KzcInputStream *inputStream, kzInt *out_value)
 Reads a signed 32-bit value casted to a signed integer from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadFloat (struct KzcInputStream *inputStream, kzFloat *out_value)
 Reads a 32-bit floating point value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadFloatArray (struct KzcInputStream *inputStream, kzUint valueCount, kzFloat *values)
 Reads a float array from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadDouble (struct KzcInputStream *inputStream, kzDouble *out_value)
 Reads a 64-bit floating point value from an input stream. More...
 
KANZI_API kzsException kzcInputStreamReadAllBytes (struct KzcInputStream *inputStream, const struct KzcMemoryManager *memoryManager, kzUint *out_size, kzByte **out_data)
 Reads the rest of the input stream to an array of bytes. More...
 
KANZI_API kzsException kzcInputStreamReadText (struct KzcInputStream *inputStream, const struct KzcMemoryManager *memoryManager, kzMutableString *out_string)
 Reads the rest of the input stream to a string. More...
 
KANZI_API kzsException kzcInputStreamReadTextLines (struct KzcInputStream *inputStream, const struct KzcMemoryManager *memoryManager, kzMutableString **out_lines)
 Reads the rest of the input stream to an array of strings. More...
 

Detailed Description

Input stream.

Input streams are used for reading binary data from several different data sources. Supprted data sources are:

  • Files
  • Resources
  • Memory buffers
  • Nested input streams

Streams are configured to read data in either little-endian, big-endian or platform's native endianness format.

Copyright 2008-2020 by Rightware. All rights reserved.

Macro Definition Documentation

#define KZC_INPUT_STREAM_BUFFER_DEFAULT_SIZE

Default size for input stream buffer.

Typedef Documentation

typedef kzsError(* KzcCustomInputStreamDeleteFunction)(void *customData)

Function type for deleting custom input stream.

typedef kzsError(* KzcCustomInputStreamReadFunction)(void *customData, kzUint byteCount, kzUint *out_bytesReadCount, kzByte *out_bytes)

Function type for reading bytes from custom input stream.

typedef kzsException(* KzcCustomInputStreamSkipFunction)(void *customData, kzUint skipAmount)

Function type for skipping in a custom input stream.

Function Documentation

KANZI_API kzsException kzcInputStreamCreateFromFile ( const struct KzcMemoryManager memoryManager,
kzString  filePath,
enum KzcIOStreamEndianness  endianness,
struct KzcInputStream **  out_inputStream 
)

Creates an input stream pointing to a file, whose path is given as a parameter.

KANZI_API kzsException kzcInputStreamCreateFromResource ( const struct KzcMemoryManager memoryManager,
kzString  resourcePath,
enum KzcIOStreamEndianness  endianness,
struct KzcInputStream **  out_inputStream 
)

Creates an input stream pointing to a resource file, whose path is given as a parameter.

KANZI_API kzsException kzcInputStreamCreateFromMemory ( const struct KzcMemoryManager memoryManager,
const kzByte buffer,
kzUint  size,
enum KzcIOStreamEndianness  endianness,
struct KzcInputStream **  out_inputStream 
)

Creates an input stream pointing to a given memory buffer of given size.

KANZI_API kzsException kzcInputStreamCreateFromMemoryTemporary ( const struct KzcMemoryManager memoryManager,
const kzByte buffer,
kzUint  size,
enum KzcIOStreamEndianness  endianness,
struct KzcInputStream **  out_inputStream 
)

Creates an input stream pointing to a given memory buffer of given size.

Even if this is a stream from memory buffer, it is considered temporary and cannot be mapped.

KANZI_API kzsException kzcInputStreamCreateFromStream ( const struct KzcMemoryManager memoryManager,
struct KzcInputStream targetInputStream,
kzInt  targetLength,
enum KzcIOStreamEndianness  endianness,
struct KzcInputStream **  out_inputStream 
)

Creates an input stream pointing to another input stream.

Length of the target input stream can be given as a parameter. In this case the stream will read at most that many bytes from the target stream and possibly unread bytes are skipped when deleting the stream.

Parameters
targetLengthLength of the target input stream or KZC_IO_STREAM_LENGTH_UNKNOWN if unknown.
KANZI_API kzsException kzcInputStreamCreateCustom ( const struct KzcMemoryManager memoryManager,
void *  customData,
KzcCustomInputStreamDeleteFunction  deleteFunction,
KzcCustomInputStreamReadFunction  readFunction,
KzcCustomInputStreamSkipFunction  skipFunction,
enum KzcIOStreamEndianness  endianness,
struct KzcInputStream **  out_inputStream 
)

Creates an input stream using custom read functions.

KANZI_API kzsError kzcInputStreamDelete ( struct KzcInputStream inputStream)

Deletes an input stream.

KANZI_API kzsError kzcInputStreamInitBuffer ( struct KzcInputStream inputStream,
kzUint  bufferSize 
)

Initializes the size of input stream buffer.

KANZI_API kzsException kzcInputStreamRead ( struct KzcInputStream inputStream,
kzUint  byteCount,
kzUint out_bytesReadCount,
kzByte out_bytes 
)

Reads some amount of bytes from the given input stream.

The maximum number of bytes is given as parameter and the actual number of bytes read is returned. Negative number is returned, if no bytes can be read because end of stream has been reached. This function can be used to read input stream where the number of expected bytes available is not known.

KANZI_API kzsException kzcInputStreamTryMap ( struct KzcInputStream inputStream,
kzUint  byteCount,
const kzByte **  out_data 
)

If the input stream is memory based, this will get a pointer to the current position and will advance the stream by byteCount.

If the input stream is not memory based, this will give out a null-pointer.

Parameters
byteCountThe number of bytes that the stream will be advanced by if mapping is successful.
out_dataWill be set to the memory-address of current position if mapping is successful, otherwise will be set to KZ_NULL.
Returns
KZC_EXCEPTION_END_OF_STREAM if byteCount larger that bytes left in the stream, otherwise KZS_SUCCESS.
KANZI_API kzsException kzcInputStreamSkip ( struct KzcInputStream inputStream,
kzUint  skipByteCount 
)

Skips the given amount of bytes in an input stream.

KANZI_API kzUint kzcInputStreamGetPosition ( const struct KzcInputStream inputStream)

Gets the current position in an input stream.

KANZI_API enum KzcIOStreamEndianness kzcInputStreamGetEndianness ( const struct KzcInputStream inputStream)

Gets endianness of input stream.

KANZI_API void kzcInputStreamSetEndianness ( struct KzcInputStream inputStream,
enum KzcIOStreamEndianness  endianness 
)

Sets endianness for input stream.

KANZI_API kzsException kzcInputStreamReadBytes ( struct KzcInputStream inputStream,
kzUint  byteCount,
kzByte out_bytes 
)

Reads given amount of bytes from the input stream.

An error is returned if the input stream has an error, or end of stream is reached too soon.

KANZI_API kzsException kzcInputStreamReadBoolean ( struct KzcInputStream inputStream,
kzBool out_value 
)

Reads a boolean from an input stream.

KANZI_API kzsException kzcInputStreamReadBoolean ( struct KzcInputStream inputStream,
bool *  out_value 
)
KANZI_API kzsException kzcInputStreamReadU8 ( struct KzcInputStream inputStream,
kzU8 out_value 
)

Reads an unsigned 8-bit value from an input stream.

KANZI_API kzsException kzcInputStreamReadU8Int ( struct KzcInputStream inputStream,
kzUint out_value 
)

Reads an unsigned 8-bit value casted to an unsigned integer from an input stream.

KANZI_API kzsException kzcInputStreamReadS8 ( struct KzcInputStream inputStream,
kzS8 out_value 
)

Reads a signed 8-bit value from an input stream.

KANZI_API kzsException kzcInputStreamReadS8Int ( struct KzcInputStream inputStream,
kzInt out_value 
)

Reads a signed 8-bit value casted to a signed integer from an input stream.

KANZI_API kzsException kzcInputStreamReadU16 ( struct KzcInputStream inputStream,
kzU16 out_value 
)

Reads an unsigned 16-bit value from an input stream.

KANZI_API kzsException kzcInputStreamReadU16Array ( struct KzcInputStream inputStream,
kzUint  valueCount,
kzU16 values 
)

Reads an array of 16-bit values form an input stream.

KANZI_API kzsException kzcInputStreamReadU16Int ( struct KzcInputStream inputStream,
kzUint out_value 
)

Reads an unsigned 16-bit value casted to an unsigned integer from an input stream.

KANZI_API kzsException kzcInputStreamReadS16 ( struct KzcInputStream inputStream,
kzS16 out_value 
)

Reads a signed 16-bit value from an input stream.

KANZI_API kzsException kzcInputStreamReadS16Array ( struct KzcInputStream inputStream,
kzUint  valueCount,
kzS16 values 
)

Reads an array of signed 16-bit values form an input stream.

KANZI_API kzsException kzcInputStreamReadS16Int ( struct KzcInputStream inputStream,
kzInt out_value 
)

Reads a signed 16-bit value casted to a signed integer from an input stream.

KANZI_API kzsException kzcInputStreamReadU32 ( struct KzcInputStream inputStream,
kzU32 out_value 
)

Reads an unsigned 32-bit value from an input stream.

KANZI_API kzsException kzcInputStreamReadU32Array ( struct KzcInputStream inputStream,
kzUint  valueCount,
kzU32 values 
)

Reads an array of unsigned 32-bit values from an input stream.

KANZI_API kzsException kzcInputStreamReadU32Int ( struct KzcInputStream inputStream,
kzUint out_value 
)

Reads an unsigned 32-bit value casted to an unsigned integer from an input stream.

KANZI_API kzsException kzcInputStreamReadS32 ( struct KzcInputStream inputStream,
kzS32 out_value 
)

Reads a signed 32-bit value from an input stream.

KANZI_API kzsException kzcInputStreamReadS32Array ( struct KzcInputStream inputStream,
kzUint  valueCount,
kzS32 values 
)

Reads an array of signed 32-bit values from an input stream.

KANZI_API kzsException kzcInputStreamReadS32Int ( struct KzcInputStream inputStream,
kzInt out_value 
)

Reads a signed 32-bit value casted to a signed integer from an input stream.

KANZI_API kzsException kzcInputStreamReadFloat ( struct KzcInputStream inputStream,
kzFloat out_value 
)

Reads a 32-bit floating point value from an input stream.

KANZI_API kzsException kzcInputStreamReadFloatArray ( struct KzcInputStream inputStream,
kzUint  valueCount,
kzFloat values 
)

Reads a float array from an input stream.

KANZI_API kzsException kzcInputStreamReadDouble ( struct KzcInputStream inputStream,
kzDouble out_value 
)

Reads a 64-bit floating point value from an input stream.

KANZI_API kzsException kzcInputStreamReadAllBytes ( struct KzcInputStream inputStream,
const struct KzcMemoryManager memoryManager,
kzUint out_size,
kzByte **  out_data 
)

Reads the rest of the input stream to an array of bytes.

The caller must free the returned data using kzcMemoryFreePointer().

KANZI_API kzsException kzcInputStreamReadText ( struct KzcInputStream inputStream,
const struct KzcMemoryManager memoryManager,
kzMutableString out_string 
)

Reads the rest of the input stream to a string.

The caller must free the returned string using kzcStringDelete().

KANZI_API kzsException kzcInputStreamReadTextLines ( struct KzcInputStream inputStream,
const struct KzcMemoryManager memoryManager,
kzMutableString **  out_lines 
)

Reads the rest of the input stream to an array of strings.

Each item in the array is a line of text from the input stream. Newline and carriage return characters are discarded from the text. The caller must free the returned lines using kzcStringDelete() and the string array using kzcMemoryFreeArray().